diff options
Diffstat (limited to 'protocols/YAMN/src')
| -rw-r--r-- | protocols/YAMN/src/proto/netclient.h | 2 | ||||
| -rw-r--r-- | protocols/YAMN/src/proto/netlib.h | 6 | ||||
| -rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3.cpp | 205 | ||||
| -rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3.h | 2 | ||||
| -rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3comm.cpp | 2 | 
5 files changed, 104 insertions, 113 deletions
diff --git a/protocols/YAMN/src/proto/netclient.h b/protocols/YAMN/src/proto/netclient.h index 99ec0888f1..dff43ae0f1 100644 --- a/protocols/YAMN/src/proto/netclient.h +++ b/protocols/YAMN/src/proto/netclient.h @@ -5,6 +5,8 @@ class CNetClient  {  public:  	CNetClient(): Stopped(FALSE) {} +	virtual ~CNetClient() {} +  	virtual void Connect(const char* servername, const int port)=0;  	virtual void Send(const char *query)=0;  	virtual char* Recv(char *buf= nullptr, int buflen=65536)=0; diff --git a/protocols/YAMN/src/proto/netlib.h b/protocols/YAMN/src/proto/netlib.h index 778d6497ed..dfa3d93508 100644 --- a/protocols/YAMN/src/proto/netlib.h +++ b/protocols/YAMN/src/proto/netlib.h @@ -4,7 +4,7 @@  class CNLClient: public CNetClient  {  public: -	CNLClient(): hConnection(nullptr) {} +	CNLClient() {}  	void Connect(const char* servername, const int port) throw(DWORD);  	void Send(const char *query) throw(DWORD);  	char* Recv(char *buf= nullptr, int buflen = 65536) throw(DWORD); @@ -14,8 +14,8 @@ public:  	inline BOOL Connected() {return hConnection != nullptr;}  protected: -	HNETLIBCONN hConnection; -	BOOL isTLSed; +	HNETLIBCONN hConnection = nullptr; +	BOOL isTLSed = false;  	int LocalNetlib_Send(HNETLIBCONN hConn, const char *buf, int len, int flags);  	int LocalNetlib_Recv(HNETLIBCONN hConn, char *buf, int len, int flags);  }; diff --git a/protocols/YAMN/src/proto/pop3/pop3.cpp b/protocols/YAMN/src/proto/pop3/pop3.cpp index d47fac4836..d263d332e4 100644 --- a/protocols/YAMN/src/proto/pop3/pop3.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3.cpp @@ -34,51 +34,48 @@  //sets AckFlag  char *CPop3Client::Connect(const char* servername,const int port,BOOL UseSSL, BOOL NoTLS)  { -	char *temp = nullptr; -	if (Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +	if (Stopped) // check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED; -	if (NetClient != nullptr) -		delete NetClient; -	SSL=UseSSL; -	NetClient=new CNLClient; +	delete NetClient; +	SSL = UseSSL; +	NetClient = new CNLClient;  #ifdef DEBUG_DECODE -	DebugLog(DecodeFile,"Connect:servername: %s port:%d\n",servername,port); +	DebugLog(DecodeFile, "Connect:servername: %s port:%d\n", servername, port);  #endif -	POP3Error=EPOP3_CONNECT; -	NetClient->Connect(servername,port); -	POP3Error=0; - -	if (SSL) -	{ -		try { NetClient->SSLify(); }  -		catch (...)  -		{ +	POP3Error = EPOP3_CONNECT; +	NetClient->Connect(servername, port); +	POP3Error = 0; + +	if (SSL) { +		try {  +			NetClient->SSLify(); +		} +		catch (...) {  			NetClient->Disconnect();  			return nullptr;  		}  	} -	temp = RecvRest(NetClient->Recv(),POP3_SEARCHACK); +	char *temp = RecvRest(NetClient->Recv(), POP3_SEARCHACK);  	extern BOOL SSLLoaded;  	if (!NoTLS & !(SSL)) {  		if (NetClient->Stopped)			//check if we can work with this POP3 client session -			throw POP3Error=(DWORD)EPOP3_STOPPED; +			throw POP3Error = (DWORD)EPOP3_STOPPED;  		NetClient->Send("STLS\r\n");  		free(temp); -		temp=RecvRest(NetClient->Recv(),POP3_SEARCHACK); -		if (AckFlag==POP3_FOK) { // Ok, we are going to tls +		temp = RecvRest(NetClient->Recv(), POP3_SEARCHACK); +		if (AckFlag == POP3_FOK) { // Ok, we are going to tls  			try {  				NetClient->SSLify(); -			} catch (...) { +			} +			catch (...) {  				NetClient->Disconnect();  				return nullptr;  			} -//			temp = RecvRest(NetClient->Recv(),POP3_SEARCHACK);  		} -	}  -//	SSL_DebugLog("Received: %s",temp); +	}  	return temp;  } @@ -91,6 +88,7 @@ char *CPop3Client::Connect(const char* servername,const int port,BOOL UseSSL, BO  //       new memory. New allocated memory has allocated size more bytes  //       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)  {  	int SizeRead=0; @@ -134,18 +132,17 @@ char* CPop3Client::RecvRest(char* prev,int mode,int size)  // if you need to add condition for mode, insert it into switch statement  BOOL CPop3Client::SearchFromEnd(char *end,int bs,int mode)  { -	while(bs>=0) -	{ -		switch(mode) -		{ -			case POP3_SEARCHDOT: -				if (DOTLINE(end)) -					return 1; -				break; -			case POP3_SEARCHNL: -				if (ENDLINE(end)) -					return 1; -				break; +	while (bs >= 0) { +		switch (mode) { +		case POP3_SEARCHDOT: +			if (DOTLINE(end)) +				return 1; +			break; + +		case POP3_SEARCHNL: +			if (ENDLINE(end)) +				return 1; +			break;  		}  		end--;  		bs--; @@ -159,31 +156,26 @@ BOOL CPop3Client::SearchFromEnd(char *end,int bs,int mode)  //if you need to add condition for mode, insert it into switch statement  BOOL CPop3Client::SearchFromStart(char *start,int bs,int mode)  { -	while(bs>=0) -	{ -		switch(mode) -		{ -			case POP3_SEARCHOK: -				if (OKLINE(start)) -				{ -					AckFlag=POP3_FOK; -					return 1; -				} -				break; -			case POP3_SEARCHERR: -				if (ERRLINE(start)) -				{ -					AckFlag=POP3_FERR; -					return 1; -				} -				break; -			case POP3_SEARCHACK: -				if (ACKLINE(start)) -				{ -					OKLINE(start) ? AckFlag=POP3_FOK : AckFlag=POP3_FERR; -					return 1; -				} -				break; +	while (bs >= 0) { +		switch (mode) { +		case POP3_SEARCHOK: +			if (OKLINE(start)) { +				AckFlag = POP3_FOK; +				return 1; +			} +			break; +		case POP3_SEARCHERR: +			if (ERRLINE(start)) { +				AckFlag = POP3_FERR; +				return 1; +			} +			break; +		case POP3_SEARCHACK: +			if (ACKLINE(start)) { +				OKLINE(start) ? AckFlag = POP3_FOK : AckFlag = POP3_FERR; +				return 1; +			} +			break;  		}  		start++;  		bs--; @@ -195,18 +187,18 @@ BOOL CPop3Client::SearchFromStart(char *start,int bs,int mode)  //sets AckFlag  char* CPop3Client::User(char* name)  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +	if (NetClient->Stopped) // check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED;  	char query[128];  	char *Result;  	mir_snprintf(query, "USER %s\r\n", name);  	NetClient->Send(query); -	Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); -	if (AckFlag==POP3_FERR) -		throw POP3Error=(DWORD)EPOP3_BADUSER; -	POP3Error=0; +	Result = RecvRest(NetClient->Recv(), POP3_SEARCHACK); +	if (AckFlag == POP3_FERR) +		throw POP3Error = (DWORD)EPOP3_BADUSER; +	POP3Error = 0;  	return Result;  } @@ -215,16 +207,15 @@ char* CPop3Client::User(char* name)  char* CPop3Client::Pass(char* pw)  {  	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +		throw POP3Error = (DWORD)EPOP3_STOPPED;  	char query[128]; -	char *Result; -  	mir_snprintf(query, "PASS %s\r\n", pw);  	NetClient->Send(query); -	Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); -	if (AckFlag==POP3_FERR) -		throw POP3Error=(DWORD)EPOP3_BADPASS; +	 +	char *Result = RecvRest(NetClient->Recv(), POP3_SEARCHACK); +	if (AckFlag == POP3_FERR) +		throw POP3Error = (DWORD)EPOP3_BADPASS;  	return Result;  } @@ -232,28 +223,28 @@ char* CPop3Client::Pass(char* pw)  //sets AckFlag  char* CPop3Client::APOP(char* name, char* pw, char* timestamp)  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +	if (NetClient->Stopped) // check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED;  	char query[512];  	char *Result;  	unsigned char digest[16]; -	if (timestamp==nullptr) -		throw POP3Error=(DWORD)EPOP3_APOP; +	if (timestamp == nullptr) +		throw POP3Error = (DWORD)EPOP3_APOP;  	mir_md5_state_s ctx;  	mir_md5_init(&ctx); -	mir_md5_append(&ctx,(const unsigned char *)timestamp,(unsigned int)mir_strlen(timestamp)); -	mir_md5_append(&ctx,(const unsigned char *)pw,(unsigned int)mir_strlen(pw)); +	mir_md5_append(&ctx, (const unsigned char *)timestamp, (unsigned int)mir_strlen(timestamp)); +	mir_md5_append(&ctx, (const unsigned char *)pw, (unsigned int)mir_strlen(pw));  	mir_md5_finish(&ctx, digest);  	char hexdigest[40];  	mir_snprintf(query, "APOP %s %s\r\n", name, bin2hex(digest, sizeof(digest), hexdigest));  	NetClient->Send(query); -	Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); -	if (AckFlag==POP3_FERR) -		throw POP3Error=(DWORD)EPOP3_BADUSER; +	Result = RecvRest(NetClient->Recv(), POP3_SEARCHACK); +	if (AckFlag == POP3_FERR) +		throw POP3Error = (DWORD)EPOP3_BADUSER;  	return Result;  } @@ -271,33 +262,32 @@ char* CPop3Client::Quit()  //sets AckFlag  char* CPop3Client::Stat()  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; - -	char query[]="STAT\r\n"; +	if (NetClient->Stopped) //check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED; +	char query[] = "STAT\r\n";  	NetClient->Send(query); -	return RecvRest(NetClient->Recv(),POP3_SEARCHACK); +	return RecvRest(NetClient->Recv(), POP3_SEARCHACK);  }  //Performs "LIST" pop query and returns server response  //sets AckFlag  char* CPop3Client::List()  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +	if (NetClient->Stopped) // check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED; -	char query[]="LIST\r\n"; +	char query[] = "LIST\r\n";  	NetClient->Send(query); -	return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); +	return RecvRest(NetClient->Recv(), POP3_SEARCHDOT);  }  //Performs "TOP" pop query and returns server response  //sets AckFlag  char* CPop3Client::Top(int nr, int lines)  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session +	if (NetClient->Stopped) // check if we can work with this POP3 client session  		throw POP3Error=(DWORD)EPOP3_STOPPED;  	char query[128]; @@ -311,46 +301,45 @@ char* CPop3Client::Top(int nr, int lines)  //sets AckFlag  char* CPop3Client::Uidl(int nr)  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +	if (NetClient->Stopped) // check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED;  	char query[128]; - -	if (nr) -	{ +	if (nr) {  		mir_snprintf(query, "UIDL %d\r\n", nr);  		NetClient->Send(query); -		return RecvRest(NetClient->Recv(),POP3_SEARCHACK); +		return RecvRest(NetClient->Recv(), POP3_SEARCHACK);  	}  	mir_snprintf(query, "UIDL\r\n");  	NetClient->Send(query); -	return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); +	return RecvRest(NetClient->Recv(), POP3_SEARCHDOT);  }  //Performs "DELE" pop query and returns server response  //sets AckFlag  char* CPop3Client::Dele(int nr)  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +	if (NetClient->Stopped) // check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED;  	char query[128];  	mir_snprintf(query, "DELE %d\r\n", nr);  	NetClient->Send(query); -	return RecvRest(NetClient->Recv(),POP3_SEARCHACK); +	return RecvRest(NetClient->Recv(), POP3_SEARCHACK);  } +  //Performs "RETR" pop query and returns server response  //sets AckFlag  char* CPop3Client::Retr(int nr)  { -	if (NetClient->Stopped)			//check if we can work with this POP3 client session -		throw POP3Error=(DWORD)EPOP3_STOPPED; +	if (NetClient->Stopped) // check if we can work with this POP3 client session +		throw POP3Error = (DWORD)EPOP3_STOPPED;  	char query[128]; -  	mir_snprintf(query, "RETR %d\r\n", nr);  	NetClient->Send(query); -	RecvRest(NetClient->Recv(),POP3_SEARCHACK); + +	RecvRest(NetClient->Recv(), POP3_SEARCHACK);  	return NetClient->Recv(); -}
\ No newline at end of file +} diff --git a/protocols/YAMN/src/proto/pop3/pop3.h b/protocols/YAMN/src/proto/pop3/pop3.h index 1fd7994bed..1005f3a47b 100644 --- a/protocols/YAMN/src/proto/pop3/pop3.h +++ b/protocols/YAMN/src/proto/pop3/pop3.h @@ -20,7 +20,7 @@ class CPop3Client  {  public:  	CPop3Client(): NetClient(nullptr), Stopped(FALSE) {} -	~CPop3Client() {if (NetClient != nullptr) delete NetClient;} +	~CPop3Client() { delete NetClient; }  	char* Connect(const char* servername,const int port=110,BOOL UseSSL=FALSE, BOOL NoTLS=FALSE);  	char* RecvRest(char* prev,int mode,int size=65536); diff --git a/protocols/YAMN/src/proto/pop3/pop3comm.cpp b/protocols/YAMN/src/proto/pop3/pop3comm.cpp index 4d85a94f0c..93f7885135 100644 --- a/protocols/YAMN/src/proto/pop3/pop3comm.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3comm.cpp @@ -1488,7 +1488,7 @@ void ExtractList(char *stream, int len, HYAMNMAIL queue)  		while (!WS(finder)) finder++;			//jump characters  		while (WS(finder)) finder++;			//jump whitespace  		finderend = finder + 1; -		if (1 != sscanf(finder, "%d", &queueptr->MailData->Size)) +		if (1 != sscanf(finder, "%u", &queueptr->MailData->Size))  			throw (DWORD)EPOP3_LIST;  #ifdef DEBUG_DECODE  		DebugLog(DecodeFile,"<Nr>%d</Nr>\n",queueptr->MailData->Size);  | 
