diff options
Diffstat (limited to 'protocols/YAMN/src/mails')
-rw-r--r-- | protocols/YAMN/src/mails/decode.cpp | 413 | ||||
-rw-r--r-- | protocols/YAMN/src/mails/mails.cpp | 399 | ||||
-rw-r--r-- | protocols/YAMN/src/mails/mime.cpp | 122 |
3 files changed, 444 insertions, 490 deletions
diff --git a/protocols/YAMN/src/mails/decode.cpp b/protocols/YAMN/src/mails/decode.cpp index e0070658eb..414edfce60 100644 --- a/protocols/YAMN/src/mails/decode.cpp +++ b/protocols/YAMN/src/mails/decode.cpp @@ -158,19 +158,19 @@ int CPLENSUPP = 1; //Gets codepage ID from string representing charset such as "iso-8859-1" // input- the string // size- max length of input string -int GetCharsetFromString(char *input,size_t size); +int GetCharsetFromString(char *input, size_t size); //HexValue to DecValue ('a' to 10) // HexValue- hexa value ('a') // DecValue- poiner where to store dec value // returns 0 if not success -int FromHexa(char HexValue,char *DecValue); +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); +int FromBase64(char Base64Value, char *DecValue); //Decodes string in quoted printable // Src- input string @@ -178,58 +178,57 @@ int FromBase64(char Base64Value,char *DecValue); // DstLen- how max long should be output string // isQ- if is "Q-encoding" modification. should be TRUE in headers // always returns 1 -int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ); +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 DecodeBase64(char *Src, char *Dst, int DstLen); //Converts string to unicode from string with specified codepage // stream- input string // cp- codepage of input string // out- pointer to new allocated memory that contains unicode string -int ConvertStringToUnicode(char *stream,unsigned int cp,wchar_t **out); +int ConvertStringToUnicode(char *stream, unsigned int cp, wchar_t **out); //Converts string from MIME header to unicode // stream- input string // cp- codepage of input string // storeto- pointer to memory that contains unicode string // mode- MIME_PLAIN or MIME_MAIL (MIME_MAIL deletes '"' from start and end of string) -void ConvertCodedStringToUnicode(char *stream,wchar_t **storeto,uint32_t cp,int mode); +void ConvertCodedStringToUnicode(char *stream, wchar_t **storeto, uint32_t cp, int mode); //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- -int GetCharsetFromString(char *input,size_t size) +int GetCharsetFromString(char *input, size_t size) //"ISO-8859-1" to ID from table { - char *pin=input; - char *pout,*parser; + char *pin = input; + char *pout, *parser; - if ((size<1) || (parser=pout=new char[size+1])==nullptr) + if ((size < 1) || (parser = pout = new char[size + 1]) == nullptr) return -1; - while((*pin != 0) && (pin-input< (INT_PTR)size)) - { - if ((*pin>='a') && (*pin<='z')) - *parser++=*(pin++)-('a'-'A'); // make it capital + 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++; + else + *parser++ = *pin++; } *parser = 0; -#ifdef DEBUG_DECODECODEPAGE - DebugLog(DecodeFile,"<CodePage>%s</CodePage>",pout); -#endif - for (int i=0;i<CPLENALL;i++) { + #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)) { - if (0==mir_strcmp(pout+len,CodePageNamesAll[i].NameSub)) { + if (0 == strncmp(pout, CodePageNamesAll[i].NameBase, len)) { + if (0 == mir_strcmp(pout + len, CodePageNamesAll[i].NameSub)) { delete[] pout; return CodePageNamesAll[i].CP; } @@ -239,312 +238,292 @@ int GetCharsetFromString(char *input,size_t size) return -1; //not found } -int FromHexa(char HexValue,char *DecValue) +int FromHexa(char HexValue, char *DecValue) { - if (HexValue>='0' && HexValue<='9') - { - *DecValue=HexValue-'0'; + if (HexValue >= '0' && HexValue <= '9') { + *DecValue = HexValue - '0'; return 1; } - if (HexValue>='A' && HexValue<='F') - { - *DecValue=HexValue-'A'+10; + if (HexValue >= 'A' && HexValue <= 'F') { + *DecValue = HexValue - 'A' + 10; return 1; } - if (HexValue>='a' && HexValue<='f') - { - *DecValue=HexValue-'a'+10; + if (HexValue >= 'a' && HexValue <= 'f') { + *DecValue = HexValue - 'a' + 10; return 1; } return 0; } -int FromBase64(char Base64Value,char *DecValue) +int FromBase64(char Base64Value, char *DecValue) { - if (Base64Value>='A' && Base64Value<='Z') - { - *DecValue=Base64Value-'A'; + if (Base64Value >= 'A' && Base64Value <= 'Z') { + *DecValue = Base64Value - 'A'; return 1; } - if (Base64Value>='a' && Base64Value<='z') - { - *DecValue=Base64Value-'a'+26; + if (Base64Value >= 'a' && Base64Value <= 'z') { + *DecValue = Base64Value - 'a' + 26; return 1; } - if (Base64Value>='0' && Base64Value<='9') - { - *DecValue=Base64Value-'0'+52; + if (Base64Value >= '0' && Base64Value <= '9') { + *DecValue = Base64Value - '0' + 52; return 1; } - if (Base64Value=='+') - { - *DecValue=Base64Value-'+'+62; + if (Base64Value == '+') { + *DecValue = Base64Value - '+' + 62; return 1; } - if (Base64Value=='/') - { - *DecValue=Base64Value-'/'+63; + if (Base64Value == '/') { + *DecValue = Base64Value - '/' + 63; return 1; } - if (Base64Value=='=') - { - *DecValue=0; + if (Base64Value == '=') { + *DecValue = 0; return 1; } return 0; } -int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ) +int DecodeQuotedPrintable(char *Src, char *Dst, int DstLen, BOOL isQ) { -#ifdef DEBUG_DECODEQUOTED - char *DstTemp=Dst; - DebugLog(DecodeFile,"<Decode Quoted><Input>%s</Input>",Src); -#endif - for (int Counter=0;(*Src != 0) && DstLen && (Counter++<DstLen);Src++,Dst++) - if (*Src=='=') - { + #ifdef DEBUG_DECODEQUOTED + char *DstTemp = Dst; + DebugLog(DecodeFile, "<Decode Quoted><Input>%s</Input>", Src); + #endif + for (int Counter = 0; (*Src != 0) && DstLen && (Counter++ < DstLen); Src++, Dst++) + if (*Src == '=') { if (!isQ) { - if (Src[1]==0x0D) { + if (Src[1] == 0x0D) { Src++; Src++; - if (Src[0]==0x0A) Src++; + if (Src[0] == 0x0A) Src++; goto CopyCharQuotedPrintable; } - if (Src[1]==0x0A) { + if (Src[1] == 0x0A) { Src++; Src++; goto CopyCharQuotedPrintable; } } - char First,Second; - if (!FromHexa(*(++Src),&First)) - { - *Dst++='=';Src--; + char First, Second; + if (!FromHexa(*(++Src), &First)) { + *Dst++ = '='; Src--; continue; } - if (!FromHexa(*(++Src),&Second)) - { - *Dst++='=';Src--;Src--; + if (!FromHexa(*(++Src), &Second)) { + *Dst++ = '='; Src--; Src--; continue; } - *Dst=(char)(First)<<4; - *Dst+=Second; + *Dst = (char)(First) << 4; + *Dst += Second; } - else if (isQ && *Src=='_') - *Dst=' '; + else if (isQ && *Src == '_') + *Dst = ' '; else -CopyCharQuotedPrintable: // Yeah. Bad programming stile. - *Dst=*Src; - *Dst=0; -#ifdef DEBUG_DECODEQUOTED - DebugLog(DecodeFile,"<Output>%s</Output></Decode Quoted>",DstTemp); -#endif + CopyCharQuotedPrintable: // Yeah. Bad programming stile. + *Dst = *Src; + *Dst = 0; + #ifdef DEBUG_DECODEQUOTED + DebugLog(DecodeFile, "<Output>%s</Output></Decode Quoted>", DstTemp); + #endif return 1; } -int DecodeBase64(char *Src,char *Dst,int DstLen) +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++; + 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 + 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 + 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 + *Dst = 0; + #ifdef DEBUG_DECODEBASE64 + DebugLog(DecodeFile, "<Output>\n%s\n</Output></Decode Base64>", DstTemp); + #endif return 1; } -int ConvertStringToUnicode(char *stream,unsigned int cp,wchar_t **out) +int ConvertStringToUnicode(char *stream, unsigned int cp, wchar_t **out) { CPINFO CPInfo; - wchar_t *temp,*src=*out,*dest; + wchar_t *temp, *src = *out, *dest; size_t outlen; - int streamlen,Index; + int streamlen, Index; //codepages, which require to have set 0 in dwFlags parameter when calling MultiByteToWideChar - uint32_t CodePagesZeroFlags[]={50220,50221,50222,50225,50227,50229,52936,54936,57002,57003,57004,57005,57006,57007,57008,57009,57010,57011,65000,65001}; - - 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 - - for (Index=0;Index<sizeof(CodePagesZeroFlags)/sizeof(CodePagesZeroFlags[0]);Index++) - if (CodePagesZeroFlags[Index]==cp) - { - Index=-1; + uint32_t CodePagesZeroFlags[] = {50220, 50221, 50222, 50225, 50227, 50229, 52936, 54936, 57002, 57003, 57004, 57005, 57006, 57007, 57008, 57009, 57010, 57011, 65000, 65001}; + + 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 + + for (Index = 0; Index < sizeof(CodePagesZeroFlags) / sizeof(CodePagesZeroFlags[0]); Index++) + if (CodePagesZeroFlags[Index] == cp) { + Index = -1; break; } - if (Index==-1) - streamlen=MultiByteToWideChar(cp,0,stream,-1,nullptr,0); + if (Index == -1) + streamlen = MultiByteToWideChar(cp, 0, stream, -1, nullptr, 0); else - streamlen=MultiByteToWideChar(cp,MB_USEGLYPHCHARS,stream,-1,nullptr,0); + streamlen = MultiByteToWideChar(cp, MB_USEGLYPHCHARS, stream, -1, nullptr, 0); if (*out != nullptr) - outlen=mir_wstrlen(*out); + outlen = mir_wstrlen(*out); else - outlen=0; - temp=new wchar_t[streamlen+outlen+1]; - - if (*out != nullptr) - { - for (dest=temp;*src != (wchar_t)0;src++,dest++) //copy old string from *out to temp - *dest=*src; -// *dest++=L' '; //add space? - delete[] *out; + outlen = 0; + temp = new wchar_t[streamlen + outlen + 1]; + + if (*out != nullptr) { + for (dest = temp; *src != (wchar_t)0; src++, dest++) //copy old string from *out to temp + *dest = *src; + // *dest++=L' '; //add space? + delete[] * out; } else - dest=temp; - *out=temp; - - if (Index==-1) - { - if (!MultiByteToWideChar(cp,0,stream,-1,dest,streamlen)) + dest = temp; + *out = temp; + + if (Index == -1) { + if (!MultiByteToWideChar(cp, 0, stream, -1, dest, streamlen)) return 0; } - else - { - if (!MultiByteToWideChar(cp,MB_USEGLYPHCHARS,stream,-1,dest,streamlen)) + else { + if (!MultiByteToWideChar(cp, MB_USEGLYPHCHARS, stream, -1, dest, streamlen)) return 0; } return 1; } -void ConvertCodedStringToUnicode(char *stream,wchar_t **storeto,uint32_t cp,int mode) +void ConvertCodedStringToUnicode(char *stream, wchar_t **storeto, uint32_t cp, int mode) { - char *start=stream,*finder,*finderend; - char Encoding=0; + char *start = stream, *finder, *finderend; + char Encoding = 0; - if (stream==nullptr) + if (stream == nullptr) return; - while(WS(start)) start++; - wchar_t *tempstore=nullptr; - if (!ConvertStringToUnicode(stream,cp,&tempstore))return; + while (WS(start)) start++; + wchar_t *tempstore = nullptr; + if (!ConvertStringToUnicode(stream, cp, &tempstore))return; size_t tempstoreLength = mir_wstrlen(tempstore); - + size_t outind = 0; - while(*start != 0) { + while (*start != 0) { if (CODES(start)) { - finder=start+2;finderend=finder; - while(!CODED(finderend) && !EOS(finderend)) finderend++; + finder = start + 2; finderend = finder; + while (!CODED(finderend) && !EOS(finderend)) finderend++; start = finderend; - if (CODED(finderend)) - { - Encoding=*(finderend+1); - switch(Encoding) - { - case 'b': - case 'B': - case 'q': - case 'Q': - break; - default: - goto NotEncoded; + if (CODED(finderend)) { + Encoding = *(finderend + 1); + switch (Encoding) { + case 'b': + case 'B': + case 'q': + case 'Q': + break; + default: + goto NotEncoded; } - if (-1==(cp=(uint32_t)GetCharsetFromString(finder,finderend-finder))) - cp=CP_ACP; - if (Encoding != 0) - { - int size = 0,codeend; + if (-1 == (cp = (uint32_t)GetCharsetFromString(finder, finderend - finder))) + cp = CP_ACP; + if (Encoding != 0) { + int size = 0, codeend; char *pcodeend = nullptr; - finder=finderend+2; + finder = finderend + 2; if (CODED(finder)) finder++; - while(WS(finder)) finder++; - finderend=finder; - while(!CODEE(finderend) && !EOS(finderend)) finderend++; - if (codeend=CODEE(finderend)) - pcodeend=finderend; - while(WS(finderend-1)) finderend--; - if ((mode==MIME_MAIL) && (((*finder=='"') && (*(finderend-1)=='"')))) - { + while (WS(finder)) finder++; + finderend = finder; + while (!CODEE(finderend) && !EOS(finderend)) finderend++; + if (codeend = CODEE(finderend)) + pcodeend = finderend; + while (WS(finderend - 1)) finderend--; + if ((mode == MIME_MAIL) && (((*finder == '"') && (*(finderend - 1) == '"')))) { finder++; finderend--; } - char *oneWordEncoded = new char[finderend-finder+1]; - strncpy(oneWordEncoded,finder,finderend-finder); - oneWordEncoded[finderend-finder]=0; - switch(Encoding) - { - case 'b': - case 'B': - size=(finderend-finder)*3/4+3+1+1; - break; - case 'q': - case 'Q': - size=finderend-finder+1+1; - break; + char *oneWordEncoded = new char[finderend - finder + 1]; + strncpy(oneWordEncoded, finder, finderend - finder); + oneWordEncoded[finderend - finder] = 0; + switch (Encoding) { + case 'b': + case 'B': + size = (finderend - finder) * 3 / 4 + 3 + 1 + 1; + break; + case 'q': + case 'Q': + size = finderend - finder + 1 + 1; + break; } - char *DecodedResult = new char[size+1]; - switch(Encoding) - { - case 'q': - case 'Q': - DecodeQuotedPrintable(oneWordEncoded,DecodedResult,size, TRUE); - break; - case 'b': - case 'B': - DecodeBase64(oneWordEncoded,DecodedResult,size); - break; + char *DecodedResult = new char[size + 1]; + switch (Encoding) { + case 'q': + case 'Q': + DecodeQuotedPrintable(oneWordEncoded, DecodedResult, size, TRUE); + break; + case 'b': + case 'B': + DecodeBase64(oneWordEncoded, DecodedResult, size); + break; } delete[] oneWordEncoded; if (codeend) - finderend=pcodeend+2; + finderend = pcodeend + 2; if (WS(finderend)) //if string continues and there's some whitespace, add space to string that is to be converted { - size_t len=mir_strlen(DecodedResult); - DecodedResult[len]=' '; - DecodedResult[len+1]=0; + size_t len = mir_strlen(DecodedResult); + DecodedResult[len] = ' '; + DecodedResult[len + 1] = 0; finderend++; } - wchar_t *oneWord=nullptr; - if (ConvertStringToUnicode(DecodedResult,cp,&oneWord)) { + wchar_t *oneWord = nullptr; + if (ConvertStringToUnicode(DecodedResult, cp, &oneWord)) { size_t len = mir_wstrlen(oneWord); - memcpy(&tempstore[outind],oneWord,len*sizeof(wchar_t)); + memcpy(&tempstore[outind], oneWord, len * sizeof(wchar_t)); outind += len; } delete oneWord; oneWord = nullptr; delete[] DecodedResult; start = finderend; - } else if (!EOS(start)) start++; - } else if (!EOS(start)) start++; - }else{ + } + else if (!EOS(start)) start++; + } + else if (!EOS(start)) start++; + } + else { NotEncoded: - tempstore[outind] = tempstore[start-stream]; + tempstore[outind] = tempstore[start - stream]; outind++; if (outind > tempstoreLength) break; start++; diff --git a/protocols/YAMN/src/mails/mails.cpp b/protocols/YAMN/src/mails/mails.cpp index d0dbba76ab..168c6c9397 100644 --- a/protocols/YAMN/src/mails/mails.cpp +++ b/protocols/YAMN/src/mails/mails.cpp @@ -6,32 +6,32 @@ #include "../stdafx.h" -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- -// SMALL INTRO -// Mails are queued in a queue (chained list). Pointer to first mail is pointed from Account structure -// member called Mails. -// Mail queue is ended with NULL- pointered mail (NULL handle) + // SMALL INTRO + // Mails are queued in a queue (chained list). Pointer to first mail is pointed from Account structure + // member called Mails. + // Mail queue is ended with NULL- pointered mail (NULL handle) -//Creates new mail for plugin (calling plugin's constructor, when plugin imported to YAMN) -INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam); + //Creates new mail for plugin (calling plugin's constructor, when plugin imported to YAMN) +INT_PTR CreateAccountMailSvc(WPARAM wParam, LPARAM lParam); //Deletes mail for plugin (calling plugin's destructor, when plugin imported to YAMN) -INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam); +INT_PTR DeleteAccountMailSvc(WPARAM wParam, LPARAM lParam); //Loads mail data from standard storage to memory -INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam); +INT_PTR LoadMailDataSvc(WPARAM wParam, LPARAM lParam); //Deletes mail data from memory -INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM); +INT_PTR UnloadMailDataSvc(WPARAM wParam, LPARAM); //Saves mail data from memory to standard storage -INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam); +INT_PTR SaveMailDataSvc(WPARAM wParam, LPARAM lParam); //Appends second MIME mail queue to the first one //Only finds the end of first queue and its Next memember repoints to second one -void WINAPI AppendQueueFcn(HYAMNMAIL first,HYAMNMAIL second); +void WINAPI AppendQueueFcn(HYAMNMAIL first, HYAMNMAIL second); //Synchronizes two accounts //Function finds, if there were some mails deleted from mailbox and deletes (depends on RemovedOld param) them from OldQueue @@ -50,31 +50,31 @@ void WINAPI AppendQueueFcn(HYAMNMAIL first,HYAMNMAIL second); //So function works like: //1. delete (or move to RemovedOld queue if RemovedOld is not NULL) all mails from OldQueue not found in NewQueue //2. delete (or move to RemovedNew queue if RemovedNew is not NULL) all mails from NewQueue found in OldQueue -void WINAPI SynchroMessagesFcn(CAccount *Account,HYAMNMAIL *OldQueue,HYAMNMAIL *RemovedOld,HYAMNMAIL *NewQueue,HYAMNMAIL *RemovedNew); +void WINAPI SynchroMessagesFcn(CAccount *Account, HYAMNMAIL *OldQueue, HYAMNMAIL *RemovedOld, HYAMNMAIL *NewQueue, HYAMNMAIL *RemovedNew); //Deletes messages from mail From to the end // Account- account who owns mails // From- first mail in queue, which is going to delete -void WINAPI DeleteMessagesToEndFcn(CAccount *Account,HYAMNMAIL From); +void WINAPI DeleteMessagesToEndFcn(CAccount *Account, HYAMNMAIL From); //Removes message from queue, does not delete from memory // From- queue pointer // Which- mail to delete // mode- nonzero if you want to decrement numbers in messages that are bigger than the one in Which mail, 0 if not -void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode); +void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From, HYAMNMAIL Which, int mode); //Finds message in queue that has the same ID number // From- message queue // ID- pointer to ID // returns pointer to found message, NULL if not found -HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From,char *ID); +HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From, char *ID); //Translate header from text to queue of CMimeItem structures //This means that new queue will contain all info about headers // stream- pointer to text containing header (can be ended with zero) // len- length of stream // head- function fills this pointer to first header item in queue -void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head); +void WINAPI TranslateHeaderFcn(char *stream, int len, struct CMimeItem **head); //Creates new mail queue, copying only these mails, that have set flag for deleting // From- message queue, whose mail with given flag are duplicated @@ -89,69 +89,66 @@ HYAMNMAIL WINAPI CreateNewDeleteQueueFcn(HYAMNMAIL From); // FlagsNotSet- ...and must not have set these flags... // FlagsToSetRemove- ...to set/remove these flags (see mode) // mode- nonzero to set, else remove -void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,uint32_t FlagsSet,uint32_t FlagsNotSet,uint32_t FlagsToSetRemove,int mode); +void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From, uint32_t FlagsSet, uint32_t FlagsNotSet, uint32_t FlagsToSetRemove, int mode); -struct CExportedFunctions MailExportedFcn[]= +struct CExportedFunctions MailExportedFcn[] = { - {YAMN_SYNCHROMIMEMSGSID,(void *)SynchroMessagesFcn}, - {YAMN_TRANSLATEHEADERID,(void *)TranslateHeaderFcn}, - {YAMN_APPENDQUEUEID,(void *)AppendQueueFcn}, - {YAMN_DELETEMIMEQUEUEID,(void *)DeleteMessagesToEndFcn}, - {YAMN_DELETEMIMEMESSAGEID,(void *)DeleteMessageFromQueueFcn}, - {YAMN_FINDMIMEMESSAGEID,(void *)FindMessageByIDFcn}, - {YAMN_CREATENEWDELETEQUEUEID,(void *)CreateNewDeleteQueueFcn}, - {YAMN_SETREMOVEQUEUEFLAGSID,(void *)SetRemoveFlagsInQueueFcn}, + {YAMN_SYNCHROMIMEMSGSID, (void *)SynchroMessagesFcn}, + {YAMN_TRANSLATEHEADERID, (void *)TranslateHeaderFcn}, + {YAMN_APPENDQUEUEID, (void *)AppendQueueFcn}, + {YAMN_DELETEMIMEQUEUEID, (void *)DeleteMessagesToEndFcn}, + {YAMN_DELETEMIMEMESSAGEID, (void *)DeleteMessageFromQueueFcn}, + {YAMN_FINDMIMEMESSAGEID, (void *)FindMessageByIDFcn}, + {YAMN_CREATENEWDELETEQUEUEID, (void *)CreateNewDeleteQueueFcn}, + {YAMN_SETREMOVEQUEUEFLAGSID, (void *)SetRemoveFlagsInQueueFcn}, }; -struct CExportedServices MailExportedSvc[]= +struct CExportedServices MailExportedSvc[] = { - {MS_YAMN_CREATEACCOUNTMAIL,CreateAccountMailSvc}, - {MS_YAMN_DELETEACCOUNTMAIL,DeleteAccountMailSvc}, - {MS_YAMN_LOADMAILDATA,LoadMailDataSvc}, - {MS_YAMN_UNLOADMAILDATA,UnloadMailDataSvc}, - {MS_YAMN_SAVEMAILDATA,SaveMailDataSvc}, + {MS_YAMN_CREATEACCOUNTMAIL, CreateAccountMailSvc}, + {MS_YAMN_DELETEACCOUNTMAIL, DeleteAccountMailSvc}, + {MS_YAMN_LOADMAILDATA, LoadMailDataSvc}, + {MS_YAMN_UNLOADMAILDATA, UnloadMailDataSvc}, + {MS_YAMN_SAVEMAILDATA, SaveMailDataSvc}, }; //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- -INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam) +INT_PTR CreateAccountMailSvc(WPARAM wParam, LPARAM lParam) { - CAccount *Account=(CAccount *)wParam; - uint32_t MailVersion=(uint32_t)lParam; + CAccount *Account = (CAccount *)wParam; + uint32_t MailVersion = (uint32_t)lParam; HYAMNMAIL NewMail; -//test if we are going to initialize members of suitable structure (structures of plugin and YAMN must match) + //test if we are going to initialize members of suitable structure (structures of plugin and YAMN must match) if (MailVersion != YAMN_MAILVERSION) return NULL; - if (Account->Plugin != nullptr) - { - if (Account->Plugin->MailFcn->NewMailFcnPtr != nullptr) - { -//Let plugin create its own structure, which can be derived from CAccount structure - if (nullptr==(NewMail=Account->Plugin->MailFcn->NewMailFcnPtr(Account,YAMN_MAILVERSION))) + if (Account->Plugin != nullptr) { + if (Account->Plugin->MailFcn->NewMailFcnPtr != nullptr) { + //Let plugin create its own structure, which can be derived from CAccount structure + if (nullptr == (NewMail = Account->Plugin->MailFcn->NewMailFcnPtr(Account, YAMN_MAILVERSION))) return NULL; } - else - { -//We suggest plugin uses standard CAccount structure, so we create it - if (nullptr==(NewMail=new YAMNMAIL)) -//If not created successfully + else { + //We suggest plugin uses standard CAccount structure, so we create it + if (nullptr == (NewMail = new YAMNMAIL)) + //If not created successfully return NULL; - NewMail->MailData=nullptr; + NewMail->MailData = nullptr; } -//Init every members of structure, used by YAMN + //Init every members of structure, used by YAMN return (INT_PTR)NewMail; } return NULL; } -INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam) +INT_PTR DeleteAccountMailSvc(WPARAM wParam, LPARAM lParam) { - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - HYAMNMAIL OldMail=(HYAMNMAIL)lParam; + HYAMNPROTOPLUGIN Plugin = (HYAMNPROTOPLUGIN)wParam; + HYAMNMAIL OldMail = (HYAMNMAIL)lParam; struct CMimeItem *TH; if (Plugin->MailFcn != nullptr) { @@ -164,15 +161,15 @@ INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam) if (OldMail->MailData != nullptr) { if (OldMail->MailData->Body != nullptr) delete[] OldMail->MailData->Body; - if ((TH=OldMail->MailData->TranslatedHeader) != nullptr) - for (;OldMail->MailData->TranslatedHeader != nullptr;) { - TH=TH->Next; + if ((TH = OldMail->MailData->TranslatedHeader) != nullptr) + for (; OldMail->MailData->TranslatedHeader != nullptr;) { + TH = TH->Next; if (OldMail->MailData->TranslatedHeader->name != nullptr) delete[] OldMail->MailData->TranslatedHeader->name; if (OldMail->MailData->TranslatedHeader->value != nullptr) delete[] OldMail->MailData->TranslatedHeader->value; delete OldMail->MailData->TranslatedHeader; - OldMail->MailData->TranslatedHeader=TH; + OldMail->MailData->TranslatedHeader = TH; } delete OldMail->MailData; } @@ -184,17 +181,17 @@ INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam) } -void WINAPI AppendQueueFcn(HYAMNMAIL first,HYAMNMAIL second) +void WINAPI AppendQueueFcn(HYAMNMAIL first, HYAMNMAIL second) { - HYAMNMAIL Finder=first; - while(Finder->Next != nullptr) Finder=Finder->Next; - Finder->Next=second; + HYAMNMAIL Finder = first; + while (Finder->Next != nullptr) Finder = Finder->Next; + Finder->Next = second; } -INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam) +INT_PTR LoadMailDataSvc(WPARAM wParam, LPARAM lParam) { - HYAMNMAIL Mail=(HYAMNMAIL)wParam; - uint32_t MailVersion=(uint32_t)lParam; + HYAMNMAIL Mail = (HYAMNMAIL)wParam; + uint32_t MailVersion = (uint32_t)lParam; if (MailVersion != YAMN_MAILDATAVERSION) return NULL; @@ -210,7 +207,7 @@ INT_PTR UnloadMailDataSvc(WPARAM, LPARAM) INT_PTR SaveMailDataSvc(WPARAM, LPARAM lParam) { - uint32_t MailVersion=(uint32_t)lParam; + uint32_t MailVersion = (uint32_t)lParam; if (MailVersion != YAMN_MAILDATAVERSION) return (INT_PTR)-1; @@ -219,203 +216,192 @@ INT_PTR SaveMailDataSvc(WPARAM, LPARAM lParam) return (INT_PTR)0; } -void WINAPI SynchroMessagesFcn(CAccount *Account,HYAMNMAIL *OldQueue,HYAMNMAIL *RemovedOld,HYAMNMAIL *NewQueue,HYAMNMAIL *RemovedNew) +void WINAPI SynchroMessagesFcn(CAccount *Account, HYAMNMAIL *OldQueue, HYAMNMAIL *RemovedOld, HYAMNMAIL *NewQueue, HYAMNMAIL *RemovedNew) //deletes messages from new queue, if they are old //it also deletes messages from old queue, if they are not in mailbox anymore //"YAMN_MSG_DELETED" messages in old queue remain in old queue (are never removed, although they are not in new queue) //"YAMN_MSG_DELETED" messages in new queue remain in new queue (are never removed, although they can be in old queue) { - HYAMNMAIL Finder,FinderPrev; - HYAMNMAIL Parser,ParserPrev; - HYAMNMAIL RemovedOldParser =nullptr; - HYAMNMAIL RemovedNewParser =nullptr; - if (RemovedOld != nullptr) *RemovedOld=nullptr; - if (RemovedNew != nullptr) *RemovedNew=nullptr; - - for (FinderPrev=nullptr,Finder=*OldQueue;Finder != nullptr;) - { + HYAMNMAIL Finder, FinderPrev; + HYAMNMAIL Parser, ParserPrev; + HYAMNMAIL RemovedOldParser = nullptr; + HYAMNMAIL RemovedNewParser = nullptr; + if (RemovedOld != nullptr) *RemovedOld = nullptr; + if (RemovedNew != nullptr) *RemovedNew = nullptr; + + for (FinderPrev = nullptr, Finder = *OldQueue; Finder != nullptr;) { if (Finder->Flags & YAMN_MSG_DELETED) //if old queue contains deleted mail { - FinderPrev=Finder; - Finder=Finder->Next; //get next message in old queue for testing + FinderPrev = Finder; + Finder = Finder->Next; //get next message in old queue for testing continue; } - for (ParserPrev=nullptr,Parser=*NewQueue;Parser != nullptr;ParserPrev=Parser,Parser=Parser->Next) - { + for (ParserPrev = nullptr, Parser = *NewQueue; Parser != nullptr; ParserPrev = Parser, Parser = Parser->Next) { if (Parser->Flags & YAMN_MSG_DELETED) continue; - if (Parser->ID==nullptr) //simply ignore the message, that has not filled its ID + if (Parser->ID == nullptr) //simply ignore the message, that has not filled its ID continue; - if (0==mir_strcmp(Parser->ID,Finder->ID)) //search for equal message in new queue + if (0 == mir_strcmp(Parser->ID, Finder->ID)) //search for equal message in new queue break; } if (Parser != nullptr) //found equal message in new queue { - if (Parser==*NewQueue) - *NewQueue=(*NewQueue)->Next; + if (Parser == *NewQueue) + *NewQueue = (*NewQueue)->Next; else - ParserPrev->Next=Parser->Next; - Finder->Number=Parser->Number; //rewrite the number of current message in old queue + ParserPrev->Next = Parser->Next; + Finder->Number = Parser->Number; //rewrite the number of current message in old queue - if (RemovedNew==nullptr) //delete from new queue - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Parser); + if (RemovedNew == nullptr) //delete from new queue + DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Parser); else //or move to RemovedNew { - if (RemovedNewParser==nullptr) //if it is first mail removed from NewQueue - *RemovedNew=Parser; //set RemovedNew queue to point to first message in removed queue + if (RemovedNewParser == nullptr) //if it is first mail removed from NewQueue + *RemovedNew = Parser; //set RemovedNew queue to point to first message in removed queue else - RemovedNewParser->Next=Parser; //else don't forget to show to next message in RemovedNew queue - RemovedNewParser=Parser; //follow RemovedNew queue - RemovedNewParser->Next=nullptr; + RemovedNewParser->Next = Parser; //else don't forget to show to next message in RemovedNew queue + RemovedNewParser = Parser; //follow RemovedNew queue + RemovedNewParser->Next = nullptr; } - FinderPrev=Finder; - Finder=Finder->Next; //get next message in old queue for testing + FinderPrev = Finder; + Finder = Finder->Next; //get next message in old queue for testing } else //a message was already deleted from mailbox { - if (Finder==*OldQueue) //if we are at the first item in OldQueue + if (Finder == *OldQueue) //if we are at the first item in OldQueue { - *OldQueue=(*OldQueue)->Next; //set OldQueue to next item - if (RemovedOld==nullptr) //delete from old queue - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Finder); + *OldQueue = (*OldQueue)->Next; //set OldQueue to next item + if (RemovedOld == nullptr) //delete from old queue + DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Finder); else //or move to RemovedOld { - if (RemovedOldParser==nullptr) //if it is first mail removed from OldQueue - *RemovedOld=Finder; //set RemovedOld queue to point to first message in removed queue + if (RemovedOldParser == nullptr) //if it is first mail removed from OldQueue + *RemovedOld = Finder; //set RemovedOld queue to point to first message in removed queue else - RemovedOldParser->Next=Finder; //else don't forget to show to next message in RemovedNew queue - RemovedOldParser=Finder; //follow RemovedOld queue - RemovedOldParser->Next=nullptr; + RemovedOldParser->Next = Finder; //else don't forget to show to next message in RemovedNew queue + RemovedOldParser = Finder; //follow RemovedOld queue + RemovedOldParser->Next = nullptr; } - Finder=*OldQueue; + Finder = *OldQueue; } - else - { - FinderPrev->Next=Finder->Next; - if (RemovedOld==nullptr) //delete from old queue - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Finder); + else { + FinderPrev->Next = Finder->Next; + if (RemovedOld == nullptr) //delete from old queue + DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Finder); else //or move to RemovedOld { - if (RemovedOldParser==nullptr) //if it is first mail removed from OldQueue - *RemovedOld=Finder; //set RemovedOld queue to point to first message in removed queue + if (RemovedOldParser == nullptr) //if it is first mail removed from OldQueue + *RemovedOld = Finder; //set RemovedOld queue to point to first message in removed queue else - RemovedOldParser->Next=Finder; //else don't forget to show to next message in RemovedNew queue - RemovedOldParser=Finder; //follow RemovedOld queue - RemovedOldParser->Next=nullptr; + RemovedOldParser->Next = Finder; //else don't forget to show to next message in RemovedNew queue + RemovedOldParser = Finder; //follow RemovedOld queue + RemovedOldParser->Next = nullptr; } - Finder=FinderPrev->Next; + Finder = FinderPrev->Next; } } } } -void WINAPI DeleteMessagesToEndFcn(CAccount *Account,HYAMNMAIL From) +void WINAPI DeleteMessagesToEndFcn(CAccount *Account, HYAMNMAIL From) { HYAMNMAIL Temp; - while(From != nullptr) - { - Temp=From; - From=From->Next; - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Temp); + while (From != nullptr) { + Temp = From; + From = From->Next; + DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Temp); } } -void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode=0) +void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From, HYAMNMAIL Which, int mode = 0) { - uint32_t Number=Which->Number; + uint32_t Number = Which->Number; HYAMNMAIL Parser; - if (*From==Which) - { - Parser=Which->Next; - *From=Parser; + if (*From == Which) { + Parser = Which->Next; + *From = Parser; + } + else { + for (Parser = *From; Which != Parser->Next; Parser = Parser->Next) + if (mode && (Parser->Number > Number)) Parser->Number--; + if (mode && (Parser->Number > Number)) Parser->Number--; + Parser->Next = Parser->Next->Next; + Parser = Which->Next; } - else - { - for (Parser=*From;Which != Parser->Next;Parser=Parser->Next) - if (mode && (Parser->Number>Number)) Parser->Number--; - if (mode && (Parser->Number>Number)) Parser->Number--; - Parser->Next=Parser->Next->Next; - Parser=Which->Next; - } if (mode) - for (;Parser != nullptr;Parser=Parser->Next) - if (Parser->Number>Number) Parser->Number--; + for (; Parser != nullptr; Parser = Parser->Next) + if (Parser->Number > Number) Parser->Number--; } -void DeleteMessagesFromQueue(HYAMNMAIL *From,HYAMNMAIL Which,int mode=0) +void DeleteMessagesFromQueue(HYAMNMAIL *From, HYAMNMAIL Which, int mode = 0) { HYAMNMAIL Parser; - for (Parser=Which;Parser != nullptr;Parser=Parser->Next) - DeleteMessageFromQueueFcn(From,Parser,mode); + for (Parser = Which; Parser != nullptr; Parser = Parser->Next) + DeleteMessageFromQueueFcn(From, Parser, mode); } -HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From,char *ID) +HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From, char *ID) { HYAMNMAIL Browser; - for (Browser=From;Browser != nullptr;Browser=Browser->Next) - if (0==mir_strcmp(Browser->ID,ID)) + for (Browser = From; Browser != nullptr; Browser = Browser->Next) + if (0 == mir_strcmp(Browser->ID, ID)) break; return Browser; } -void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head) +void WINAPI TranslateHeaderFcn(char *stream, int len, struct CMimeItem **head) { - try - { - char *finder=stream; - char *prev1,*prev2,*prev3; - struct CMimeItem *Item=nullptr; + try { + char *finder = stream; + char *prev1, *prev2, *prev3; + struct CMimeItem *Item = nullptr; - while(finder<=(stream+len)) - { - while(ENDLINEWS(finder)) finder++; + while (finder <= (stream + len)) { + while (ENDLINEWS(finder)) finder++; //at the start of line - if (DOTLINE(finder+1)) //at the end of stream + if (DOTLINE(finder + 1)) //at the end of stream break; - prev1=finder; + prev1 = finder; - while(*finder != ':' && !EOS(finder)) finder++; + while (*finder != ':' && !EOS(finder)) finder++; if (!EOS(finder)) - prev2=finder++; + prev2 = finder++; else break; - while(WS(finder) && !EOS(finder)) finder++; + while (WS(finder) && !EOS(finder)) finder++; if (!EOS(finder)) - prev3=finder; + prev3 = finder; else break; - do - { - if (ENDLINEWS(finder)) finder+=2; //after endline information continues - while(!ENDLINE(finder) && !EOS(finder)) finder++; - }while(ENDLINEWS(finder)); + do { + if (ENDLINEWS(finder)) finder += 2; //after endline information continues + while (!ENDLINE(finder) && !EOS(finder)) finder++; + } while (ENDLINEWS(finder)); - if (Item != nullptr) - { - if (nullptr==(Item->Next=new struct CMimeItem)) + if (Item != nullptr) { + if (nullptr == (Item->Next = new struct CMimeItem)) break; - Item=Item->Next; + Item = Item->Next; } - else - { + else { Item = new CMimeItem; *head = Item; } - Item->Next=nullptr; - Item->name=new char [prev2-prev1+1]; - mir_strncpy(Item->name,prev1,prev2-prev1+1); - Item->value=new char [finder-prev3+1]; - mir_strncpy(Item->value,prev3,finder-prev3+1); + Item->Next = nullptr; + Item->name = new char[prev2 - prev1 + 1]; + mir_strncpy(Item->name, prev1, prev2 - prev1 + 1); + Item->value = new char[finder - prev3 + 1]; + mir_strncpy(Item->value, prev3, finder - prev3 + 1); if (EOS(finder)) break; @@ -427,68 +413,61 @@ void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head) finder++; if (ENDLINE(finder))finder++; prev1 = finder; - while (!DOTLINE(finder+1))finder++; + while (!DOTLINE(finder + 1))finder++; if (ENDLINE(finder))finder--; prev2 = finder; - if (prev2>prev1) { // yes, we have body - if (nullptr==(Item->Next=new struct CMimeItem)) break; // Cant create new item?! - Item=Item->Next; - Item->Next=nullptr;//just in case; - Item->name=new char[5]; strncpy(Item->name,"Body",5); - Item->value=new char [prev2-prev1]; - mir_strncpy(Item->value,prev1,prev2-prev1-1); + if (prev2 > prev1) { // yes, we have body + if (nullptr == (Item->Next = new struct CMimeItem)) break; // Cant create new item?! + Item = Item->Next; + Item->Next = nullptr;//just in case; + Item->name = new char[5]; strncpy(Item->name, "Body", 5); + Item->value = new char[prev2 - prev1]; + mir_strncpy(Item->value, prev1, prev2 - prev1 - 1); } break; // there is nothing else } } } } - catch(...) - { - MessageBoxA(nullptr,"Translate header error","",0); + catch (...) { + MessageBoxA(nullptr, "Translate header error", "", 0); } } HYAMNMAIL WINAPI CreateNewDeleteQueueFcn(HYAMNMAIL From) { - HYAMNMAIL FirstMail,Browser = nullptr; + HYAMNMAIL FirstMail, Browser = nullptr; - for (FirstMail=nullptr;From != nullptr;From=From->Next) - { - if ((From->Flags & (YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE)) && !(From->Flags & YAMN_MSG_DELETED)) - { - if (FirstMail==nullptr) - { - FirstMail=Browser=new YAMNMAIL; - if (FirstMail==nullptr) + for (FirstMail = nullptr; From != nullptr; From = From->Next) { + if ((From->Flags & (YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE)) && !(From->Flags & YAMN_MSG_DELETED)) { + if (FirstMail == nullptr) { + FirstMail = Browser = new YAMNMAIL; + if (FirstMail == nullptr) break; } - else - { - Browser->Next=new YAMNMAIL; - Browser=Browser->Next; + else { + Browser->Next = new YAMNMAIL; + Browser = Browser->Next; } - Browser->ID=new char[mir_strlen(From->ID)+1]; - mir_strcpy(Browser->ID,From->ID); - Browser->Number=From->Number; - Browser->Flags=From->Flags; + Browser->ID = new char[mir_strlen(From->ID) + 1]; + mir_strcpy(Browser->ID, From->ID); + Browser->Number = From->Number; + Browser->Flags = From->Flags; } } return FirstMail; } -void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,uint32_t FlagsSet,uint32_t FlagsNotSet,uint32_t FlagsToSetRemove,int mode) +void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From, uint32_t FlagsSet, uint32_t FlagsNotSet, uint32_t FlagsToSetRemove, int mode) { HYAMNMAIL msgq; - for (msgq=(HYAMNMAIL)From;msgq != nullptr;msgq=msgq->Next) - { - if ((FlagsSet==(msgq->Flags & FlagsSet)) && (0==(msgq->Flags & FlagsNotSet))) - { + for (msgq = (HYAMNMAIL)From; msgq != nullptr; msgq = msgq->Next) { + if ((FlagsSet == (msgq->Flags & FlagsSet)) && (0 == (msgq->Flags & FlagsNotSet))) { if (mode) - msgq->Flags=msgq->Flags | FlagsToSetRemove; + msgq->Flags = msgq->Flags | FlagsToSetRemove; else - msgq->Flags=msgq->Flags & ~FlagsToSetRemove; + msgq->Flags = msgq->Flags & ~FlagsToSetRemove; } } } diff --git a/protocols/YAMN/src/mails/mime.cpp b/protocols/YAMN/src/mails/mime.cpp index 54f8e66943..69099af808 100644 --- a/protocols/YAMN/src/mails/mime.cpp +++ b/protocols/YAMN/src/mails/mime.cpp @@ -114,8 +114,7 @@ void ExtractAddressFromLine(char *finder, char **storeto, char **storetonick) if (ENDLINEWS(finderend)) //after endline information continues finderend += 2; while (!ENDLINE(finderend) && !EOS(finderend)) finderend++; //seek to the end of line or to the end of string - } - while (ENDLINEWS(finderend)); + } while (ENDLINEWS(finderend)); finderend--; while (WS(finderend) || ENDLINE(finderend)) finderend--; //find the end of text, no whitespace if (*finderend != '>') //not '>' at the end of line @@ -139,8 +138,7 @@ void ExtractAddressFromLine(char *finder, char **storeto, char **storetonick) if (ENDLINEWS(finderend)) //after endline information continues finderend += 2; while (!ENDLINE(finderend) && (*finderend != '>') && !EOS(finderend)) finderend++; //seek to the matching < or to the end of line or to the end of string - } - while (ENDLINEWS(finderend)); + } while (ENDLINEWS(finderend)); CopyToHeader(finder, finderend + 1, storeto, MIME_MAIL); //go to first '>' or to the end and copy finder = finderend + 1; while (WS(finder)) finder++; //parse whitespace @@ -167,8 +165,7 @@ void ExtractStringFromLine(char *finder, char **storeto) do { if (ENDLINEWS(finderend)) finderend++; //after endline information continues while (!ENDLINE(finderend) && !EOS(finderend)) finderend++; - } - while (ENDLINEWS(finderend)); + } while (ENDLINEWS(finderend)); finderend--; while (WS(finderend)) finderend--; //find the end of line, no whitespace CopyToHeader(finder, finderend + 1, storeto, MIME_PLAIN); @@ -220,70 +217,70 @@ void ExtractShortHeader(struct CMimeItem *items, struct CShortHeader *head) if (0 == _strnicmp(items->name, "From", 4)) { if (items->value == nullptr) continue; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting from>"); - #endif + #endif ExtractAddressFromLine(items->value, &head->From, &head->FromNick); - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif } else if (0 == _strnicmp(items->name, "Return-Path", 11)) { if (items->value == nullptr) continue; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting return-path>"); - #endif + #endif ExtractAddressFromLine(items->value, &head->ReturnPath, &head->ReturnPathNick); - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif } else if (0 == _strnicmp(items->name, "Subject", 7)) { if (items->value == nullptr) continue; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting subject>"); - #endif + #endif ExtractStringFromLine(items->value, &head->Subject); - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif } else if (0 == _strnicmp(items->name, "Body", 4)) { if (items->value == nullptr) continue; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting body>"); - #endif + #endif ExtractStringFromLine(items->value, &head->Body); - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif } else if (0 == _strnicmp(items->name, "Date", 4)) { if (items->value == nullptr) continue; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting date>"); - #endif + #endif ExtractStringFromLine(items->value, &head->Date); - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif } else if (0 == _strnicmp(items->name, "Content-Type", 12)) { if (items->value == nullptr) continue; char *ContentType = nullptr, *CharSetStr; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting Content-Type>"); - #endif + #endif ExtractStringFromLine(items->value, &ContentType); - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif ToLower(ContentType); if (nullptr != (CharSetStr = ExtractFromContentType(ContentType, "charset="))) { head->CP = GetCharsetFromString(CharSetStr, mir_strlen(CharSetStr)); @@ -294,9 +291,9 @@ void ExtractShortHeader(struct CMimeItem *items, struct CShortHeader *head) else if (0 == _strnicmp(items->name, "Importance", 10)) { if (items->value == nullptr) continue; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting importance>"); - #endif + #endif if (head->Priority != -1) { if (0 == strncmp(items->value, "low", 3)) head->Priority = 5; @@ -305,21 +302,21 @@ void ExtractShortHeader(struct CMimeItem *items, struct CShortHeader *head) else if (0 == strncmp(items->value, "high", 4)) head->Priority = 1; } - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif } else if (0 == _strnicmp(items->name, "X-Priority", 10)) { if (items->value == nullptr) continue; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<X-Priority>"); - #endif + #endif if ((*items->value >= '1') && (*items->value <= '5')) head->Priority = *items->value - '0'; - #ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Extracting>\n"); - #endif + #endif } } @@ -331,14 +328,14 @@ void ExtractHeader(struct CMimeItem *items, int &CP, struct CHeader *head) memset(&ShortHeader, 0, sizeof(struct CShortHeader)); ShortHeader.Priority = ShortHeader.CP = -1; -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "<Extracting header>\n"); -#endif + #endif ExtractShortHeader(items, &ShortHeader); head->Priority = ShortHeader.Priority == -1 ? 3 : ShortHeader.Priority; CP = ShortHeader.CP == -1 ? CP : ShortHeader.CP; -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != ShortHeader.From) DebugLog(DecodeFile, "<Decoded from>%s</Decoded)\n", ShortHeader.From); if (NULL != ShortHeader.FromNick) @@ -353,49 +350,49 @@ void ExtractHeader(struct CMimeItem *items, int &CP, struct CHeader *head) DebugLog(DecodeFile, "<Decoded date>%s</Decoded)\n", ShortHeader.Date); DebugLog(DecodeFile, "</Extracting header>\n"); DebugLog(DecodeFile, "<Convert>\n"); -#endif + #endif ConvertCodedStringToUnicode(ShortHeader.From, &head->From, CP, MIME_PLAIN); -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != head->From) DebugLogW(DecodeFile, L"<Converted from>%s</Converted>\n", head->From); -#endif + #endif ConvertCodedStringToUnicode(ShortHeader.FromNick, &head->FromNick, CP, MIME_MAIL); -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != head->FromNick) DebugLogW(DecodeFile, L"<Converted from-nick>%s</Converted>\n", head->FromNick); -#endif + #endif ConvertCodedStringToUnicode(ShortHeader.ReturnPath, &head->ReturnPath, CP, MIME_PLAIN); -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != head->ReturnPath) DebugLogW(DecodeFile, L"<Converted return-path>%s</Converted>\n", head->ReturnPath); -#endif + #endif ConvertCodedStringToUnicode(ShortHeader.ReturnPathNick, &head->ReturnPathNick, CP, MIME_MAIL); -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != head->ReturnPathNick) DebugLogW(DecodeFile, L"<Converted return-path nick>%s</Converted>\n", head->ReturnPathNick); -#endif + #endif ConvertCodedStringToUnicode(ShortHeader.Subject, &head->Subject, CP, MIME_PLAIN); -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != head->Subject) DebugLogW(DecodeFile, L"<Converted subject>%s</Converted>\n", head->Subject); -#endif + #endif ConvertCodedStringToUnicode(ShortHeader.Date, &head->Date, CP, MIME_PLAIN); -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != head->Date) DebugLogW(DecodeFile, L"<Converted date>%s</Converted>\n", head->Date); -#endif + #endif ConvertCodedStringToUnicode(ShortHeader.Body, &head->Body, CP, MIME_PLAIN); -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE if (NULL != head->Body) DebugLogW(DecodeFile, L"<Converted Body>%s</Converted>\n", head->Body); -#endif + #endif -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</Convert>\n"); -#endif + #endif DeleteShortHeaderContent(&ShortHeader); @@ -440,7 +437,7 @@ void DeleteNames(CMimeNames *Names) delete[] Parser->Value; if (Parser->ValueNick != nullptr) delete[] Parser->ValueNick; - + CMimeNames *Old = Parser; Parser = Parser->Next; delete Old; @@ -455,7 +452,7 @@ void DeleteShortNames(CShortNames *Names) delete[] Parser->Value; if (Parser->ValueNick != nullptr) delete[] Parser->ValueNick; - + CShortNames *Old = Parser; Parser = Parser->Next; delete Old; @@ -521,8 +518,7 @@ void ParseAPart(APartDataType *data) do { if (ENDLINEWS(finder)) finder += 2; //after endline information continues while (!ENDLINE(finder) && !EOS(finder)) finder++; - } - while (ENDLINEWS(finder)); + } while (ENDLINEWS(finder)); if (!_strnicmp(prev1, "Content-type", prev2 - prev1)) { data->ContType = prev3; @@ -579,7 +575,7 @@ wchar_t *ParseMultipartBody(char *src, char *bond) wchar_t *dest; for (; (courbond = strstr(courbond, bond)); numparts++, courbond += sizebond); APartDataType *partData = new APartDataType[numparts]; - memset(partData, 0, sizeof(APartDataType)*numparts); + memset(partData, 0, sizeof(APartDataType) * numparts); partData[0].Src = courbond = srcback; for (i = 1; (courbond = strstr(courbond, bond)); i++, courbond += sizebond) { *(courbond - 2) = 0; |