added 3 changesets to branch 'refs/remotes/axeld-github/imap' old head: 9f59320a95d055e53d866fc0709f532e2c14a56a new head: 3c3383e3b1917d10bf6d259f65ba4f57dde7aa61 overview: https://github.com/axeld/haiku/compare/9f59320...3c3383e ---------------------------------------------------------------------------- d04e209: IMAP: FolderList is supposed to be an interface. * Made its methods pure virtual. 3422cc6: IMAP: Early work in progress of main protocol class. 3c3383e: Minor cleanup. [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 7 files changed, 177 insertions(+), 6 deletions(-) headers/os/add-ons/mail_daemon/MailProtocol.h | 2 +- .../inbound_protocols/imap/IMAPFolder.h | 6 +- .../inbound_protocols/imap/IMAPProtocol.cpp | 110 +++++++++++++++++++ .../inbound_protocols/imap/IMAPProtocol.h | 46 ++++++++ .../mail_daemon/inbound_protocols/imap/Jamfile | 1 + .../inbound_protocols/imap/Settings.cpp | 13 ++- .../inbound_protocols/imap/Settings.h | 5 +- ############################################################################ Commit: d04e2093a467153c0f6c9c457f1e707d223e6ce5 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Fri Jan 18 17:17:46 2013 UTC IMAP: FolderList is supposed to be an interface. * Made its methods pure virtual. ---------------------------------------------------------------------------- diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h index 9742fef..0fd4b89 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h @@ -25,12 +25,12 @@ struct MessageToken { class FolderListener { public: virtual uint32 MessageAdded(const MessageToken& fromToken, - const entry_ref& ref); - virtual void MessageDeleted(const MessageToken& token); + const entry_ref& ref) = 0; + virtual void MessageDeleted(const MessageToken& token) = 0; virtual void MessageFlagsChanged(const MessageToken& token, const entry_ref& ref, uint32 oldFlags, - uint32 newFlags); + uint32 newFlags) = 0; }; ############################################################################ Commit: 3422cc6d161059403c19d5e1c6e483b817617b02 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Fri Jan 18 17:19:24 2013 UTC IMAP: Early work in progress of main protocol class. ---------------------------------------------------------------------------- diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp new file mode 100644 index 0000000..d44b1f8 --- /dev/null +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp @@ -0,0 +1,110 @@ +/* + * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. + * Distributed under the terms of the MIT License. + */ + + +#include "IMAPProtocol.h" + +#include <Directory.h> + +#include "IMAPConnectionWorker.h" + + +IMAPProtocol::IMAPProtocol(const BMailAccountSettings& settings) + : + BInboundMailProtocol(settings), + fSettings(settings.InboundSettings()) +{ + puts("IMAP protocol started"); + + BPath destination = fSettings.Destination(); + + status_t status = create_directory(destination.Path(), 0755); + if (status != B_OK) { + fprintf(stderr, "imap: Could not create destination directory %s: %s\n", + destination.Path(), strerror(status)); + } + + PostMessage(B_READY_TO_RUN); +} + + +IMAPProtocol::~IMAPProtocol() +{ +} + + +status_t +IMAPProtocol::SyncMessages() +{ + puts("IMAP: sync"); + return B_ERROR; +} + + +status_t +IMAPProtocol::FetchBody(const entry_ref& ref) +{ + printf("IMAP: fetch body %s\n", ref.name); + return B_ERROR; +} + + +status_t +IMAPProtocol::MarkMessageAsRead(const entry_ref& ref, read_flags flags) +{ + printf("IMAP: mark as read %s: %d\n", ref.name, flags); + return B_ERROR; +} + + +status_t +IMAPProtocol::DeleteMessage(const entry_ref& ref) +{ + printf("IMAP: delete message %s\n", ref.name); + return B_ERROR; +} + + +status_t +IMAPProtocol::AppendMessage(const entry_ref& ref) +{ + printf("IMAP: append message %s\n", ref.name); + return B_ERROR; +} + + +void +IMAPProtocol::MessageReceived(BMessage* message) +{ + switch (message->what) { + case B_READY_TO_RUN: + ReadyToRun(); + break; + } +} + + +void +IMAPProtocol::ReadyToRun() +{ + // Determine how many connection workers we'll need + // TODO: in passive mode, this should be done on every sync + + IMAP::Protocol protocol; + status_t status = protocol.Connect(fSettings.ServerAddress(), + fSettings.Username(), fSettings.Password(), fSettings.UseSSL()); + if (status != B_OK) + return; +} + + +// #pragma mark - + + +extern "C" BInboundMailProtocol* +instantiate_inbound_protocol(const BMailAccountSettings& settings) +{ + return new IMAPProtocol(settings); +} diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.h b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.h new file mode 100644 index 0000000..cce468c --- /dev/null +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.h @@ -0,0 +1,46 @@ +/* + * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. + * Distributed under the terms of the MIT License. + */ +#ifndef IMAP_PROTOCOL_H +#define IMAP_PROTOCOL_H + + +#include <set> + +#include <MailProtocol.h> +#include <ObjectList.h> + +#include "Settings.h" + + +class IMAPConnectionWorker; +typedef std::set<BString> StringSet; + + +class IMAPProtocol : public BInboundMailProtocol { +public: + IMAPProtocol( + const BMailAccountSettings& settings); + virtual ~IMAPProtocol(); + + virtual status_t SyncMessages(); + virtual status_t FetchBody(const entry_ref& ref); + virtual status_t MarkMessageAsRead(const entry_ref& ref, + read_flags flags = B_READ); + virtual status_t DeleteMessage(const entry_ref& ref); + virtual status_t AppendMessage(const entry_ref& ref); + + virtual void MessageReceived(BMessage* message); + +protected: + void ReadyToRun(); + +protected: + Settings fSettings; + BObjectList<IMAPConnectionWorker> fWorkers; + StringSet fKnownMailboxes; +}; + + +#endif // IMAP_PROTOCOL_H diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile b/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile index 80cfe1d..46c6513 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/Jamfile @@ -18,6 +18,7 @@ SubDirHdrs [ FDirName $(HAIKU_TOP) headers os add-ons mail_daemon ] ; local sources = # IMAPInboundProtocol.cpp # IMAPRootInboundProtocol.cpp + IMAPProtocol.cpp ConfigView.cpp FolderConfigWindow.cpp IMAPFolder.cpp diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.cpp index a872b9e..c647e41 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. + * Copyright 2011-2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. * Distributed under the terms of the MIT License. */ @@ -85,3 +85,14 @@ Settings::Password() const return ""; } + + +BPath +Settings::Destination() const +{ + BString destination; + if (fMessage.FindString("destination", &destination) == B_OK) + return BPath(destination); + + return "/boot/home/mail/in"; +} diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.h b/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.h index 2022a8b..db49290 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.h +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.h @@ -1,5 +1,5 @@ /* - * Copyright 2011, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. + * Copyright 2011-2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. * Distributed under the terms of the MIT License. */ #ifndef SETTINGS_H @@ -8,6 +8,7 @@ #include <Message.h> #include <NetworkAddress.h> +#include <Path.h> class Settings { @@ -24,6 +25,8 @@ public: BString Username() const; BString Password() const; + BPath Destination() const; + private: const BMessage fMessage; }; ############################################################################ Commit: 3c3383e3b1917d10bf6d259f65ba4f57dde7aa61 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Fri Jan 18 17:20:01 2013 UTC Minor cleanup. ---------------------------------------------------------------------------- diff --git a/headers/os/add-ons/mail_daemon/MailProtocol.h b/headers/os/add-ons/mail_daemon/MailProtocol.h index cd5a306..bb90719 100644 --- a/headers/os/add-ons/mail_daemon/MailProtocol.h +++ b/headers/os/add-ons/mail_daemon/MailProtocol.h @@ -127,7 +127,7 @@ public: virtual status_t SyncMessages() = 0; virtual status_t FetchBody(const entry_ref& ref) = 0; virtual status_t MarkMessageAsRead(const entry_ref& ref, - read_flags flag = B_READ); + read_flags flags = B_READ); virtual status_t DeleteMessage(const entry_ref& ref) = 0; virtual status_t AppendMessage(const entry_ref& ref);