IMAP: Early work in progress of main protocol class.
This commit is contained in:
parent
3ab3f57ad2
commit
186c96d50c
110
src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp
Normal file
110
src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.cpp
Normal file
@ -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 <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);
|
||||
}
|
@ -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 <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
|
@ -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
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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 <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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user