pop3: minor cleanup.

This commit is contained in:
Axel Dörfler
2015-01-06 15:24:24 +01:00
parent a9de7ece6b
commit d6ce6060b9
2 changed files with 21 additions and 19 deletions
@@ -671,11 +671,13 @@ POP3Protocol::RetrieveInternal(const char* command, int32 message,
testStr = buf + testIndex; testStr = buf + testIndex;
if (testStr[0] == '\r' && testStr[1] == '\n' && testStr[2] == '.') { if (testStr[0] == '\r' && testStr[1] == '\n' && testStr[2] == '.') {
if (testStr[3] == '\r' && testStr[4] == '\n') { if (testStr[3] == '\r' && testStr[4] == '\n') {
// Found the end of the message marker. Ignore remaining data. // Found the end of the message marker.
if (amountInBuffer > testIndex + 5) // Ignore remaining data.
printf ("POP3Protocol::RetrieveInternal Ignoring %d bytes " if (amountInBuffer > testIndex + 5) {
"of extra data past message end.\n", printf("POP3Protocol::RetrieveInternal Ignoring %d "
"bytes of extra data past message end.\n",
amountInBuffer - (testIndex + 5)); amountInBuffer - (testIndex + 5));
}
amountInBuffer = testIndex + 2; // Don't include ".\r\n". amountInBuffer = testIndex + 2; // Don't include ".\r\n".
buf[amountInBuffer] = 0; buf[amountInBuffer] = 0;
cont = false; cont = false;
@@ -685,8 +687,8 @@ POP3Protocol::RetrieveInternal(const char* command, int32 message,
// dot starting a line of text. Of course, a file with a // dot starting a line of text. Of course, a file with a
// lot of double period lines will get processed very // lot of double period lines will get processed very
// slowly. // slowly.
memmove (buf + testIndex + 2, buf + testIndex + 3, memmove(buf + testIndex + 2, buf + testIndex + 3,
amountInBuffer - (testIndex + 3) + 1 /* for NUL at end */); amountInBuffer - (testIndex + 3) + 1);
amountInBuffer--; amountInBuffer--;
// Watch out for the end of buffer case, when the POP text // Watch out for the end of buffer case, when the POP text
// is "\r\n..X". Don't want to leave the resulting // is "\r\n..X". Don't want to leave the resulting
@@ -694,7 +696,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32 message,
// since that will get mistakenly evaluated again in the // since that will get mistakenly evaluated again in the
// next loop and delete a character by mistake. // next loop and delete a character by mistake.
if (testIndex >= amountInBuffer - 4 && testStr[2] == '.') { if (testIndex >= amountInBuffer - 4 && testStr[2] == '.') {
printf ("POP3Protocol::RetrieveInternal: Jackpot! " printf("POP3Protocol::RetrieveInternal: Jackpot! "
"You have hit the rare situation with an escaped " "You have hit the rare situation with an escaped "
"period at the end of the buffer. Aren't you happy" "period at the end of the buffer. Aren't you happy"
"it decodes it correctly?\n"); "it decodes it correctly?\n");
@@ -712,7 +714,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32 message,
to->Write(buf, amountInBuffer - 4); to->Write(buf, amountInBuffer - 4);
if (postProgress) if (postProgress)
ReportProgress(0, amountInBuffer - 4); ReportProgress(0, amountInBuffer - 4);
memmove (buf, buf + amountInBuffer - 4, 4); memmove(buf, buf + amountInBuffer - 4, 4);
amountInBuffer = 4; amountInBuffer = 4;
} }
} else { } else {
@@ -728,10 +730,10 @@ POP3Protocol::RetrieveInternal(const char* command, int32 message,
void void
POP3Protocol::Delete(int32 num) POP3Protocol::Delete(int32 index)
{ {
BString cmd = "DELE "; BString cmd = "DELE ";
cmd << (num+1) << CRLF; cmd << (index + 1) << CRLF;
if (SendCommand(cmd.String()) != B_OK) { if (SendCommand(cmd.String()) != B_OK) {
// Error // Error
} }
@@ -838,7 +840,7 @@ POP3Protocol::SendCommand(const char* cmd)
void void
POP3Protocol::MD5Digest(unsigned char *in, char *asciiDigest) POP3Protocol::MD5Digest(unsigned char* in, char* asciiDigest)
{ {
unsigned char digest[16]; unsigned char digest[16];
@@ -38,15 +38,15 @@ public:
status_t FetchBody(const entry_ref& ref); status_t FetchBody(const entry_ref& ref);
status_t DeleteMessage(const entry_ref& ref); status_t DeleteMessage(const entry_ref& ref);
status_t Retrieve(int32 message, BPositionIO *write_to); status_t Retrieve(int32 message, BPositionIO* to);
status_t GetHeader(int32 message, BPositionIO *write_to); status_t GetHeader(int32 message, BPositionIO* to);
void Delete(int32 num); void Delete(int32 index);
protected: protected:
// pop3 methods // pop3 methods
status_t Open(const char *server, int port, status_t Open(const char* server, int port,
int protocol); int protocol);
status_t Login(const char *uid, const char *password, status_t Login(const char* uid, const char* password,
int method); int method);
size_t MessageSize(int32 index); size_t MessageSize(int32 index);
@@ -55,13 +55,13 @@ protected:
size_t MailDropSize(void); size_t MailDropSize(void);
void CheckForDeletedMessages(); void CheckForDeletedMessages();
status_t RetrieveInternal(const char *command, status_t RetrieveInternal(const char* command,
int32 message, BPositionIO *writeTo, int32 message, BPositionIO* to,
bool showProgress); bool showProgress);
ssize_t ReceiveLine(BString& line); ssize_t ReceiveLine(BString& line);
status_t SendCommand(const char* cmd); status_t SendCommand(const char* cmd);
void MD5Digest(unsigned char *in, char *out); void MD5Digest(unsigned char* in, char* out);
private: private:
status_t _RetrieveUniqueIDs(); status_t _RetrieveUniqueIDs();