From 186c96d50c1df03eb711dce3d1d22ebae88c18ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 18 Jan 2013 18:19:24 +0100 Subject: [PATCH] IMAP: Early work in progress of main protocol class. --- .../inbound_protocols/imap/IMAPProtocol.cpp | 110 ++++++++++++++++++ .../inbound_protocols/imap/IMAPProtocol.h | 46 ++++++++ .../inbound_protocols/imap/Jamfile | 1 + .../inbound_protocols/imap/Settings.cpp | 13 ++- .../inbound_protocols/imap/Settings.h | 5 +- 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp create mode 100644 src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.h 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 0000000000..d44b1f8dd0 --- /dev/null +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp @@ -0,0 +1,110 @@ +/* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include "IMAPProtocol.h" + +#include + +#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 0000000000..cce468cadc --- /dev/null +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.h @@ -0,0 +1,46 @@ +/* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef IMAP_PROTOCOL_H +#define IMAP_PROTOCOL_H + + +#include + +#include +#include + +#include "Settings.h" + + +class IMAPConnectionWorker; +typedef std::set 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 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 8345f8b5a8..ff846fc482 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 a872b9eb60..c647e416a2 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@pinc-software.de. + * Copyright 2011-2013, Axel Dörfler, axeld@pinc-software.de. * 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 2022a8b816..db49290821 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@pinc-software.de. + * Copyright 2011-2013, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ #ifndef SETTINGS_H @@ -8,6 +8,7 @@ #include #include +#include class Settings { @@ -24,6 +25,8 @@ public: BString Username() const; BString Password() const; + BPath Destination() const; + private: const BMessage fMessage; };