From 1704480100a35875a8742f3c7a11426d92bb1b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 3 Dec 2011 01:05:11 +0100 Subject: [PATCH] Read some more specs, cleaned Protocol a bit. * Added some TODO comments based on the various IMAP specs and extensions. * Removed SelectMailbox() functionality from the Protocol class; it's not really useful to have it there. * Removed some other methods that don't belong into the Protocol class. --- .../imap/imap_lib/Commands.cpp | 1 + .../imap/imap_lib/Commands.h | 1 + .../imap/imap_lib/Protocol.cpp | 49 ++++--------------- .../imap/imap_lib/Protocol.h | 14 +----- src/tests/add-ons/mail/imap/imap_tester.cpp | 8 ++- 5 files changed, 19 insertions(+), 54 deletions(-) diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.cpp index 20734f6770..4c07b16eb0 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.cpp @@ -216,6 +216,7 @@ SelectCommand::CommandString() return ""; BString command = "SELECT \""; + // TODO: properly quote the string! command += fMailboxName; command += "\""; return command; diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.h b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.h index 08d8f66467..6af04f7b74 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.h +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Commands.h @@ -39,6 +39,7 @@ enum MessageFlags { kFlagged = 0x04, kDeleted = 0x08, kDraft = 0x10 + // \Recent doesn't really have any useful meaning, so we just ignore it }; diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp index dbd3d6f737..9b7c60f67f 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp @@ -28,7 +28,6 @@ Protocol::Protocol() fSocket(NULL), fBufferedSocket(NULL), fCommandID(0), - fStopNow(0), fIsConnected(false) { } @@ -44,21 +43,6 @@ Protocol::~Protocol() } - -void -Protocol::SetStopNow() -{ - atomic_set(&fStopNow, 1); -} - - -bool -Protocol::StopNow() -{ - return (atomic_get(&fStopNow) != 0); -} - - status_t Protocol::Connect(const BNetworkAddress& address, const char* username, const char* password, bool useSSL) @@ -93,6 +77,16 @@ Protocol::Connect(const BNetworkAddress& address, const char* username, } _ParseCapabilities(login.Capabilities()); + + if (fCapabilities.IsEmpty()) { + CapabilityHandler capabilityHandler; + status = ProcessCommand(capabilityHandler); + if (status != B_OK) + return status; + + _ParseCapabilities(capabilityHandler.Capabilities()); + } + return B_OK; } @@ -179,29 +173,6 @@ Protocol::UnsubscribeFolder(const char* folder) } -status_t -Protocol::SelectMailbox(const char* mailbox) -{ - TRACE("SELECT %s\n", mailbox); - SelectCommand command(mailbox); - status_t status = ProcessCommand(command); - if (status != B_OK) - return status; - - if (fCapabilities.IsEmpty()) { - CapabilityHandler capabilityHandler; - status = ProcessCommand(capabilityHandler); - if (status != B_OK) - return status; - - _ParseCapabilities(capabilityHandler.Capabilities()); - } - - fMailbox = mailbox; - return B_OK; -} - - status_t Protocol::GetQuota(uint64& used, uint64& total) { diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h index 218b8d3b90..1244d1bfe9 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h @@ -55,11 +55,6 @@ public: Protocol(); ~Protocol(); - /*! Indicates that the current action should be interrupted because - we are going to be deleted. */ - void SetStopNow(); - bool StopNow(); - status_t Connect(const BNetworkAddress& address, const char* username, const char* password, bool useSSL = true); @@ -70,17 +65,12 @@ public: status_t SendCommand(int32 id, const char* command); ssize_t SendData(const char* buffer, uint32 length); + // Some convenience methods status_t GetFolders(FolderList& folders); status_t SubscribeFolder(const char* folder); status_t UnsubscribeFolder(const char* folder); - - status_t SelectMailbox(const char* mailbox); - const BString& Mailbox() const { return fMailbox; } - status_t GetQuota(uint64& used, uint64& total); - /*! Install a temporary handler at first position in the handler - list. */ status_t ProcessCommand(Command& command, bigtime_t timeout = kIMAP4ClientTimeout); @@ -117,12 +107,10 @@ protected: ArgumentList fCapabilities; private: - BString fMailbox; int32 fCommandID; CommandIDMap fOngoingCommands; BString fCommandError; - vint32 fStopNow; bool fIsConnected; }; diff --git a/src/tests/add-ons/mail/imap/imap_tester.cpp b/src/tests/add-ons/mail/imap/imap_tester.cpp index 702c649860..b9173de98b 100644 --- a/src/tests/add-ons/mail/imap/imap_tester.cpp +++ b/src/tests/add-ons/mail/imap/imap_tester.cpp @@ -53,8 +53,12 @@ do_select(int argc, char** argv) if (argc > 1) folder = argv[1]; - status_t status = sProtocol.SelectMailbox(folder); - if (status != B_OK) + IMAP::SelectCommand command(folder); + status_t status = sProtocol.ProcessCommand(command); + if (status == B_OK) { + printf("Next UID: %" B_PRIu32 ", UID validity: %" B_PRIu32 "\n", + command.NextUID(), command.UIDValidity()); + } else error("select", status); }