diff options
author | George Hazan <george.hazan@gmail.com> | 2014-11-16 18:15:16 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-11-16 18:15:16 +0000 |
commit | 8a59f88f48312eb877347a233b0a6ec11c9ab550 (patch) | |
tree | 8c9724efe668b5744bd37fe6ae3b45330a53b742 /protocols/MSN/src/msn_mime.cpp | |
parent | 8148930684c823e526ab8092b33c129a8b17db74 (diff) |
MSN protocol's death-scream
git-svn-id: http://svn.miranda-ng.org/main/trunk@10998 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/MSN/src/msn_mime.cpp')
-rw-r--r-- | protocols/MSN/src/msn_mime.cpp | 242 |
1 files changed, 107 insertions, 135 deletions
diff --git a/protocols/MSN/src/msn_mime.cpp b/protocols/MSN/src/msn_mime.cpp index 6f9d15d587..9a60356ab1 100644 --- a/protocols/MSN/src/msn_mime.cpp +++ b/protocols/MSN/src/msn_mime.cpp @@ -47,8 +47,7 @@ MimeHeaders::~MimeHeaders() void MimeHeaders::clear(void)
{
- for (unsigned i=0; i < mCount; i++)
- {
+ for (unsigned i = 0; i < mCount; i++) {
MimeHeader& H = mVals[i];
if (H.flags & 1) mir_free((void*)H.name);
if (H.flags & 2) mir_free((void*)H.value);
@@ -58,8 +57,7 @@ void MimeHeaders::clear(void) unsigned MimeHeaders::allocSlot(void)
{
- if (++mCount >= mAllocCount)
- {
+ if (++mCount >= mAllocCount) {
mAllocCount += 10;
mVals = (MimeHeader*)mir_realloc(mVals, sizeof(MimeHeader) * mAllocCount);
}
@@ -115,19 +113,16 @@ char* MimeHeaders::flipStr(const char* src, size_t len, char* dest) {
if (len == -1) len = strlen(src);
- if (src == dest)
- {
+ if (src == dest) {
const unsigned b = (unsigned)len-- / 2;
- for (unsigned i = 0; i < b; i++)
- {
+ for (unsigned i = 0; i < b; i++) {
const char c = dest[i];
dest[i] = dest[len - i];
dest[len - i] = c;
}
++len;
}
- else
- {
+ else {
for (unsigned i = 0; i < len; i++)
dest[i] = src[len - 1 - i];
dest[len] = 0;
@@ -142,8 +137,7 @@ char* MimeHeaders::flipStr(const char* src, size_t len, char* dest) size_t MimeHeaders::getLength(void)
{
size_t iResult = 0;
- for (unsigned i=0; i < mCount; i++)
- {
+ for (unsigned i = 0; i < mCount; i++) {
MimeHeader& H = mVals[i];
iResult += strlen(H.name) + strlen(H.value) + 4;
}
@@ -153,11 +147,9 @@ size_t MimeHeaders::getLength(void) char* MimeHeaders::writeToBuffer(char* dest)
{
- for (unsigned i=0; i < mCount; i++)
- {
+ for (unsigned i = 0; i < mCount; i++) {
MimeHeader& H = mVals[i];
- if (H.flags & 4)
- {
+ if (H.flags & 4) {
dest = flipStr(H.name, -1, dest);
*(dest++) = ':';
@@ -173,8 +165,7 @@ char* MimeHeaders::writeToBuffer(char* dest) dest += sprintf(dest, "%s: %s\r\n", H.name, H.value); //!!!!!!!!!!!!
}
- if (mCount)
- {
+ if (mCount) {
*(dest++) = '\r';
*(dest++) = '\n';
*dest = 0;
@@ -190,22 +181,20 @@ char* MimeHeaders::readFromBuffer(char* src) {
clear();
- while (*src)
- {
+ while (*src) {
char* peol = strchr(src, '\n');
if (peol == NULL)
return strchr(src, 0);
else if (peol == src)
return src + 1;
- else if (peol == (src + 1) && *src == '\r')
+ else if (peol == (src + 1) && *src == '\r')
return src + 2;
*peol = 0;
char* delim = strchr(src, ':');
- if (delim)
- {
+ if (delim) {
*delim = 0;
MimeHeader& H = mVals[allocSlot()];
@@ -224,8 +213,7 @@ char* MimeHeaders::readFromBuffer(char* src) const char* MimeHeaders::find(const char* szFieldName)
{
size_t i;
- for (i = 0; i < mCount; i++)
- {
+ for (i = 0; i < mCount; i++) {
MimeHeader& MH = mVals[i];
if (_stricmp(MH.name, szFieldName) == 0)
return MH.value;
@@ -235,11 +223,9 @@ const char* MimeHeaders::find(const char* szFieldName) char* szFieldNameR = (char*)alloca(len + 1);
flipStr(szFieldName, len, szFieldNameR);
- for (i = 0; i < mCount; i++)
- {
+ for (i = 0; i < mCount; i++) {
MimeHeader& MH = mVals[i];
- if (_stricmp(MH.name, szFieldNameR) == 0 && (MH.flags & 3) == 0)
- {
+ if (_stricmp(MH.name, szFieldNameR) == 0 && (MH.flags & 3) == 0) {
strcpy((char*)MH.name, szFieldNameR);
flipStr(MH.value, -1, (char*)MH.value);
return MH.value;
@@ -255,54 +241,54 @@ static const struct _tag_cpltbl const char* mimecp;
} cptbl[] =
{
- { 37, "IBM037" }, // IBM EBCDIC US-Canada
- { 437, "IBM437" }, // OEM United States
- { 500, "IBM500" }, // IBM EBCDIC International
- { 708, "ASMO-708" }, // Arabic (ASMO 708)
- { 720, "DOS-720" }, // Arabic (Transparent ASMO); Arabic (DOS)
- { 737, "ibm737" }, // OEM Greek (formerly 437G); Greek (DOS)
- { 775, "ibm775" }, // OEM Baltic; Baltic (DOS)
- { 850, "ibm850" }, // OEM Multilingual Latin 1; Western European (DOS)
- { 852, "ibm852" }, // OEM Latin 2; Central European (DOS)
- { 855, "IBM855" }, // OEM Cyrillic (primarily Russian)
- { 857, "ibm857" }, // OEM Turkish; Turkish (DOS)
- { 858, "IBM00858" }, // OEM Multilingual Latin 1 + Euro symbol
- { 860, "IBM860" }, // OEM Portuguese; Portuguese (DOS)
- { 861, "ibm861" }, // OEM Icelandic; Icelandic (DOS)
- { 862, "DOS-862" }, // OEM Hebrew; Hebrew (DOS)
- { 863, "IBM863" }, // OEM French Canadian; French Canadian (DOS)
- { 864, "IBM864" }, // OEM Arabic; Arabic (864)
- { 865, "IBM865" }, // OEM Nordic; Nordic (DOS)
- { 866, "cp866" }, // OEM Russian; Cyrillic (DOS)
- { 869, "ibm869" }, // OEM Modern Greek; Greek, Modern (DOS)
- { 870, "IBM870" }, // IBM EBCDIC Multilingual/ROECE (Latin 2); IBM EBCDIC Multilingual Latin 2
- { 874, "windows-874" }, // ANSI/OEM Thai (same as 28605, ISO 8859-15); Thai (Windows)
- { 875, "cp875" }, // IBM EBCDIC Greek Modern
- { 932, "shift_jis" }, // ANSI/OEM Japanese; Japanese (Shift-JIS)
- { 936, "gb2312" }, // ANSI/OEM Simplified Chinese (PRC, Singapore); Chinese Simplified (GB2312)
- { 949, "ks_c_5601-1987" }, // ANSI/OEM Korean (Unified Hangul Code)
- { 950, "big5" }, // ANSI/OEM Traditional Chinese (Taiwan; Hong Kong SAR, PRC); Chinese Traditional (Big5)
- { 1026, "IBM1026" }, // IBM EBCDIC Turkish (Latin 5)
- { 1047, "IBM01047" }, // IBM EBCDIC Latin 1/Open System
- { 1140, "IBM01140" }, // IBM EBCDIC US-Canada (037 + Euro symbol); IBM EBCDIC (US-Canada-Euro)
- { 1141, "IBM01141" }, // IBM EBCDIC Germany (20273 + Euro symbol); IBM EBCDIC (Germany-Euro)
- { 1142, "IBM01142" }, // IBM EBCDIC Denmark-Norway (20277 + Euro symbol); IBM EBCDIC (Denmark-Norway-Euro)
- { 1143, "IBM01143" }, // IBM EBCDIC Finland-Sweden (20278 + Euro symbol); IBM EBCDIC (Finland-Sweden-Euro)
- { 1144, "IBM01144" }, // IBM EBCDIC Italy (20280 + Euro symbol); IBM EBCDIC (Italy-Euro)
- { 1145, "IBM01145" }, // IBM EBCDIC Latin America-Spain (20284 + Euro symbol); IBM EBCDIC (Spain-Euro)
- { 1146, "IBM01146" }, // IBM EBCDIC United Kingdom (20285 + Euro symbol); IBM EBCDIC (UK-Euro)
- { 1147, "IBM01147" }, // IBM EBCDIC France (20297 + Euro symbol); IBM EBCDIC (France-Euro)
- { 1148, "IBM01148" }, // IBM EBCDIC International (500 + Euro symbol); IBM EBCDIC (International-Euro)
- { 1149, "IBM01149" }, // IBM EBCDIC Icelandic (20871 + Euro symbol); IBM EBCDIC (Icelandic-Euro)
- { 1250, "windows-1250" }, // ANSI Central European; Central European (Windows)
- { 1251, "windows-1251" }, // ANSI Cyrillic; Cyrillic (Windows)
- { 1252, "windows-1252" }, // ANSI Latin 1; Western European (Windows)
- { 1253, "windows-1253" }, // ANSI Greek; Greek (Windows)
- { 1254, "windows-1254" }, // ANSI Turkish; Turkish (Windows)
- { 1255, "windows-1255" }, // ANSI Hebrew; Hebrew (Windows)
- { 1256, "windows-1256" }, // ANSI Arabic; Arabic (Windows)
- { 1257, "windows-1257" }, // ANSI Baltic; Baltic (Windows)
- { 1258, "windows-1258" }, // ANSI/OEM Vietnamese; Vietnamese (Windows)
+ { 37, "IBM037" }, // IBM EBCDIC US-Canada
+ { 437, "IBM437" }, // OEM United States
+ { 500, "IBM500" }, // IBM EBCDIC International
+ { 708, "ASMO-708" }, // Arabic (ASMO 708)
+ { 720, "DOS-720" }, // Arabic (Transparent ASMO); Arabic (DOS)
+ { 737, "ibm737" }, // OEM Greek (formerly 437G); Greek (DOS)
+ { 775, "ibm775" }, // OEM Baltic; Baltic (DOS)
+ { 850, "ibm850" }, // OEM Multilingual Latin 1; Western European (DOS)
+ { 852, "ibm852" }, // OEM Latin 2; Central European (DOS)
+ { 855, "IBM855" }, // OEM Cyrillic (primarily Russian)
+ { 857, "ibm857" }, // OEM Turkish; Turkish (DOS)
+ { 858, "IBM00858" }, // OEM Multilingual Latin 1 + Euro symbol
+ { 860, "IBM860" }, // OEM Portuguese; Portuguese (DOS)
+ { 861, "ibm861" }, // OEM Icelandic; Icelandic (DOS)
+ { 862, "DOS-862" }, // OEM Hebrew; Hebrew (DOS)
+ { 863, "IBM863" }, // OEM French Canadian; French Canadian (DOS)
+ { 864, "IBM864" }, // OEM Arabic; Arabic (864)
+ { 865, "IBM865" }, // OEM Nordic; Nordic (DOS)
+ { 866, "cp866" }, // OEM Russian; Cyrillic (DOS)
+ { 869, "ibm869" }, // OEM Modern Greek; Greek, Modern (DOS)
+ { 870, "IBM870" }, // IBM EBCDIC Multilingual/ROECE (Latin 2); IBM EBCDIC Multilingual Latin 2
+ { 874, "windows-874" }, // ANSI/OEM Thai (same as 28605, ISO 8859-15); Thai (Windows)
+ { 875, "cp875" }, // IBM EBCDIC Greek Modern
+ { 932, "shift_jis" }, // ANSI/OEM Japanese; Japanese (Shift-JIS)
+ { 936, "gb2312" }, // ANSI/OEM Simplified Chinese (PRC, Singapore); Chinese Simplified (GB2312)
+ { 949, "ks_c_5601-1987" }, // ANSI/OEM Korean (Unified Hangul Code)
+ { 950, "big5" }, // ANSI/OEM Traditional Chinese (Taiwan; Hong Kong SAR, PRC); Chinese Traditional (Big5)
+ { 1026, "IBM1026" }, // IBM EBCDIC Turkish (Latin 5)
+ { 1047, "IBM01047" }, // IBM EBCDIC Latin 1/Open System
+ { 1140, "IBM01140" }, // IBM EBCDIC US-Canada (037 + Euro symbol); IBM EBCDIC (US-Canada-Euro)
+ { 1141, "IBM01141" }, // IBM EBCDIC Germany (20273 + Euro symbol); IBM EBCDIC (Germany-Euro)
+ { 1142, "IBM01142" }, // IBM EBCDIC Denmark-Norway (20277 + Euro symbol); IBM EBCDIC (Denmark-Norway-Euro)
+ { 1143, "IBM01143" }, // IBM EBCDIC Finland-Sweden (20278 + Euro symbol); IBM EBCDIC (Finland-Sweden-Euro)
+ { 1144, "IBM01144" }, // IBM EBCDIC Italy (20280 + Euro symbol); IBM EBCDIC (Italy-Euro)
+ { 1145, "IBM01145" }, // IBM EBCDIC Latin America-Spain (20284 + Euro symbol); IBM EBCDIC (Spain-Euro)
+ { 1146, "IBM01146" }, // IBM EBCDIC United Kingdom (20285 + Euro symbol); IBM EBCDIC (UK-Euro)
+ { 1147, "IBM01147" }, // IBM EBCDIC France (20297 + Euro symbol); IBM EBCDIC (France-Euro)
+ { 1148, "IBM01148" }, // IBM EBCDIC International (500 + Euro symbol); IBM EBCDIC (International-Euro)
+ { 1149, "IBM01149" }, // IBM EBCDIC Icelandic (20871 + Euro symbol); IBM EBCDIC (Icelandic-Euro)
+ { 1250, "windows-1250" }, // ANSI Central European; Central European (Windows)
+ { 1251, "windows-1251" }, // ANSI Cyrillic; Cyrillic (Windows)
+ { 1252, "windows-1252" }, // ANSI Latin 1; Western European (Windows)
+ { 1253, "windows-1253" }, // ANSI Greek; Greek (Windows)
+ { 1254, "windows-1254" }, // ANSI Turkish; Turkish (Windows)
+ { 1255, "windows-1255" }, // ANSI Hebrew; Hebrew (Windows)
+ { 1256, "windows-1256" }, // ANSI Arabic; Arabic (Windows)
+ { 1257, "windows-1257" }, // ANSI Baltic; Baltic (Windows)
+ { 1258, "windows-1258" }, // ANSI/OEM Vietnamese; Vietnamese (Windows)
{ 20127, "us-ascii" }, // US-ASCII (7-bit)
{ 20273, "IBM273" }, // IBM EBCDIC Germany
{ 20277, "IBM277" }, // IBM EBCDIC Denmark-Norway
@@ -353,10 +339,8 @@ static const struct _tag_cpltbl static unsigned FindCP(const char* mimecp)
{
unsigned cp = CP_ACP;
- for (unsigned i = 0; i < SIZEOF(cptbl); ++i)
- {
- if (_stricmp(mimecp, cptbl[i].mimecp) == 0)
- {
+ for (unsigned i = 0; i < SIZEOF(cptbl); ++i) {
+ if (_stricmp(mimecp, cptbl[i].mimecp) == 0) {
cp = cptbl[i].cp;
break;
}
@@ -367,9 +351,9 @@ static unsigned FindCP(const char* mimecp) static int SingleHexToDecimal(char c)
{
- if (c >= '0' && c <= '9') return c-'0';
- if (c >= 'a' && c <= 'f') return c-'a'+10;
- if (c >= 'A' && c <= 'F') return c-'A'+10;
+ if (c >= '0' && c <= '9') return c - '0';
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
return -1;
}
@@ -377,32 +361,28 @@ static void PQDecode(char* str) {
char* s = str, *d = str;
- while(*s)
- {
- switch (*s)
+ while (*s) {
+ switch (*s) {
+ case '=':
{
- case '=':
- {
- int digit1 = SingleHexToDecimal(s[1]);
- if (digit1 != -1)
- {
- int digit2 = SingleHexToDecimal(s[2]);
- if (digit2 != -1)
- {
- s += 3;
- *d++ = (char)((digit1 << 4) | digit2);
- }
+ int digit1 = SingleHexToDecimal(s[1]);
+ if (digit1 != -1) {
+ int digit2 = SingleHexToDecimal(s[2]);
+ if (digit2 != -1) {
+ s += 3;
+ *d++ = (char)((digit1 << 4) | digit2);
}
- break;
}
+ break;
+ }
- case '_':
- *d++ = ' '; ++s;
- break;
+ case '_':
+ *d++ = ' '; ++s;
+ break;
- default:
- *d++ = *s++;
- break;
+ default:
+ *d++ = *s++;
+ break;
}
}
*d = 0;
@@ -428,8 +408,7 @@ wchar_t* MimeHeaders::decode(const char* val) wchar_t* resp = res;
char *p = tbuf;
- while (*p)
- {
+ while (*p) {
char *cp = strstr(p, "=?");
if (cp == NULL) break;
*cp = 0;
@@ -450,30 +429,27 @@ wchar_t* MimeHeaders::decode(const char* val) if (pe == NULL) break;
*pe = 0;
- switch (*enc)
+ switch (*enc) {
+ case 'b':
+ case 'B':
{
- case 'b':
- case 'B':
- {
- char* dec = (char*)mir_base64_decode(fld, 0);
- strcpy(fld, dec);
- mir_free(dec);
- break;
- }
+ char* dec = (char*)mir_base64_decode(fld, 0);
+ strcpy(fld, dec);
+ mir_free(dec);
+ break;
+ }
- case 'q':
- case 'Q':
- PQDecode(fld);
- break;
+ case 'q':
+ case 'Q':
+ PQDecode(fld);
+ break;
}
- if (_stricmp(cp, "UTF-8") == 0)
- {
+ if (_stricmp(cp, "UTF-8") == 0) {
sz = utf8toutf16(fld, resp);
ssz -= sz; resp += sz;
}
- else
- {
+ else {
int sz = MultiByteToWideChar(FindCP(cp), 0, fld, -1, resp, (int)ssz);
if (sz == 0)
sz = MultiByteToWideChar(CP_ACP, 0, fld, -1, resp, (int)ssz);
@@ -492,19 +468,16 @@ char* MimeHeaders::decodeMailBody(char* msgBody) {
char* res;
const char *val = find("Content-Transfer-Encoding");
- if (val && _stricmp(val, "base64") == 0)
- {
+ if (val && _stricmp(val, "base64") == 0) {
char *src = msgBody, *dst = msgBody;
- while (*src != 0)
- {
+ while (*src != 0) {
if (isspace(*src)) ++src;
else *(dst++) = *(src++);
}
*dst = 0;
res = (char*)mir_base64_decode(msgBody, 0);
}
- else
- {
+ else {
res = mir_strdup(msgBody);
if (val && _stricmp(val, "quoted-printable") == 0)
PQDecode(res);
@@ -516,8 +489,7 @@ char* MimeHeaders::decodeMailBody(char* msgBody) int sttDivideWords(char* parBuffer, int parMinItems, char** parDest)
{
int i;
- for (i=0; i < parMinItems; i++)
- {
+ for (i = 0; i < parMinItems; i++) {
parDest[i] = parBuffer;
size_t tWordLen = strcspn(parBuffer, " \t");
@@ -525,12 +497,12 @@ int sttDivideWords(char* parBuffer, int parMinItems, char** parDest) return i;
parBuffer += tWordLen;
- if (*parBuffer != '\0')
- {
+ if (*parBuffer != '\0') {
size_t tSpaceLen = strspn(parBuffer, " \t");
memset(parBuffer, 0, tSpaceLen);
parBuffer += tSpaceLen;
- } }
+ }
+ }
return i;
}
|