diff options
-rw-r--r-- | protocols/YAMN/res/YAMN.rc | 12 | ||||
-rw-r--r-- | protocols/YAMN/src/account.cpp | 604 | ||||
-rw-r--r-- | protocols/YAMN/src/browser/badconnect.cpp | 62 | ||||
-rw-r--r-- | protocols/YAMN/src/browser/mailbrowser.cpp | 258 | ||||
-rw-r--r-- | protocols/YAMN/src/debug.cpp | 18 | ||||
-rw-r--r-- | protocols/YAMN/src/debug.h | 1 | ||||
-rw-r--r-- | protocols/YAMN/src/filterplugin.cpp | 167 | ||||
-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 | ||||
-rw-r--r-- | protocols/YAMN/src/main.cpp | 23 | ||||
-rw-r--r-- | protocols/YAMN/src/proto/netlib.cpp | 7 | ||||
-rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3.cpp | 95 | ||||
-rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3comm.cpp | 221 | ||||
-rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3opt.cpp | 10 | ||||
-rw-r--r-- | protocols/YAMN/src/protoplugin.cpp | 134 | ||||
-rw-r--r-- | protocols/YAMN/src/resource.h | 6 | ||||
-rw-r--r-- | protocols/YAMN/src/services.cpp | 62 | ||||
-rw-r--r-- | protocols/YAMN/src/synchro.cpp | 274 | ||||
-rw-r--r-- | protocols/YAMN/src/yamn.cpp | 162 |
20 files changed, 1117 insertions, 1933 deletions
diff --git a/protocols/YAMN/res/YAMN.rc b/protocols/YAMN/res/YAMN.rc index 52a7aa6a0f..1268b0dc8a 100644 --- a/protocols/YAMN/res/YAMN.rc +++ b/protocols/YAMN/res/YAMN.rc @@ -143,17 +143,17 @@ BEGIN GROUPBOX "Account",IDC_STATIC,4,22,151,120 LTEXT "Name:",IDC_STATIC,10,34,44,10 EDITTEXT IDC_EDITNAME,56,32,92,12,ES_AUTOHSCROLL - LTEXT "Server:",IDC_STSERVER,10,50,44,8 + LTEXT "Server:",IDC_STATIC,10,50,44,8 EDITTEXT IDC_EDITSERVER,56,48,92,12,ES_AUTOHSCROLL | WS_GROUP - LTEXT "Port:",IDC_STPORT,10,65,44,8,SS_CENTERIMAGE + LTEXT "Port:",IDC_STATIC,10,65,44,8,SS_CENTERIMAGE EDITTEXT IDC_EDITPORT,57,64,27,12,ES_AUTOHSCROLL | ES_NUMBER | WS_GROUP CONTROL "SSL",IDC_CHECKSSL,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,87,66,27,10 CONTROL "APOP",IDC_CHECKAPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,119,66,34,10 - LTEXT "User Name:",IDC_STLOGIN,10,82,44,8 + LTEXT "User Name:",IDC_STATIC,10,82,44,8 EDITTEXT IDC_EDITLOGIN,57,80,92,12,ES_AUTOHSCROLL | WS_GROUP - LTEXT "Password:",IDC_STPASS,10,96,44,8 + LTEXT "Password:",IDC_STATIC,10,96,44,8 EDITTEXT IDC_EDITPASS,57,94,92,12,ES_PASSWORD | ES_AUTOHSCROLL | WS_GROUP - LTEXT "Codepage:",IDC_STCP,10,111,44,8 + LTEXT "Codepage:",IDC_STATIC,10,111,44,8 COMBOBOX IDC_COMBOCP,57,108,92,130,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "Default",IDC_BTNDEFAULT,9,124,54,13 CONTROL "Disable STLS",IDC_CHECKNOTLS,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,83,125,69,10 @@ -162,7 +162,7 @@ BEGIN GROUPBOX "Options",IDC_STATIC,161,22,147,120 CONTROL "Check this account",IDC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,167,32,118,10,WS_EX_TRANSPARENT CONTROL "Startup check",IDC_CHECKSTART,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,167,43,78,10 - LTEXT "Check interval [min]:",IDC_STINTERVAL,168,56,94,8 + LTEXT "Check interval [min]:",IDC_STATIC,168,56,94,8 EDITTEXT IDC_EDITINTERVAL,259,53,20,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_TRANSPARENT PUSHBUTTON "Only check when...",IDC_BTNSTATUS,195,69,81,13 CONTROL "Auto retrieve body",IDC_AUTOBODY,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,166,86,137,10 diff --git a/protocols/YAMN/src/account.cpp b/protocols/YAMN/src/account.cpp index 9749462f24..91b57ad544 100644 --- a/protocols/YAMN/src/account.cpp +++ b/protocols/YAMN/src/account.cpp @@ -8,9 +8,9 @@ #include "stdafx.h" -// Account status CS -// When we check some account, thread should change status of account to idle, connecting etc. -// So if we want to read status, we have to successfully write and then read. + // Account status CS + // When we check some account, thread should change status of account to idle, connecting etc. + // So if we want to read status, we have to successfully write and then read. static mir_cs csAccountStatusCS; // File Writing CS @@ -19,19 +19,19 @@ static mir_cs csFileWritingCS; struct CExportedFunctions AccountExportedFcn[] = { - { YAMN_GETSTATUSID, (void *)GetStatusFcn }, - { YAMN_SETSTATUSID, (void *)SetStatusFcn }, + {YAMN_GETSTATUSID, (void *)GetStatusFcn}, + {YAMN_SETSTATUSID, (void *)SetStatusFcn}, }; struct CExportedServices AccountExportedSvc[] = { - { MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc }, - { MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc }, - { MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc }, - { MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc }, - { MS_YAMN_DELETEACCOUNT, DeletePluginAccountSvc }, - { MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc }, - { MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc }, + {MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc}, + {MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc}, + {MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc}, + {MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc}, + {MS_YAMN_DELETEACCOUNT, DeletePluginAccountSvc}, + {MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc}, + {MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc}, }; //-------------------------------------------------------------------------------------------------- @@ -46,8 +46,7 @@ INT_PTR CreatePluginAccountSvc(WPARAM wParam, LPARAM lParam) if (AccountVersion != YAMN_ACCOUNTVERSION) return NULL; - if (Plugin != nullptr) - { + if (Plugin != nullptr) { CAccount *NewAccount; if (Plugin->Fcn->NewAccountFcnPtr != nullptr) //Let plugin create its own structure, which can be derived from CAccount structure @@ -59,7 +58,7 @@ INT_PTR CreatePluginAccountSvc(WPARAM wParam, LPARAM lParam) //If not created successfully if (NewAccount == nullptr) return NULL; - + NewAccount->Plugin = Plugin; //Init every members of structure, used by YAMN InitAccount(NewAccount); @@ -73,20 +72,14 @@ INT_PTR DeletePluginAccountSvc(WPARAM wParam, LPARAM) { CAccount *OldAccount = (CAccount *)wParam; - if (OldAccount->Plugin->Fcn != nullptr) - { - //Deinit every members and allocated fields of structure used by YAMN + if (OldAccount->Plugin->Fcn != nullptr) { + // Deinit every members and allocated fields of structure used by YAMN DeInitAccount(OldAccount); - if (OldAccount->Plugin->Fcn->DeleteAccountFcnPtr != nullptr) - { - //Let plugin delete its own CAccount derived structure + if (OldAccount->Plugin->Fcn->DeleteAccountFcnPtr != nullptr) { + // Let plugin delete its own CAccount derived structure OldAccount->Plugin->Fcn->DeleteAccountFcnPtr(OldAccount); } - else - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeletePluginAccountSvc:delete OldAccount\n"); -#endif + else { delete OldAccount; //consider account as standard YAMN CAccount *and use its own destructor } return 1; @@ -115,7 +108,7 @@ int InitAccount(CAccount *Which) Which->Mails = nullptr; Which->Interval = 0; Which->Flags = 0; - Which->StatusFlags = 0; + Which->StatusFlags = YAMN_ACC_ST1 + YAMN_ACC_ST7; Which->Next = nullptr; Which->Server = new struct CServer; @@ -150,9 +143,6 @@ void DeInitAccount(CAccount *Which) void StopSignalFcn(CAccount *Which) //set event that we are going to delete account { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tStopSignalFcn:stop account: %x\n",Which); -#endif Which->AbleToWork = FALSE; //do not use synchronizing objects anymore //any access to these objects then ends with WAIT_FAILED @@ -167,8 +157,7 @@ void CodeDecodeString(char *Dest, BOOL Encrypt) if (Dest == nullptr) return; - for (; *Dest != (wchar_t)0; Dest++) - { + for (; *Dest != (wchar_t)0; Dest++) { if (Encrypt) *Dest = *Dest + Code; else @@ -186,15 +175,13 @@ static uint32_t PostFileToMemory(HANDLE File, char **MemFile, char **End) } //allocate space in memory, where we copy the whole file - if (nullptr == (*MemFile = new char[FileSize])) - { + if (nullptr == (*MemFile = new char[FileSize])) { CloseHandle(File); return EACC_ALLOC; } //copy file to memory - if (!ReadFile(File, (LPVOID)*MemFile, FileSize, &ReadBytes, nullptr)) - { + if (!ReadFile(File, (LPVOID)*MemFile, FileSize, &ReadBytes, nullptr)) { CloseHandle(File); delete[] * MemFile; return EACC_SYSTEM; @@ -214,30 +201,28 @@ uint32_t FileToMemory(wchar_t *FileName, char **MemFile, char **End) } #if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) -uint32_t ReadStringFromMemory(char **Parser,wchar_t *End,char **StoreTo,wchar_t *DebugString) +uint32_t ReadStringFromMemory(char **Parser, wchar_t *End, char **StoreTo, wchar_t *DebugString) { //This is the debug version of ReadStringFromMemory function. This version shows MessageBox where //read string is displayed - wchar_t *Dest,*Finder; + wchar_t *Dest, *Finder; uint32_t Size; wchar_t Debug[65536]; - Finder=*Parser; - while((*Finder != (wchar_t)0) && (Finder<=End)) Finder++; - mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder-*Parser, End-Finder); - MessageBox(NULL,Debug,L"debug",MB_OK); - if (Finder>=End) + Finder = *Parser; + while ((*Finder != (wchar_t)0) && (Finder <= End)) Finder++; + mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder - *Parser, End - Finder); + MessageBox(NULL, Debug, L"debug", MB_OK); + if (Finder >= End) return EACC_FILECOMPATIBILITY; - if (Size=Finder-*Parser) - { - if (NULL==(Dest=*StoreTo=new wchar_t[Size+1])) + if (Size = Finder - *Parser) { + if (NULL == (Dest = *StoreTo = new wchar_t[Size + 1])) return EACC_ALLOC; - for (;*Parser<=Finder;(*Parser)++,Dest++) - *Dest=**Parser; + for (; *Parser <= Finder; (*Parser)++, Dest++) + *Dest = **Parser; } - else - { - *StoreTo=NULL; + else { + *StoreTo = NULL; (*Parser)++; } return 0; @@ -253,15 +238,13 @@ uint32_t ReadStringFromMemory(char **Parser, char *End, char **StoreTo) while ((*Finder != (wchar_t)0) && (Finder <= End)) Finder++; if (Finder >= End) return EACC_FILECOMPATIBILITY; - if (Size = Finder - *Parser) - { + if (Size = Finder - *Parser) { if (nullptr == (Dest = *StoreTo = new char[Size + 1])) return EACC_ALLOC; for (; *Parser <= Finder; (*Parser)++, Dest++) *Dest = **Parser; } - else - { + else { *StoreTo = nullptr; (*Parser)++; } @@ -269,30 +252,28 @@ uint32_t ReadStringFromMemory(char **Parser, char *End, char **StoreTo) } #if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) -uint32_t ReadStringFromMemoryW(wchar_t **Parser,wchar_t *End,wchar_t **StoreTo,wchar_t *DebugString) +uint32_t ReadStringFromMemoryW(wchar_t **Parser, wchar_t *End, wchar_t **StoreTo, wchar_t *DebugString) { //This is the debug version of ReadStringFromMemoryW function. This version shows MessageBox where //read string is displayed - wchar_t *Dest,*Finder; + wchar_t *Dest, *Finder; uint32_t Size; wchar_t Debug[65536]; - Finder=*Parser; - while((*Finder != (wchar_t)0) && (Finder<=(wchar_t *)End)) Finder++; - mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder-*Parser, (wchar_t *)End-Finder); - MessageBoxW(NULL,Debug,L"debug",MB_OK); - if (Finder>=(wchar_t *)End) + Finder = *Parser; + while ((*Finder != (wchar_t)0) && (Finder <= (wchar_t *)End)) Finder++; + mir_snwprintf(Debug, L"%s: %s,length is %d, remaining %d chars", DebugString, *Parser, Finder - *Parser, (wchar_t *)End - Finder); + MessageBoxW(NULL, Debug, L"debug", MB_OK); + if (Finder >= (wchar_t *)End) return EACC_FILECOMPATIBILITY; - if (Size=Finder-*Parser) - { - if (NULL==(Dest=*StoreTo=new wchar_t[Size+1])) + if (Size = Finder - *Parser) { + if (NULL == (Dest = *StoreTo = new wchar_t[Size + 1])) return EACC_ALLOC; - for (;*Parser<=Finder;(*Parser)++,Dest++) - *Dest=**Parser; + for (; *Parser <= Finder; (*Parser)++, Dest++) + *Dest = **Parser; } - else - { - *StoreTo=NULL; + else { + *StoreTo = NULL; (*Parser)++; } return 0; @@ -308,15 +289,13 @@ uint32_t ReadStringFromMemoryW(wchar_t **Parser, wchar_t *End, wchar_t **StoreTo while ((*Finder != (wchar_t)0) && (Finder <= (wchar_t *)End)) Finder++; if (Finder >= (wchar_t *)End) return EACC_FILECOMPATIBILITY; - if (Size = Finder - *Parser) - { + if (Size = Finder - *Parser) { if (nullptr == (Dest = *StoreTo = new wchar_t[Size + 1])) return EACC_ALLOC; for (; *Parser <= Finder; (*Parser)++, Dest++) *Dest = **Parser; } - else - { + else { *StoreTo = nullptr; (*Parser)++; } @@ -326,55 +305,55 @@ uint32_t ReadStringFromMemoryW(wchar_t **Parser, wchar_t *End, wchar_t **StoreTo static uint32_t ReadNotificationFromMemory(char **Parser, char *End, YAMN_NOTIFICATION *Which) { uint32_t Stat; -#ifdef DEBUG_FILEREAD + #ifdef DEBUG_FILEREAD wchar_t Debug[65536]; -#endif + #endif Which->Flags = *(uint32_t *)(*Parser); (*Parser) += sizeof(uint32_t); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"NFlags: %04x, remaining %d chars", Which->Flags, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"NFlags: %04x, remaining %d chars", Which->Flags, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif Which->PopupB = *(COLORREF *)(*Parser); (*Parser) += sizeof(COLORREF); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"PopupB: %04x, remaining %d chars", Which->PopupB, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"PopupB: %04x, remaining %d chars", Which->PopupB, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif Which->PopupT = *(COLORREF *)(*Parser); (*Parser) += sizeof(COLORREF); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"PopupT: %04x, remaining %d chars", Which->PopupT, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"PopupT: %04x, remaining %d chars", Which->PopupT, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif Which->PopupTime = *(uint32_t *)(*Parser); (*Parser) += sizeof(uint32_t); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"PopupTime: %04x, remaining %d chars", Which->PopupTime, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif - -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemoryW((wchar_t **)Parser,(wchar_t*)End,&Which->App,L"App")) -#else - if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t*)End, &Which->App)) -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"PopupTime: %04x, remaining %d chars", Which->PopupTime, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif + + #ifdef DEBUG_FILEREAD + if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->App, L"App")) + #else + if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->App)) + #endif return Stat; -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemoryW((wchar_t **)Parser,(wchar_t*)End,&Which->AppParam,L"AppParam")) -#else - if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t*)End, &Which->AppParam)) -#endif + #ifdef DEBUG_FILEREAD + if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->AppParam, L"AppParam")) + #else + if (Stat = ReadStringFromMemoryW((wchar_t **)Parser, (wchar_t *)End, &Which->AppParam)) + #endif return Stat; return 0; } @@ -387,35 +366,32 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End) struct CMimeItem *items; char *ReadString; -#ifdef DEBUG_FILEREAD - MessageBox(NULL,L"going to read messages, if any...",L"debug",MB_OK); -#endif - do - { + #ifdef DEBUG_FILEREAD + MessageBox(NULL, L"going to read messages, if any...", L"debug", MB_OK); + #endif + do { Finder = *Parser; while ((*Finder != (wchar_t)0) && (Finder <= End)) Finder++; if (Finder >= End) return EACC_FILECOMPATIBILITY; - if (Size = Finder - *Parser) - { + if (Size = Finder - *Parser) { if (Which->Mails == nullptr) //First message in queue { if (nullptr == (Which->Mails = ActualMail = CreateAccountMail(Which))) return EACC_ALLOC; } - else - { + else { if (nullptr == (ActualMail->Next = CreateAccountMail(Which))) { return EACC_ALLOC; } ActualMail = ActualMail->Next; } items = nullptr; -#ifdef DEBUG_FILEREADMESSAGES - if (Stat=ReadStringFromMemory(Parser,End,&ActualMail->ID,L"ID")) -#else + #ifdef DEBUG_FILEREADMESSAGES + if (Stat = ReadStringFromMemory(Parser, End, &ActualMail->ID, L"ID")) + #else if (Stat = ReadStringFromMemory(Parser, End, &ActualMail->ID)) -#endif + #endif return Stat; // ActualMail->MailData=new MAILDATA; !!! mem leake !!! this is alloc by CreateAccountMail, no need for doubble alloc !!!! @@ -435,25 +411,23 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End) if ((nullptr != Which->Plugin->MailFcn) && (nullptr != Which->Plugin->MailFcn->ReadMailOptsFcnPtr)) Which->Plugin->MailFcn->ReadMailOptsFcnPtr(ActualMail, Parser, End); //read plugin mail settings from file - do - { -#if defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_FILEREAD) - if (Stat=ReadStringFromMemory(Parser,End,&ReadString,L"Name")) -#else + do { + #if defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_FILEREAD) + if (Stat = ReadStringFromMemory(Parser, End, &ReadString, L"Name")) + #else if (Stat = ReadStringFromMemory(Parser, End, &ReadString)) -#endif + #endif return Stat; if (ReadString == nullptr) break; -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"<read name>%s</read name>",ReadString); -#endif + #ifdef DEBUG_DECODE + DebugLog(DecodeFile, "<read name>%s</read name>", ReadString); + #endif if (items == nullptr) items = ActualMail->MailData->TranslatedHeader = new struct CMimeItem; - else - { + else { items->Next = new struct CMimeItem; items = items->Next; } @@ -461,16 +435,16 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End) return EACC_ALLOC; items->name = ReadString; -#ifdef DEBUG_FILEREADMESSAGES - if (Stat=ReadStringFromMemory(Parser,End,&ReadString,L"Value")) -#else + #ifdef DEBUG_FILEREADMESSAGES + if (Stat = ReadStringFromMemory(Parser, End, &ReadString, L"Value")) + #else if (Stat = ReadStringFromMemory(Parser, End, &ReadString)) -#endif + #endif return Stat; items->value = ReadString; -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"<read value>%s</read value>\n",ReadString); -#endif + #ifdef DEBUG_DECODE + DebugLog(DecodeFile, "<read value>%s</read value>\n", ReadString); + #endif } while (1); } else @@ -484,46 +458,46 @@ uint32_t ReadMessagesFromMemory(CAccount *Which, char **Parser, char *End) uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End) { uint32_t Stat; -#ifdef DEBUG_FILEREAD + #ifdef DEBUG_FILEREAD wchar_t Debug[65536]; -#endif + #endif //Read name of account -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Name,L"Name")) -#else + #ifdef DEBUG_FILEREAD + if (Stat = ReadStringFromMemory(Parser, End, &Which->Name, L"Name")) + #else if (Stat = ReadStringFromMemory(Parser, End, &Which->Name)) -#endif + #endif return Stat; if (Which->Name == nullptr) return EACC_FILECOMPATIBILITY; //Read server parameters -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Name,L"Server")) -#else + #ifdef DEBUG_FILEREAD + if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Name, L"Server")) + #else if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Name)) -#endif + #endif return Stat; Which->Server->Port = *(uint16_t *)(*Parser); (*Parser) += sizeof(uint16_t); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"Port: %d, remaining %d chars", Which->Server->Port, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Login,L"Login")) -#else + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"Port: %d, remaining %d chars", Which->Server->Port, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif + #ifdef DEBUG_FILEREAD + if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Login, L"Login")) + #else if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Login)) -#endif + #endif return Stat; -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Passwd,L"Password")) -#else + #ifdef DEBUG_FILEREAD + if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Passwd, L"Password")) + #else if (Stat = ReadStringFromMemory(Parser, End, &Which->Server->Passwd)) -#endif + #endif return Stat; CodeDecodeString(Which->Server->Passwd, FALSE); @@ -532,22 +506,22 @@ uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End) (*Parser) += sizeof(uint32_t); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"Flags: %04x, remaining %d chars", Which->Flags, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"Flags: %04x, remaining %d chars", Which->Flags, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif Which->StatusFlags = *(uint32_t *)(*Parser); (*Parser) += sizeof(uint32_t); -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"STFlags: %04x, remaining %d chars", Which->StatusFlags, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"STFlags: %04x, remaining %d chars", Which->StatusFlags, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif Which->PluginFlags = *(uint32_t *)(*Parser); (*Parser) += sizeof(uint32_t); -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"PFlags: %04x, remaining %d chars", Which->PluginFlags, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"PFlags: %04x, remaining %d chars", Which->PluginFlags, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif //Read account miscellaneous parameters Which->Interval = *(uint16_t *)(*Parser); @@ -555,10 +529,10 @@ uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End) (*Parser) += sizeof(uint16_t); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"Interval: %d, remaining %d chars", Which->Interval, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + #ifdef DEBUG_FILEREAD + mir_snwprintf(Debug, L"Interval: %d, remaining %d chars", Which->Interval, End - *Parser); + MessageBox(NULL, Debug, L"debug", MB_OK); + #endif //Read notification parameters if (Stat = ReadNotificationFromMemory(Parser, End, &Which->NewMailN)) @@ -572,162 +546,108 @@ uint32_t ReadAccountFromMemory(CAccount *Which, char **Parser, char *End) if (Which->Plugin->Fcn != nullptr && Which->Plugin->Fcn->ReadPluginOptsFcnPtr != nullptr) if (Stat = Which->Plugin->Fcn->ReadPluginOptsFcnPtr(Which, Parser, End)) return Stat; - //Read mails -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write wait\n"); -#endif + + // Read mails WaitToWriteFcn(Which->MessagesAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write enter\n"); -#endif - if (Stat = ReadMessagesFromMemory(Which, Parser, End)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n"); -#endif + + if (Stat = ReadMessagesFromMemory(Which, Parser, End)) { WriteDoneFcn(Which->MessagesAccessSO); return Stat; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n"); -#endif + WriteDoneFcn(Which->MessagesAccessSO); - //Read timestamps + // Read timestamps Which->LastChecked = *(SYSTEMTIME *)(*Parser); (*Parser) += sizeof(SYSTEMTIME); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"LastChecked: %04x, remaining %d chars", Which->LastChecked, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + Which->LastSChecked = *(SYSTEMTIME *)(*Parser); (*Parser) += sizeof(SYSTEMTIME); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"LastSChecked: %04x, remaining %d chars", Which->LastSChecked, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + Which->LastSynchronised = *(SYSTEMTIME *)(*Parser); (*Parser) += sizeof(SYSTEMTIME); if (*Parser >= End) return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"LastSynchronised: %04x, remaining %d chars", Which->LastSynchronised, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + Which->LastMail = *(SYSTEMTIME *)(*Parser); (*Parser) += sizeof(SYSTEMTIME); if (*Parser > End) //WARNING! There's only > at the end of testing return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - mir_snwprintf(Debug, L"LastMail: %04x, remaining %d chars", Which->LastMail, End-*Parser); - MessageBox(NULL,Debug,L"debug",MB_OK); -#endif + if (*Parser == End) return EACC_ENDOFFILE; return 0; - } static INT_PTR PerformAccountReading(HYAMNPROTOPLUGIN Plugin, char *MemFile, char *End) { - //Retrieve info for account from memory + // Retrieve info for account from memory char *Parser; uint32_t Ver, Stat; CAccount *ActualAccount, *FirstAllocatedAccount; Ver = *(uint32_t *)MemFile; - if (Ver > YAMN_ACCOUNTFILEVERSION) - { + if (Ver > YAMN_ACCOUNTFILEVERSION) { delete[] MemFile; return EACC_FILEVERSION; } Parser = MemFile + sizeof(Ver); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write wait\n"); -#endif SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write enter\n"); -#endif - if (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION))) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); -#endif + + if (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION))) { SWMRGDoneWriting(Plugin->AccountBrowserSO); delete[] MemFile; return EACC_ALLOC; } + FirstAllocatedAccount = ActualAccount; - do - { + do { CAccount *Temp; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write wait\n"); -#endif WaitToWriteFcn(ActualAccount->AccountAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write enter\n"); -#endif Stat = ReadAccountFromMemory(ActualAccount, &Parser, End); if (ActualAccount->StatusFlags & (YAMN_ACC_STARTA | YAMN_ACC_STARTS)) ActualAccount->TimeLeft = 1; //check on loading - if (Stat && (Stat != EACC_ENDOFFILE)) - { - for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp) - { + if (Stat && (Stat != EACC_ENDOFFILE)) { + for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp) { Temp = ActualAccount->Next; delete ActualAccount; } delete[] MemFile; if (Plugin->FirstAccount == FirstAllocatedAccount) Plugin->FirstAccount = nullptr; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n"); -#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); return (INT_PTR)Stat; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n"); -#endif WriteDoneFcn(ActualAccount->AccountAccessSO); - if ((Stat != EACC_ENDOFFILE) && (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION)))) - { - for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp) - { + if ((Stat != EACC_ENDOFFILE) && (nullptr == (ActualAccount = (CAccount *)CallService(MS_YAMN_GETNEXTFREEACCOUNT, (WPARAM)Plugin, (LPARAM)YAMN_ACCOUNTVERSION)))) { + for (ActualAccount = FirstAllocatedAccount; ActualAccount != nullptr; ActualAccount = Temp) { Temp = ActualAccount->Next; delete ActualAccount; } delete[] MemFile; if (Plugin->FirstAccount == FirstAllocatedAccount) Plugin->FirstAccount = nullptr; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); -#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); return EACC_ALLOC; } } while (Stat != EACC_ENDOFFILE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); -#endif SWMRGDoneWriting(Plugin->AccountBrowserSO); delete[] MemFile; - return 0; } @@ -735,7 +655,7 @@ static INT_PTR PerformAccountReading(HYAMNPROTOPLUGIN Plugin, char *MemFile, cha INT_PTR AddAccountsFromFileSvc(WPARAM wParam, LPARAM lParam) { char *MemFile, *End; - uint32_t Stat = FileToMemory((wchar_t*)lParam, &MemFile, &End); + uint32_t Stat = FileToMemory((wchar_t *)lParam, &MemFile, &End); if (Stat != NO_ERROR) return (INT_PTR)Stat; @@ -765,15 +685,13 @@ uint32_t WriteStringToFileW(HANDLE File, wchar_t *Source) DWORD Length, WrittenBytes; wchar_t null = (wchar_t)0; - if ((Source == nullptr) || !(Length = (uint32_t)mir_wstrlen(Source))) - { - if (!WriteFile(File, &null, sizeof(wchar_t), &WrittenBytes, nullptr)) - { + if ((Source == nullptr) || !(Length = (uint32_t)mir_wstrlen(Source))) { + if (!WriteFile(File, &null, sizeof(wchar_t), &WrittenBytes, nullptr)) { CloseHandle(File); return EACC_SYSTEM; } } - else if (!WriteFile(File, Source, (Length + 1)*sizeof(wchar_t), &WrittenBytes, nullptr)) + else if (!WriteFile(File, Source, (Length + 1) * sizeof(wchar_t), &WrittenBytes, nullptr)) return EACC_SYSTEM; return 0; } @@ -784,19 +702,17 @@ DWORD WriteMessagesToFile(HANDLE File, CAccount *Which) HYAMNMAIL ActualMail = (HYAMNMAIL)Which->Mails; struct CMimeItem *items; - while (ActualMail != nullptr) - { + while (ActualMail != nullptr) { if (Stat = WriteStringToFile(File, ActualMail->ID)) return Stat; - + if (!WriteFile(File, (char *)&ActualMail->MailData->Size, sizeof(ActualMail->MailData->Size), &WrittenBytes, nullptr) || !WriteFile(File, (char *)&ActualMail->Flags, sizeof(ActualMail->Flags), &WrittenBytes, nullptr) || !WriteFile(File, (char *)&ActualMail->Number, sizeof(ActualMail->Number), &WrittenBytes, nullptr)) return EACC_SYSTEM; if ((nullptr != Which->Plugin->MailFcn) && (nullptr != Which->Plugin->MailFcn->WriteMailOptsFcnPtr)) Which->Plugin->MailFcn->WriteMailOptsFcnPtr(File, ActualMail); //write plugin mail options to file - for (items = ActualMail->MailData->TranslatedHeader; items != nullptr; items = items->Next) - { + for (items = ActualMail->MailData->TranslatedHeader; items != nullptr; items = items->Next) { if (Stat = WriteStringToFile(File, items->name)) return Stat; if (Stat = WriteStringToFile(File, items->value)) @@ -819,45 +735,27 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File) BOOL Writed = FALSE; uint32_t ReturnValue = 0, EnterCode; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read wait\n"); -#endif SWMRGWaitToRead(Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read enter\n"); -#endif - try - { - for (ActualAccount = Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait\n"); -#endif + + try { + for (ActualAccount = Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next) { EnterCode = WaitToReadFcn(ActualAccount->AccountAccessSO); if (EnterCode == WAIT_FINISH) //account is about to delete { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait failed\n"); -#endif ActualAccount = ActualAccount->Next; continue; } if (EnterCode == WAIT_FAILED) //account is deleted break; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read enter\n"); -#endif - if ((ActualAccount->Name == nullptr) || (*ActualAccount->Name == (wchar_t)0)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); -#endif + + if ((ActualAccount->Name == nullptr) || (*ActualAccount->Name == (wchar_t)0)) { ReadDoneFcn(ActualAccount->AccountAccessSO); continue; } if (!Writed && !WriteFile(File, &Ver, sizeof(Ver), &WrittenBytes, nullptr)) throw (uint32_t)EACC_SYSTEM; + Writed = TRUE; if (Stat = WriteStringToFile(File, ActualAccount->Name)) @@ -874,8 +772,7 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File) CodeDecodeString(ActualAccount->Server->Passwd, TRUE); - if (Stat = WriteStringToFile(File, ActualAccount->Server->Passwd)) - { + if (Stat = WriteStringToFile(File, ActualAccount->Server->Passwd)) { CodeDecodeString(ActualAccount->Server->Passwd, FALSE); throw (uint32_t)Stat; } @@ -923,24 +820,15 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File) if (ActualAccount->Plugin->Fcn != nullptr && ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr != nullptr) if (Stat = ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr(File, ActualAccount)) throw (uint32_t)Stat; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read wait\n"); -#endif + WaitToReadFcn(ActualAccount->MessagesAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read enter\n"); -#endif - if (Stat = WriteMessagesToFile(File, ActualAccount)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); -#endif + + if (Stat = WriteMessagesToFile(File, ActualAccount)) { + ReadDoneFcn(ActualAccount->MessagesAccessSO); throw (uint32_t)Stat; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); -#endif + ReadDoneFcn(ActualAccount->MessagesAccessSO); if ((!WriteFile(File, (char *)&ActualAccount->LastChecked, sizeof(SYSTEMTIME), &WrittenBytes, nullptr)) || @@ -949,23 +837,14 @@ static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin, HANDLE File) (!WriteFile(File, (char *)&ActualAccount->LastMail, sizeof(SYSTEMTIME), &WrittenBytes, nullptr))) throw (uint32_t)Stat; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); -#endif ReadDoneFcn(ActualAccount->AccountAccessSO); } } - catch (uint32_t ErrorCode) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); -#endif + catch (uint32_t ErrorCode) { ReadDoneFcn(ActualAccount->AccountAccessSO); ReturnValue = ErrorCode; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read done\n"); -#endif + SWMRGDoneReading(Plugin->AccountBrowserSO); CloseHandle(File); return 0; @@ -977,7 +856,7 @@ INT_PTR WriteAccountsToFileSvc(WPARAM wParam, LPARAM lParam) HYAMNPROTOPLUGIN Plugin = (HYAMNPROTOPLUGIN)wParam; mir_cslock lck(csFileWritingCS); - HANDLE hFile = CreateFile((wchar_t*)lParam, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE hFile = CreateFile((wchar_t *)lParam, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) return EACC_SYSTEM; @@ -990,19 +869,12 @@ INT_PTR FindAccountByNameSvc(WPARAM wParam, LPARAM lParam) char *SearchedAccount = (char *)lParam; CAccount *Finder; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read wait\n"); -#endif SWMRGWaitToRead(Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read enter\n"); -#endif + for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) if ((Finder->Name != nullptr) && (0 == mir_strcmp(SearchedAccount, Finder->Name))) break; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read done\n"); -#endif + SWMRGDoneReading(Plugin->AccountBrowserSO); return (INT_PTR)Finder; } @@ -1012,8 +884,7 @@ INT_PTR GetNextFreeAccountSvc(WPARAM wParam, LPARAM lParam) HYAMNPROTOPLUGIN Plugin = (HYAMNPROTOPLUGIN)wParam; CAccount *Finder; - if (Plugin->FirstAccount == nullptr) - { + if (Plugin->FirstAccount == nullptr) { Plugin->FirstAccount = (CAccount *)CallService(MS_YAMN_CREATEPLUGINACCOUNT, wParam, lParam); return (INT_PTR)Plugin->FirstAccount; } @@ -1022,18 +893,6 @@ INT_PTR GetNextFreeAccountSvc(WPARAM wParam, LPARAM lParam) return (INT_PTR)Finder->Next; } -/* -int FindPluginAccount(WPARAM wParam,LPARAM lParam) -{ -HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; -CAccount *Finder=(CAccount *)lParam; - -if (Finder=NULL) Finder=Plugin->FirstAccount; - -// for (;Finder != NULL && Finder->PluginID != Plugin->PluginInfo->PluginID;Finder=(CAccount *)Finder->Next); -return (int)Finder; -} -*/ INT_PTR DeleteAccountSvc(WPARAM wParam, LPARAM lParam) { //Deleting account works on these steps: @@ -1072,37 +931,23 @@ INT_PTR DeleteAccountSvc(WPARAM wParam, LPARAM lParam) Plugin->Fcn->StopAccountFcnPtr(Which); //2. wait to get write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write wait\n"); -#endif SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write enter\n"); -#endif //3. remove from queue (chained list) - if (Plugin->FirstAccount == nullptr) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n"); -#endif + if (Plugin->FirstAccount == nullptr) { SWMRGDoneWriting(Plugin->AccountBrowserSO); return 0; } - if (Plugin->FirstAccount == Which) - { + if (Plugin->FirstAccount == Which) { Finder = Plugin->FirstAccount->Next; Plugin->FirstAccount = Finder; } - else - { + else { for (Finder = Plugin->FirstAccount; Which != Finder->Next; Finder = Finder->Next); Finder->Next = Finder->Next->Next; } + //leave write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n"); -#endif SWMRGDoneWriting(Plugin->AccountBrowserSO); //4. wait while event "UsingThread" is not signaled @@ -1113,7 +958,7 @@ INT_PTR DeleteAccountSvc(WPARAM wParam, LPARAM lParam) if ((Plugin->Fcn != nullptr) && (Plugin->Fcn->WriteAccountsFcnPtr != nullptr)) Plugin->Fcn->WriteAccountsFcnPtr(); - CloseHandle(mir_forkthread(DeleteAccountInBackground, (void*)Which)); + CloseHandle(mir_forkthread(DeleteAccountInBackground, (void *)Which)); //Now, plugin can consider account as deleted, but plugin really can achieve deleting this account from memory when using //event UsingThreads. @@ -1132,15 +977,9 @@ int StopAccounts(HYAMNPROTOPLUGIN Plugin) CAccount *Finder; //1. wait to get write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write wait\n"); -#endif SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write enter\n"); -#endif - for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) - { + + for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) { //2. set stop signal StopSignalFcn(Finder); WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_STOPACCOUNT, (WPARAM)Finder, 0); @@ -1149,9 +988,6 @@ int StopAccounts(HYAMNPROTOPLUGIN Plugin) } //leave write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write done\n"); -#endif SWMRGDoneWriting(Plugin->AccountBrowserSO); //Now, account is stopped. It can be removed from memory... @@ -1160,37 +996,17 @@ int StopAccounts(HYAMNPROTOPLUGIN Plugin) int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin, BOOL GetAccountBrowserAccess) { - CAccount *Finder; - - if (GetAccountBrowserAccess) - { + if (GetAccountBrowserAccess) { //1. wait to get write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write wait\n"); -#endif SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write enter\n"); -#endif } - for (Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) - { + for (CAccount *Finder = Plugin->FirstAccount; Finder != nullptr; Finder = Finder->Next) { //2. wait for signal that account is not in use -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:waiting for UsingThreadEV %x (account %x)\n",Finder->UsingThreads,Finder); -#endif WaitForSingleObject(Finder->UsingThreads->Event, INFINITE); SetEvent(Finder->UsingThreads->Event); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:UsingThreadEV signaled\n"); -#endif } - if (GetAccountBrowserAccess) - { + if (GetAccountBrowserAccess) { //leave write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write done\n"); -#endif SWMRGDoneWriting(Plugin->AccountBrowserSO); } @@ -1199,30 +1015,18 @@ int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin, BOOL GetAccountBrowserAccess) int DeleteAccounts(HYAMNPROTOPLUGIN Plugin) { - CAccount *Finder; - //1. wait to get write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write wait\n"); -#endif SWMRGWaitToWrite(Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write enter\n"); -#endif WaitForAllAccounts(Plugin, FALSE); - for (Finder = Plugin->FirstAccount; Finder != nullptr;) - { + for (CAccount *Finder = Plugin->FirstAccount; Finder != nullptr;) { CAccount *Next = Finder->Next; DeletePluginAccountSvc((WPARAM)Finder, 0); Finder = Next; } //leave write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write done\n"); -#endif SWMRGDoneWriting(Plugin->AccountBrowserSO); return 1; } diff --git a/protocols/YAMN/src/browser/badconnect.cpp b/protocols/YAMN/src/browser/badconnect.cpp index d69de06986..fe060e20bf 100644 --- a/protocols/YAMN/src/browser/badconnect.cpp +++ b/protocols/YAMN/src/browser/badconnect.cpp @@ -9,7 +9,7 @@ #define BADCONNECTTITLE LPGEN("%s - connection error") #define BADCONNECTMSG LPGEN("An error occurred. Error code: %d")//is in use? - //-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- LRESULT CALLBACK BadConnectPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -22,13 +22,8 @@ LRESULT CALLBACK BadConnectPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM memset(&si, 0, sizeof(si)); si.cb = sizeof(si); CAccount *ActualAccount = (CAccount *)PUGetPluginData(hWnd); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read wait\n"); -#endif + if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read enter\n"); -#endif if (ActualAccount->BadConnectN.App != nullptr) { wchar_t *Command; if (ActualAccount->BadConnectN.AppParam != nullptr) @@ -46,15 +41,10 @@ LRESULT CALLBACK BadConnectPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM delete[] Command; } } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read done\n"); -#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); } -#ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); -#endif + PUDeletePopup(hWnd); } break; @@ -81,25 +71,17 @@ INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg, UINT msg, WPARAM wParam, LP BOOL ShowPopup, ShowMsg, ShowIco; CAccount *ActualAccount; uint32_t ErrorCode; - char* TitleStrA; + char *TitleStrA; char *Message1A = nullptr; wchar_t *Message1W = nullptr; POPUPDATAW BadConnectPopup = {}; ActualAccount = ((struct BadConnectionParam *)lParam)->account; ErrorCode = ((struct BadConnectionParam *)lParam)->errcode; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read wait failed\n"); -#endif + + if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) return FALSE; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read enter\n"); -#endif + int size = (int)(mir_strlen(ActualAccount->Name) + mir_strlen(Translate(BADCONNECTTITLE))); TitleStrA = new char[size]; mir_snprintf(TitleStrA, size, Translate(BADCONNECTTITLE), ActualAccount->Name); @@ -143,9 +125,7 @@ INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg, UINT msg, WPARAM wParam, LP if (!ShowMsg && !ShowIco) DestroyWindow(hDlg); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read done\n"); -#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); SetWindowTextA(hDlg, TitleStrA); @@ -210,9 +190,7 @@ void __cdecl BadConnection(void *Param) struct BadConnectionParam MyParam = *(struct BadConnectionParam *)Param; ActualAccount = MyParam.account; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:Incrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); -#endif + SCIncFcn(ActualAccount->UsingThreads); // we will not use params in stack anymore @@ -222,18 +200,9 @@ void __cdecl BadConnection(void *Param) hBadConnect = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DLGBADCONNECT), nullptr, DlgProcYAMNBadConnection, (LPARAM)&MyParam); Window_SetIcon_IcoLib(hBadConnect, g_plugin.getIconHandle(IDI_BADCONNECT)); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read wait failed\n"); -#endif + if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) return; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read enter\n"); -#endif + if (ActualAccount->BadConnectN.Flags & YAMN_ACC_SND) Skin_PlaySound(YAMN_CONNECTFAILSOUND); @@ -251,9 +220,6 @@ void __cdecl BadConnection(void *Param) Shell_NotifyIcon(NIM_ADD, &nid); } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:ActualAccountSO-read done\n"); -#endif ReadDoneFcn(ActualAccount->AccountAccessSO); UpdateWindow(hBadConnect); @@ -267,14 +233,10 @@ void __cdecl BadConnection(void *Param) ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr(); } __finally { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "BadConnect:Decrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); -#endif SCDecFcn(ActualAccount->UsingThreads); } } - INT_PTR RunBadConnectionSvc(WPARAM wParam, LPARAM lParam) { // an event for successfull copy parameters to which point a pointer in stack for new thread diff --git a/protocols/YAMN/src/browser/mailbrowser.cpp b/protocols/YAMN/src/browser/mailbrowser.cpp index 55d6ef9655..1d62ad00dc 100644 --- a/protocols/YAMN/src/browser/mailbrowser.cpp +++ b/protocols/YAMN/src/browser/mailbrowser.cpp @@ -21,7 +21,7 @@ void __cdecl ShowEmailThread(void *Param); //-------------------------------------------------------------------------------------------------- -char* s_MonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +char *s_MonthNames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; bool bDate = false, bSub = false, bSize = false, bFrom = false; int PosX = 0, PosY = 0, SizeX = 460, SizeY = 100; int HeadSizeX = 0x2b2, HeadSizeY = 0x0b5, HeadPosX = 100, HeadPosY = 100; @@ -284,31 +284,31 @@ void IncrementMailCounters(HYAMNMAIL msgq, struct CMailNumbers *MN) MN->Virtual.SysTrayUC++; else MN->Real.SysTrayUC++; - /* if (msgq->MailData->Flags & YAMN_MSG_SOUND) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.Sound++; - else - MN->Real.Sound++; - */ if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_SOUND)) == (YAMN_MSG_NEW | YAMN_MSG_SOUND)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.SoundNC++; - else - MN->Real.SoundNC++; - /* if (msgq->MailData->Flags & YAMN_MSG_APP) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.App++; - else - MN->Real.App++; - */ if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_APP)) == (YAMN_MSG_NEW | YAMN_MSG_APP)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.AppNC++; - else - MN->Real.AppNC++; - if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_NEVENT)) == (YAMN_MSG_NEW | YAMN_MSG_NEVENT)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.EventNC++; - else - MN->Real.EventNC++; + /* if (msgq->MailData->Flags & YAMN_MSG_SOUND) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.Sound++; + else + MN->Real.Sound++; + */ if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_SOUND)) == (YAMN_MSG_NEW | YAMN_MSG_SOUND)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.SoundNC++; + else + MN->Real.SoundNC++; + /* if (msgq->MailData->Flags & YAMN_MSG_APP) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.App++; + else + MN->Real.App++; + */ if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_APP)) == (YAMN_MSG_NEW | YAMN_MSG_APP)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.AppNC++; + else + MN->Real.AppNC++; + if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_NEVENT)) == (YAMN_MSG_NEW | YAMN_MSG_NEVENT)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.EventNC++; + else + MN->Real.EventNC++; } int UpdateMails(HWND hDlg, CAccount *ActualAccount, uint32_t nflags, uint32_t nnflags) @@ -320,37 +320,16 @@ int UpdateMails(HWND hDlg, CAccount *ActualAccount, uint32_t nflags, uint32_t nn struct CMailWinUserInfo *mwui = (struct CMailWinUserInfo *)GetWindowLongPtr(hDlg, DWLP_USER); //now we ensure read access for account and write access for its mails -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:ActualAccountSO-read wait failed\n"); -#endif PostMessage(hDlg, WM_DESTROY, 0, 0); - return UPDATE_FAIL; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:ActualAccountSO-read enter\n"); -#endif -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:ActualAccountMsgsSO-write wait\n"); -#endif if (WAIT_OBJECT_0 != WaitToWriteFcn(ActualAccount->MessagesAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:ActualAccountMsgsSO-write wait failed\n"); - DebugLog(SynchroFile, "UpdateMails:ActualAccountSO-read done\n"); -#endif ReadDoneFcn(ActualAccount->AccountAccessSO); - PostMessage(hDlg, WM_DESTROY, 0, 0); return UPDATE_FAIL; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:ActualAccountMsgsSO-write enter\n"); -#endif memset(&MN, 0, sizeof(MN)); @@ -377,7 +356,7 @@ int UpdateMails(HWND hDlg, CAccount *ActualAccount, uint32_t nflags, uint32_t nn //If popups will be displayed or mailbrowser window if ((((mwui != nullptr) && !(mwui->RunFirstTime)) && ( - ((nnflags & YAMN_ACC_MSGP) && !(MN.Real.BrowserUC + MN.Virtual.BrowserUC)) || + ((nnflags & YAMN_ACC_MSGP) && !(MN.Real.BrowserUC + MN.Virtual.BrowserUC)) || ((nflags & YAMN_ACC_MSGP) && (MN.Real.BrowserUC + MN.Virtual.BrowserUC)) ) ) || //if mail window was displayed before and flag YAMN_ACC_MSGP is set @@ -411,16 +390,8 @@ int UpdateMails(HWND hDlg, CAccount *ActualAccount, uint32_t nflags, uint32_t nn delete[] TitleStrW; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:Do mail actions\n"); -#endif - DoMailActions(hDlg, ActualAccount, &MN, nflags, nnflags); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:Do mail actions done\n"); -#endif - SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails, YAMN_MSG_NEW, 0, YAMN_MSG_NEW, YAMN_FLAG_REMOVE); //rempve the new flag if (!RunMailBrowser) SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails, YAMN_MSG_UNSEEN, YAMN_MSG_STAYUNSEEN, YAMN_MSG_UNSEEN, YAMN_FLAG_REMOVE); //remove the unseen flag when it was not displayed and it has not "stay unseen" flag set @@ -429,10 +400,7 @@ int UpdateMails(HWND hDlg, CAccount *ActualAccount, uint32_t nflags, uint32_t nn mwui->UpdateMailsMessagesAccess = FALSE; mwui->RunFirstTime = FALSE; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UpdateMails:ActualAccountMsgsSO-write done\n"); - DebugLog(SynchroFile, "UpdateMails:ActualAccountSO-read done\n"); -#endif + WriteDoneFcn(ActualAccount->MessagesAccessSO); ReadDoneFcn(ActualAccount->AccountAccessSO); @@ -565,7 +533,7 @@ int AddNewMailsToListView(HWND hListView, CAccount *ActualAccount, uint32_t nfla item.iItem = SendMessage(hListView, LVM_INSERTITEM, 0, (LPARAM)&item); item.iSubItem = 1; - item.pszText = (nullptr != UnicodeHeader.Subject ? UnicodeHeader.Subject : (wchar_t*)L""); + item.pszText = (nullptr != UnicodeHeader.Subject ? UnicodeHeader.Subject : (wchar_t *)L""); SendMessage(hListView, LVM_SETITEMTEXT, (WPARAM)item.iItem, (LPARAM)&item); item.iSubItem = 2; @@ -810,37 +778,22 @@ LRESULT CALLBACK NewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa Account = (CAccount *)CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); db_free(&dbv); } - else - Account = (CAccount *)hContact; //???? - + else Account = (CAccount *)hContact; //???? -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 == WaitToReadFcn(Account->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read enter\n"); -#endif switch (msg) { case WM_COMMAND: { - YAMN_MAILBROWSERPARAM Param = { (HANDLE)nullptr, Account, + YAMN_MAILBROWSERPARAM Param = {(HANDLE)nullptr, Account, (Account->NewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG, - (Account->NoNewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG }; + (Account->NoNewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG}; RunMailBrowserSvc((WPARAM)&Param, (LPARAM)YAMN_MAILBROWSERVERSION); } break; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read done\n"); -#endif ReadDoneFcn(Account->AccountAccessSO); } -#ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); -#endif } if ((Account->NewMailN.Flags & YAMN_ACC_CONT) && !(Account->NewMailN.Flags & YAMN_ACC_CONTNOEVENT)) g_clistApi.pfnRemoveEvent(hContact, hContact); @@ -906,17 +859,11 @@ LRESULT CALLBACK NoNewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l else ActualAccount = (CAccount *)hContact; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read enter\n"); -#endif switch (msg) { case WM_COMMAND: { - YAMN_MAILBROWSERPARAM Param = { (HANDLE)nullptr, ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr }; + YAMN_MAILBROWSERPARAM Param = {(HANDLE)nullptr, ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr}; Param.nnflags = Param.nnflags | YAMN_ACC_MSG; //show mails in account even no new mail in account Param.nnflags = Param.nnflags & ~YAMN_ACC_POP; @@ -928,15 +875,8 @@ LRESULT CALLBACK NoNewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l } break; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read done\n"); -#endif ReadDoneFcn(ActualAccount->AccountAccessSO); } -#ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "PopupProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); -#endif PUDeletePopup(hWnd); } break; @@ -975,16 +915,6 @@ LRESULT CALLBACK NoNewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l DestroyWindow(hWnd); return 0; } - case WM_NOTIFY: - /* switch(((LPNMHDR)lParam)->code) - { - case NM_CLICK: - { - } - } - break; - */ default: - break; } return DefWindowProc(hWnd, msg, wParam, lParam); } @@ -1057,7 +987,7 @@ ULONGLONG MimeDateToFileTime(char *datein) int ismin = atoi(smin); smin[0] = 0; int ishour = atoi(shift); - wShiftSeconds = (ishour * 60 + (ishour < 0 ? -1 : 1)*ismin) * 60; + wShiftSeconds = (ishour * 60 + (ishour < 0 ? -1 : 1) * ismin) * 60; } } } // if (datein) @@ -1086,7 +1016,7 @@ void FileTimeToLocalizedDateTime(LONGLONG filetime, wchar_t *dateout, int lendat SYSTEMTIME st; uint16_t wTodayYear = 0, wTodayMonth = 0, wTodayDay = 0; FILETIME ft; - BOOL willShowDate = !(optDateTime&SHOWDATENOTODAY); + BOOL willShowDate = !(optDateTime & SHOWDATENOTODAY); if (!willShowDate) { GetLocalTime(&st); wTodayYear = st.wYear; @@ -1110,11 +1040,11 @@ void FileTimeToLocalizedDateTime(LONGLONG filetime, wchar_t *dateout, int lendat int templen = 0; if (!willShowDate) willShowDate = (wTodayYear != st.wYear) || (wTodayMonth != st.wMonth) || (wTodayDay != st.wDay); if (willShowDate) { - templen = GetDateFormatW(localeID, (optDateTime&SHOWDATELONG) ? DATE_LONGDATE : DATE_SHORTDATE, &st, nullptr, dateout, lendateout - 2); + templen = GetDateFormatW(localeID, (optDateTime & SHOWDATELONG) ? DATE_LONGDATE : DATE_SHORTDATE, &st, nullptr, dateout, lendateout - 2); dateout[templen - 1] = ' '; } if (templen < (lendateout - 1)) { - GetTimeFormatW(localeID, (optDateTime&SHOWDATENOSECONDS) ? TIME_NOSECONDS : 0, &st, nullptr, &dateout[templen], lendateout - templen - 1); + GetTimeFormatW(localeID, (optDateTime & SHOWDATENOSECONDS) ? TIME_NOSECONDS : 0, &st, nullptr, &dateout[templen], lendateout - templen - 1); } } } @@ -1132,8 +1062,8 @@ int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSo return 0; int nResult = 0; - char *str1; - char *str2; + char *str1; + char *str2; HYAMNMAIL email1 = (HYAMNMAIL)lParam1; HYAMNMAIL email2 = (HYAMNMAIL)lParam2; struct CShortHeader Header1; @@ -1274,8 +1204,8 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR iValueW = new wchar_t[StrLen + 1]; MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, Translate("Value"), -1, iValueW, StrLen); - LVCOLUMN lvc0 = { LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, 130, iHeaderW, 0, 0 }; - LVCOLUMN lvc1 = { LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, 400, iValueW, 0, 0 }; + LVCOLUMN lvc0 = {LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, 130, iHeaderW, 0, 0}; + LVCOLUMN lvc1 = {LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, 400, iValueW, 0, 0}; SendMessage(hListView, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc0); SendMessage(hListView, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc1); if (nullptr != iHeaderW) @@ -1306,7 +1236,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR for (Header = MailParam->mail->MailData->TranslatedHeader; Header != nullptr; Header = Header->Next) { wchar_t *str1 = nullptr; wchar_t *str2 = nullptr; - wchar_t str_nul[2] = { 0 }; + wchar_t str_nul[2] = {0}; if (!body) if (!_stricmp(Header->name, "Body")) { body = Header->value; continue; } if (!contentType) if (!_stricmp(Header->name, "Content-Type")) contentType = Header->value; if (!transEncoding) if (!_stricmp(Header->name, "Content-Transfer-Encoding")) transEncoding = Header->value; @@ -1334,7 +1264,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR (str2[ofs] == 0x09) || (str2[ofs] == 0x0A) || (str2[ofs] == 0x0D))count++; ofs++; } - split = new wchar_t*[count + 1]; + split = new wchar_t *[count + 1]; count = 0; ofs = 0; split[0] = str2; while (str2[ofs]) { @@ -1414,7 +1344,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR MailParam->mail->Flags &= ~YAMN_MSG_UNSEEN; //mark the message as seen HWND hMailBrowser = WindowList_Find(YAMNVar.NewMailAccountWnd, (UINT_PTR)MailParam->account); if (hMailBrowser) { - struct CChangeContent Params = { MailParam->account->NewMailN.Flags | YAMN_ACC_MSGP, MailParam->account->NoNewMailN.Flags | YAMN_ACC_MSGP }; + struct CChangeContent Params = {MailParam->account->NewMailN.Flags | YAMN_ACC_MSGP, MailParam->account->NoNewMailN.Flags | YAMN_ACC_MSGP}; SendMessage(hMailBrowser, WM_YAMN_CHANGECONTENT, (WPARAM)MailParam->account, (LPARAM)&Params); } else UpdateMails(nullptr, MailParam->account, MailParam->account->NewMailN.Flags, MailParam->account->NoNewMailN.Flags); @@ -1451,9 +1381,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR break; if ((CAccount *)wParam != MailParam->account) break; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ShowMessage:STOPACCOUNT:sending destroy msg\n"); -#endif + DestroyWindow(hDlg); } return 1; @@ -1513,7 +1441,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR BOOL isBodyShown = ((PYAMN_MAILSHOWPARAM)(GetWindowLongPtr(hDlg, DWLP_USER)))->mail->Flags & YAMN_MSG_BODYRECEIVED; HeadSizeX = LOWORD(lParam); //((LPRECT)lParam)->right-((LPRECT)lParam)->left; HeadSizeY = HIWORD(lParam); //((LPRECT)lParam)->bottom-((LPRECT)lParam)->top; - int localSplitPos = (HeadSplitPos*HeadSizeY) / 1000; + int localSplitPos = (HeadSplitPos * HeadSizeY) / 1000; int localSizeX; RECT coord; MoveWindow(GetDlgItem(hDlg, IDC_SPLITTER), 5, localSplitPos, HeadSizeX - 10, 2, TRUE); @@ -1534,7 +1462,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR if (GetWindowLongPtr((HWND)wParam, GWLP_ID) == IDC_LISTHEADERS) { //MessageBox(0,"LISTHEADERS","Debug",0); HWND hList = GetDlgItem(hDlg, IDC_LISTHEADERS); - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + POINT pt = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; if (pt.x == -1) pt.x = 0; if (pt.y == -1) pt.y = 0; if (int numRows = ListView_GetItemCount(hList)) { @@ -1548,7 +1476,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR if (nReturnCmd > 0) { int courRow = 0; size_t sizeNeeded = 0; - wchar_t headname[64] = { 0 }, headvalue[256] = { 0 }; + wchar_t headname[64] = {0}, headvalue[256] = {0}; for (courRow = 0; courRow < numRows; courRow++) { if ((nReturnCmd == 1) && (ListView_GetItemState(hList, courRow, LVIS_SELECTED) == 0)) continue; ListView_GetItemText(hList, courRow, 0, headname, _countof(headname)); @@ -1560,7 +1488,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg, UINT msg, WPARAM wParam, LPAR if (sizeNeeded && OpenClipboard(hDlg)) { EmptyClipboard(); HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, (sizeNeeded + 1) * sizeof(wchar_t)); - wchar_t *buff = (wchar_t*)GlobalLock(hData); + wchar_t *buff = (wchar_t *)GlobalLock(hData); int courPos = 0; for (courRow = 0; courRow < numRows; courRow++) { if ((nReturnCmd == 1) && (ListView_GetItemState(hList, courRow, LVIS_SELECTED) == 0)) continue; @@ -1587,9 +1515,6 @@ void __cdecl ShowEmailThread(void *Param) { struct MailShowMsgWinParam MyParam = *(struct MailShowMsgWinParam *)Param; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ShowMessage:Incrementing \"using threads\" %x (account %x)\n", MyParam.account->UsingThreads, MyParam.account); -#endif SCIncFcn(MyParam.account->UsingThreads); if (MyParam.mail->MsgWindow) { @@ -1599,7 +1524,7 @@ void __cdecl ShowEmailThread(void *Param) MyParam.mail->MsgWindow = nullptr; goto CREADTEVIEWMESSAGEWINDOW; } - + if (IsIconic(MyParam.mail->MsgWindow)) OpenIcon(MyParam.mail->MsgWindow); } @@ -1617,11 +1542,9 @@ CREADTEVIEWMESSAGEWINDOW: WindowList_Remove(YAMNVar.MessageWnds, MyParam.mail->MsgWindow); MyParam.mail->MsgWindow = nullptr; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ShowMessage:Decrementing \"using threads\" %x (account %x)\n", MyParam.account->UsingThreads, MyParam.account); -#endif + SCDecFcn(MyParam.account->UsingThreads); - delete (struct MailShowMsgWinParam*)Param; + delete (struct MailShowMsgWinParam *)Param; } INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) @@ -1656,10 +1579,10 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR SetDlgItemText(hDlg, IDC_BTNCHECKALL, TranslateT("Select All")); SetDlgItemText(hDlg, IDC_BTNOK, TranslateT("OK")); - LVCOLUMN lvc0 = { LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, FromWidth, TranslateT("From"), 0, 0 }; - LVCOLUMN lvc1 = { LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, SubjectWidth, TranslateT("Subject"), 0, 0 }; - LVCOLUMN lvc2 = { LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, SizeWidth, TranslateT("Size"), 0, 0 }; - LVCOLUMN lvc3 = { LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, SizeDate, TranslateT("Date"), 0, 0 }; + LVCOLUMN lvc0 = {LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, FromWidth, TranslateT("From"), 0, 0}; + LVCOLUMN lvc1 = {LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, SubjectWidth, TranslateT("Subject"), 0, 0}; + LVCOLUMN lvc2 = {LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, SizeWidth, TranslateT("Size"), 0, 0}; + LVCOLUMN lvc3 = {LVCF_FMT | LVCF_TEXT | LVCF_WIDTH, LVCFMT_LEFT, SizeDate, TranslateT("Date"), 0, 0}; SendDlgItemMessage(hDlg, IDC_LISTMAILS, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc0); SendDlgItemMessage(hDlg, IDC_LISTMAILS, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc1); SendDlgItemMessage(hDlg, IDC_LISTMAILS, LVM_INSERTCOLUMN, (WPARAM)2, (LPARAM)&lvc2); @@ -1710,9 +1633,6 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR if (ListView_GetColumn(GetDlgItem(hDlg, IDC_LISTMAILS), 3, &ColInfo)) SizeDate = ColInfo.cx; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DESTROY:save window position\n"); -#endif if (!YAMNVar.Shutdown && GetWindowRect(hDlg, &coord)) //the YAMNVar.Shutdown testing is because M<iranda strange functionality at shutdown phase, when call to DBWriteContactSetting freezes calling thread { PosX = coord.left; @@ -1726,24 +1646,12 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR } KillTimer(hDlg, TIMER_FLASHING); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DESTROY:remove window from list\n"); -#endif WindowList_Remove(YAMNVar.NewMailAccountWnd, hDlg); WindowList_Remove(YAMNVar.MessageWnds, hDlg); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DESTROY:ActualAccountMsgsSO-write wait\n"); -#endif - if (WAIT_OBJECT_0 != WaitToWriteFcn(ActualAccount->MessagesAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DESTROY:ActualAccountMsgsSO-write wait failed\n"); -#endif + if (WAIT_OBJECT_0 != WaitToWriteFcn(ActualAccount->MessagesAccessSO)) break; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DESTROY:ActualAccountMsgsSO-write enter\n"); -#endif + //delete mails from queue, which are deleted from server (spam level 3 mails e.g.) for (Parser = (HYAMNMAIL)ActualAccount->Mails; Parser != nullptr; Parser = Parser->Next) { if ((Parser->Flags & YAMN_MSG_DELETED) && YAMN_MSG_SPAML(Parser->Flags, YAMN_MSG_SPAML3) && mwui->Seen) //if spaml3 was already deleted and user knows about it @@ -1756,9 +1664,7 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR //mark mails as read (remove "new" and "unseen" flags) if (mwui->Seen) SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails, YAMN_MSG_DISPLAY, 0, YAMN_MSG_NEW | YAMN_MSG_UNSEEN, 0); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DESTROY:ActualAccountMsgsSO-write done\n"); -#endif + WriteDoneFcn(ActualAccount->MessagesAccessSO); NOTIFYICONDATA nid; @@ -1808,24 +1714,14 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR UpdateParams.Flags = (struct CChangeContent *)lParam; UpdateParams.Waiting = !ThisThreadWindow; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:CHANGECONTENT:posting UPDATEMAILS\n"); -#endif if (ThisThreadWindow) { if (!UpdateMails(hDlg, (CAccount *)wParam, UpdateParams.Flags->nflags, UpdateParams.Flags->nnflags)) DestroyWindow(hDlg); } else if (PostMessage(hDlg, WM_YAMN_UPDATEMAILS, wParam, (LPARAM)&UpdateParams)) //this ensures UpdateMails will execute the thread who created the browser window { - if (!ThisThreadWindow) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:CHANGECONTENT:waiting for event\n"); -#endif + if (!ThisThreadWindow) WaitForSingleObject(UpdateParams.Copied, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:CHANGECONTENT:event signaled\n"); -#endif - } } CloseHandle(UpdateParams.Copied); @@ -1836,10 +1732,6 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR struct CUpdateMails *um = (struct CUpdateMails *)lParam; uint32_t nflags, nnflags; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:UPDATEMAILS\n"); -#endif - if (nullptr == (ActualAccount = GetWindowAccount(hDlg))) return 0; if ((CAccount *)wParam != ActualAccount) @@ -1869,27 +1761,16 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR switch (lParam) { case WM_LBUTTONDBLCLK: -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DBLCLICKICON:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DBLCLICKICON:ActualAccountSO-read wait failed\n"); -#endif return 0; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DBLCLICKICON:ActualAccountSO-read enter\n"); -#endif + if (ActualAccount->AbilityFlags & YAMN_ACC_BROWSE) { ShowWindow(hDlg, SW_SHOWNORMAL); SetForegroundWindow(hDlg); } - else - DestroyWindow(hDlg); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:DBLCLICKICON:ActualAccountSO-read done\n"); -#endif + else DestroyWindow(hDlg); + ReadDoneFcn(ActualAccount->AccountAccessSO); break; } @@ -2019,7 +1900,7 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR mir_snwprintf(DeleteMsg, TranslateT("Do you really want to delete %d selected mails?"), Total); if (IDOK == MessageBox(hDlg, DeleteMsg, TranslateT("Delete confirmation"), MB_OKCANCEL | MB_ICONWARNING)) { - struct DeleteParam ParamToDeleteMails = { YAMN_DELETEVERSION, ThreadRunningEV, ActualAccount, nullptr }; + struct DeleteParam ParamToDeleteMails = {YAMN_DELETEVERSION, ThreadRunningEV, ActualAccount, nullptr}; // Find if there's mail marked to delete, which was deleted before if (WAIT_OBJECT_0 == WaitToWriteFcn(ActualAccount->MessagesAccessSO)) { @@ -2102,11 +1983,8 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR case LVN_COLUMNCLICK: if (nullptr != (ActualAccount = GetWindowAccount(hDlg))) { - NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lParam; + NM_LISTVIEW *pNMListView = (NM_LISTVIEW *)lParam; if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "MailBrowser:COLUMNCLICK:ActualAccountSO-read enter\n"); -#endif switch ((int)pNMListView->iSubItem) { case 0: bFrom = !bFrom; @@ -2197,7 +2075,7 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR if (GetWindowLongPtr((HWND)wParam, GWLP_ID) == IDC_LISTMAILS) { //MessageBox(0,"LISTHEADERS","Debug",0); HWND hList = GetDlgItem(hDlg, IDC_LISTMAILS); - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + POINT pt = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; if (pt.x == -1) pt.x = 0; if (pt.y == -1) pt.y = 0; if (int numRows = ListView_GetItemCount(hList)) { @@ -2211,7 +2089,7 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR if (nReturnCmd > 0) { int courRow = 0; size_t sizeNeeded = 0; - wchar_t from[128] = { 0 }, subject[256] = { 0 }, size[16] = { 0 }, date[64] = { 0 }; + wchar_t from[128] = {0}, subject[256] = {0}, size[16] = {0}, date[64] = {0}; for (courRow = 0; courRow < numRows; courRow++) { if ((nReturnCmd == 1) && (ListView_GetItemState(hList, courRow, LVIS_SELECTED) == 0)) continue; ListView_GetItemText(hList, courRow, 0, from, _countof(from)); @@ -2325,7 +2203,7 @@ void __cdecl MailBrowser(void *Param) } if (hMailBrowser != nullptr) { - struct CChangeContent Params = { MyParam.nflags, MyParam.nnflags }; //if this thread created window, just post message to update mails + struct CChangeContent Params = {MyParam.nflags, MyParam.nnflags}; //if this thread created window, just post message to update mails SendMessage(hMailBrowser, WM_YAMN_CHANGECONTENT, (WPARAM)ActualAccount, (LPARAM)&Params); //we ensure this will do the thread who created the browser window } diff --git a/protocols/YAMN/src/debug.cpp b/protocols/YAMN/src/debug.cpp index 3ed7507c40..1fc41adc19 100644 --- a/protocols/YAMN/src/debug.cpp +++ b/protocols/YAMN/src/debug.cpp @@ -17,11 +17,6 @@ wchar_t DebugUserDirectory[MAX_PATH] = L"."; CRITICAL_SECTION FileAccessCS; -#ifdef DEBUG_SYNCHRO -wchar_t DebugSynchroFileName2[]=L"%s\\yamn-debug.synchro.log"; -HANDLE SynchroFile; -#endif - #ifdef DEBUG_COMM wchar_t DebugCommFileName2[]=L"%s\\yamn-debug.comm.log"; HANDLE CommFile; @@ -37,18 +32,11 @@ HANDLE DecodeFile; void InitDebug() { -#if defined (DEBUG_SYNCHRO) || defined (DEBUG_COMM) || defined (DEBUG_DECODE) +#if defined (DEBUG_COMM) || defined (DEBUG_DECODE) wchar_t DebugFileName[MAX_PATH]; #endif InitializeCriticalSection(&FileAccessCS); -#ifdef DEBUG_SYNCHRO - mir_snwprintf(DebugFileName, DebugSynchroFileName2, DebugUserDirectory); - - SynchroFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); - DebugLog(SynchroFile,"Synchro debug file created by %s\n",YAMN_VER); -#endif - #ifdef DEBUG_COMM mir_snwprintf(DebugFileName, DebugCommFileName2, DebugUserDirectory); @@ -67,10 +55,6 @@ void InitDebug() void UnInitDebug() { DeleteCriticalSection(&FileAccessCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"File is being closed normally."); - CloseHandle(SynchroFile); -#endif #ifdef DEBUG_COMM DebugLog(CommFile,"File is being closed normally."); CloseHandle(CommFile); diff --git a/protocols/YAMN/src/debug.h b/protocols/YAMN/src/debug.h index 0da7d79574..a13ac952b0 100644 --- a/protocols/YAMN/src/debug.h +++ b/protocols/YAMN/src/debug.h @@ -3,7 +3,6 @@ #ifdef _DEBUG -//#define DEBUG_SYNCHRO //debug synchro to a file //#define DEBUG_COMM //debug communiation to a file //#define DEBUG_DECODE //debug header decoding to a file //#define DEBUG_DECODECODEPAGE //add info about codepage used in conversion diff --git a/protocols/YAMN/src/filterplugin.cpp b/protocols/YAMN/src/filterplugin.cpp index c3660415e6..1d55f3a9c1 100644 --- a/protocols/YAMN/src/filterplugin.cpp +++ b/protocols/YAMN/src/filterplugin.cpp @@ -6,22 +6,22 @@ #include "stdafx.h" -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- -PYAMN_FILTERPLUGINQUEUE FirstFilterPlugin=nullptr; +PYAMN_FILTERPLUGINQUEUE FirstFilterPlugin = nullptr; -INT_PTR RegisterFilterPluginSvc(WPARAM,LPARAM); +INT_PTR RegisterFilterPluginSvc(WPARAM, LPARAM); //Removes plugin from queue and deletes its structures INT_PTR UnregisterFilterPlugin(HYAMNFILTERPLUGIN Plugin); -INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM lParam); +INT_PTR UnregisterFilterPluginSvc(WPARAM wParam, LPARAM lParam); //Removes all filter plugins INT_PTR UnregisterFilterPlugins(); -INT_PTR FilterMailSvc(WPARAM,LPARAM); +INT_PTR FilterMailSvc(WPARAM, LPARAM); //Sets imported functions for an plugin and therefore it starts plugin to be registered and running // Plugin- plugin, which wants to set its functions @@ -29,83 +29,71 @@ INT_PTR FilterMailSvc(WPARAM,LPARAM); // YAMNFilterFcn- pointer to imported functions // YAMNfilterFcnVer- version of YAMN_FILTERIMPORTFCN, use YAMN_FILTERIMPORTFCNVERSION // returns nonzero if success -int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,uint32_t Importance,PYAMN_FILTERIMPORTFCN YAMNFilterFcn,uint32_t YAMNFilterFcnVer); +int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin, uint32_t Importance, PYAMN_FILTERIMPORTFCN YAMNFilterFcn, uint32_t YAMNFilterFcnVer); -struct CExportedFunctions FilterPluginExportedFcn[]= +struct CExportedFunctions FilterPluginExportedFcn[] = { - {YAMN_SETFILTERPLUGINFCNIMPORTID,(void *)SetFilterPluginFcnImportFcn}, + {YAMN_SETFILTERPLUGINFCNIMPORTID, (void *)SetFilterPluginFcnImportFcn}, }; -struct CExportedServices FilterPluginExportedSvc[]= +struct CExportedServices FilterPluginExportedSvc[] = { - {MS_YAMN_REGISTERFILTERPLUGIN,RegisterFilterPluginSvc}, - {MS_YAMN_UNREGISTERFILTERPLUGIN,UnregisterFilterPluginSvc}, + {MS_YAMN_REGISTERFILTERPLUGIN, RegisterFilterPluginSvc}, + {MS_YAMN_UNREGISTERFILTERPLUGIN, UnregisterFilterPluginSvc}, }; //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- -INT_PTR RegisterFilterPluginSvc(WPARAM wParam,LPARAM lParam) +INT_PTR RegisterFilterPluginSvc(WPARAM wParam, LPARAM lParam) { - PYAMN_FILTERREGISTRATION Registration=(PYAMN_FILTERREGISTRATION)wParam; + PYAMN_FILTERREGISTRATION Registration = (PYAMN_FILTERREGISTRATION)wParam; HYAMNFILTERPLUGIN Plugin; if (lParam != YAMN_FILTERREGISTRATIONVERSION) return 0; - if ((Registration->Name==nullptr) || (Registration->Ver==nullptr)) + if ((Registration->Name == nullptr) || (Registration->Ver == nullptr)) return NULL; - if (nullptr==(Plugin=new YAMN_FILTERPLUGIN)) + if (nullptr == (Plugin = new YAMN_FILTERPLUGIN)) return NULL; - Plugin->PluginInfo=Registration; - - Plugin->FilterFcn=nullptr; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- new filter registered: %0x (%s) :::\n",Plugin,Registration->Name); -#endif + Plugin->PluginInfo = Registration; + Plugin->FilterFcn = nullptr; return (INT_PTR)Plugin; } INT_PTR UnregisterFilterPlugin(HYAMNFILTERPLUGIN Plugin) { - PYAMN_FILTERPLUGINQUEUE Parser,Found; + PYAMN_FILTERPLUGINQUEUE Parser, Found; - if (FirstFilterPlugin->Plugin==Plugin) - { - Found=FirstFilterPlugin; - FirstFilterPlugin=FirstFilterPlugin->Next; + if (FirstFilterPlugin->Plugin == Plugin) { + Found = FirstFilterPlugin; + FirstFilterPlugin = FirstFilterPlugin->Next; } - else - { - for (Parser=FirstFilterPlugin;(Parser->Next != nullptr) && (Plugin != Parser->Next->Plugin);Parser=Parser->Next); - if (Parser->Next != nullptr) - { - Found=Parser->Next; - Parser->Next=Parser->Next->Next; + else { + for (Parser = FirstFilterPlugin; (Parser->Next != nullptr) && (Plugin != Parser->Next->Plugin); Parser = Parser->Next); + if (Parser->Next != nullptr) { + Found = Parser->Next; + Parser->Next = Parser->Next->Next; } else - Found=nullptr; + Found = nullptr; } - if (Found != nullptr) - { + if (Found != nullptr) { if (Plugin->FilterFcn->UnLoadFcn != nullptr) Plugin->FilterFcn->UnLoadFcn((void *)nullptr); - + delete Found->Plugin; delete Found; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- filter %0x unregistered :::\n",Plugin); -#endif + return 1; } - else - return 0; - return 1; + + return 0; } -INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM) +INT_PTR UnregisterFilterPluginSvc(WPARAM wParam, LPARAM) { - HYAMNFILTERPLUGIN Plugin=(HYAMNFILTERPLUGIN)wParam; + HYAMNFILTERPLUGIN Plugin = (HYAMNFILTERPLUGIN)wParam; mir_cslock lck(PluginRegCS); UnregisterFilterPlugin(Plugin); @@ -115,86 +103,67 @@ INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM) INT_PTR UnregisterFilterPlugins() { mir_cslock lck(PluginRegCS); - + // We remove protocols from the protocol list - while(FirstFilterPlugin != nullptr) + while (FirstFilterPlugin != nullptr) UnregisterFilterPlugin(FirstFilterPlugin->Plugin); return 1; } -int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,uint32_t Importance,PYAMN_FILTERIMPORTFCN YAMNFilterFcn,uint32_t YAMNFilterFcnVer) +int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin, uint32_t Importance, PYAMN_FILTERIMPORTFCN YAMNFilterFcn, uint32_t YAMNFilterFcnVer) { - PYAMN_FILTERPLUGINQUEUE Parser,Previous; + PYAMN_FILTERPLUGINQUEUE Parser, Previous; if (YAMNFilterFcnVer != YAMN_FILTERIMPORTFCNVERSION) return 0; - if (YAMNFilterFcn==nullptr) + if (YAMNFilterFcn == nullptr) return 0; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- filter %0x import succeed :::\n",Plugin); -#endif - Plugin->Importance=Importance; - Plugin->FilterFcn=YAMNFilterFcn; + Plugin->Importance = Importance; + Plugin->FilterFcn = YAMNFilterFcn; mir_cslock lck(PluginRegCS); + // We add protocol to the protocol list for (Previous = nullptr, Parser = FirstFilterPlugin; Parser != nullptr && Parser->Next != nullptr && Parser->Plugin->Importance <= Importance; Previous = Parser, Parser = Parser->Next); - if (Previous==nullptr) //insert to the beginnig of queue - { - FirstFilterPlugin=new YAMN_FILTERPLUGINQUEUE; - FirstFilterPlugin->Plugin=Plugin; - FirstFilterPlugin->Next=Parser; + + if (Previous == nullptr) { //insert to the beginnig of queue + FirstFilterPlugin = new YAMN_FILTERPLUGINQUEUE; + FirstFilterPlugin->Plugin = Plugin; + FirstFilterPlugin->Next = Parser; } - else - { - Previous->Next=new YAMN_FILTERPLUGINQUEUE; - Previous=Previous->Next; //leave previous, go to actual plugin - Previous->Plugin=Plugin; - Previous->Next=Parser; //and in actual plugin set, that next plugin is the one we insert in front of + else { + Previous->Next = new YAMN_FILTERPLUGINQUEUE; + Previous = Previous->Next; //leave previous, go to actual plugin + Previous->Plugin = Plugin; + Previous->Next = Parser; //and in actual plugin set, that next plugin is the one we insert in front of } return 1; } -INT_PTR FilterMailSvc(WPARAM wParam,LPARAM lParam) +INT_PTR FilterMailSvc(WPARAM wParam, LPARAM lParam) { - CAccount *Account=(CAccount *)wParam; - HYAMNMAIL Mail=(HYAMNMAIL)lParam; + CAccount *Account = (CAccount *)wParam; + HYAMNMAIL Mail = (HYAMNMAIL)lParam; PYAMN_FILTERPLUGINQUEUE ActualPlugin; mir_cslock lck(PluginRegCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write wait\n"); -#endif WaitToWriteFcn(Account->MessagesAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write enter\n"); -#endif - for (ActualPlugin=FirstFilterPlugin;ActualPlugin != nullptr;ActualPlugin=ActualPlugin->Next) - { + + for (ActualPlugin = FirstFilterPlugin; ActualPlugin != nullptr; ActualPlugin = ActualPlugin->Next) if (ActualPlugin->Plugin->FilterFcn->FilterMailFcnPtr != nullptr) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tFiltering Mail, running plugin %0x to filter mail\n",ActualPlugin->Plugin); -#endif - ActualPlugin->Plugin->FilterFcn->FilterMailFcnPtr(Account,YAMN_ACCOUNTVERSION,Mail,YAMN_MAILVERSION); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tFiltering Mail done\n"); -#endif - } - } - Mail->Flags|=YAMN_MSG_FILTERED; + ActualPlugin->Plugin->FilterFcn->FilterMailFcnPtr(Account, YAMN_ACCOUNTVERSION, Mail, YAMN_MAILVERSION); -//Set mail flags according to spamlevel settings + Mail->Flags |= YAMN_MSG_FILTERED; + + //Set mail flags according to spamlevel settings if ((Mail->Flags & YAMN_MSG_SPAMMASK) > YAMN_MSG_SPAML1) - Mail->Flags=Mail->Flags & ~(YAMN_MSG_BROWSER | YAMN_MSG_POPUP | YAMN_MSG_SYSTRAY | YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_NEVENT); - if (YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML3) || YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML4)) - Mail->Flags=Mail->Flags | (YAMN_MSG_AUTODELETE | YAMN_MSG_DELETEOK); //set message to delete - if (YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML3)) - Mail->Flags=Mail->Flags & ~(YAMN_MSG_MEMDELETE); //set message not to delete it immidiatelly from memory -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write done\n"); -#endif + Mail->Flags = Mail->Flags & ~(YAMN_MSG_BROWSER | YAMN_MSG_POPUP | YAMN_MSG_SYSTRAY | YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_NEVENT); + if (YAMN_MSG_SPAML(Mail->Flags, YAMN_MSG_SPAML3) || YAMN_MSG_SPAML(Mail->Flags, YAMN_MSG_SPAML4)) + Mail->Flags = Mail->Flags | (YAMN_MSG_AUTODELETE | YAMN_MSG_DELETEOK); //set message to delete + if (YAMN_MSG_SPAML(Mail->Flags, YAMN_MSG_SPAML3)) + Mail->Flags = Mail->Flags & ~(YAMN_MSG_MEMDELETE); //set message not to delete it immidiatelly from memory + WriteDoneFcn(Account->MessagesAccessSO); return 1; } 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; diff --git a/protocols/YAMN/src/main.cpp b/protocols/YAMN/src/main.cpp index ee7f6da5a1..72b831f765 100644 --- a/protocols/YAMN/src/main.cpp +++ b/protocols/YAMN/src/main.cpp @@ -54,7 +54,7 @@ static void GetProfileDirectory(wchar_t *szPath, int cbPath) FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT, false, nullptr, - L"" }; + L""}; SHFileOperation(&file_op); wcsncpy(szPath, ptszNewPath, cbPath); @@ -62,7 +62,7 @@ static void GetProfileDirectory(wchar_t *szPath, int cbPath) ///////////////////////////////////////////////////////////////////////////////////////// -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_PROTOCOL, MIID_LAST}; ///////////////////////////////////////////////////////////////////////////////////////// @@ -142,10 +142,10 @@ int SystemModulesLoaded(WPARAM, LPARAM) static IconItem iconList[] = { - { LPGEN("Check mail"), "YAMN_Check", IDI_CHECKMAIL }, - { LPGEN("Launch application"), "YAMN_Launch", IDI_LAUNCHAPP }, - { LPGEN("New Mail"), "YAMN_NewMail", IDI_NEWMAIL }, - { LPGEN("Connect Fail"), "YAMN_ConnectFail", IDI_BADCONNECT }, + {LPGEN("Check mail"), "YAMN_Check", IDI_CHECKMAIL}, + {LPGEN("Launch application"), "YAMN_Launch", IDI_LAUNCHAPP}, + {LPGEN("New Mail"), "YAMN_NewMail", IDI_NEWMAIL}, + {LPGEN("Connect Fail"), "YAMN_ConnectFail", IDI_BADCONNECT}, }; void LoadIcons() @@ -171,7 +171,7 @@ static void LoadPlugins() // we have a dot int len = (int)mir_wstrlen(fd.cFileName); // find the length of the string - wchar_t* end = fd.cFileName + len; // get a pointer to the NULL + wchar_t *end = fd.cFileName + len; // get a pointer to the NULL int safe = (end - dot) - 1; // figure out how many chars after the dot are "safe", not including NULL if ((safe != 3) || (mir_wstrcmpi(dot + 1, L"dll") != 0)) //not bound, however the "dll" string should mean only 3 chars are compared @@ -255,9 +255,9 @@ int CMPlugin::Load() hCurSplitNS = LoadCursor(nullptr, IDC_SIZENS); hCurSplitWE = LoadCursor(nullptr, IDC_SIZEWE); -#ifdef _DEBUG + #ifdef _DEBUG InitDebug(); -#endif + #endif CreateServiceFunctions(); @@ -290,6 +290,7 @@ static void UnloadPlugins() { if (hDllPlugins == nullptr) return; + for (int i = iDllPlugins - 1; i >= 0; i--) { if (FreeLibrary(hDllPlugins[i])) { hDllPlugins[i] = nullptr; //for safety @@ -302,9 +303,9 @@ static void UnloadPlugins() int CMPlugin::Unload() { -#ifdef _DEBUG + #ifdef _DEBUG UnInitDebug(); -#endif + #endif WindowList_Destroy(YAMNVar.MessageWnds); WindowList_Destroy(YAMNVar.NewMailAccountWnd); diff --git a/protocols/YAMN/src/proto/netlib.cpp b/protocols/YAMN/src/proto/netlib.cpp index 29222dd980..cf477e8219 100644 --- a/protocols/YAMN/src/proto/netlib.cpp +++ b/protocols/YAMN/src/proto/netlib.cpp @@ -7,7 +7,6 @@ #include "../stdafx.h" //-------------------------------------------------------------------------------------------------- - //-------------------------------------------------------------------------------------------------- BOOL SSLLoaded = FALSE; HNETLIBUSER hNetlibUser = nullptr; @@ -79,7 +78,7 @@ void CNLClient::SSLify() throw(DWORD) //Connects to the server through the sock //if not success, exception is throwed -void CNLClient::Connect(const char* servername, const int port) throw(DWORD) +void CNLClient::Connect(const char *servername, const int port) throw(DWORD) { NetworkError = SystemError = 0; isTLSed = false; @@ -159,14 +158,14 @@ int CNLClient::LocalNetlib_Recv(HNETLIBCONN hConn, char *buf, int len, int flags return iReturn; } -char* CNLClient::Recv(char *buf, int buflen) throw(DWORD) +char *CNLClient::Recv(char *buf, int buflen) throw(DWORD) { #ifdef DEBUG_COMM DebugLog(CommFile, "<reading>"); #endif try { if (buf == nullptr) - buf = (char *)malloc(sizeof(char)*(buflen + 1)); + buf = (char *)malloc(sizeof(char) * (buflen + 1)); if (buf == nullptr) throw NetworkError = (uint32_t)ENL_RECVALLOC; diff --git a/protocols/YAMN/src/proto/pop3/pop3.cpp b/protocols/YAMN/src/proto/pop3/pop3.cpp index a90eccd90f..d8f704dbd6 100644 --- a/protocols/YAMN/src/proto/pop3/pop3.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3.cpp @@ -25,14 +25,13 @@ #include "../../stdafx.h" -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- -//Connects to the server through the netlib -//if not success, exception is throwed -//returns welcome string returned by server -//sets AckFlag -char *CPop3Client::Connect(const char* servername,const int port,BOOL UseSSL, BOOL NoTLS) + //Connects to the server through the netlib + //if not success, exception is throwed + //returns welcome string returned by server + //sets AckFlag +char *CPop3Client::Connect(const char *servername, const int port, BOOL UseSSL, BOOL NoTLS) { if (Stopped) // check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -41,15 +40,15 @@ char *CPop3Client::Connect(const char* servername,const int port,BOOL UseSSL, BO SSL = UseSSL; NetClient = new CNLClient; -#ifdef DEBUG_DECODE + #ifdef DEBUG_DECODE DebugLog(DecodeFile, "Connect:servername: %s port:%d\n", servername, port); -#endif + #endif POP3Error = EPOP3_CONNECT; NetClient->Connect(servername, port); POP3Error = 0; if (SSL) { - try { + try { NetClient->SSLify(); } catch (...) { @@ -89,48 +88,48 @@ char *CPop3Client::Connect(const char* servername,const int port,BOOL UseSSL, BO // This value can be selectable: if you think it is better to reallocate by 1kB size, select size to 1024, // default is 128. You do not need to use this parameter -char* CPop3Client::RecvRest(char* prev,int mode,int size) +char *CPop3Client::RecvRest(char *prev, int mode, int size) { - int SizeRead=0; - int SizeLeft=size-NetClient->Rcv; - int RcvAll=NetClient->Rcv; - char *LastString,*PrevString=prev; + int SizeRead = 0; + int SizeLeft = size - NetClient->Rcv; + int RcvAll = NetClient->Rcv; + char *LastString, *PrevString = prev; - AckFlag=0; + AckFlag = 0; - while(((mode==POP3_SEARCHDOT) && !SearchFromEnd(PrevString+RcvAll-1,RcvAll-3,POP3_SEARCHDOT) && !SearchFromStart(PrevString,2,POP3_SEARCHERR)) || //we are looking for dot or -err phrase - ((mode==POP3_SEARCHACK) && (!SearchFromStart(PrevString,RcvAll-3,mode) || !((RcvAll>3) && SearchFromEnd(PrevString+RcvAll-1,1,POP3_SEARCHNL))))) //we are looking for +ok or -err phrase ended with newline + while (((mode == POP3_SEARCHDOT) && !SearchFromEnd(PrevString + RcvAll - 1, RcvAll - 3, POP3_SEARCHDOT) && !SearchFromStart(PrevString, 2, POP3_SEARCHERR)) || //we are looking for dot or -err phrase + ((mode == POP3_SEARCHACK) && (!SearchFromStart(PrevString, RcvAll - 3, mode) || !((RcvAll > 3) && SearchFromEnd(PrevString + RcvAll - 1, 1, POP3_SEARCHNL))))) //we are looking for +ok or -err phrase ended with newline { //if not found if (NetClient->Stopped) //check if we can work with this POP3 client session { if (PrevString != nullptr) free(PrevString); - throw POP3Error=(uint32_t)EPOP3_STOPPED; + throw POP3Error = (uint32_t)EPOP3_STOPPED; } - if (SizeLeft==0) //if block is full + if (SizeLeft == 0) //if block is full { - SizeRead+=size; - SizeLeft=size; - LastString=NetClient->Recv(nullptr,SizeLeft); - PrevString=(char *)realloc(PrevString,sizeof(char)*(SizeRead+size)); - if (PrevString==nullptr) - throw POP3Error=(uint32_t)EPOP3_RESTALLOC; - memcpy(PrevString+SizeRead,LastString,size); + SizeRead += size; + SizeLeft = size; + LastString = NetClient->Recv(nullptr, SizeLeft); + PrevString = (char *)realloc(PrevString, sizeof(char) * (SizeRead + size)); + if (PrevString == nullptr) + throw POP3Error = (uint32_t)EPOP3_RESTALLOC; + memcpy(PrevString + SizeRead, LastString, size); free(LastString); } else - NetClient->Recv(PrevString+RcvAll,SizeLeft); //to Rcv stores received bytes - SizeLeft=SizeLeft-NetClient->Rcv; - RcvAll+=NetClient->Rcv; + NetClient->Recv(PrevString + RcvAll, SizeLeft); //to Rcv stores received bytes + SizeLeft = SizeLeft - NetClient->Rcv; + RcvAll += NetClient->Rcv; } - NetClient->Rcv=RcvAll; //at the end, store the number of all bytes, no the number of last received bytes + NetClient->Rcv = RcvAll; //at the end, store the number of all bytes, no the number of last received bytes return PrevString; } // CPop3Client::SearchFromEnd // returns 1 if substring DOTLINE or ENDLINE found from end in bs bytes // if you need to add condition for mode, insert it into switch statement -BOOL CPop3Client::SearchFromEnd(char *end,int bs,int mode) +BOOL CPop3Client::SearchFromEnd(char *end, int bs, int mode) { while (bs >= 0) { switch (mode) { @@ -154,7 +153,7 @@ BOOL CPop3Client::SearchFromEnd(char *end,int bs,int mode) // returns 1 if substring OKLINE, ERRLINE or any of them found from start in bs bytes //call only this function to retrieve ack status (+OK or -ERR), because it sets flag AckFlag //if you need to add condition for mode, insert it into switch statement -BOOL CPop3Client::SearchFromStart(char *start,int bs,int mode) +BOOL CPop3Client::SearchFromStart(char *start, int bs, int mode) { while (bs >= 0) { switch (mode) { @@ -185,7 +184,7 @@ BOOL CPop3Client::SearchFromStart(char *start,int bs,int mode) //Performs "USER" pop query and returns server response //sets AckFlag -char* CPop3Client::User(char* name) +char *CPop3Client::User(char *name) { if (NetClient->Stopped) // check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -204,7 +203,7 @@ char* CPop3Client::User(char* name) //Performs "PASS" pop query and returns server response //sets AckFlag -char* CPop3Client::Pass(char* pw) +char *CPop3Client::Pass(char *pw) { if (NetClient->Stopped) //check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -212,7 +211,7 @@ char* CPop3Client::Pass(char* pw) char query[128]; mir_snprintf(query, "PASS %s\r\n", pw); NetClient->Send(query); - + char *Result = RecvRest(NetClient->Recv(), POP3_SEARCHACK); if (AckFlag == POP3_FERR) throw POP3Error = (uint32_t)EPOP3_BADPASS; @@ -221,7 +220,7 @@ char* CPop3Client::Pass(char* pw) //Performs "APOP" pop query and returns server response //sets AckFlag -char* CPop3Client::APOP(char* name, char* pw, char* timestamp) +char *CPop3Client::APOP(char *name, char *pw, char *timestamp) { if (NetClient->Stopped) // check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -250,17 +249,17 @@ char* CPop3Client::APOP(char* name, char* pw, char* timestamp) //Performs "QUIT" pop query and returns server response //sets AckFlag -char* CPop3Client::Quit() +char *CPop3Client::Quit() { - char query[]="QUIT\r\n"; + char query[] = "QUIT\r\n"; NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHACK); + return RecvRest(NetClient->Recv(), POP3_SEARCHACK); } //Performs "STAT" pop query and returns server response //sets AckFlag -char* CPop3Client::Stat() +char *CPop3Client::Stat() { if (NetClient->Stopped) //check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -272,7 +271,7 @@ char* CPop3Client::Stat() //Performs "LIST" pop query and returns server response //sets AckFlag -char* CPop3Client::List() +char *CPop3Client::List() { if (NetClient->Stopped) // check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -285,21 +284,21 @@ char* CPop3Client::List() //Performs "TOP" pop query and returns server response //sets AckFlag -char* CPop3Client::Top(int nr, int lines) +char *CPop3Client::Top(int nr, int lines) { if (NetClient->Stopped) // check if we can work with this POP3 client session - throw POP3Error=(uint32_t)EPOP3_STOPPED; + throw POP3Error = (uint32_t)EPOP3_STOPPED; char query[128]; mir_snprintf(query, "TOP %d %d\r\n", nr, lines); NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); + return RecvRest(NetClient->Recv(), POP3_SEARCHDOT); } //Performs "UIDL" pop query and returns server response //sets AckFlag -char* CPop3Client::Uidl(int nr) +char *CPop3Client::Uidl(int nr) { if (NetClient->Stopped) // check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -317,7 +316,7 @@ char* CPop3Client::Uidl(int nr) //Performs "DELE" pop query and returns server response //sets AckFlag -char* CPop3Client::Dele(int nr) +char *CPop3Client::Dele(int nr) { if (NetClient->Stopped) // check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; @@ -331,7 +330,7 @@ char* CPop3Client::Dele(int nr) //Performs "RETR" pop query and returns server response //sets AckFlag -char* CPop3Client::Retr(int nr) +char *CPop3Client::Retr(int nr) { if (NetClient->Stopped) // check if we can work with this POP3 client session throw POP3Error = (uint32_t)EPOP3_STOPPED; diff --git a/protocols/YAMN/src/proto/pop3/pop3comm.cpp b/protocols/YAMN/src/proto/pop3/pop3comm.cpp index cd513f6a70..39bd4063fd 100644 --- a/protocols/YAMN/src/proto/pop3/pop3comm.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3comm.cpp @@ -14,7 +14,7 @@ #define ERRORSTR_MAXLEN 1024 //in wide-chars -//-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- HANDLE hNetLib = nullptr; PSCOUNTER CPOP3Account::AccountWriterSO = nullptr; @@ -61,7 +61,7 @@ void __cdecl DeleteMailsPOP3(void *param); //Function makes readable message about error. It sends it back to YAMN, so YAMN then //can show it to the message window -wchar_t* WINAPI GetErrorString(DWORD Code); +wchar_t *WINAPI GetErrorString(DWORD Code); //Function deletes string allocated in GetErrorString void WINAPI DeleteErrorString(LPVOID String); @@ -320,9 +320,6 @@ DWORD WINAPI UnLoadPOP3(void *) CallService(MS_YAMN_DELETEFILENAME, (WPARAM)FileName, 0); FileName = nullptr; } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "UnLoadPOP3:done\n"); - #endif return 1; } @@ -492,30 +489,17 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) ActualAccount = (HPOP3ACCOUNT)WhichTemp->AccountParam; //copy address of structure from calling thread to stack of this thread YAMNParam = WhichTemp->BrowserParam; CheckFlags = WhichTemp->Flags; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:Incrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif + SCInc(ActualAccount->UsingThreads); //Unblock YAMN, signal that we have copied all parameters from YAMN thread stack if (INVALID_HANDLE_VALUE != WhichTemp->ThreadRunningEV) SetEvent(WhichTemp->ThreadRunningEV); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountSO-read wait\n"); - #endif if (WAIT_OBJECT_0 != WaitToRead(ActualAccount)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountSO-read wait failed\n"); - #endif - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:Decrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif SCDec(ActualAccount->UsingThreads); return 0; } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountSO-read enter\n"); - #endif + MyClient = &ActualAccount->Client; //Now, copy all needed information about account to local variables, so ActualAccount is not blocked in read mode during all connection process, which can last for several minutes. ActualCopied.ServerName = _strdup(ActualAccount->Server->Name); @@ -526,32 +510,17 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) ActualCopied.NFlags = ActualAccount->NewMailN.Flags; ActualCopied.NNFlags = ActualAccount->NoNewMailN.Flags; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountSO-read done\n"); - #endif ReadDone(ActualAccount); - SCInc(ActualAccount->InternetQueries); //increment counter, that there is one more thread waiting for connection - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:InternetFreeEV-wait\n"); - #endif + WaitForSingleObject(ActualAccount->UseInternetFree, INFINITE); //wait until we can use connection - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:InternetFreeEV-enter\n"); - #endif SCDec(ActualAccount->InternetQueries); //OK, we enter the "use internet" section. But after we start communication, we can test if we did not enter the "use internet" section only for the reason, //that previous thread release the internet section because this account has stop signal (we stop account and there are 2 threads: one communicating, //the second one waiting for network access- the first one ends because we want to stop account, this one is released, but should be stopped as well). if (!ActualAccount->AbleToWork) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:stop signal-InternetFreeEV-done\n"); - #endif SetEvent(ActualAccount->UseInternetFree); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:stop signal-Decrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif SCDec(ActualAccount->UsingThreads); return 0; } @@ -561,9 +530,7 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) ActualAccount->SystemError = 0; //now we can use internet for this socket. First, clear errorcode. try { SetContactStatus(ActualAccount, ID_STATUS_OCCUPIED); - #ifdef DEBUG_COMM - DebugLog(CommFile, "<--------Communication-------->\n"); - #endif + // if we are already connected, we have open session (another thread left us open session), so we don't need to login // note that connected state without logging cannot occur, because if we close session, we always close socket too (we must close socket is the right word :)) if ((MyClient->NetClient == nullptr) || !MyClient->NetClient->Connected()) { @@ -611,16 +578,8 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) DataRX = MyClient->Stat(); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "<--------Account checking-------->\n"); - DebugLog(DecodeFile, "<Extracting stat>\n"); - #endif ExtractStat(DataRX, &mboxsize, &msgs); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "<MailBoxSize>%d</MailBoxSize>\n", mboxsize); - DebugLog(DecodeFile, "<Msgs>%d</Msgs>\n", msgs); - DebugLog(DecodeFile, "</Extracting stat>\n"); - #endif + if (DataRX != nullptr) free(DataRX); DataRX = nullptr; @@ -639,41 +598,21 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) if (msgs) { DataRX = MyClient->List(); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "<Extracting list>\n"); - #endif ExtractList(DataRX, MyClient->NetClient->Rcv, NewMails); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "</Extracting list>\n"); - #endif if (DataRX != nullptr) free(DataRX); - DataRX = nullptr; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "<Extracting UIDL>\n"); - #endif DataRX = MyClient->Uidl(); ExtractUIDL(DataRX, MyClient->NetClient->Rcv, NewMails); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "</Extracting UIDL>\n"); - #endif + if (DataRX != nullptr) free(DataRX); DataRX = nullptr; } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0 != MsgsWaitToWrite(ActualAccount)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); - #endif + + if (WAIT_OBJECT_0 != MsgsWaitToWrite(ActualAccount)) throw (uint32_t)(ActualAccount->SystemError = EACC_STOPPED); - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write enter\n"); - #endif + ActualAccount->LastChecked = now; for (MsgQueuePtr = (HYAMNMAIL)ActualAccount->Mails; MsgQueuePtr != nullptr; MsgQueuePtr = MsgQueuePtr->Next) { if (MsgQueuePtr->Flags & YAMN_MSG_BODYREQUESTED) { @@ -684,10 +623,6 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) mir_snwprintf(accstatus, TranslateT("Reading body %s"), NewMsgsPtr->ID); SetAccountStatus(ActualAccount, accstatus); DataRX = MyClient->Top(MsgQueuePtr->Number, 100); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "<Reading body>\n"); - DebugLog(DecodeFile, "<Header>%s</Header>\n", DataRX); - #endif if (DataRX != nullptr) { Temp = DataRX; while ((Temp < DataRX + MyClient->NetClient->Rcv) && (WS(Temp) || ENDLINE(Temp))) Temp++; @@ -712,10 +647,6 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) TranslateHeader(Temp, MyClient->NetClient->Rcv - (Temp - DataRX), &MsgQueuePtr->MailData->TranslatedHeader); - - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "</Reading body>\n"); - #endif MsgQueuePtr->Flags |= YAMN_MSG_BODYRECEIVED; if (DataRX != nullptr) @@ -728,11 +659,7 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) } SynchroMessages(ActualAccount, (HYAMNMAIL *)&ActualAccount->Mails, nullptr, (HYAMNMAIL *)&NewMails, nullptr); //we get only new mails on server! - // NewMails=NULL; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write done\n"); - #endif MsgsWriteDone(ActualAccount); for (MsgQueuePtr = (HYAMNMAIL)ActualAccount->Mails; MsgQueuePtr != nullptr; MsgQueuePtr = MsgQueuePtr->Next) { if ((MsgQueuePtr->Flags & YAMN_MSG_BODYREQUESTED) && (MsgQueuePtr->Flags & YAMN_MSG_BODYRECEIVED)) { @@ -753,10 +680,6 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) mir_snwprintf(accstatus, TranslateT("Reading new mail messages (%d%% done)"), 100 * i / msgs); SetAccountStatus(ActualAccount, accstatus); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "<New mail>\n"); - DebugLog(DecodeFile, "<Header>%s</Header>\n", DataRX); - #endif if (DataRX != nullptr) { Temp = DataRX; while ((Temp < DataRX + MyClient->NetClient->Rcv) && (WS(Temp) || ENDLINE(Temp))) Temp++; @@ -792,31 +715,17 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) MsgQueuePtr = MsgQueuePtr->Next; } - #ifdef DEBUG_DECODE - DebugLog(DecodeFile, "</--------Account checking-------->\n"); - #endif - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0 != MsgsWaitToWrite(ActualAccount)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); - #endif + if (WAIT_OBJECT_0 != MsgsWaitToWrite(ActualAccount)) throw (uint32_t)ActualAccount->SystemError == EACC_STOPPED; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write enter\n"); - #endif + if (ActualAccount->Mails == nullptr) ActualAccount->Mails = NewMails; else { ActualAccount->LastMail = ActualAccount->LastChecked; AppendQueue((HYAMNMAIL)ActualAccount->Mails, NewMails); } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write done\n"); - #endif + MsgsWriteDone(ActualAccount); // we are going to delete mails having SPAM flag level3 and 4 (see m_mails.h) set @@ -840,9 +749,6 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) } UsingInternet = FALSE; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:InternetFreeEV-done\n"); - #endif SetEvent(ActualAccount->UseInternetFree); ActualAccount->LastSChecked = ActualAccount->LastChecked; @@ -873,23 +779,10 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) #ifdef DEBUG_COMM DebugLog(CommFile, "ERROR: %x\n", ErrorCode); #endif - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write wait\n"); - #endif if (WAIT_OBJECT_0 == MsgsWaitToWrite(ActualAccount)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write enter\n"); - #endif ActualAccount->LastChecked = now; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write done\n"); - #endif MsgsWriteDone(ActualAccount); } - #ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); - #endif DeleteMIMEQueue(ActualAccount, NewMails); @@ -906,12 +799,8 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) } if (UsingInternet) //if our thread still uses internet - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:InternetFreeEV-done\n"); - #endif SetEvent(ActualAccount->UseInternetFree); - } + SetContactStatus(ActualAccount, ID_STATUS_NA); } free(ActualCopied.ServerName); @@ -920,10 +809,8 @@ DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp) #ifdef DEBUG_COMM DebugLog(CommFile, "</--------Communication-------->\n"); #endif + // WriteAccounts(); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:Decrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif SCDec(ActualAccount->UsingThreads); return 0; } @@ -962,48 +849,28 @@ void __cdecl DeleteMailsPOP3(void *param) HPOP3ACCOUNT ActualAccount = (HPOP3ACCOUNT)WhichTemp->AccountParam; //copy address of structure from calling thread to stack of this thread LPVOID YAMNParam = WhichTemp->BrowserParam; UINT_PTR POP3PluginParam = (UINT_PTR)((struct DeleteParam *)WhichTemp)->CustomParam; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:Incrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif + SCInc(ActualAccount->UsingThreads); if (INVALID_HANDLE_VALUE != WhichTemp->ThreadRunningEV) SetEvent(WhichTemp->ThreadRunningEV); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountSO-read wait\n"); - #endif if (WAIT_OBJECT_0 != WaitToRead(ActualAccount)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountSO-read wait failed\n"); - #endif - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif SCDec(ActualAccount->UsingThreads); return; } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountSO-read enter\n"); - #endif + if (nullptr == (DeleteMails = (HYAMNMAIL)CreateNewDeleteQueue((HYAMNMAIL)ActualAccount->Mails))) //if there's no mail for deleting, return { if (POP3_DELETEFROMCHECK != POP3PluginParam) //We do not wait for free internet when calling from SynchroPOP3. It is because UseInternetFree is blocked { YAMN_MAILBROWSERPARAM Param = {(HANDLE)nullptr, ActualAccount, YAMN_ACC_MSGP, YAMN_ACC_MSGP, YAMNParam}; //Just update the window - CallService(MS_YAMN_MAILBROWSER, (WPARAM)&Param, (LPARAM)YAMN_MAILBROWSERVERSION); } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountSO-read done\n"); - #endif - ReadDone(ActualAccount); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif - SCDec(ActualAccount->UsingThreads); + SCDec(ActualAccount->UsingThreads); return; } + MyClient = &(ActualAccount->Client); //Now, copy all needed information about account to local variables, so ActualAccount is not blocked in read mode during all connection process, which can last for several minutes. @@ -1015,22 +882,12 @@ void __cdecl DeleteMailsPOP3(void *param) ActualCopied.NFlags = ActualAccount->NewMailN.Flags; ActualCopied.NNFlags = ActualAccount->NoNewMailN.Flags; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountSO-read done\n"); - #endif ReadDone(ActualAccount); SCInc(ActualAccount->InternetQueries); //This is POP3-internal SCOUNTER, we set another thread wait for this account to be connected to inet if (POP3_DELETEFROMCHECK != POP3PluginParam) //We do not wait for free internet when calling from SynchroPOP3. It is because UseInternetFree is blocked - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:InternetFreeEV-wait\n"); - #endif WaitForSingleObject(ActualAccount->UseInternetFree, INFINITE); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:InternetFreeEV-enter\n"); - #endif - } + SCDec(ActualAccount->InternetQueries); UsingInternet = TRUE; @@ -1131,20 +988,11 @@ void __cdecl DeleteMailsPOP3(void *param) SynchroMessages(ActualAccount, (HYAMNMAIL *)&DeleteMails, nullptr, (HYAMNMAIL *)&NewMails, nullptr); } } - else - SetAccountStatus(ActualAccount, TranslateT("Deleting spam")); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0 != MsgsWaitToWrite(ActualAccount)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountMsgsSO-write wait failed\n"); - #endif + else SetAccountStatus(ActualAccount, TranslateT("Deleting spam")); + + if (WAIT_OBJECT_0 != MsgsWaitToWrite(ActualAccount)) throw (uint32_t)EACC_STOPPED; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountMsgsSO-write enter\n"); - #endif + if (msgs || POP3_DELETEFROMCHECK == POP3PluginParam) { try { HYAMNMAIL Temp; @@ -1184,9 +1032,6 @@ void __cdecl DeleteMailsPOP3(void *param) } catch (...) //if any exception in the code where we have write-access to account occured, don't forget to leave write-access { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountMsgsSO-write done\n"); - #endif MsgsWriteDone(ActualAccount); throw; //and go to the main exception handling } @@ -1209,9 +1054,7 @@ void __cdecl DeleteMailsPOP3(void *param) DeleteMIMEQueue(ActualAccount, (HYAMNMAIL)ActualAccount->Mails); ActualAccount->Mails = nullptr; } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:ActualAccountMsgsSO-write done\n"); - #endif + MsgsWriteDone(ActualAccount); #ifdef DEBUG_DECODE DebugLog(DecodeFile, "</--------Deleting requested mails-------->\n"); @@ -1239,9 +1082,6 @@ void __cdecl DeleteMailsPOP3(void *param) } UsingInternet = FALSE; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:InternetFreeEV-done\n"); - #endif SetEvent(ActualAccount->UseInternetFree); } SetContactStatus(ActualAccount, ActualAccount->isCounting ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE); @@ -1269,12 +1109,7 @@ void __cdecl DeleteMailsPOP3(void *param) } if (UsingInternet && (POP3_DELETEFROMCHECK != POP3PluginParam)) //if our thread still uses internet and it is needed to release internet - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "CheckPOP3:InternetFreeEV-done\n"); - #endif SetEvent(ActualAccount->UseInternetFree); - } } free(ActualCopied.ServerName); @@ -1287,10 +1122,8 @@ void __cdecl DeleteMailsPOP3(void *param) #ifdef DEBUG_COMM DebugLog(CommFile, "</--------Communication-------->\n"); #endif + // WriteAccounts(); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n", ActualAccount->UsingThreads, ActualAccount); - #endif SCDec(ActualAccount->UsingThreads); return; } diff --git a/protocols/YAMN/src/proto/pop3/pop3opt.cpp b/protocols/YAMN/src/proto/pop3/pop3opt.cpp index 011d10fbdf..0dfaeabb50 100644 --- a/protocols/YAMN/src/proto/pop3/pop3opt.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3opt.cpp @@ -212,7 +212,7 @@ static INT_PTR CALLBACK DlgProcPOP3AccStatusOpt(HWND hDlg, UINT msg, WPARAM wPar ActualAccount = (HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)DlgInput); if (ActualAccount != nullptr) { DlgShowAccountStatus(hDlg, ActualAccount); - for (auto &it: g_iStatusControls) + for (auto &it : g_iStatusControls) EnableWindow(GetDlgItem(hDlg, it), true); } else { @@ -344,7 +344,7 @@ public: // Fill accounts WaitToReadSO(POP3Plugin->AccountBrowserSO); - + for (ActualAccount = (HPOP3ACCOUNT)POP3Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = (HPOP3ACCOUNT)ActualAccount->Next) if (ActualAccount->Name != nullptr) cmbAccount.AddStringA(ActualAccount->Name); @@ -439,7 +439,7 @@ public: } } - void onSelChange_CP(CCtrlCombo*) + void onSelChange_CP(CCtrlCombo *) { int sel = cmbCP.GetCurSel(); CPINFOEX info; GetCPInfoEx(CodePageNamesSupp[sel].CP, 0, &info); @@ -540,7 +540,7 @@ public: DlgShowAccount(0); } - void onClick_Reset(CCtrlButton*) + void onClick_Reset(CCtrlButton *) { if (ActualAccount != nullptr) ActualAccount->TimeLeft = ActualAccount->Interval; @@ -584,7 +584,7 @@ public: SetFocus(GetDlgItem(m_hwnd, IDC_EDITPORT)); return false; } - + UINT Interval = GetDlgItemInt(m_hwnd, IDC_EDITINTERVAL, &Translated, FALSE); if (!Translated) { MessageBox(m_hwnd, TranslateT("This is not a valid number value"), TranslateT("Input error"), MB_OK); diff --git a/protocols/YAMN/src/protoplugin.cpp b/protocols/YAMN/src/protoplugin.cpp index c119f887bb..c6e6a6aecc 100644 --- a/protocols/YAMN/src/protoplugin.cpp +++ b/protocols/YAMN/src/protoplugin.cpp @@ -6,17 +6,16 @@ #include "stdafx.h" -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- -PYAMN_PROTOPLUGINQUEUE FirstProtoPlugin=nullptr; +PYAMN_PROTOPLUGINQUEUE FirstProtoPlugin = nullptr; -INT_PTR RegisterProtocolPluginSvc(WPARAM,LPARAM); +INT_PTR RegisterProtocolPluginSvc(WPARAM, LPARAM); //Removes plugin from queue and deletes registration structures INT_PTR UnregisterProtocolPlugin(HYAMNPROTOPLUGIN Plugin); -INT_PTR UnregisterProtocolPluginSvc(WPARAM,LPARAM); +INT_PTR UnregisterProtocolPluginSvc(WPARAM, LPARAM); //Removes plugins from queue and deletes registration structures INT_PTR UnregisterProtoPlugins(); @@ -28,53 +27,50 @@ INT_PTR UnregisterProtoPlugins(); // YAMNMailFcn- pointer to imported functions with mails // YAMNMailFcnVer- version of YAMN_MAILIMPORTFCN, use YAMN_MAILIMPORTFCNVERSION // returns nonzero if success -int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPORTFCN YAMNFcn,uint32_t YAMNFcnVer,PYAMN_MAILIMPORTFCN YAMNMailFcn,uint32_t YAMNMailFcnVer); +int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin, PYAMN_PROTOIMPORTFCN YAMNFcn, uint32_t YAMNFcnVer, PYAMN_MAILIMPORTFCN YAMNMailFcn, uint32_t YAMNMailFcnVer); -struct CExportedFunctions ProtoPluginExportedFcn[]= +struct CExportedFunctions ProtoPluginExportedFcn[] = { - {YAMN_SETPROTOCOLPLUGINFCNIMPORTID,(void *)SetProtocolPluginFcnImportFcn}, + {YAMN_SETPROTOCOLPLUGINFCNIMPORTID, (void *)SetProtocolPluginFcnImportFcn}, }; -struct CExportedServices ProtoPluginExportedSvc[]= +struct CExportedServices ProtoPluginExportedSvc[] = { - {MS_YAMN_REGISTERPROTOPLUGIN,RegisterProtocolPluginSvc}, - {MS_YAMN_UNREGISTERPROTOPLUGIN,UnregisterProtocolPluginSvc}, - {MS_YAMN_GETFILENAME,GetFileNameSvc}, - {MS_YAMN_DELETEFILENAME,DeleteFileNameSvc}, + {MS_YAMN_REGISTERPROTOPLUGIN, RegisterProtocolPluginSvc}, + {MS_YAMN_UNREGISTERPROTOPLUGIN, UnregisterProtocolPluginSvc}, + {MS_YAMN_GETFILENAME, GetFileNameSvc}, + {MS_YAMN_DELETEFILENAME, DeleteFileNameSvc}, }; //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- -INT_PTR RegisterProtocolPluginSvc(WPARAM wParam,LPARAM lParam) +INT_PTR RegisterProtocolPluginSvc(WPARAM wParam, LPARAM lParam) { - PYAMN_PROTOREGISTRATION Registration=(PYAMN_PROTOREGISTRATION)wParam; + PYAMN_PROTOREGISTRATION Registration = (PYAMN_PROTOREGISTRATION)wParam; HYAMNPROTOPLUGIN Plugin; if (lParam != YAMN_PROTOREGISTRATIONVERSION) return 0; - if ((Registration->Name==nullptr) || (Registration->Ver==nullptr)) + if ((Registration->Name == nullptr) || (Registration->Ver == nullptr)) return (INT_PTR)NULL; - if (nullptr==(Plugin=new YAMN_PROTOPLUGIN)) + if (nullptr == (Plugin = new YAMN_PROTOPLUGIN)) return (INT_PTR)NULL; - Plugin->PluginInfo=Registration; + Plugin->PluginInfo = Registration; - Plugin->FirstAccount=nullptr; + Plugin->FirstAccount = nullptr; - Plugin->AccountBrowserSO=new SWMRG; - SWMRGInitialize(Plugin->AccountBrowserSO,nullptr); + Plugin->AccountBrowserSO = new SWMRG; + SWMRGInitialize(Plugin->AccountBrowserSO, nullptr); - Plugin->Fcn=nullptr; - Plugin->MailFcn=nullptr; + Plugin->Fcn = nullptr; + Plugin->MailFcn = nullptr; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- new protocol registered: %0x (%s) :::\n",Plugin,Registration->Name); -#endif return (INT_PTR)Plugin; } -int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPORTFCN YAMNFcn,uint32_t YAMNFcnVer,PYAMN_MAILIMPORTFCN YAMNMailFcn,uint32_t YAMNMailFcnVer) +int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin, PYAMN_PROTOIMPORTFCN YAMNFcn, uint32_t YAMNFcnVer, PYAMN_MAILIMPORTFCN YAMNMailFcn, uint32_t YAMNMailFcnVer) { PYAMN_PROTOPLUGINQUEUE Parser; @@ -82,82 +78,66 @@ int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPO return 0; if (YAMNMailFcnVer != YAMN_MAILIMPORTFCNVERSION) return 0; - if (YAMNFcn==nullptr) + if (YAMNFcn == nullptr) return 0; - if (YAMNMailFcn==nullptr) + if (YAMNMailFcn == nullptr) return 0; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- protocol %0x import succeed :::\n",Plugin); -#endif - Plugin->Fcn=YAMNFcn; - Plugin->MailFcn=YAMNMailFcn; + Plugin->Fcn = YAMNFcn; + Plugin->MailFcn = YAMNMailFcn; mir_cslock lck(PluginRegCS); // We add protocol to the protocol list - for (Parser=FirstProtoPlugin;Parser != nullptr && Parser->Next != nullptr;Parser=Parser->Next); - if (Parser==nullptr) - { - FirstProtoPlugin=new YAMN_PROTOPLUGINQUEUE; - Parser=FirstProtoPlugin; + for (Parser = FirstProtoPlugin; Parser != nullptr && Parser->Next != nullptr; Parser = Parser->Next); + if (Parser == nullptr) { + FirstProtoPlugin = new YAMN_PROTOPLUGINQUEUE; + Parser = FirstProtoPlugin; } - else - { - Parser->Next=new YAMN_PROTOPLUGINQUEUE; - Parser=Parser->Next; + else { + Parser->Next = new YAMN_PROTOPLUGINQUEUE; + Parser = Parser->Next; } - Parser->Plugin=Plugin; - Parser->Next=nullptr; + Parser->Plugin = Plugin; + Parser->Next = nullptr; return 1; } INT_PTR UnregisterProtocolPlugin(HYAMNPROTOPLUGIN Plugin) { - PYAMN_PROTOPLUGINQUEUE Parser,Found; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Entering UnregisterProtocolPlugin\n"); -#endif - if (FirstProtoPlugin->Plugin==Plugin) - { - Found=FirstProtoPlugin; - FirstProtoPlugin=FirstProtoPlugin->Next; + PYAMN_PROTOPLUGINQUEUE Parser, Found; + + if (FirstProtoPlugin->Plugin == Plugin) { + Found = FirstProtoPlugin; + FirstProtoPlugin = FirstProtoPlugin->Next; } - else - { - for (Parser=FirstProtoPlugin;(Parser->Next != nullptr) && (Plugin != Parser->Next->Plugin);Parser=Parser->Next); - if (Parser->Next != nullptr) - { - Found=Parser->Next; - Parser->Next=Parser->Next->Next; + else { + for (Parser = FirstProtoPlugin; (Parser->Next != nullptr) && (Plugin != Parser->Next->Plugin); Parser = Parser->Next); + if (Parser->Next != nullptr) { + Found = Parser->Next; + Parser->Next = Parser->Next->Next; } else - Found=nullptr; + Found = nullptr; } - if (Found != nullptr) - { + if (Found != nullptr) { StopAccounts(Plugin); DeleteAccounts(Plugin); if (Plugin->Fcn->UnLoadFcn != nullptr) Plugin->Fcn->UnLoadFcn((void *)nullptr); - + delete Found->Plugin->AccountBrowserSO; delete Found->Plugin; delete Found; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- protocol %0x unregistered :::\n",Plugin); -#endif } else return 0; return 1; } -INT_PTR UnregisterProtocolPluginSvc(WPARAM wParam,LPARAM) +INT_PTR UnregisterProtocolPluginSvc(WPARAM wParam, LPARAM) { - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + HYAMNPROTOPLUGIN Plugin = (HYAMNPROTOPLUGIN)wParam; mir_cslock lck(PluginRegCS); UnregisterProtocolPlugin(Plugin); @@ -168,25 +148,25 @@ INT_PTR UnregisterProtoPlugins() { mir_cslock lck(PluginRegCS); // We remove protocols from the protocol list - while(FirstProtoPlugin != nullptr) + while (FirstProtoPlugin != nullptr) UnregisterProtocolPlugin(FirstProtoPlugin->Plugin); return 1; } -INT_PTR GetFileNameSvc(WPARAM wParam,LPARAM) +INT_PTR GetFileNameSvc(WPARAM wParam, LPARAM) { wchar_t *FileName = new wchar_t[MAX_PATH]; if (FileName == nullptr) return NULL; - mir_snwprintf(FileName, MAX_PATH, L"%s\\yamn-accounts.%s.%s.book", UserDirectory, (wchar_t*)wParam, ProfileName); + mir_snwprintf(FileName, MAX_PATH, L"%s\\yamn-accounts.%s.%s.book", UserDirectory, (wchar_t *)wParam, ProfileName); return (INT_PTR)FileName; } -INT_PTR DeleteFileNameSvc(WPARAM wParam,LPARAM) +INT_PTR DeleteFileNameSvc(WPARAM wParam, LPARAM) { - if (( wchar_t* )wParam != nullptr) - delete[] ( wchar_t* ) wParam; + if ((wchar_t *)wParam != nullptr) + delete[](wchar_t *) wParam; return 0; } diff --git a/protocols/YAMN/src/resource.h b/protocols/YAMN/src/resource.h index 2f20c00151..3f6a52fa55 100644 --- a/protocols/YAMN/src/resource.h +++ b/protocols/YAMN/src/resource.h @@ -31,7 +31,6 @@ #define IDC_CHECKICO 1012 #define IDC_CHECK 1013 #define IDC_BTNDEL 1014 -#define IDC_STSERVER 1015 #define IDC_CHECKFSND 1016 #define IDC_CHECKFMSG 1017 #define IDC_CHECKFICO 1018 @@ -53,12 +52,7 @@ #define IDC_EDITAPPPARAM 1044 #define IDC_BTNOK 1047 #define IDC_COMBOCP 1050 -#define IDC_STCP 1055 #define IDC_STATICMSG 1055 -#define IDC_STPORT 1056 -#define IDC_STLOGIN 1057 -#define IDC_STPASS 1058 -#define IDC_STINTERVAL 1059 #define IDC_AUTOBODY 1062 #define IDC_BTNRESET 1063 #define IDC_CHECKSTART 1064 diff --git a/protocols/YAMN/src/services.cpp b/protocols/YAMN/src/services.cpp index 682842bdaa..8265676b02 100644 --- a/protocols/YAMN/src/services.cpp +++ b/protocols/YAMN/src/services.cpp @@ -2,7 +2,7 @@ static INT_PTR Service_GetCaps(WPARAM wParam, LPARAM) { - switch(wParam) { + switch (wParam) { case PFLAGNUM_4: return PF4_NOCUSTOMAUTH; case PFLAG_UNIQUEIDTEXT: @@ -13,7 +13,7 @@ static INT_PTR Service_GetCaps(WPARAM wParam, LPARAM) case PFLAGNUM_5: return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND; } - + return 0; } @@ -33,7 +33,7 @@ static INT_PTR Service_LoadIcon(WPARAM wParam, LPARAM) INT_PTR ClistContactDoubleclicked(WPARAM, LPARAM lParam) { - ContactDoubleclicked(((CLISTEVENT*)lParam)->lParam, lParam); + ContactDoubleclicked(((CLISTEVENT *)lParam)->lParam, lParam); return 0; } @@ -55,16 +55,10 @@ static INT_PTR ContactApplication(WPARAM wParam, LPARAM) CAccount *ActualAccount = (CAccount *)CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); if (ActualAccount != nullptr) { - STARTUPINFOW si = { 0 }; + STARTUPINFOW si = {0}; si.cb = sizeof(si); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ContactApplication:ualAccountSO-read enter\n"); -#endif if (ActualAccount->NewMailN.App != nullptr) { wchar_t *Command; if (ActualAccount->NewMailN.AppParam != nullptr) @@ -85,15 +79,8 @@ static INT_PTR ContactApplication(WPARAM wParam, LPARAM) } } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read done\n"); -#endif ReadDoneFcn(ActualAccount->AccountAccessSO); } -#ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read enter failed\n"); -#endif } db_free(&dbv); return 0; @@ -115,20 +102,11 @@ static INT_PTR AccountMailCheck(WPARAM wParam, LPARAM lParam) return 0; mir_cslock lck(PluginRegCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "AccountCheck:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualAccount->AccountAccessSO, 0)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); -#endif } else { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); -#endif if ((ActualAccount->Flags & YAMN_ACC_ENA) && ActualAccount->Plugin->Fcn->SynchroFcnPtr) { - CheckParam ParamToPlugin = { YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, lParam != 0 ? YAMN_FORCECHECK : YAMN_NORMALCHECK, nullptr, nullptr }; + CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, lParam != 0 ? YAMN_FORCECHECK : YAMN_NORMALCHECK, nullptr, nullptr}; ActualAccount->TimeLeft = ActualAccount->Interval; DWORD tid; @@ -165,25 +143,16 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0)) return 0; mir_cslock lck(PluginRegCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); -#endif } else { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); -#endif if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check { if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr == nullptr) ReadDoneFcn(ActualAccount->AccountAccessSO); DWORD tid; - struct CheckParam ParamToPlugin = { YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)nullptr, nullptr }; + struct CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)nullptr, nullptr}; if (nullptr == CreateThread(nullptr, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid)) ReadDoneFcn(ActualAccount->AccountAccessSO); else @@ -209,14 +178,8 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) CAccount *ActualAccount = (CAccount *)CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); if (ActualAccount != nullptr) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read wait\n"); -#endif if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read enter\n"); -#endif - YAMN_MAILBROWSERPARAM Param = { nullptr, ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr }; + YAMN_MAILBROWSERPARAM Param = {nullptr, ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr}; Param.nnflags = Param.nnflags | YAMN_ACC_MSG; //show mails in account even no new mail in account Param.nnflags = Param.nnflags & ~YAMN_ACC_POP; @@ -225,17 +188,8 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) Param.nflags = Param.nflags & ~YAMN_ACC_POP; RunMailBrowserSvc((WPARAM)&Param, YAMN_MAILBROWSERVERSION); - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read done\n"); -#endif ReadDoneFcn(ActualAccount->AccountAccessSO); } -#ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read enter failed\n"); -#endif - } db_free(&dbv); } @@ -249,7 +203,7 @@ HBITMAP LoadBmpFromIcon(HICON hIcon) HBRUSH hBkgBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); - BITMAPINFOHEADER bih = { 0 }; + BITMAPINFOHEADER bih = {0}; bih.biSize = sizeof(bih); bih.biBitCount = 24; bih.biPlanes = 1; diff --git a/protocols/YAMN/src/synchro.cpp b/protocols/YAMN/src/synchro.cpp index f377ef158a..c4bb58e6de 100644 --- a/protocols/YAMN/src/synchro.cpp +++ b/protocols/YAMN/src/synchro.cpp @@ -7,14 +7,14 @@ #include "stdafx.h" -// Initializes a SWMRG structure. This structure must be -// initialized before any writer or reader threads attempt -// to wait on it. -// The structure must be allocated by the application and -// the structure's address is passed as the first parameter. -// The lpszName parameter is the name of the object. Pass -// NULL if you do not want to share the object. -BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG,wchar_t *Name); + // Initializes a SWMRG structure. This structure must be + // initialized before any writer or reader threads attempt + // to wait on it. + // The structure must be allocated by the application and + // the structure's address is passed as the first parameter. + // The lpszName parameter is the name of the object. Pass + // NULL if you do not want to share the object. +BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG, wchar_t *Name); // Deletes the system resources associated with a SWMRG // structure. The structure must be deleted only when @@ -26,7 +26,7 @@ void WINAPI SWMRGDelete(PSWMRG pSWMRG); // it can successfully write to the shared data. // returns WAIT_FINISH when we are in write-access or WAIT_FAILED // when event about quick finishing is set (or when system returns fail when waiting for synchro object) -uint32_t WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,uint32_t dwTimeout); +uint32_t WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG, uint32_t dwTimeout); // A writer thread calls this function to let other threads // know that it no longer needs to write to the shared data. @@ -70,15 +70,15 @@ uint32_t WINAPI SCIncFcn(PSCOUNTER SCounter); // Returns Number after decrementing uint32_t WINAPI SCDecFcn(PSCOUNTER SCounter); -struct CExportedFunctions SynchroExportedFcn[]= +struct CExportedFunctions SynchroExportedFcn[] = { - {YAMN_WAITTOWRITEID,(void *)WaitToWriteFcn}, - {YAMN_WRITEDONEID,(void *)WriteDoneFcn}, - {YAMN_WAITTOREADID,(void *)WaitToReadFcn}, - {YAMN_READDONEID,(void *)ReadDoneFcn}, - {YAMN_SCGETNUMBERID,(void *)SCGetNumberFcn}, - {YAMN_SCINCID,(void *)SCIncFcn}, - {YAMN_SCDECID,(void *)SCDecFcn}, + {YAMN_WAITTOWRITEID, (void *)WaitToWriteFcn}, + {YAMN_WRITEDONEID, (void *)WriteDoneFcn}, + {YAMN_WAITTOREADID, (void *)WaitToReadFcn}, + {YAMN_READDONEID, (void *)ReadDoneFcn}, + {YAMN_SCGETNUMBERID, (void *)SCGetNumberFcn}, + {YAMN_SCINCID, (void *)SCIncFcn}, + {YAMN_SCDECID, (void *)SCDecFcn}, }; //-------------------------------------------------------------------------------------------------- @@ -86,8 +86,8 @@ struct CExportedFunctions SynchroExportedFcn[]= void WINAPI SWMRGDelete(PSWMRG pSWMRG) { -// Destroys any synchronization objects that were -// successfully created. + // Destroys any synchronization objects that were + // successfully created. if (nullptr != pSWMRG->hEventNoWriter) CloseHandle(pSWMRG->hEventNoWriter); if (nullptr != pSWMRG->hEventNoReaders) @@ -98,77 +98,75 @@ void WINAPI SWMRGDelete(PSWMRG pSWMRG) CloseHandle(pSWMRG->hFinishEV); } -BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG,wchar_t *Name) +BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG, wchar_t *Name) { - pSWMRG->hEventNoWriter=nullptr; - pSWMRG->hEventNoReaders=nullptr; - pSWMRG->hSemNumReaders=nullptr; - pSWMRG->hFinishEV=nullptr; - -// Creates the automatic-reset event that is signalled when -// no writer threads are writing. -// Initially no reader threads are reading. + pSWMRG->hEventNoWriter = nullptr; + pSWMRG->hEventNoReaders = nullptr; + pSWMRG->hSemNumReaders = nullptr; + pSWMRG->hFinishEV = nullptr; + + // Creates the automatic-reset event that is signalled when + // no writer threads are writing. + // Initially no reader threads are reading. if (Name != nullptr) - Name[0]=(wchar_t)'W'; - pSWMRG->hEventNoWriter=CreateEvent(nullptr,FALSE,TRUE,Name); + Name[0] = (wchar_t)'W'; + pSWMRG->hEventNoWriter = CreateEvent(nullptr, FALSE, TRUE, Name); -// Creates the manual-reset event that is signalled when -// no reader threads are reading. -// Initially no reader threads are reading. + // Creates the manual-reset event that is signalled when + // no reader threads are reading. + // Initially no reader threads are reading. if (Name != nullptr) - Name[0]=(wchar_t)'R'; - pSWMRG->hEventNoReaders=CreateEvent(nullptr,TRUE,TRUE,Name); + Name[0] = (wchar_t)'R'; + pSWMRG->hEventNoReaders = CreateEvent(nullptr, TRUE, TRUE, Name); -// Initializes the variable that indicates the number of -// reader threads that are reading. -// Initially no reader threads are reading. + // Initializes the variable that indicates the number of + // reader threads that are reading. + // Initially no reader threads are reading. if (Name != nullptr) - Name[0]=(wchar_t)'C'; - pSWMRG->hSemNumReaders=CreateSemaphore(nullptr,0,0x7FFFFFFF,Name); + Name[0] = (wchar_t)'C'; + pSWMRG->hSemNumReaders = CreateSemaphore(nullptr, 0, 0x7FFFFFFF, Name); if (Name != nullptr) - Name[0]=(wchar_t)'F'; - pSWMRG->hFinishEV=CreateEvent(nullptr,TRUE,FALSE,Name); + Name[0] = (wchar_t)'F'; + pSWMRG->hFinishEV = CreateEvent(nullptr, TRUE, FALSE, Name); -// If a synchronization object could not be created, -// destroys any created objects and return failure. - if ((nullptr==pSWMRG->hEventNoWriter) || (nullptr==pSWMRG->hEventNoReaders) || (nullptr==pSWMRG->hSemNumReaders) || (nullptr==pSWMRG->hFinishEV)) - { + // If a synchronization object could not be created, + // destroys any created objects and return failure. + if ((nullptr == pSWMRG->hEventNoWriter) || (nullptr == pSWMRG->hEventNoReaders) || (nullptr == pSWMRG->hSemNumReaders) || (nullptr == pSWMRG->hFinishEV)) { SWMRGDelete(pSWMRG); return FALSE; } return TRUE; } -uint32_t WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,uint32_t dwTimeout) +uint32_t WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG, uint32_t dwTimeout) { - uint32_t dw; + uint32_t dw; HANDLE aHandles[2]; -// We can write if the following are true: -// 1. No other threads are writing. -// 2. No threads are reading. -// But first we have to know if SWMRG structure is not about to delete - aHandles[0]=pSWMRG->hEventNoWriter; - aHandles[1]=pSWMRG->hEventNoReaders; - if (WAIT_OBJECT_0==(dw=WaitForSingleObject(pSWMRG->hFinishEV,0))) + // We can write if the following are true: + // 1. No other threads are writing. + // 2. No threads are reading. + // But first we have to know if SWMRG structure is not about to delete + aHandles[0] = pSWMRG->hEventNoWriter; + aHandles[1] = pSWMRG->hEventNoReaders; + if (WAIT_OBJECT_0 == (dw = WaitForSingleObject(pSWMRG->hFinishEV, 0))) return WAIT_FINISH; - if (WAIT_FAILED==dw) + if (WAIT_FAILED == dw) return dw; - dw=WaitForMultipleObjects(2,aHandles,TRUE,dwTimeout); -// if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete - if ((dw != WAIT_FAILED) && (WAIT_OBJECT_0==(WaitForSingleObject(pSWMRG->hFinishEV,0)))) - { + dw = WaitForMultipleObjects(2, aHandles, TRUE, dwTimeout); + // if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete + if ((dw != WAIT_FAILED) && (WAIT_OBJECT_0 == (WaitForSingleObject(pSWMRG->hFinishEV, 0)))) { SetEvent(pSWMRG->hEventNoWriter); return WAIT_FINISH; } -// This thread can write to the shared data. -// Automatic event for NoWriter sets hEventNoWriter to nonsignaled after WaitForMultipleObject + // This thread can write to the shared data. + // Automatic event for NoWriter sets hEventNoWriter to nonsignaled after WaitForMultipleObject -// Because a writer thread is writing, the Event -// should not be reset. This stops other -// writers and readers. + // Because a writer thread is writing, the Event + // should not be reset. This stops other + // writers and readers. return dw; } @@ -178,38 +176,36 @@ void WINAPI SWMRGDoneWriting(PSWMRG pSWMRG) // do not have to wait on any synchronization objects // here because the writer already owns the Event. { -// Allow other writer/reader threads to use -// the SWMRG synchronization object. + // Allow other writer/reader threads to use + // the SWMRG synchronization object. SetEvent(pSWMRG->hEventNoWriter); } uint32_t WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, uint32_t dwTimeout) { - uint32_t dw; + uint32_t dw; LONG lPreviousCount; -// We can read if no threads are writing. -// And there's not request to delete structure - if (WAIT_OBJECT_0==(dw=WaitForSingleObject(pSWMRG->hFinishEV,0))) + // We can read if no threads are writing. + // And there's not request to delete structure + if (WAIT_OBJECT_0 == (dw = WaitForSingleObject(pSWMRG->hFinishEV, 0))) return WAIT_FINISH; - if (WAIT_FAILED==dw) + if (WAIT_FAILED == dw) return dw; - dw=WaitForSingleObject(pSWMRG->hEventNoWriter, dwTimeout); -// if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete - if ((dw != WAIT_FAILED) && (WAIT_OBJECT_0==(WaitForSingleObject(pSWMRG->hFinishEV,0)))) - { + dw = WaitForSingleObject(pSWMRG->hEventNoWriter, dwTimeout); + // if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete + if ((dw != WAIT_FAILED) && (WAIT_OBJECT_0 == (WaitForSingleObject(pSWMRG->hFinishEV, 0)))) { SetEvent(pSWMRG->hEventNoWriter); return WAIT_FINISH; } - if (dw==WAIT_OBJECT_0) - { - // This thread can read from the shared data. - // Increment the number of reader threads. - // But there can't be more than one thread incrementing readers, - // so this is why we use semaphore. - ReleaseSemaphore(pSWMRG->hSemNumReaders,1,&lPreviousCount); - if (lPreviousCount==0) + if (dw == WAIT_OBJECT_0) { + // This thread can read from the shared data. + // Increment the number of reader threads. + // But there can't be more than one thread incrementing readers, + // so this is why we use semaphore. + ReleaseSemaphore(pSWMRG->hSemNumReaders, 1, &lPreviousCount); + if (lPreviousCount == 0) // If this is the first reader thread, // set event to reflect this. Other reader threads can read, no writer thread can write. ResetEvent(pSWMRG->hEventNoReaders); @@ -228,49 +224,45 @@ void WINAPI SWMRGDoneReading(PSWMRG pSWMRG) HANDLE aHandles[2]; LONG lNumReaders; -// We can stop reading if the events are available, -// but when we stop reading we must also decrement the -// number of reader threads. - aHandles[0]=pSWMRG->hEventNoWriter; - aHandles[1]=pSWMRG->hSemNumReaders; - WaitForMultipleObjects(2,aHandles,TRUE,INFINITE); - -// Get the remaining number of readers by releasing the -// semaphore and then restoring the count by immediately -// performing a wait. - ReleaseSemaphore(pSWMRG->hSemNumReaders,1,&lNumReaders); - WaitForSingleObject(pSWMRG->hSemNumReaders,INFINITE); - -// If there are no remaining readers, -// set the event to relect this. - if (lNumReaders==0) + // We can stop reading if the events are available, + // but when we stop reading we must also decrement the + // number of reader threads. + aHandles[0] = pSWMRG->hEventNoWriter; + aHandles[1] = pSWMRG->hSemNumReaders; + WaitForMultipleObjects(2, aHandles, TRUE, INFINITE); + + // Get the remaining number of readers by releasing the + // semaphore and then restoring the count by immediately + // performing a wait. + ReleaseSemaphore(pSWMRG->hSemNumReaders, 1, &lNumReaders); + WaitForSingleObject(pSWMRG->hSemNumReaders, INFINITE); + + // If there are no remaining readers, + // set the event to relect this. + if (lNumReaders == 0) // If there are no reader threads, // set our event to reflect this. SetEvent(pSWMRG->hEventNoReaders); -// Allow other writer/reader threads to use -// the SWMRG synchronization object. -// (it looks like writer is processing thread, but it is not true) + // Allow other writer/reader threads to use + // the SWMRG synchronization object. + // (it looks like writer is processing thread, but it is not true) SetEvent(pSWMRG->hEventNoWriter); } -uint32_t WINAPI WaitToWriteFcn(PSWMRG SObject,PSCOUNTER SCounter) +uint32_t WINAPI WaitToWriteFcn(PSWMRG SObject, PSCOUNTER SCounter) { uint32_t EnterCode; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO WaitToWrite: %x\n",SObject); -#endif - if (WAIT_OBJECT_0==(EnterCode=SWMRGWaitToWrite(SObject,INFINITE))) + + if (WAIT_OBJECT_0 == (EnterCode = SWMRGWaitToWrite(SObject, INFINITE))) if (SCounter != nullptr) SCIncFcn(SCounter); + return EnterCode; } -void WINAPI WriteDoneFcn(PSWMRG SObject,PSCOUNTER SCounter) +void WINAPI WriteDoneFcn(PSWMRG SObject, PSCOUNTER SCounter) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO WriteDone: %x\n",SObject); -#endif SWMRGDoneWriting(SObject); if (SCounter != nullptr) SCDecFcn(SCounter); @@ -278,57 +270,33 @@ void WINAPI WriteDoneFcn(PSWMRG SObject,PSCOUNTER SCounter) uint32_t WINAPI WaitToReadFcn(PSWMRG SObject) { - uint32_t EnterCode; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO WaitToRead: %x\n",SObject); -#endif - EnterCode=SWMRGWaitToRead(SObject,INFINITE); + uint32_t EnterCode = SWMRGWaitToRead(SObject, INFINITE); return EnterCode; } void WINAPI ReadDoneFcn(PSWMRG SObject) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO ReadDone: %x\n",SObject); -#endif SWMRGDoneReading(SObject); } uint32_t WINAPI SCGetNumberFcn(PSCOUNTER SCounter) { - uint32_t Temp; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetNumber-cs wait\n"); -#endif + EnterCriticalSection(&SCounter->CounterCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetNumber-cs enter\n"); -#endif - Temp=SCounter->Number; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tValue: %d\n",Temp); - DebugLog(SynchroFile,"\tGetNumber-cs done\n"); -#endif + + uint32_t Temp = SCounter->Number; + LeaveCriticalSection(&SCounter->CounterCS); return Temp; } uint32_t WINAPI SCIncFcn(PSCOUNTER SCounter) { - uint32_t Temp; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tIncrementValue-cs wait\n"); -#endif EnterCriticalSection(&SCounter->CounterCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tIncrementValue-cs enter\n"); -#endif - Temp=++SCounter->Number; + + uint32_t Temp = ++SCounter->Number; ResetEvent(SCounter->Event); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tValue: %d\n",Temp); - DebugLog(SynchroFile,"\tIncrementValue-cs done\n"); -#endif + LeaveCriticalSection(&SCounter->CounterCS); return Temp; } @@ -336,24 +304,12 @@ uint32_t WINAPI SCIncFcn(PSCOUNTER SCounter) uint32_t WINAPI SCDecFcn(PSCOUNTER SCounter) { uint32_t Temp; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tDecrementValue-cs wait\n"); -#endif EnterCriticalSection(&SCounter->CounterCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tDecrementValue-cs enter\n"); -#endif - if (!(Temp=--SCounter->Number)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tDecrementValue-zero ev set\n"); -#endif + + if (!(Temp = --SCounter->Number)) { SetEvent(SCounter->Event); } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tValue: %d\n",Temp); - DebugLog(SynchroFile,"\tDecrementValue-cs done\n"); -#endif + LeaveCriticalSection(&SCounter->CounterCS); return Temp; } diff --git a/protocols/YAMN/src/yamn.cpp b/protocols/YAMN/src/yamn.cpp index 95156a4496..d0d80021f8 100644 --- a/protocols/YAMN/src/yamn.cpp +++ b/protocols/YAMN/src/yamn.cpp @@ -99,144 +99,80 @@ void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) CAccount *ActualAccount; DWORD Status, tid; -// we use event to signal, that running thread has all needed stack parameters copied + // we use event to signal, that running thread has all needed stack parameters copied HANDLE ThreadRunningEV = CreateEvent(nullptr, FALSE, FALSE, nullptr); if (ThreadRunningEV == nullptr) return; -// if we want to close miranda, we get event and do not run checking anymore - if (WAIT_OBJECT_0==WaitForSingleObject(ExitEV, 0)) + + // if we want to close miranda, we get event and do not run checking anymore + if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0)) return; -// Get actual status of current user in Miranda - Status=CallService(MS_CLIST_GETSTATUSMODE, 0, 0); + + // Get actual status of current user in Miranda + Status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0); mir_cslock lck(PluginRegCS); for (PYAMN_PROTOPLUGINQUEUE ActualPlugin = FirstProtoPlugin; ActualPlugin != nullptr; ActualPlugin = ActualPlugin->Next) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read wait\n"); -#endif - if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, 0)) //we want to access accounts immiadtelly - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter failed\n"); -#endif + if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, 0)) // we want to access accounts immiadtelly return; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter\n"); -#endif - for (ActualAccount=ActualPlugin->Plugin->FirstAccount;ActualAccount != nullptr;ActualAccount=ActualAccount->Next) - { - if (ActualAccount->Plugin==nullptr || ActualAccount->Plugin->Fcn==nullptr) //account not inited + + for (ActualAccount = ActualPlugin->Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next) { + if (ActualAccount->Plugin == nullptr || ActualAccount->Plugin->Fcn == nullptr) //account not inited continue; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait\n"); -#endif + if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualAccount->AccountAccessSO, 0)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait failed\n"); -#endif continue; - } -#ifdef DEBUG_SYNCHRO - switch(Status) - { - case ID_STATUS_OFFLINE: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status offline\n"); - break; - case ID_STATUS_ONLINE: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status online\n"); - break; - case ID_STATUS_AWAY: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status away\n"); - break; - case ID_STATUS_DND: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status dnd\n"); - break; - case ID_STATUS_NA: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status na\n"); - break; - case ID_STATUS_OCCUPIED: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status occupied\n"); - break; - case ID_STATUS_FREECHAT: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status freechat\n"); - break; - case ID_STATUS_INVISIBLE: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status invisible\n"); - break; - default: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status unknown\n"); - break; - } -#endif BOOL isAccountCounting = 0; - if ( - (ActualAccount->Flags & YAMN_ACC_ENA) && - (((ActualAccount->StatusFlags & YAMN_ACC_ST0) && (Status<=ID_STATUS_OFFLINE)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST1) && (Status==ID_STATUS_ONLINE)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST2) && (Status==ID_STATUS_AWAY)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST3) && (Status==ID_STATUS_DND)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST4) && (Status==ID_STATUS_NA)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST5) && (Status==ID_STATUS_OCCUPIED)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST6) && (Status==ID_STATUS_FREECHAT)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST7) && (Status==ID_STATUS_INVISIBLE)))) + if ((ActualAccount->Flags & YAMN_ACC_ENA) && + (((ActualAccount->StatusFlags & YAMN_ACC_ST0) && (Status <= ID_STATUS_OFFLINE)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST1) && (Status == ID_STATUS_ONLINE)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST2) && (Status == ID_STATUS_AWAY)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST3) && (Status == ID_STATUS_DND)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST4) && (Status == ID_STATUS_NA)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST5) && (Status == ID_STATUS_OCCUPIED)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST6) && (Status == ID_STATUS_FREECHAT)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST7) && (Status == ID_STATUS_INVISIBLE)))) { - - if ((!ActualAccount->Interval && !ActualAccount->TimeLeft) || ActualAccount->Plugin->Fcn->TimeoutFcnPtr==nullptr) - { + if ((!ActualAccount->Interval && !ActualAccount->TimeLeft) || ActualAccount->Plugin->Fcn->TimeoutFcnPtr == nullptr) goto ChangeIsCountingStatusLabel; - } + if (ActualAccount->TimeLeft) { ActualAccount->TimeLeft--; isAccountCounting = TRUE; } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:time left : %i\n", ActualAccount->TimeLeft); -#endif + WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_CHANGETIME, (WPARAM)ActualAccount, (LPARAM)ActualAccount->TimeLeft); - if (!ActualAccount->TimeLeft) - { - struct CheckParam ParamToPlugin={YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_NORMALCHECK, (void *)nullptr, nullptr}; + if (!ActualAccount->TimeLeft) { + struct CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_NORMALCHECK, (void *)nullptr, nullptr}; - ActualAccount->TimeLeft=ActualAccount->Interval; + ActualAccount->TimeLeft = ActualAccount->Interval; HANDLE NewThread = CreateThread(nullptr, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->TimeoutFcnPtr, &ParamToPlugin, 0, &tid); - if (NewThread == nullptr) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); -#endif + if (NewThread == nullptr) { ReadDoneFcn(ActualAccount->AccountAccessSO); continue; } - else - { + else { WaitForSingleObject(ThreadRunningEV, INFINITE); CloseHandle(NewThread); } } - } + ChangeIsCountingStatusLabel: -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); -#endif if (((ActualAccount->isCounting) != 0) != isAccountCounting) { - ActualAccount->isCounting=isAccountCounting; + ActualAccount->isCounting = isAccountCounting; uint16_t cStatus = g_plugin.getWord(ActualAccount->hContact, "Status"); switch (cStatus) { - case ID_STATUS_ONLINE: - case ID_STATUS_OFFLINE: - g_plugin.setWord(ActualAccount->hContact, "Status", isAccountCounting ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE); - default: break; + case ID_STATUS_ONLINE: + case ID_STATUS_OFFLINE: + g_plugin.setWord(ActualAccount->hContact, "Status", isAccountCounting ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE); + default: + break; } } ReadDoneFcn(ActualAccount->AccountAccessSO); } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read done\n"); -#endif SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); } CloseHandle(ThreadRunningEV); @@ -258,30 +194,15 @@ INT_PTR ForceCheckSvc(WPARAM, LPARAM) { mir_cslock lck(PluginRegCS); for (PYAMN_PROTOPLUGINQUEUE ActualPlugin = FirstProtoPlugin; ActualPlugin != nullptr; ActualPlugin = ActualPlugin->Next) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read wait\n"); -#endif SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read enter\n"); -#endif for (ActualAccount = ActualPlugin->Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next) { if (ActualAccount->Plugin->Fcn == nullptr) //account not inited continue; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); -#endif + + if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) continue; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); -#endif - if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check - { + + if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) { //account cannot be forced to check if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr == nullptr) { ReadDoneFcn(ActualAccount->AccountAccessSO); continue; @@ -297,9 +218,6 @@ INT_PTR ForceCheckSvc(WPARAM, LPARAM) } ReadDoneFcn(ActualAccount->AccountAccessSO); } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read done\n"); -#endif SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); } } |