summaryrefslogtreecommitdiff
path: root/protocols/YAMN/src/proto
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-12-12 21:11:44 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-12-12 21:11:44 +0300
commit46793bcdf9bdc0c48a509aa1a2d41dbc262500bf (patch)
treee0a2f1824c50a2ee0a0b9b4de82867db43e67f85 /protocols/YAMN/src/proto
parentf72215dbc4afeaf81fad333eb6de01591637021b (diff)
YAMN: code cleaning
Diffstat (limited to 'protocols/YAMN/src/proto')
-rw-r--r--protocols/YAMN/src/proto/netlib.cpp7
-rw-r--r--protocols/YAMN/src/proto/pop3/pop3.cpp95
-rw-r--r--protocols/YAMN/src/proto/pop3/pop3comm.cpp221
-rw-r--r--protocols/YAMN/src/proto/pop3/pop3opt.cpp10
4 files changed, 82 insertions, 251 deletions
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);