diff options
author | Don Sanders <don.sanders@nokia.com> | 2012-05-04 16:09:54 +0300 |
---|---|---|
committer | Don Sanders <don.sanders@nokia.com> | 2012-05-04 16:11:23 +0300 |
commit | fb77481ebc850cd5dee7d4dc3496cff206ac69be (patch) | |
tree | a83ab7093f232c6b329c4f6edc08316fe3e6a937 | |
parent | 0466e0c8cf7367b1cf50ca25b3aa5cbeff08eadc (diff) |
Fix bug with pop mails not being deleted from pop server.
When syncing pop service was not waiting for response from
server after sending a QUIT command.
Fix by updating pop service logic as follows, if mails are
to be deleted from server then issue a QUIT command immediately
after deleting mails. This is because after issuing a DELE
command a QUIT command must be issued to force the POP server
to really delete mails.
Otherwise if not mails are deleted then keep the connection
open for several seconds, so that if a client makes another service
request, e.g. to fetch the body of a mail left on the server then
the existing connection can be reused.
However as an exception if a sync (retrieveMessageList) is
requested, when the connection is already open, then the
connection is closed and reopened, because this is necessary
in order to see new mails listed.
To test this change a tried several different uses cases
1) Sync after deleting (empty from trash) mails using device
2) Sync after not deleting mails
3) Do 1 then quickly sync before connection is closed
4) Do 1 then sync after connection is closed
5) Do 2 then quickly do 1 before connection is closed
6) Do 2 then do 1 again after connection is closed
7) Do 1 then download body of message left on server
-rw-r--r-- | src/plugins/messageservices/pop/popclient.cpp | 46 | ||||
-rw-r--r-- | src/plugins/messageservices/pop/popclient.h | 2 |
2 files changed, 38 insertions, 10 deletions
diff --git a/src/plugins/messageservices/pop/popclient.cpp b/src/plugins/messageservices/pop/popclient.cpp index a7b9199d..d9feaea8 100644 --- a/src/plugins/messageservices/pop/popclient.cpp +++ b/src/plugins/messageservices/pop/popclient.cpp @@ -83,7 +83,8 @@ PopClient::PopClient(QObject* parent) partialContent(false), dataStream(new LongStream), transport(0), - testing(false) + testing(false), + pendingDeletes(false) { inactiveTimer.setSingleShot(true); connect(&inactiveTimer, SIGNAL(timeout()), this, SLOT(connectionInactive())); @@ -123,9 +124,26 @@ void PopClient::createTransport() } } +void PopClient::deleteTransport() +{ + if (transport) { + // Need to immediately disconnect these signals or slots may try to use null transport object + disconnect(transport, SIGNAL(updateStatus(QString)), this, SIGNAL(updateStatus(QString))); + disconnect(transport, SIGNAL(connected(QMailTransport::EncryptType)), this, SLOT(connected(QMailTransport::EncryptType))); + disconnect(transport, SIGNAL(errorOccurred(int,QString)), this, SLOT(transportError(int,QString))); + disconnect(transport, SIGNAL(readyRead()), this, SLOT(incomingData())); + + // A Qt socket remains in an unusuable state for a short time after closing, + // thus it can't be immediately reused + transport->deleteLater(); + transport = 0; + } +} + void PopClient::testConnection() { testing = true; + pendingDeletes = false; closeConnection(); PopConfiguration popCfg(config); @@ -145,6 +163,7 @@ void PopClient::testConnection() void PopClient::newConnection() { testing = false; + pendingDeletes = false; lastStatusTimer.start(); if (transport && transport->connected()) { if (selected) { @@ -366,10 +385,7 @@ void PopClient::closeConnection() transport->close(); } } - // A Qt socket remains in an unusuable state for a short time after closing, - // thus it can't be immediately reused - transport->deleteLater(); - transport = 0; + deleteTransport(); } void PopClient::sendCommand(const char *data, int len) @@ -415,7 +431,7 @@ QString PopClient::readResponse() void PopClient::incomingData() { - while (transport->canReadLine()) { + while (transport && transport->canReadLine()) { QString response = readResponse(); processResponse(response); } @@ -614,7 +630,9 @@ void PopClient::processResponse(const QString &response) } case Exit: { - transport->close(); //close regardless of response + closeConnection(); //close regardless of response + retrieveOperationCompleted(); + waitForInput = true; break; } @@ -632,7 +650,7 @@ void PopClient::processResponse(const QString &response) } // Are we waiting for further input? - if (!waitForInput && transport->inUse()) { + if (!waitForInput && transport && transport->inUse()) { // Go on to the next action nextAction(); } @@ -841,6 +859,7 @@ void PopClient::nextAction() QMailStore::instance()->removeMessages(accountKey & uidKey, QMailStore::NoRemovalRecord); } } else { + pendingDeletes = true; messageUid = uid; } } @@ -874,10 +893,13 @@ void PopClient::nextAction() setSelectedMails(completionList); nextStatus = RequestMessage; + } else if (pendingDeletes) { + nextStatus = Quit; } else { // We're all done retrieveOperationCompleted(); waitForInput = true; + nextStatus = Quit; } break; } @@ -886,11 +908,11 @@ void PopClient::nextAction() emit updateStatus(tr("Logging out")); nextStatus = Exit; nextCommand = "QUIT"; + waitForInput = true; break; } case Exit: { - transport->close(); //close regardless waitForInput = true; break; } @@ -1205,7 +1227,9 @@ void PopClient::retrieveOperationCompleted() // Or it may have been requested by a waiting client emit retrievalCompleted(); - deactivateConnection(); + if (transport) { + deactivateConnection(); + } } void PopClient::deactivateConnection() @@ -1239,6 +1263,7 @@ void PopClient::operationFailed(int code, const QString &text) { if (transport && transport->inUse()) { transport->close(); + deleteTransport(); } emit errorOccurred(code, text); @@ -1248,6 +1273,7 @@ void PopClient::operationFailed(QMailServiceAction::Status::ErrorCode code, cons { if (transport && transport->inUse()) { transport->close(); + deleteTransport(); } QString msg; diff --git a/src/plugins/messageservices/pop/popclient.h b/src/plugins/messageservices/pop/popclient.h index b8b677a5..23012b03 100644 --- a/src/plugins/messageservices/pop/popclient.h +++ b/src/plugins/messageservices/pop/popclient.h @@ -75,6 +75,7 @@ public: bool synchronizationEnabled(const QMailFolderId &id) const; void createTransport(); + void deleteTransport(); void testConnection(); void newConnection(); void closeConnection(); @@ -187,6 +188,7 @@ private: QVector<QMailMessage*> _bufferedMessages; QVector<QMailMessageBufferFlushCallback*> callbacks; bool testing; + bool pendingDeletes; }; #endif |