/* * Create a DiscID based on the TOC data found in the DiscId object. * The DiscID is placed in the provided string buffer. */ static void create_disc_id(mb_disc_private *d, char buf[]) { SHA_INFO sha; unsigned char digest[20], *base64; unsigned long size; char tmp[17]; /* for 8 hex digits (16 to avoid trouble) */ int i; assert( d != NULL ); sha_init(&sha); sprintf(tmp, "%02X", d->first_track_num); sha_update(&sha, (unsigned char *) tmp, strlen(tmp)); sprintf(tmp, "%02X", d->last_track_num); sha_update(&sha, (unsigned char *) tmp, strlen(tmp)); for (i = 0; i < 100; i++) { sprintf(tmp, "%08X", d->track_offsets[i]); sha_update(&sha, (unsigned char *) tmp, strlen(tmp)); } sha_final(digest, &sha); base64 = rfc822_binary(digest, sizeof(digest), &size); memcpy(buf, base64, size); buf[size] = '\0'; free(base64); }
static Variant HHVM_FUNCTION(imap_binary, const String& str) { unsigned long newlength; char *decode = (char *)rfc822_binary((unsigned char *) str.data(), str.length(), &newlength); if (decode == NULL) { return false; } String ret = String(decode, newlength, CopyString); fs_give((void**) &decode); return ret; }
long smtp_response (void *s,char *response,unsigned long size) { SENDSTREAM *stream = (SENDSTREAM *) s; unsigned long i,j; char *t,*u; if (response) { /* make CRLFless BASE64 string */ if (size) { for (t = (char *) rfc822_binary ((void *) response,size,&i),u = t,j = 0; j < i; j++) if (t[j] > ' ') *u++ = t[j]; *u = '\0'; /* tie off string */ i = smtp_send (stream,t,NIL); fs_give ((void **) &t); } else i = smtp_send (stream,"",NIL); } else { /* abort requested */ i = smtp_send (stream,"*",NIL); stream->saslcancel = T; /* mark protocol-requested SASL cancel */ } return LONGT; }
// encode the given text unconditionally, i.e. without checking if it must be // encoded (this is supposed to be done in the caller) and using the specified // encodings and charset (which are supposed to be detected by the caller too) static String EncodeText(const String& in, wxFontEncoding enc, MIME::Encoding enc2047, const String& csName) { // encode the word splitting it in the chunks such that they will be no // longer than 75 characters each wxCharBuffer buf(in.mb_str(wxCSConv(enc))); if ( !buf ) { // if the header can't be encoded using the given encoding, use UTF-8 // which always works buf = in.utf8_str(); } String out; out.reserve(csName.length() + strlen(buf) + 7 /* for =?...?X?...?= */); const char *s = buf; while ( *s ) { // if we wrapped, insert a line break if ( !out.empty() ) out += "\r\n "; static const size_t RFC2047_MAXWORD_LEN = 75; // how many characters may we put in this encoded word? size_t len = 0; // take into account the length of "=?charset?...?=" int lenRemaining = RFC2047_MAXWORD_LEN - (5 + csName.length()); // for QP we need to examine all characters if ( enc2047 == MIME::Encoding_QuotedPrintable ) { for ( ; s[len]; len++ ) { const char c = s[len]; // normal characters stand for themselves in QP, the encoded ones // take 3 positions (=XX) lenRemaining -= (NeedsEncodingInHeader(c) || strchr(" \t=?", c)) ? 3 : 1; if ( lenRemaining <= 0 ) { // can't put any more chars into this word break; } } } else // Base64 { // rfc822_binary() splits lines after 60 characters so don't make // chunks longer than this as the base64-encoded headers can't have // EOLs in them static const int CCLIENT_MAX_BASE64_LEN = 60; if ( lenRemaining > CCLIENT_MAX_BASE64_LEN ) lenRemaining = CCLIENT_MAX_BASE64_LEN; // we can calculate how many characters we may put into lenRemaining // directly len = (lenRemaining / 4) * 3 - 2; // but not more than what we have size_t lenMax = wxStrlen(s); if ( len > lenMax ) { len = lenMax; } } // do encode this word unsigned char *text = (unsigned char *)s; // cast for cclient // length of the encoded text and the text itself unsigned long lenEnc; unsigned char *textEnc; if ( enc2047 == MIME::Encoding_QuotedPrintable ) { textEnc = rfc822_8bit(text, len, &lenEnc); } else // Encoding_Base64 { textEnc = rfc822_binary(text, len, &lenEnc); while ( textEnc[lenEnc - 2] == '\r' && textEnc[lenEnc - 1] == '\n' ) { // discard eol which we don't need in the header lenEnc -= 2; } } // put into string as we might want to do some more replacements... String encword(wxString::FromAscii(CHAR_CAST(textEnc), lenEnc)); // hack: rfc822_8bit() doesn't encode spaces normally but we must // do it inside the headers // // we also have to encode '?'s in the headers which are not encoded by it if ( enc2047 == MIME::Encoding_QuotedPrintable ) { String encword2; encword2.reserve(encword.length()); bool replaced = false; for ( const wxChar *p = encword.c_str(); *p; p++ ) { switch ( *p ) { case ' ': encword2 += _T("=20"); break; case '\t': encword2 += _T("=09"); break; case '?': encword2 += _T("=3F"); break; default: encword2 += *p; // skip assignment to replaced below continue; } replaced = true; } if ( replaced ) { encword = encword2; } } // append this word to the header out << _T("=?") << csName << _T('?') << (char)enc2047 << _T('?') << encword << _T("?="); fs_give((void **)&textEnc); // skip the already encoded part s += len; } return out; }