Imported MDR. Some code still not entirely functional -- I haven't been able to figure out how to detect SSL, so IMAP and POP have it turned off. PPP auto-detect is also not functional at the moment. Other than that, it seems to work beautifully. Packaging will come later.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9016 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Nathan Whitehorn
2004-09-20 22:31:50 +00:00
parent 48061f2026
commit f7215ac853
154 changed files with 75670 additions and 0 deletions
@@ -0,0 +1,98 @@
#ifndef ZOIDBERG_MAIL_CHAIN_RUNNER_H
#define ZOIDBERG_MAIL_CHAIN_RUNNER_H
/* ChainRunner - runs the mail inbound and outbound chains
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <MailAddon.h>
#include <MailSettings.h>
#include <Looper.h>
#include <status.h>
class BStringList;
class BMailStatusWindow;
class BMailChain;
class BMailChainCallback {
public:
virtual void Callback(status_t result) = 0;
// Called by the callback routines in ChainRunner
// result is the message that ended the chain
// (MD_HANDLED, MD_DISCARD, MD_NO_MORE_MESSAGES)
// Obviously, for process callbacks, result is
// gauranteed to be MD_NO_MORE_MESSAGES.
};
class BMailChainRunner : public BLooper {
public:
BMailChainRunner(BMailChain *chain, BMailStatusWindow *status,
bool self_destruct_when_done = true, bool save_chain_when_done = false,
bool destruct_chain_when_done = false);
~BMailChainRunner();
//----Callback functions. Callback objects will be deleted for you.
void RegisterMessageCallback(BMailChainCallback *callback);
// Your callback->Callback() function will be called when
// the current message is done being processed.
void RegisterProcessCallback(BMailChainCallback *callback);
// Your callback->Callback() function will be called when
// a filter returns MD_PASS_COMPLETE and before we go back
// to waiting for new messages, or when the fetch list
// runs out.
void RegisterChainCallback(BMailChainCallback *callback);
// Your callback->Callback() function will be called when
// a filter returns MD_ALL_PASSES_DONE and before everything
// is unloaded and sent home.
void Stop();
void ReportProgress(int bytes, int messages, const char *message = NULL);
void ResetProgress(const char *message = NULL);
void GetMessages(BStringList *list, int32 bytes);
void GetSingleMessage(const char *uid, int32 length, BPath *into);
// The bytes or length field is the total size, used for updating the
// progress bar. Use -1 for unknown maximum size.
bool QuitRequested();
void ShowError(const char *error);
void ShowMessage(const char *message);
BMailChain *Chain();
//----The big, bad asynchronous RunChain() function. Pretty harmless looking, huh?
status_t RunChain(bool asynchronous = true);
void MessageReceived (BMessage *msg);
private:
void CallCallbacksFor(BList &list, status_t code);
void get_messages(BStringList *list);
status_t Init();
#if USE_NASTY_SYNC_THREAD_HACK
static int32 thread_sync_func(void *arg);
status_t init_addons();
#endif
BMailChain *_chain;
BList message_cb, process_cb, chain_cb;
bool destroy_self, destroy_chain, save_chain;
BMailStatusWindow *_status;
BMailStatusView *_statview;
BList addons;
bool suicide;
uint8 _other_reserved[3];
uint32 _reserved[4];
};
BMailChainRunner *GetMailChainRunner(int32 chain_id, BMailStatusWindow *status, bool selfDestruct = true);
#endif /* ZOIDBERG_MAIL_CHAIN_RUNNER_H */
+151
View File
@@ -0,0 +1,151 @@
#ifndef ZOIDBERG_MAIL_ADDON_H
#define ZOIDBERG_MAIL_ADDON_H
/* Filter - the base class for all mail filters
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
class BMessage;
class BView;
class BPositionIO;
class BEntry;
class BPath;
class BView;
class BString;
class BPositionIO;
class BEntry;
enum {
B_MAIL_DISCARD = B_MAIL_ERROR_BASE + 8,
//--- This terminates the chain and removes the message being processed
// both from disk and from the server.
B_MAIL_END_FETCH,
//--- Terminates the current operation
B_MAIL_END_CHAIN
//--- This is for yikes errors, like an unreachable server.
};
class BMailStatusView;
class BMailChainRunner;
class BMailFilter
{
public:
BMailFilter(BMessage* settings);
// How to support queueing messages until a time of the
// day/week/month/year? The settings will contain a
// persistent ChainID field, the same for all Filters
// on the same "chain".
virtual ~BMailFilter();
// This will be called when the settings for this Filter
// are changed, or there are no new messages to consume
// after settings->FindInt32("timeout") seconds.
virtual status_t InitCheck(BString* out_message = NULL) = 0;
// Returns B_OK if the Filter was constructed success-
// fully. Otherwise it returns an error code. If it is
// passed a valid BString*, it may add an error message
// to the end of that BString iff it returns an error.
// If it returns an error code then the MailFilter will
// probably be deleted and the error shown to the user.
virtual status_t ProcessMailMessage
(
BPositionIO** io_message, BEntry* io_entry,
BMessage* io_headers, BPath* io_folder, const char *io_uid
) = 0;
// Filters a message. On input and output, the arguments
// are expected to be as below; however it is allowed for
// the MailFilter to alter any of these values as nece-
// ssary, so long as the constraints are as described when
// the function returns:
//
// * io_message - a PositionIO that contains the message
// data, pointing to the first byte of the message's
// header. This can be swapped if, eg, the message
// is copied across volume boundries. When the chain
// begins this is a file in /tmp.
// * io_entry - The entry for the PositionIO above.
// * io_headers - a list of attributes that will be added
// to the message file.
// * io_folder - The message's "folder"---may be com-
// pletely unrelated to its on-disk Entry.
// * io_uid - The unique ID provided by the message's
// Protocol
//
// At most one Filter::ProcessMailMessage() for a given
// chain (and thus ChainID) will be called at a time.
private:
virtual void _ReservedFilter1();
virtual void _ReservedFilter2();
virtual void _ReservedFilter3();
virtual void _ReservedFilter4();
};
//
// The addon interface: export instantiate_mailfilter()
// and instantiate_mailconfig() to create a Filter addon
//
extern "C" _EXPORT BView* instantiate_config_panel(BMessage *settings,BMessage *metadata);
// return a view that configures the MailProtocol or MailFilter
// returned by the functions below. BView::Archive(foo,true)
// produces this addon's settings, which are passed to the in-
// stantiate_* functions and stored persistently. This function
// should gracefully handle empty and NULL settings.
// A note on the metadata argument: The metadata pointer is
// guaranteed to remain valid as long as this view exists. As it is
// a pointer to the chain's metadata, your view can save any
// chain-global settings to it in its Archive() function. Note that
// you must cache this pointer yourself! You will never get it again.
// Also note that it is possible for it to be NULL.
extern "C" _EXPORT BMailFilter* instantiate_mailfilter(BMessage *settings,
BMailChainRunner *runner);
// Return a MailProtocol or MailFilter ready to do its thing,
// based on settings produced by archiving your config panel.
// Note that a Mail::Protocol is a Mail::Filter, so use
// instantiate_mailfilter to start things up.
extern "C" _EXPORT status_t descriptive_name(BMessage *msg, char *buffer);
// the config panel will show this name in the chains filter
// list if this function returns B_OK.
// The buffer is as big as B_FILE_NAME_LENGTH.
// standard Filters:
//
// * Parser - does ParseRFC2822(io_message,io_headers)
// * Folder - stores the message in the specified folder,
// optionally under io_folder, returns MD_HANDLED
// * HeaderFilter(regex,Yes_fiters,No_filters) -
// Applies Nes_filters to messages that have a header
// matching regex; applies No_filters otherwise.
// * CompatabilityFilter - Invokes the standard mail_dae-
// mon filter ~/config/settings/add-ons/MailDaemon/Filter
// on the message's Entry.
// * Producer - Reads outbound messages from disk and inserts
// them into the queue.
// * SMTPSender - Sends the message, via the specified
// SMTP server, to the people in header field
// "MAIL:recipients", changes the the Entry's
// "MAIL:flags" field to no longer pending, changes the
// "MAIL:status" header field to "Sent", and adds a header
// field "MAIL:when" with the time it was sent.
// * Dumper - returns MD_DISCARD
//
//
// Standard chain types:
//
// Incoming Mail: Protocol - Parser - Notifier - Folder
// Outgoing Mail: Producer - SMTPSender
//
// "chains" are lists of addons that appear in, or can be
// added to, the "Accounts" list in the config panel, a tree-
// view ordered by the chain type and the chain's AccountName().
// Their config views should be shown, one after the other,
// in the config panel.
#endif /* ZOIDBERG_MAIL_ADDON_H */
@@ -0,0 +1,107 @@
#ifndef ZOIDBERG_MAIL_PROTOCOL_H
#define ZOIDBERG_MAIL_PROTOCOL_H
/* Protocol - the base class for protocol filters
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <OS.h>
#include <MailAddon.h>
class BHandler;
class BStringList;
class BMailChainRunner;
class BMailProtocol : public BMailFilter
{
public:
BMailProtocol(BMessage* settings, BMailChainRunner *runner);
// Open a connection based on 'settings'. 'settings' will
// contain a persistent uint32 ChainID field. At most one
// Protocol per ChainID will exist at a given time.
// The constructor of Mail::Protocol initializes manifest.
// It is your responsibility to fill in unique_ids, *and
// to keep it updated* in the course of whatever nefarious
// things your protocol does.
virtual ~BMailProtocol();
// Close the connection and clean up. This will be cal-
// led after FetchMessage() or FetchNewMessage() returns
// B_TIMED_OUT or B_ERROR, or when the settings for this
// Protocol are changed.
virtual status_t GetMessage(
const char* uid,
BPositionIO** out_file, BMessage* out_headers,
BPath* out_folder_location
)=0;
// Downloads the message with id uid, writing the message's
// RFC2822 contents to *out_file and storing any headers it
// wants to add other than those from the message itself into
// out_headers. It may store a path (if this type of account
// supports folders) in *out_folder_location.
//
// Returns B_OK if the message is now available in out_file,
// B_NAME_NOT_FOUND if there is no message with id 'uid' on
// the server, or another error if the connection failed.
//
// B_OK will cause the message to be stored and processed.
// B_NAME_NOT_FOUND will cause appropriate recovery to be
// taken (if such exists) but not cause the connection to
// be terminated. Any other error will cause anything writen
// to be discarded and and the connection closed.
// OBS:
// The Protocol may replace *out_file with a custom (read-
// only) BPositionIO-derived object that preserves the il-
// lusion that the message is writen to *out_file, but in
// fact only reads from the server and writes to *out_file
// on demand. This BPositionIO must guarantee that any
// data returned by Read() has also been writen to *out_-
// file. It must return a read error if reading from the
// network or writing to *out_file fails.
//
// The mail_daemon will delete *out_file before invoking
// FetchMessage() or FetchNewMessage() again.
virtual status_t DeleteMessage(const char* uid)=0;
// Removes the message from the server. After this, it's
// assumed (but not required) that GetMessage(uid,...)
// et al will fail with B_NAME_NOT_FOUND.
void CheckForDeletedMessages();
// You can call this to trigger a sweep for deleted messages.
// Automatically called at the beginning of the chain.
//------MailFilter calls
virtual status_t ProcessMailMessage
(
BPositionIO** io_message, BEntry* io_entry,
BMessage* io_headers, BPath* io_folder, const char* io_uid
);
protected:
BStringList *manifest, *unique_ids;
BMessage *settings;
BMailChainRunner *runner;
private:
inline void error_alert(const char *process, status_t error);
virtual void _ReservedProtocol1();
virtual void _ReservedProtocol2();
virtual void _ReservedProtocol3();
virtual void _ReservedProtocol4();
virtual void _ReservedProtocol5();
friend class DeletePass;
BHandler *trash_monitor;
BStringList *uids_on_disk;
uint32 _reserved[3];
};
#endif // ZOIDBERG_MAIL_PROTOCOL_H
@@ -0,0 +1,38 @@
#ifndef ZOIDBERG_PROTOCOL_CONFIG_VIEW_H
#define ZOIDBERG_PROTOCOL_CONFIG_VIEW_H
/* ProtocolConfigView - the standard config view for all protocols
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <View.h>
typedef enum {
B_MAIL_PROTOCOL_HAS_AUTH_METHODS = 1,
B_MAIL_PROTOCOL_HAS_FLAVORS = 2,
B_MAIL_PROTOCOL_HAS_USERNAME = 4,
B_MAIL_PROTOCOL_HAS_PASSWORD = 8,
B_MAIL_PROTOCOL_HAS_HOSTNAME = 16,
B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER = 32
} b_mail_protocol_config_options;
class BMailProtocolConfigView : public BView {
public:
BMailProtocolConfigView(uint32 options_mask = B_MAIL_PROTOCOL_HAS_FLAVORS | B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME);
virtual ~BMailProtocolConfigView();
void SetTo(BMessage *archive);
void AddFlavor(const char *label);
void AddAuthMethod(const char *label,bool needUserPassword = true);
virtual status_t Archive(BMessage *into, bool deep = true) const;
virtual void GetPreferredSize(float *width, float *height);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *msg);
private:
uint32 _reserved[5];
};
#endif /* ZOIDBERG_PROTOCOL_CONFIG_VIEW_H */
@@ -0,0 +1,41 @@
#ifndef ZOIDBERG_MAIL_REMOTESTORAGEPROTOCOL_H
#define ZOIDBERG_MAIL_REMOTESTORAGEPROTOCOL_H
/* RemoteStorageProtocol - the base class for protocol filters
**
** Copyright 2003 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <MailProtocol.h>
#include <StringList.h>
class BMailRemoteStorageProtocol : public BMailProtocol {
public:
BMailRemoteStorageProtocol(BMessage *settings, BMailChainRunner *runner);
virtual ~BMailRemoteStorageProtocol();
virtual status_t GetMessage(const char *mailbox, const char *message, BPositionIO **, BMessage *headers) = 0;
virtual status_t AddMessage(const char *mailbox, BPositionIO *data, BString *id) = 0;
virtual status_t DeleteMessage(const char *mailbox, const char *message) = 0;
virtual status_t CopyMessage(const char *mailbox, const char *to_mailbox, BString *message) = 0;
virtual status_t CreateMailbox(const char *mailbox) = 0;
virtual status_t DeleteMailbox(const char *mailbox) = 0;
void SyncMailbox(const char *mailbox);
//----Mail::Protocol stuff
virtual status_t GetMessage(
const char* uid,
BPositionIO** out_file, BMessage* out_headers,
BPath* out_folder_location);
virtual status_t DeleteMessage(const char* uid);
//---Data members
BStringList mailboxes;
private:
BHandler *handler;
};
#endif // ZOIDBERG_MAIL_REMOTESTORAGEPROTOCOL_H
@@ -0,0 +1,73 @@
#ifndef ZOIDBERG_STRING_LIST_H
#define ZOIDBERG_STRING_LIST_H
/* StringList - a string list implementation
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <Flattenable.h>
class BList;
class BStringList : public BFlattenable {
public:
BStringList();
BStringList(const BStringList&);
~BStringList(void);
BStringList &operator=(const BStringList &from);
/* Flattenable stuff */
virtual bool IsFixedSize() const; //--false for obvious reasons
virtual type_code TypeCode() const;
virtual ssize_t FlattenedSize() const;
virtual status_t Flatten(void *buffer, ssize_t size) const;
virtual bool AllowsTypeCode(type_code code) const;
virtual status_t Unflatten(type_code c, const void *buf, ssize_t size);
/* Adding and removing items. */
void AddItem(const char *item);
void AddList(const BStringList *newItems);
bool RemoveItem(const char *item);
void MakeEmpty();
/* Retrieving items. */
const char *ItemAt(int32) const;
int32 IndexOf(const char *) const;
/* Querying the list. */
bool HasItem(const char *item) const;
int32 CountItems() const;
bool IsEmpty() const;
/* Determining differences between lists */
void NotHere(BStringList &other_list, BStringList *results);
void NotThere(BStringList &other_list, BStringList *results);
/* Useful list logic operators */
BStringList &operator += (const char *item);
BStringList &operator += (BStringList &list);
BStringList &operator -= (const char *item);
BStringList &operator -= (BStringList &list);
BStringList operator | (BStringList &list);
BStringList &operator |= (BStringList &list);
BStringList operator ^ (BStringList &list);
BStringList &operator ^= (BStringList &list);
bool operator == (BStringList &list);
const char *operator [] (int32 index);
private:
void *_buckets[256];
int32 _items;
BList *_indexed;
uint32 _reserved[5];
};
#endif /* ZOIDBERG_STRING_LIST_H */