diff options
author | George Hazan <george.hazan@gmail.com> | 2023-10-10 18:54:46 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-10-10 18:54:46 +0300 |
commit | ee35b17e21bc5e4388e47c6af1c9736af910d306 (patch) | |
tree | e0e1c25ff17b14b5698c2eaa7307ab16e58dc72c /protocols | |
parent | ab5d35225db150cfd20158cfae1b38ca77d5b5ab (diff) |
YAMN: custom base64 decoder eliminated
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/YAMN/src/browser/mailbrowser.cpp | 13 | ||||
-rw-r--r-- | protocols/YAMN/src/mails/decode.cpp | 432 | ||||
-rw-r--r-- | protocols/YAMN/src/mails/mime.cpp | 29 | ||||
-rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3comm.cpp | 53 | ||||
-rw-r--r-- | protocols/YAMN/src/stdafx.h | 4 |
5 files changed, 225 insertions, 306 deletions
diff --git a/protocols/YAMN/src/browser/mailbrowser.cpp b/protocols/YAMN/src/browser/mailbrowser.cpp index 1cc60c42b7..f92e8b4d6a 100644 --- a/protocols/YAMN/src/browser/mailbrowser.cpp +++ b/protocols/YAMN/src/browser/mailbrowser.cpp @@ -1216,19 +1216,17 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR }
if (body) {
wchar_t *bodyDecoded = nullptr;
- char *localBody = nullptr;
+ ptrA localBody;
if (contentType) {
if (!_strnicmp(contentType, "text", 4)) {
if (transEncoding) {
if (!_stricmp(transEncoding, "base64")) {
- int size = (int)mir_strlen(body) * 3 / 4 + 5;
- localBody = new char[size + 1];
- DecodeBase64(body, localBody, size);
+ localBody = (char*)mir_base64_decode(body, 0);
}
else if (!_stricmp(transEncoding, "quoted-printable")) {
- int size = (int)mir_strlen(body) + 2;
- localBody = new char[size + 1];
- DecodeQuotedPrintable(body, localBody, size, FALSE);
+ size_t size = mir_strlen(body) + 2;
+ localBody = (char*)mir_alloc(size + 1);
+ DecodeQuotedPrintable(body, localBody, (int)size, FALSE);
}
}
}
@@ -1244,7 +1242,6 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR ConvertStringToUnicode(localBody ? localBody : body, MailParam->mail->MailData->CP, &bodyDecoded);
SetWindowTextW(hEdit, bodyDecoded);
delete[] bodyDecoded;
- if (localBody) delete[] localBody;
SetFocus(hEdit);
}
if (!(MailParam->mail->Flags & YAMN_MSG_BODYRECEIVED)) {
diff --git a/protocols/YAMN/src/mails/decode.cpp b/protocols/YAMN/src/mails/decode.cpp index 436f55c641..0a2abb260e 100644 --- a/protocols/YAMN/src/mails/decode.cpp +++ b/protocols/YAMN/src/mails/decode.cpp @@ -4,157 +4,168 @@ *
* (c) majvan 2002-2004
*/
+
#include "../stdafx.h"
-//--------------------------------------------------------------------------------------------------
-//--------------------------------------------------------------------------------------------------
-struct _tcptable CodePageNamesAll[]=
+struct _tcptable CodePageNamesAll[] =
{
- { "ANSI", "",TRUE,CP_ACP},
- { "WINDOWS-1", "250",0,1250},
- { "WINDOWS-1", "251",0,1251},
- { "WINDOWS-1", "252",0,1252},
- { "WINDOWS-1", "253",0,1253},
- { "WINDOWS-1", "254",0,1254},
- { "WINDOWS-1", "255",0,1255},
- { "WINDOWS-1", "256",0,1256},
- { "WINDOWS-1", "257",0,1257},
- { "WINDOWS-1", "258",0,1258},
- { "CP1", "250",0,1250},
- { "CP1", "251",0,1251},
- { "CP1", "252",0,1252},
- { "CP1", "253",0,1253},
- { "CP1", "254",0,1254},
- { "CP1", "255",0,1255},
- { "CP1", "256",0,1256},
- { "CP1", "257",0,1257},
- { "CP1", "258",0,1258},
- { "ANSI-1", "250",0,1250},
- { "ANSI-1", "251",0,1251},
- { "ANSI-1", "252",0,1252},
- { "ANSI-1", "253",0,1253},
- { "ANSI-1", "254",0,1254},
- { "ANSI-1", "255",0,1255},
- { "ANSI-1", "256",0,1256},
- { "ANSI-1", "257",0,1257},
- { "ANSI-1", "258",0,1258},
- { "KOI8", "-R",0,20866},
- { "KOI8", "",0,20866},
- { "KOI8", "-U",0,21866},
- { "KOI8", "-RU",0,21866},
- { "US-", "ASCII",0,20127},
- { "CP", "367",0,20127},
- { "ASCII", "",0,20127},
- { "ASCII", "7",0,20127},
- { "ISO-8859", "-1",0,28591},
- { "ISO-8859", "-2",0,28592},
- { "ISO-8859", "-3",0,28593},
- { "ISO-8859", "-4",0,28594},
- { "ISO-8859", "-5",0,28595},
- { "ISO-8859", "-6",0,28596},
- { "ISO-8859", "-7",0,28597},
- { "ISO-8859", "-8",0,28598},
- { "ISO-8859", "-9",0,28599},
- { "ISO-8859", "-15",0,28605},
- { "ISO_8859", "-1",0,28591},
- { "ISO_8859", "-2",0,28592},
- { "ISO_8859", "-3",0,28593},
- { "ISO_8859", "-4",0,28594},
- { "ISO_8859", "-5",0,28595},
- { "ISO_8859", "-6",0,28596},
- { "ISO_8859", "-7",0,28597},
- { "ISO_8859", "-8",0,28598},
- { "ISO_8859", "-9",0,28599},
- { "ISO_8859", "-15",0,28605},
- { "ISO-", "10646-USC2",0,1200},
- { "ISO-2022", "/2-JP",0,50220},
- { "ISO-2022", "-JP",0,50221},
- { "ISO-2022", "/JIS-JP",0,50222},
- { "ISO-2022", "-KR",0,50225},
- { "ISO-2022", "-CH(SP)",0,50227},
- { "ISO-2022", "-CH(TR)",0,50229},
- { "UTF-", "7",0,65000},
- { "UTF-", "8",0,65001},
- { "ARAB-", "TRANSPARENT",0,710},
- { "ASMO-", "TRANSPARENT",0,720},
- { "ASMO-", "449",0,709},
- { "ASMO-", "708",0,708},
- { "BIG5", "",0,950},
- { "EUC-", "CH(SP)",0,51936},
- { "EUC-", "CH(TR)",0,51950},
- { "EUC-", "JP",0,51932},
- { "EUC-", "KR",0,51949},
- { "GB-", "2312",0,20936},
- { "GB", "2312",0,20936},
- { "HZGB-", "2312",0,52936},
- { "IBM-", "037",0,37},
- { "IBM-", "290",0,290},
- { "IBM-", "437",0,437},
- { "IBM-", "500",0,500},
- { "IBM-", "775",0,775},
- { "IBM-", "850",0,850},
- { "IBM-", "852",0,852},
- { "IBM-", "855",0,855},
- { "IBM-", "857",0,857},
- { "IBM-", "860",0,860},
- { "IBM-", "861",0,861},
- { "IBM-", "862",0,862},
- { "IBM-", "863",0,863},
- { "IBM-", "864",0,864},
- { "IBM-", "865",0,865},
- { "IBM-", "866",0,866},
- { "IBM-", "869",0,869},
- { "IBM-", "870",0,870},
- { "IBM-", "875",0,875},
- { "IBM-", "1026",0,1026},
- { "IBM-", "273",0,20273},
- { "IBM-", "277",0,20277},
- { "IBM-", "278",0,20278},
- { "IBM-", "280",0,20280},
- { "IBM-", "284",0,20284},
- { "IBM-", "285",0,20285},
- { "IBM-", "290",0,20290},
- { "IBM-", "297",0,20297},
- { "IBM-", "420",0,20420},
- { "IBM-", "423",0,20423},
- { "IBM-", "871",0,20871},
- { "IBM-", "880",0,20880},
- { "IBM-", "905",0,20905},
- { "IBM-", "THAI",0,20838},
- { "ISCII-", "DEVANAGARI",0,57002},
- { "ISCII-", "BENGALI",0,57003},
- { "ISCII-", "TAMIL",0,57004},
- { "ISCII-", "TELUGU",0,57005},
- { "ISCII-", "ASSAMESE",0,57006},
- { "ISCII-", "ORIYA",0,57007},
- { "ISCII-", "KANNADA",0,57008},
- { "ISCII-", "MALAYALAM",0,57009},
- { "ISCII-", "GUJARATI",0,57010},
- { "ISCII-", "PUNJABI",0,57011},
- { "KOR-", "JOHAB",0,1361},
- { "KSC-", "5601",0,1361},
- { "MAC-", "ROMAN",0,10000},
- { "MAC-", "JP",0,10001},
- { "MAC-", "CH(SP)(BIG5)",0,10002},
- { "MAC-", "KR",0,10003},
- { "MAC-", "AR",0,10004},
- { "MAC-", "HW",0,10005},
- { "MAC-", "GR",0,10006},
- { "MAC-", "CY",0,10007},
- { "MAC-", "CH(SP)(GB2312)",0,10008},
- { "MAC-", "ROMANIA",0,10010},
- { "MAC-", "UA",0,10017},
- { "MAC-", "TH",0,10021},
- { "MAC-", "LAT2",0,10029},
- { "MAC-", "ICE",0,10079},
- { "MAC-", "TR",0,10081},
- { "MAC-", "CR",0,10082}
+ { "ANSI", "", TRUE, CP_ACP },
+ { "WINDOWS-1", "250", 0, 1250 },
+ { "WINDOWS-1", "251", 0, 1251 },
+ { "WINDOWS-1", "252", 0, 1252 },
+ { "WINDOWS-1", "253", 0, 1253 },
+ { "WINDOWS-1", "254", 0, 1254 },
+ { "WINDOWS-1", "255", 0, 1255 },
+ { "WINDOWS-1", "256", 0, 1256 },
+ { "WINDOWS-1", "257", 0, 1257 },
+ { "WINDOWS-1", "258", 0, 1258 },
+ { "CP1", "250", 0, 1250 },
+ { "CP1", "251", 0, 1251 },
+ { "CP1", "252", 0, 1252 },
+ { "CP1", "253", 0, 1253 },
+ { "CP1", "254", 0, 1254 },
+ { "CP1", "255", 0, 1255 },
+ { "CP1", "256", 0, 1256 },
+ { "CP1", "257", 0, 1257 },
+ { "CP1", "258", 0, 1258 },
+ { "ANSI-1", "250", 0, 1250 },
+ { "ANSI-1", "251", 0, 1251 },
+ { "ANSI-1", "252", 0, 1252 },
+ { "ANSI-1", "253", 0, 1253 },
+ { "ANSI-1", "254", 0, 1254 },
+ { "ANSI-1", "255", 0, 1255 },
+ { "ANSI-1", "256", 0, 1256 },
+ { "ANSI-1", "257", 0, 1257 },
+ { "ANSI-1", "258", 0, 1258 },
+ { "KOI8", "-R", 0, 20866 },
+ { "KOI8", "", 0, 20866 },
+ { "KOI8", "-U", 0, 21866 },
+ { "KOI8", "-RU", 0, 21866 },
+ { "US-", "ASCII", 0, 20127 },
+ { "CP", "367", 0, 20127 },
+ { "ASCII", "", 0, 20127 },
+ { "ASCII", "7", 0, 20127 },
+ { "ISO-8859", "-1", 0, 28591 },
+ { "ISO-8859", "-2", 0, 28592 },
+ { "ISO-8859", "-3", 0, 28593 },
+ { "ISO-8859", "-4", 0, 28594 },
+ { "ISO-8859", "-5", 0, 28595 },
+ { "ISO-8859", "-6", 0, 28596 },
+ { "ISO-8859", "-7", 0, 28597 },
+ { "ISO-8859", "-8", 0, 28598 },
+ { "ISO-8859", "-9", 0, 28599 },
+ { "ISO-8859", "-15", 0, 28605 },
+ { "ISO_8859", "-1", 0, 28591 },
+ { "ISO_8859", "-2", 0, 28592 },
+ { "ISO_8859", "-3", 0, 28593 },
+ { "ISO_8859", "-4", 0, 28594 },
+ { "ISO_8859", "-5", 0, 28595 },
+ { "ISO_8859", "-6", 0, 28596 },
+ { "ISO_8859", "-7", 0, 28597 },
+ { "ISO_8859", "-8", 0, 28598 },
+ { "ISO_8859", "-9", 0, 28599 },
+ { "ISO_8859", "-15", 0, 28605 },
+ { "ISO-", "10646-USC2", 0, 1200 },
+ { "ISO-2022", "/2-JP", 0, 50220 },
+ { "ISO-2022", "-JP", 0, 50221 },
+ { "ISO-2022", "/JIS-JP", 0, 50222 },
+ { "ISO-2022", "-KR", 0, 50225 },
+ { "ISO-2022", "-CH(SP)", 0, 50227 },
+ { "ISO-2022", "-CH(TR)", 0, 50229 },
+ { "UTF-", "7", 0, 65000 },
+ { "UTF-", "8", 0, 65001 },
+ { "ARAB-", "TRANSPARENT", 0, 710 },
+ { "ASMO-", "TRANSPARENT", 0, 720 },
+ { "ASMO-", "449", 0, 709 },
+ { "ASMO-", "708", 0, 708 },
+ { "BIG5", "", 0, 950 },
+ { "EUC-", "CH(SP)", 0, 51936 },
+ { "EUC-", "CH(TR)", 0, 51950 },
+ { "EUC-", "JP", 0, 51932 },
+ { "EUC-", "KR", 0, 51949 },
+ { "GB-", "2312", 0, 20936 },
+ { "GB", "2312", 0, 20936 },
+ { "HZGB-", "2312", 0, 52936 },
+ { "IBM-", "037", 0, 37 },
+ { "IBM-", "290", 0, 290 },
+ { "IBM-", "437", 0, 437 },
+ { "IBM-", "500", 0, 500 },
+ { "IBM-", "775", 0, 775 },
+ { "IBM-", "850", 0, 850 },
+ { "IBM-", "852", 0, 852 },
+ { "IBM-", "855", 0, 855 },
+ { "IBM-", "857", 0, 857 },
+ { "IBM-", "860", 0, 860 },
+ { "IBM-", "861", 0, 861 },
+ { "IBM-", "862", 0, 862 },
+ { "IBM-", "863", 0, 863 },
+ { "IBM-", "864", 0, 864 },
+ { "IBM-", "865", 0, 865 },
+ { "IBM-", "866", 0, 866 },
+ { "IBM-", "869", 0, 869 },
+ { "IBM-", "870", 0, 870 },
+ { "IBM-", "875", 0, 875 },
+ { "IBM-", "1026", 0, 1026 },
+ { "IBM-", "273", 0, 20273 },
+ { "IBM-", "277", 0, 20277 },
+ { "IBM-", "278", 0, 20278 },
+ { "IBM-", "280", 0, 20280 },
+ { "IBM-", "284", 0, 20284 },
+ { "IBM-", "285", 0, 20285 },
+ { "IBM-", "290", 0, 20290 },
+ { "IBM-", "297", 0, 20297 },
+ { "IBM-", "420", 0, 20420 },
+ { "IBM-", "423", 0, 20423 },
+ { "IBM-", "871", 0, 20871 },
+ { "IBM-", "880", 0, 20880 },
+ { "IBM-", "905", 0, 20905 },
+ { "IBM-", "THAI", 0, 20838 },
+ { "ISCII-", "DEVANAGARI", 0, 57002 },
+ { "ISCII-", "BENGALI", 0, 57003 },
+ { "ISCII-", "TAMIL", 0, 57004 },
+ { "ISCII-", "TELUGU", 0, 57005 },
+ { "ISCII-", "ASSAMESE", 0, 57006 },
+ { "ISCII-", "ORIYA", 0, 57007 },
+ { "ISCII-", "KANNADA", 0, 57008 },
+ { "ISCII-", "MALAYALAM", 0, 57009 },
+ { "ISCII-", "GUJARATI", 0, 57010 },
+ { "ISCII-", "PUNJABI", 0, 57011 },
+ { "KOR-", "JOHAB", 0, 1361 },
+ { "KSC-", "5601", 0, 1361 },
+ { "MAC-", "ROMAN", 0, 10000 },
+ { "MAC-", "JP", 0, 10001 },
+ { "MAC-", "CH(SP)(BIG5)", 0, 10002 },
+ { "MAC-", "KR", 0, 10003 },
+ { "MAC-", "AR", 0, 10004 },
+ { "MAC-", "HW", 0, 10005 },
+ { "MAC-", "GR", 0, 10006 },
+ { "MAC-", "CY", 0, 10007 },
+ { "MAC-", "CH(SP)(GB2312)", 0, 10008 },
+ { "MAC-", "ROMANIA", 0, 10010 },
+ { "MAC-", "UA", 0, 10017 },
+ { "MAC-", "TH", 0, 10021 },
+ { "MAC-", "LAT2", 0, 10029 },
+ { "MAC-", "ICE", 0, 10079 },
+ { "MAC-", "TR", 0, 10081 },
+ { "MAC-", "CR", 0, 10082 }
};
int CPLENALL = _countof(CodePageNamesAll);
struct _tcptable *CodePageNamesSupp;
int CPLENSUPP = 1;
+void SkipNonSpaces(char *&p)
+{
+ while (!WS(p))
+ p++;
+}
+
+void SkipSpaces(char *&p)
+{
+ while (WS(p))
+ p++;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Gets codepage ID from string representing charset such as "iso-8859-1"
// input- the string
@@ -170,8 +181,6 @@ int GetCharsetFromString(char *input, size_t size) while ((*pin != 0) && (pin - input < (INT_PTR)size)) {
if ((*pin >= 'a') && (*pin <= 'z'))
*parser++ = *(pin++) - ('a' - 'A'); // make it capital
- //else if (*pin=='\"') // this is already done in ExtractFromContentType
- // *pin++; //skip the quotes if any
else
*parser++ = *pin++;
}
@@ -181,6 +190,7 @@ int GetCharsetFromString(char *input, size_t size) #ifdef DEBUG_DECODECODEPAGE
DebugLog(DecodeFile, "<CodePage>%s</CodePage>", pout);
#endif
+
for (int i = 0; i < CPLENALL; i++) {
size_t len = mir_strlen(CodePageNamesAll[i].NameBase);
if (0 == strncmp(pout, CodePageNamesAll[i].NameBase, len)) {
@@ -218,41 +228,6 @@ int FromHexa(char HexValue, char *DecValue) }
/////////////////////////////////////////////////////////////////////////////////////////
-// Decodes a char from Base64
-// Base64Value- input char in Base64
-// DecValue- pointer where to store the result
-// returns 0 if not success
-
-int FromBase64(char Base64Value, char *DecValue)
-{
- if (Base64Value >= 'A' && Base64Value <= 'Z') {
- *DecValue = Base64Value - 'A';
- return 1;
- }
- if (Base64Value >= 'a' && Base64Value <= 'z') {
- *DecValue = Base64Value - 'a' + 26;
- return 1;
- }
- if (Base64Value >= '0' && Base64Value <= '9') {
- *DecValue = Base64Value - '0' + 52;
- return 1;
- }
- if (Base64Value == '+') {
- *DecValue = Base64Value - '+' + 62;
- return 1;
- }
- if (Base64Value == '/') {
- *DecValue = Base64Value - '/' + 63;
- return 1;
- }
- if (Base64Value == '=') {
- *DecValue = 0;
- return 1;
- }
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// Decodes string in quoted printable
// Src- input string
// Dst- where to store output string
@@ -266,15 +241,17 @@ int DecodeQuotedPrintable(char *Src, char *Dst, int DstLen, BOOL isQ) char *DstTemp = Dst;
DebugLog(DecodeFile, "<Decode Quoted><Input>%s</Input>", Src);
#endif
- for (int Counter = 0; (*Src != 0) && DstLen && (Counter++ < DstLen); Src++, Dst++)
+
+ for (int Counter = 0; (*Src != 0) && DstLen && (Counter++ < DstLen); Src++, Dst++) {
if (*Src == '=') {
if (!isQ) {
- if (Src[1] == 0x0D) {
+ if (Src[1] == '\r') {
Src++; Src++;
- if (Src[0] == 0x0A) Src++;
+ if (Src[0] == '\n')
+ Src++;
goto CopyCharQuotedPrintable;
}
- if (Src[1] == 0x0A) {
+ if (Src[1] == '\n') {
Src++; Src++;
goto CopyCharQuotedPrintable;
}
@@ -294,9 +271,11 @@ int DecodeQuotedPrintable(char *Src, char *Dst, int DstLen, BOOL isQ) else if (isQ && *Src == '_')
*Dst = ' ';
else
- CopyCharQuotedPrintable: // Yeah. Bad programming stile.
- *Dst = *Src;
+CopyCharQuotedPrintable:
+ *Dst = *Src;
+ }
*Dst = 0;
+
#ifdef DEBUG_DECODEQUOTED
DebugLog(DecodeFile, "<Output>%s</Output></Decode Quoted>", DstTemp);
#endif
@@ -304,52 +283,6 @@ int DecodeQuotedPrintable(char *Src, char *Dst, int DstLen, BOOL isQ) }
/////////////////////////////////////////////////////////////////////////////////////////
-// Decodes string in base64
-// Src- input string
-// Dst- where to store output string
-// DstLen- how max long should be output string
-// returns 0 if string was not properly decoded
-
-int DecodeBase64(char *Src, char *Dst, int DstLen)
-{
- int Result = 0;
- char Locator = 0, MiniResult[4];
- char *End = Dst + DstLen;
-
- MiniResult[0] = MiniResult[1] = MiniResult[2] = MiniResult[3] = 0;
-
- #ifdef DEBUG_DECODEBASE64
- char *DstTemp = Dst;
- DebugLog(DecodeFile, "<Decode Base64><Input>\n%s\n</Input>\n", Src);
- #endif
- while (*Src != 0 && DstLen && Dst != End) {
- if ((*Src == 0x0D) || (*Src == 0x0A)) {
- Src++;
- continue;
- }
- if ((!(Result = FromBase64(*Src, MiniResult + Locator)) && (*Src == 0)) || Locator++ == 3) //end_of_str || end_of_4_bytes
- {
- Locator = 0; //next write to the first byte
- *Dst++ = (char)((MiniResult[0] << 2) | (MiniResult[1] >> 4));
- if (Dst == End) goto end; //DstLen exceeded?
- *Dst++ = (char)((MiniResult[1] << 4) | (MiniResult[2] >> 2));
- if (Dst == End) goto end; //someones don't like goto, but not me
- *Dst++ = (char)((MiniResult[2] << 6) | MiniResult[3]);
- if (!Result && (*Src == 0)) goto end; //end of string?
- MiniResult[0] = MiniResult[1] = MiniResult[2] = MiniResult[3] = 0; //zero 4byte buffer for next loop
- }
- if (!Result) return 0; //unrecognised character occured
- Src++;
- }
-end:
- *Dst = 0;
- #ifdef DEBUG_DECODEBASE64
- DebugLog(DecodeFile, "<Output>\n%s\n</Output></Decode Base64>", DstTemp);
- #endif
- return 1;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
// Converts string to unicode from string with specified codepage
// stream- input string
// cp- codepage of input string
@@ -367,6 +300,7 @@ int ConvertStringToUnicode(char *stream, unsigned int cp, wchar_t **out) if ((cp != CP_ACP) && (cp != CP_OEMCP) && (cp != CP_MACCP) && (cp != CP_THREAD_ACP) && (cp != CP_SYMBOL) && (cp != CP_UTF7) && (cp != CP_UTF8) && !GetCPInfo(cp, &CPInfo))
cp = CP_ACP;
+
#ifdef DEBUG_DECODECODEPAGE
DebugLog(DecodeFile, "<CodePage #>%d</CodePage #>", cp);
#endif
@@ -423,8 +357,7 @@ CMStringW ConvertCodedStringToUnicode(char *stream, uint32_t cp, int mode) if (stream == nullptr)
return ret;
- while (WS(start))
- start++;
+ SkipSpaces(start);
while (*start != 0) {
if (CODES(start)) {
@@ -445,15 +378,16 @@ CMStringW ConvertCodedStringToUnicode(char *stream, uint32_t cp, int mode) if (-1 == (cp = (uint32_t)GetCharsetFromString(finder, finderend - finder)))
cp = CP_ACP;
if (Encoding != 0) {
- int size = 0, codeend;
+ int codeend;
char *pcodeend = nullptr;
finder = finderend + 2;
if (CODED(finder))
finder++;
- while (WS(finder)) finder++;
+ SkipSpaces(finder);
finderend = finder;
- while (!CODEE(finderend) && !EOS(finderend)) finderend++;
+ while (!CODEE(finderend) && !EOS(finderend))
+ finderend++;
if (codeend = CODEE(finderend))
pcodeend = finderend;
while (WS(finderend - 1)) finderend--;
@@ -464,27 +398,19 @@ CMStringW ConvertCodedStringToUnicode(char *stream, uint32_t cp, int mode) char *oneWordEncoded = new char[finderend - finder + 1];
strncpy(oneWordEncoded, finder, finderend - finder);
oneWordEncoded[finderend - finder] = 0;
+
+ ptrA DecodedResult;
switch (Encoding) {
case 'b':
case 'B':
- size = (finderend - finder) * 3 / 4 + 3 + 1 + 1;
+ DecodedResult = (char*)mir_base64_decode(oneWordEncoded, 0);
break;
case 'q':
case 'Q':
- size = finderend - finder + 1 + 1;
- break;
- }
-
- char *DecodedResult = new char[size + 1];
- switch (Encoding) {
- case 'q':
- case 'Q':
+ int size = finderend - finder + 1 + 1;
+ DecodedResult = (char*)mir_alloc(size + 1);
DecodeQuotedPrintable(oneWordEncoded, DecodedResult, size, TRUE);
break;
- case 'b':
- case 'B':
- DecodeBase64(oneWordEncoded, DecodedResult, size);
- break;
}
delete[] oneWordEncoded;
if (codeend)
@@ -495,12 +421,10 @@ CMStringW ConvertCodedStringToUnicode(char *stream, uint32_t cp, int mode) finderend++;
wchar_t *oneWord = nullptr;
- if (ConvertStringToUnicode(DecodedResult, cp, &oneWord))
+ if (ConvertStringToUnicode(DecodedResult, cp, &oneWord)) {
ret.Append(oneWord);
-
- delete oneWord;
- oneWord = nullptr;
- delete[] DecodedResult;
+ delete oneWord;
+ }
start = finderend;
}
else if (!EOS(start))
diff --git a/protocols/YAMN/src/mails/mime.cpp b/protocols/YAMN/src/mails/mime.cpp index 265bab30d9..cc4261d236 100644 --- a/protocols/YAMN/src/mails/mime.cpp +++ b/protocols/YAMN/src/mails/mime.cpp @@ -69,7 +69,8 @@ static void ExtractAddressFromLine(char *finder, char **storeto, char **storeton *storeto = *storetonick = nullptr;
return;
}
- while (WS(finder)) finder++;
+
+ SkipSpaces(finder);
if ((*finder) != '<') {
char *finderend = finder + 1;
do {
@@ -106,8 +107,7 @@ static void ExtractAddressFromLine(char *finder, char **storeto, char **storeton CopyToHeader(finder, finderend + 1, storeto, MIME_MAIL); // go to first '>' or to the end and copy
finder = finderend + 1;
- while (WS(finder)) // parse whitespace
- finder++;
+ SkipSpaces(finder);
if (!ENDLINE(finder) && !EOS(finder)) { // if there are chars yet, it's nick
finderend = finder + 1;
while (!ENDLINE(finderend) && !EOS(finderend)) finderend++; // seek to the end of line or to the end of string
@@ -130,8 +130,8 @@ static void ExtractStringFromLine(char *finder, char **storeto) *storeto = nullptr;
return;
}
- while (WS(finder))
- finder++;
+
+ SkipSpaces(finder);
char *finderend = finder;
do {
@@ -171,8 +171,7 @@ char* ExtractFromContentType(char *ContentType, char *value) finder = finder + mir_strlen(value); // jump over value string
- while (WS(finder)) // jump over whitespaces
- finder++;
+ SkipSpaces(finder);
temp = finder;
while (*temp != 0 && *temp != ';') // jump to the end of setting (to the next ;)
temp++;
@@ -551,7 +550,6 @@ void ParseAPart(APartDataType *data) // from decode.cpp
int DecodeQuotedPrintable(char *Src, char *Dst, int DstLen, BOOL isQ);
-int DecodeBase64(char *Src, char *Dst, int DstLen);
int ConvertStringToUnicode(char *stream, unsigned int cp, wchar_t **out);
wchar_t *ParseMultipartBody(char *src, char *bond)
@@ -587,23 +585,20 @@ wchar_t *ParseMultipartBody(char *src, char *bond) }
}
if (partData[i].ContType && !_strnicmp(partData[i].ContType, "text", 4)) {
- char *localBody = nullptr;
+ ptrA localBody;
switch (partData[i].TransEncType) {
case TE_BASE64:
- {
- int size = partData[i].bodyLen * 3 / 4 + 5;
- localBody = new char[size + 1];
- DecodeBase64(partData[i].body, localBody, size);
- }break;
+ localBody = (char*)mir_base64_decode(partData[i].body, 0);
+ break;
case TE_QUOTEDPRINTABLE:
{
int size = partData[i].bodyLen + 2;
- localBody = new char[size + 1];
+ localBody = (char*)mir_alloc(size + 1);
DecodeQuotedPrintable(partData[i].body, localBody, size, FALSE);
- }break;
+ }
+ break;
}
ConvertStringToUnicode(localBody ? localBody : partData[i].body, partData[i].CodePage, &partData[i].wBody);
- if (localBody) delete[] localBody;
}
else if (partData[i].ContType && !_strnicmp(partData[i].ContType, "multipart/", 10)) {
// Multipart in mulitipart recursive? should be SPAM. Ah well
diff --git a/protocols/YAMN/src/proto/pop3/pop3comm.cpp b/protocols/YAMN/src/proto/pop3/pop3comm.cpp index 8efff5fb4d..c3ffa80e5b 100644 --- a/protocols/YAMN/src/proto/pop3/pop3comm.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3comm.cpp @@ -708,13 +708,13 @@ DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp) break;
default:
PostErrorProc(ActualAccount, YAMNParam, (uint32_t)NULL, MyClient->SSL); // it closes internet connection too
- }
+ }
if (UsingInternet) // if our thread still uses internet
SetEvent(ActualAccount->UseInternetFree);
SetContactStatus(ActualAccount, ID_STATUS_NA);
-}
+ }
free(ActualCopied.ServerName);
free(ActualCopied.ServerLogin);
free(ActualCopied.ServerPasswd);
@@ -820,11 +820,11 @@ void __cdecl DeleteMailsPOP3(void *param) timestamp = new char[sz];
memcpy(timestamp, lpos, sz - 1);
timestamp[sz - 1] = '\0';
+ }
}
- }
free(DataRX);
DataRX = nullptr;
- }
+ }
SetStatusFcn(ActualAccount, TranslateT("Entering POP3 account"));
if (ActualAccount->Flags & YAMN_ACC_APOP) {
@@ -844,7 +844,7 @@ void __cdecl DeleteMailsPOP3(void *param) free(DataRX);
DataRX = nullptr;
}
- }
+ }
#ifdef DEBUG_DECODE
DebugLog(DecodeFile, "<--------Deleting requested mails-------->\n");
@@ -878,7 +878,7 @@ void __cdecl DeleteMailsPOP3(void *param) ActualAccount->SystemError = EPOP3_QUEUEALLOC;
throw (uint32_t)ActualAccount->SystemError;
}
- }
+ }
if (msgs) {
#ifdef DEBUG_DECODE
@@ -896,7 +896,7 @@ void __cdecl DeleteMailsPOP3(void *param) // but also in DeleteMails we get only those, which are still on server with their responsable numbers
SynchroMessagesFcn(ActualAccount, (HYAMNMAIL *)&DeleteMails, nullptr, (HYAMNMAIL *)&NewMails, nullptr);
}
- }
+ }
else SetStatusFcn(ActualAccount, TranslateT("Deleting spam"));
{
@@ -951,7 +951,7 @@ void __cdecl DeleteMailsPOP3(void *param) DeleteMessagesToEndFcn(ActualAccount, (HYAMNMAIL)ActualAccount->Mails);
ActualAccount->Mails = nullptr;
}
-}
+ }
#ifdef DEBUG_DECODE
DebugLog(DecodeFile, "</--------Deleting requested mails-------->\n");
@@ -975,7 +975,7 @@ void __cdecl DeleteMailsPOP3(void *param) MyClient->NetClient->Disconnect();
SetStatusFcn(ActualAccount, TranslateT("Disconnected"));
- }
+ }
UsingInternet = FALSE;
SetEvent(ActualAccount->UseInternetFree);
@@ -1028,13 +1028,14 @@ void ExtractStat(char *stream, int *mboxsize, int *mails) char *finder = stream;
while (WS(finder) || ENDLINE(finder)) finder++;
if (ACKLINE(finder)) {
- while (!WS(finder)) finder++;
- while (WS(finder)) finder++;
-}
+ SkipNonSpaces(finder);
+ SkipSpaces(finder);
+ }
if (1 != sscanf(finder, "%d", mails))
throw (uint32_t)EPOP3_STAT;
- while (!WS(finder)) finder++;
- while (WS(finder)) finder++;
+
+ SkipNonSpaces(finder);
+ SkipSpaces(finder);
if (1 != sscanf(finder, "%d", mboxsize))
throw (uint32_t)EPOP3_STAT;
}
@@ -1055,17 +1056,16 @@ void ExtractMail(char *stream, int len, HYAMNMAIL queue) #ifdef DEBUG_DECODE
DebugLog(DecodeFile, "<Message>\n");
#endif
- while (WS(finder)) finder++; // jump whitespace
+ SkipSpaces(finder); // jump whitespace
if (1 != sscanf(finder, "%d", &msgnr))
throw (uint32_t)EPOP3_UIDL;
+
#ifdef DEBUG_DECODE
DebugLog(DecodeFile, "<Nr>%d</Nr>\n", msgnr);
#endif
- // for (i=1,queueptr=queue;(queueptr->Next != NULL) && (i<msgnr);queueptr=queueptr->Next,i++);
- // if (i != msgnr)
- // throw (uint32_t)EPOP3_UIDL;
- while (!WS(finder)) finder++; // jump characters
- while (WS(finder)) finder++; // jump whitespace
+
+ SkipNonSpaces(finder);
+ SkipSpaces(finder);
finderend = finder + 1;
while (!WS(finderend) && !ENDLINE(finderend)) finderend++;
queueptr->ID = new char[finderend - finder + 1];
@@ -1099,7 +1099,7 @@ void ExtractUIDL(char *stream, int len, HYAMNMAIL queue) #ifdef DEBUG_DECODE
DebugLog(DecodeFile, "<Message>\n");
#endif
- while (WS(finder)) finder++; // jump whitespace
+ SkipSpaces(finder);
if (1 != sscanf(finder, "%d", &msgnr))
throw (uint32_t)EPOP3_UIDL;
#ifdef DEBUG_DECODE
@@ -1108,8 +1108,8 @@ void ExtractUIDL(char *stream, int len, HYAMNMAIL queue) // for (i=1,queueptr=queue;(queueptr->Next != NULL) && (i<msgnr);queueptr=queueptr->Next,i++);
// if (i != msgnr)
// throw (uint32_t)EPOP3_UIDL;
- while (!WS(finder)) finder++; // jump characters
- while (WS(finder)) finder++; // jump whitespace
+ SkipNonSpaces(finder);
+ SkipSpaces(finder);
finderend = finder + 1;
while (!WS(finderend) && !ENDLINE(finderend)) finderend++;
queueptr->ID = new char[finderend - finder + 1];
@@ -1143,7 +1143,7 @@ void ExtractList(char *stream, int len, HYAMNMAIL queue) #ifdef DEBUG_DECODE
DebugLog(DecodeFile, "<Message>\n", NULL, 0);
#endif
- while (WS(finder)) finder++; // jump whitespace
+ SkipSpaces(finder);
if (1 != sscanf(finder, "%d", &msgnr)) // message nr.
throw (uint32_t)EPOP3_LIST;
#ifdef DEBUG_DECODE
@@ -1153,8 +1153,9 @@ void ExtractList(char *stream, int len, HYAMNMAIL queue) for (i = 1, queueptr = queue; (queueptr->Next != nullptr) && (i < msgnr); queueptr = queueptr->Next, i++);
if (i != msgnr)
throw (uint32_t)EPOP3_LIST;
- while (!WS(finder)) finder++; // jump characters
- while (WS(finder)) finder++; // jump whitespace
+
+ SkipNonSpaces(finder);
+ SkipSpaces(finder); // jump whitespace
finderend = finder + 1;
if (1 != sscanf(finder, "%u", &queueptr->MailData->Size))
throw (uint32_t)EPOP3_LIST;
diff --git a/protocols/YAMN/src/stdafx.h b/protocols/YAMN/src/stdafx.h index 92190d9f16..b27689652b 100644 --- a/protocols/YAMN/src/stdafx.h +++ b/protocols/YAMN/src/stdafx.h @@ -183,7 +183,9 @@ extern YAMN_PROTOPLUGIN *POP3Plugin; // from decode.cpp
int DecodeQuotedPrintable(char *Src, char *Dst, int DstLen, BOOL isQ);
-int DecodeBase64(char *Src, char *Dst, int DstLen);
+
+void SkipNonSpaces(char *&p);
+void SkipSpaces(char *&p);
// From protoplugin.cpp
extern YAMN_PROTOPLUGINQUEUE *FirstProtoPlugin;
|