[haiku-commits] BRANCH axeld-github.imap - src/add-ons/mail_daemon/inbound_protocols/pop3 headers/os/add-ons/mail_daemon

  • From: axeld-github.imap <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 16 Jan 2013 14:15:55 +0100 (CET)

added 3 changesets to branch 'refs/remotes/axeld-github/imap'
old head: a9f0a9774c458110d09d51cd702fba2f60668982
new head: 637d9274475e51fbd807b58623954c5a8e37436e
overview: https://github.com/axeld/haiku/compare/a9f0a97...637d927

----------------------------------------------------------------------------

f454182: Clarified progress parameter names for the MailProtocol.

9e203f2: pop3: Fixed maintaining fSizes list, and more.
  
  * The list was filled, but never emptied.
  * If SyncMessages() was called more than once for the same POP3 instance,
    this could garble the mails retrieved in the second run.
  * Maintain the total size of mails in fSizes to be able to report progress
    in more detail.
  * Also adapted progress reporting to the argument changes made in MailProtocol
    earlier.
  * Minor cleanup.

637d927: pop3: minor cleanup.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 65 insertions(+), 68 deletions(-)
headers/os/add-ons/mail_daemon/MailProtocol.h    |   6 +-
.../mail_daemon/inbound_protocols/pop3/POP3.cpp  | 106 +++++++++----------
.../mail_daemon/inbound_protocols/pop3/POP3.h    |  21 ++--

############################################################################

Commit:      f454182baf660b89237ae2c5e3fd454f8b66e0bb
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Jan 16 12:52:15 2013 UTC

Clarified progress parameter names for the MailProtocol.

----------------------------------------------------------------------------

diff --git a/headers/os/add-ons/mail_daemon/MailProtocol.h 
b/headers/os/add-ons/mail_daemon/MailProtocol.h
index 32cb150..cd5a306 100644
--- a/headers/os/add-ons/mail_daemon/MailProtocol.h
+++ b/headers/os/add-ons/mail_daemon/MailProtocol.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2012, Haiku, Inc. All Rights Reserved.
+ * Copyright 2004-2013, Haiku, Inc. All Rights Reserved.
  * Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
  * Copyright 2011 Clemens Zeidler. All rights reserved.
  *
@@ -37,7 +37,7 @@ public:
 
        virtual void                            SetTotalItems(uint32 items) = 0;
        virtual void                            SetTotalItemsSize(uint64 size) 
= 0;
-       virtual void                            ReportProgress(uint32 messages, 
uint64 bytes,
+       virtual void                            ReportProgress(uint32 items, 
uint64 bytes,
                                                                        const 
char* message = NULL) = 0;
        virtual void                            ResetProgress(const char* 
message = NULL) = 0;
 };
@@ -85,7 +85,7 @@ public:
 protected:
                        void                            SetTotalItems(uint32 
items);
                        void                            
SetTotalItemsSize(uint64 size);
-                       void                            ReportProgress(uint32 
messages, uint64 bytes,
+                       void                            ReportProgress(uint32 
items, uint64 bytes,
                                                                        const 
char* message = NULL);
                        void                            ResetProgress(const 
char* message = NULL);
 

############################################################################

Commit:      9e203f2541fc94ef06d547990adabdc0117a82ad
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Jan 16 13:01:32 2013 UTC

pop3: Fixed maintaining fSizes list, and more.

* The list was filled, but never emptied.
* If SyncMessages() was called more than once for the same POP3 instance,
  this could garble the mails retrieved in the second run.
* Maintain the total size of mails in fSizes to be able to report progress
  in more detail.
* Also adapted progress reporting to the argument changes made in MailProtocol
  earlier.
* Minor cleanup.

----------------------------------------------------------------------------

diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp 
b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
index bff7f74..f360f1b 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007-2012, Haiku, Inc. All rights reserved.
+ * Copyright 2007-2013, Haiku, Inc. All rights reserved.
  * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
  * Copyright 2011, Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx>
  *
@@ -144,15 +144,16 @@ POP3Protocol::SyncMessages()
        _ReadManifest();
 
        SetTotalItems(2);
-       ReportProgress(0, 1, B_TRANSLATE("Connect to server" B_UTF8_ELLIPSIS));
+       ReportProgress(1, 0, B_TRANSLATE("Connect to server" B_UTF8_ELLIPSIS));
 
        status_t error = Connect();
        if (error != B_OK) {
+               printf("POP3 could not connect: %s\n", strerror(error));
                ResetProgress();
                return error;
        }
 
-       ReportProgress(0, 1, B_TRANSLATE("Getting UniqueIDs" B_UTF8_ELLIPSIS));
+       ReportProgress(1, 0, B_TRANSLATE("Getting UniqueIDs" B_UTF8_ELLIPSIS));
 
        error = _RetrieveUniqueIDs();
        if (error < B_OK) {
@@ -174,6 +175,7 @@ POP3Protocol::SyncMessages()
 
        ResetProgress();
        SetTotalItems(toDownload.CountStrings());
+       SetTotalItemsSize(fTotalSize);
 
        printf("POP3: Messages to download: %i\n", 
(int)toDownload.CountStrings());
        for (int32 i = 0; i < toDownload.CountStrings(); i++) {
@@ -230,7 +232,7 @@ POP3Protocol::SyncMessages()
                        }
                        NotifyHeaderFetched(ref, &file);
                }
-               ReportProgress(0, 1);
+               ReportProgress(1, 0);
 
                if (file.WriteAttr("MAIL:unique_id", B_STRING_TYPE, 0, uid,
                                strlen(uid)) < 0)
@@ -305,7 +307,7 @@ POP3Protocol::FetchBody(const entry_ref& ref)
        if (!leaveOnServer)
                Delete(toRetrieve);
 
-       ReportProgress(0, 1);
+       ReportProgress(1, 0);
        ResetProgress();
 
        Disconnect();
@@ -361,43 +363,31 @@ POP3Protocol::Open(const char* server, int port, int)
        if (port != 110)
                errorMessage << ":" << port;
 
-       uint32 hostIP = inet_addr(server);
-               // first see if we can parse it as a numeric address
-       if (hostIP == 0 || hostIP == ~0UL) {
-               struct hostent * he = gethostbyname(server);
-               hostIP = he ? *((uint32*)he->h_addr) : 0;
-       }
-
-       if (hostIP == 0) {
-               errorMessage << B_TRANSLATE(": Connection refused or host not 
found");
-               ShowError(errorMessage.String());
-
-               return B_NAME_NOT_FOUND;
-       }
-
        delete fServerConnection;
        fServerConnection = NULL;
-       if (fUseSSL) {
-               fServerConnection = new(std::nothrow) BSecureSocket(
-                       BNetworkAddress(server, port));
-       } else {
-               fServerConnection = new(std::nothrow) BSocket(BNetworkAddress(
-                       server, port));
-       }
 
-       if (fServerConnection == NULL)
-               return B_NO_MEMORY;
-       if (fServerConnection->InitCheck() != B_OK)
-               return fServerConnection->InitCheck();
+       BNetworkAddress address(server, port);
+       if (fUseSSL)
+               fServerConnection = new(std::nothrow) BSecureSocket(address);
+       else
+               fServerConnection = new(std::nothrow) BSocket(address);
+
+       status_t status = B_NO_MEMORY;
+       if (fServerConnection != NULL)
+               status = fServerConnection->InitCheck();
 
        BString line;
-       status_t err = ReceiveLine(line);
+       if (status == B_OK) {
+               ssize_t length = ReceiveLine(line);
+               if (length < 0)
+                       status = length;
+       }
 
-       if (err < 0) {
+       if (status != B_OK) {
                fServerConnection->Disconnect();
-               errorMessage << ": " << strerror(err);
+               errorMessage << ": " << strerror(status);
                ShowError(errorMessage.String());
-               return B_ERROR;
+               return status;
        }
 
        if (strncmp(line.String(), "+OK", 3) != 0) {
@@ -584,14 +574,14 @@ POP3Protocol::Retrieve(int32 message, BPositionIO* to)
        BString cmd;
        cmd << "RETR " << message + 1 << CRLF;
        status_t status = RetrieveInternal(cmd.String(), message, to, true);
-       ReportProgress(0, 1);
+       ReportProgress(1, 0);
 
        if (status == B_OK) {
                // Check if the actual message size matches the expected one
                int32 size = MessageSize(message);
                to->Seek(0, SEEK_END);
                if (to->Position() != size) {
-                       printf ("POP3Protocol::Retrieve Note: message size is 
%d, was "
+                       printf("POP3Protocol::Retrieve Note: message size is 
%d, was "
                                "expecting %ld, for message #%ld.  Could be a 
transmission "
                                "error or a bad POP server implementation (does 
it remove "
                                "escape codes when it counts size?).\n",
@@ -623,7 +613,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
        // after the message.  Of course, if we get it wrong (or it is a huge
        // message or has lines starting with escaped periods), it will then 
switch
        // back to receiving full buffers until the message is done.
-       int amountToReceive = MessageSize (message) + 3;
+       int amountToReceive = MessageSize(message) + 3;
        if (amountToReceive >= bufSize || amountToReceive <= 0)
                amountToReceive = bufSize - 1;
 
@@ -720,7 +710,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
                        if (amountInBuffer > 4) {
                                to->Write(buf, amountInBuffer - 4);
                                if (postProgress)
-                                       ReportProgress(amountInBuffer - 4, 0);
+                                       ReportProgress(0, amountInBuffer - 4);
                                memmove (buf, buf + amountInBuffer - 4, 4);
                                amountInBuffer = 4;
                        }
@@ -728,7 +718,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
                        // Dump everything - end of message or flushing the 
whole buffer.
                        to->Write(buf, amountInBuffer);
                        if (postProgress)
-                               ReportProgress(amountInBuffer, 0);
+                               ReportProgress(0, amountInBuffer);
                        amountInBuffer = 0;
                }
        }
@@ -760,10 +750,10 @@ POP3Protocol::MessageSize(int32 index)
 }
 
 
-int32
+ssize_t
 POP3Protocol::ReceiveLine(BString& line)
 {
-       int32 len = 0;
+       int32 length = 0;
        bool flag = false;
 
        line = "";
@@ -789,16 +779,16 @@ POP3Protocol::ReceiveLine(BString& line)
                        flag = true;
                } else {
                        if (flag) {
-                               len++;
+                               length++;
                                line += '\r';
                                flag = false;
                        }
-                       len++;
+                       length++;
                        line += (char)c;
                }
        }
 
-       return len;
+       return length;
 }
 
 
@@ -873,6 +863,8 @@ status_t
 POP3Protocol::_RetrieveUniqueIDs()
 {
        fUniqueIDs.MakeEmpty();
+       fSizes.MakeEmpty();
+       fTotalSize = 0;
 
        status_t status = SendCommand("UIDL" CRLF);
        if (status != B_OK)
@@ -902,6 +894,8 @@ POP3Protocol::_RetrieveUniqueIDs()
                        size = atol(&result.String()[index]);
                else
                        size = 0;
+
+               fTotalSize += size;
                fSizes.AddItem((void*)size);
        }
 
diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h 
b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h
index 67bd408..b4092f2 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007-2012, Haiku Inc. All Rights Reserved.
+ * Copyright 2007-2013, Haiku Inc. All Rights Reserved.
  * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
  * Copyright 2011, Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx>
  *
@@ -59,7 +59,7 @@ protected:
                                                                        int32 
message, BPositionIO *writeTo,
                                                                        bool 
showProgress);
 
-                       int32                           ReceiveLine(BString 
&line);
+                       ssize_t                         ReceiveLine(BString& 
line);
                        status_t                        SendCommand(const char* 
cmd);
                        void                            MD5Digest(unsigned char 
*in, char *out);
 
@@ -73,6 +73,7 @@ private:
                        int32                           fNumMessages;
                        size_t                          fMailDropSize;
                        BList                           fSizes;
+                       off_t                           fTotalSize;
                        BMessage                        fSettings;
 
                        BStringList                     fManifest;

############################################################################

Commit:      637d9274475e51fbd807b58623954c5a8e37436e
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Wed Jan 16 13:11:14 2013 UTC

pop3: minor cleanup.

----------------------------------------------------------------------------

diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp 
b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
index f360f1b..56c677a 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.cpp
@@ -670,11 +670,13 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
                        testStr = buf + testIndex;
                        if (testStr[0] == '\r' && testStr[1] == '\n' && 
testStr[2] == '.') {
                                if (testStr[3] == '\r' && testStr[4] == '\n') {
-                                       // Found the end of the message marker. 
 Ignore remaining data.
-                                       if (amountInBuffer > testIndex + 5)
-                                               printf 
("POP3Protocol::RetrieveInternal Ignoring %d bytes "
-                                                       "of extra data past 
message end.\n",
+                                       // Found the end of the message marker.
+                                       // Ignore remaining data.
+                                       if (amountInBuffer > testIndex + 5) {
+                                               
printf("POP3Protocol::RetrieveInternal Ignoring %d "
+                                                       "bytes of extra data 
past message end.\n",
                                                        amountInBuffer - 
(testIndex + 5));
+                                       }
                                        amountInBuffer = testIndex + 2; // 
Don't include ".\r\n".
                                        buf[amountInBuffer] = 0;
                                        cont = false;
@@ -684,8 +686,8 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
                                        // dot starting a line of text.  Of 
course, a file with a
                                        // lot of double period lines will get 
processed very
                                        // slowly.
-                                       memmove (buf + testIndex + 2, buf + 
testIndex + 3,
-                                               amountInBuffer - (testIndex + 
3) + 1 /* for NUL at end */);
+                                       memmove(buf + testIndex + 2, buf + 
testIndex + 3,
+                                               amountInBuffer - (testIndex + 
3) + 1);
                                        amountInBuffer--;
                                        // Watch out for the end of buffer 
case, when the POP text
                                        // is "\r\n..X".  Don't want to leave 
the resulting
@@ -693,7 +695,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
                                        // since that will get mistakenly 
evaluated again in the
                                        // next loop and delete a character by 
mistake.
                                        if (testIndex >= amountInBuffer - 4 && 
testStr[2] == '.') {
-                                               printf 
("POP3Protocol::RetrieveInternal: Jackpot!  "
+                                               
printf("POP3Protocol::RetrieveInternal: Jackpot!  "
                                                        "You have hit the rare 
situation with an escaped "
                                                        "period at the end of 
the buffer.  Aren't you happy"
                                                        "it decodes it 
correctly?\n");
@@ -711,7 +713,7 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
                                to->Write(buf, amountInBuffer - 4);
                                if (postProgress)
                                        ReportProgress(0, amountInBuffer - 4);
-                               memmove (buf, buf + amountInBuffer - 4, 4);
+                               memmove(buf, buf + amountInBuffer - 4, 4);
                                amountInBuffer = 4;
                        }
                } else {
@@ -727,10 +729,10 @@ POP3Protocol::RetrieveInternal(const char* command, int32 
message,
 
 
 void
-POP3Protocol::Delete(int32 num)
+POP3Protocol::Delete(int32 index)
 {
        BString cmd = "DELE ";
-       cmd << (num+1) << CRLF;
+       cmd << (index + 1) << CRLF;
        if (SendCommand(cmd.String()) != B_OK) {
                // Error
        }
@@ -837,7 +839,7 @@ POP3Protocol::SendCommand(const char* cmd)
 
 
 void
-POP3Protocol::MD5Digest(unsigned char *in, char *asciiDigest)
+POP3Protocol::MD5Digest(unsigned char* in, char* asciiDigest)
 {
        unsigned char digest[16];
 
diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h 
b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h
index b4092f2..b82c942 100644
--- a/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h
+++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/POP3.h
@@ -38,15 +38,15 @@ public:
                        status_t                        FetchBody(const 
entry_ref& ref);
                        status_t                        DeleteMessage(const 
entry_ref& ref);
 
-                       status_t                        Retrieve(int32 message, 
BPositionIO *write_to);
-                       status_t                        GetHeader(int32 
message, BPositionIO *write_to);
-                       void                            Delete(int32 num);
+                       status_t                        Retrieve(int32 message, 
BPositionIO* to);
+                       status_t                        GetHeader(int32 
message, BPositionIO* to);
+                       void                            Delete(int32 index);
 
 protected:
                        // pop3 methods
-                       status_t                        Open(const char 
*server, int port,
+                       status_t                        Open(const char* 
server, int port,
                                                                        int 
protocol);
-                       status_t                        Login(const char *uid, 
const char *password,
+                       status_t                        Login(const char* uid, 
const char* password,
                                                                        int 
method);
 
                        size_t                          MessageSize(int32 
index);
@@ -55,13 +55,13 @@ protected:
                        size_t                          MailDropSize(void);
                        void                            
CheckForDeletedMessages();
 
-                       status_t                        RetrieveInternal(const 
char *command,
-                                                                       int32 
message, BPositionIO *writeTo,
+                       status_t                        RetrieveInternal(const 
char* command,
+                                                                       int32 
message, BPositionIO* to,
                                                                        bool 
showProgress);
 
                        ssize_t                         ReceiveLine(BString& 
line);
                        status_t                        SendCommand(const char* 
cmd);
-                       void                            MD5Digest(unsigned char 
*in, char *out);
+                       void                            MD5Digest(unsigned 
char* in, char* out);
 
 private:
                        status_t                        _RetrieveUniqueIDs();


Other related posts:

  • » [haiku-commits] BRANCH axeld-github.imap - src/add-ons/mail_daemon/inbound_protocols/pop3 headers/os/add-ons/mail_daemon - axeld-github . imap