mail-storage.h revision 54f9cedf212e30f690e8c7487374f2ea890494c6
#ifndef __MAIL_STORAGE_H
#define __MAIL_STORAGE_H
struct message_size;
#include "mail-types.h"
enum mailbox_open_flags {
MAILBOX_OPEN_READONLY = 0x01,
MAILBOX_OPEN_FAST = 0x02,
MAILBOX_OPEN_KEEP_RECENT = 0x04
};
enum mailbox_list_flags {
MAILBOX_LIST_SUBSCRIBED = 0x01,
MAILBOX_LIST_FAST_FLAGS = 0x02,
MAILBOX_LIST_CHILDREN = 0x04
};
enum mailbox_flags {
MAILBOX_NOSELECT = 0x001,
MAILBOX_NONEXISTENT = 0x002,
MAILBOX_PLACEHOLDER = 0x004,
MAILBOX_CHILDREN = 0x008,
MAILBOX_NOCHILDREN = 0x010,
MAILBOX_NOINFERIORS = 0x020,
MAILBOX_MARKED = 0x040,
MAILBOX_UNMARKED = 0x080,
MAILBOX_READONLY = 0x100
};
enum mailbox_status_items {
STATUS_MESSAGES = 0x01,
STATUS_RECENT = 0x02,
STATUS_UIDNEXT = 0x04,
STATUS_UIDVALIDITY = 0x08,
STATUS_UNSEEN = 0x10,
STATUS_FIRST_UNSEEN_SEQ = 0x20,
STATUS_KEYWORDS = 0x40
};
enum mailbox_name_status {
};
enum mail_sort_type {
/* Maximum size for sort program, 2x for reverse + END */
MAIL_SORT_ARRIVAL = 0x0010,
MAIL_SORT_CC = 0x0020,
MAIL_SORT_DATE = 0x0040,
MAIL_SORT_FROM = 0x0080,
MAIL_SORT_SIZE = 0x0100,
MAIL_SORT_SUBJECT = 0x0200,
MAIL_SORT_TO = 0x0400,
};
enum mail_thread_type {
};
enum mail_fetch_field {
MAIL_FETCH_FLAGS = 0x0001,
MAIL_FETCH_MESSAGE_PARTS = 0x0002,
MAIL_FETCH_RECEIVED_DATE = 0x0004,
MAIL_FETCH_DATE = 0x0008,
MAIL_FETCH_SIZE = 0x0010,
MAIL_FETCH_STREAM_HEADER = 0x0020,
MAIL_FETCH_STREAM_BODY = 0x0040,
/* specials: */
MAIL_FETCH_IMAP_BODY = 0x1000,
MAIL_FETCH_IMAP_BODYSTRUCTURE = 0x2000,
MAIL_FETCH_IMAP_ENVELOPE = 0x4000,
MAIL_FETCH_FROM_ENVELOPE = 0x8000
};
enum mailbox_sync_flags {
MAILBOX_SYNC_FLAG_FAST = 0x01,
MAILBOX_SYNC_FLAG_NO_EXPUNGES = 0x02,
MAILBOX_SYNC_AUTO_STOP = 0x04
};
enum client_workarounds {
WORKAROUND_OE6_FETCH_NO_NEWMAIL = 0x01,
WORKAROUND_OUTLOOK_IDLE = 0x02
};
struct mail_storage;
struct mail_storage_callbacks;
struct mailbox_list;
struct mailbox_status;
struct mail_search_arg;
struct fetch_context;
struct search_context;
struct mail;
struct mailbox;
struct mailbox_list_context;
struct mailbox_transaction_context;
struct mailbox_list {
const char *name;
enum mailbox_flags flags;
};
struct mailbox_status {
unsigned int diskspace_full:1;
/* may be allocated from data stack */
unsigned int keywords_count;
const char **keywords;
};
struct mail_storage_callbacks {
/* Alert: Not enough disk space */
/* "* OK <text>" */
void *context);
/* "* NO <text>" */
void *context);
/* EXPUNGE */
void *context);
/* FETCH FLAGS */
const struct mail_full_flags *flags,
void *context);
/* EXISTS */
/* RECENT */
/* FLAGS, PERMANENTFLAGS */
const char *keywords[],
unsigned int keywords_count, void *context);
};
extern enum client_workarounds client_workarounds;
extern int full_filesystem_access;
void mail_storage_init(void);
void mail_storage_deinit(void);
/* register all mail storages */
void mail_storage_register_all(void);
/* Register mail storage class with given name - all methods that are NULL
are set to default methods */
/* Create a new instance of registered mail storage class with given
storage-specific data. If data is NULL, it tries to use defaults.
May return NULL if anything fails.
If namespace is non-NULL, all mailbox names are expected to begin with it.
hierarchy_sep overrides the default separator if it's not '\0'. */
struct mail_storage *
const char *namespace, char hierarchy_sep);
struct mail_storage *
mail_storage_create_default(const char *user,
const char *namespace, char hierarchy_sep);
struct mail_storage *
const char *namespace, char hierarchy_sep);
/* Set storage callback functions to use. */
struct mail_storage_callbacks *callbacks,
void *context);
/* name is allowed to contain multiple new hierarchy levels.
If directory is TRUE, the mailbox should be created so that it
can contain children. The mailbox itself doesn't have to be
created as long as it shows in LIST. */
int directory);
/* Only the specified mailbox is deleted, ie. folders under the
specified mailbox must not be deleted. */
/* If the name has inferior hierarchical names, then the inferior
hierarchical names MUST also be renamed (ie. foo -> bar renames
hierarchies.
If oldname is case-insensitively "INBOX", the mails are moved
into new folder but the INBOX folder must not be deleted. */
/* Initialize new mailbox list request. mask may contain '%' and '*'
wildcards as defined in RFC2060. Matching against "INBOX" is
case-insensitive, but anything else is not. */
struct mailbox_list_context *
const char *mask,
enum mailbox_list_flags flags);
/* Get next mailbox. Returns the mailbox name */
struct mailbox_list *
/* Deinitialize mailbox list request. Returns FALSE if some error
occured while listing. */
/* Subscribe/unsubscribe mailbox. There should be no error when
subscribing to already subscribed mailbox. Subscribing to
unexisting mailboxes is optional. */
/* Returns mailbox name status */
const char *name,
enum mailbox_name_status *status);
/* Returns the error message of last occured error. */
int *syntax_error_r);
/* Open a mailbox. If readonly is TRUE, mailbox must not be
modified in any way even when it's asked. If fast is TRUE,
any extra time consuming operations shouldn't be performed
(eg. when opening mailbox just for STATUS).
Note that append and copy may open the selected mailbox again
with possibly different readonly-state. */
/* Close the box. Returns FALSE if some cleanup errors occured, but
the mailbox was closed anyway. */
/* Returns storage of given mailbox */
/* Returns name of given mailbox */
/* Returns TRUE if mailbox is read-only. */
/* Returns TRUE if mailbox currently supports adding keywords. */
/* Gets the mailbox status information. */
enum mailbox_status_items items,
struct mailbox_status *status);
/* Synchronize the mailbox. */
/* Synchronize mailbox in background. It's done until this function is
called with flags = MAILBOX_SYNC_AUTO_STOP. */
unsigned int min_newmail_notify_interval);
struct mailbox_transaction_context *
int mailbox_transaction_commit(struct mailbox_transaction_context *t);
void mailbox_transaction_rollback(struct mailbox_transaction_context *t);
/* Simplified fetching for a single sequence. */
enum mail_fetch_field wanted_fields);
/* Convert uid range to sequence range. */
/* Modify sort_program to specify a sort program acceptable for
search_init(). If mailbox supports no sorting, it's simply set to
{MAIL_SORT_END}. */
enum mail_sort_type *sort_program);
/* Initialize new search request. Search arguments are given so that
the storage can optimize the searching as it wants.
If sort_program is non-NULL, it requests that the returned messages
are sorted by the given criteria. sort_program must have gone
through search_get_sorting().
wanted_fields and wanted_headers aren't required, but they can be
used for optimizations. */
struct mail_search_context *
mailbox_search_init(struct mailbox_transaction_context *t,
const enum mail_sort_type *sort_program,
const char *const wanted_headers[]);
/* Deinitialize search request. */
/* Search the next message. Returned mail object can be used until
the next call to search_next() or search_deinit(). */
/* Save a mail into mailbox. timezone_offset specifies the timezone in
minutes in which received_date was originally given with. To use
current time, set received_date to (time_t)-1. */
int mailbox_save(struct mailbox_transaction_context *t,
const struct mail_full_flags *flags,
/* Copy given message. */
/* Returns TRUE if mailbox is now in inconsistent state, meaning that
the message IDs etc. may have changed - only way to recover this
would be to fully close the mailbox and reopen it. With IMAP
connection this would mean a forced disconnection since we can't
do forced CLOSE. */
struct mail {
/* always set */
unsigned int expunged:1;
/* Get the time message was received (IMAP INTERNALDATE).
Returns (time_t)-1 if error occured. */
/* Get the Date-header in mail. Timezone is in minutes.
Returns (time_t)-1 if error occured, 0 if field wasn't found or
couldn't be parsed. */
/* Get the full virtual size of mail (IMAP RFC822.SIZE).
Returns (uoff_t)-1 if error occured */
/* Get value for single header field */
/* Returns partial headers which contain _at least_ the given fields,
but it may contain others as well. */
const char *const minimum_fields[]);
/* Returns input stream pointing to beginning of message header.
hdr_size and body_size are updated unless they're NULL. */
struct message_size *hdr_size,
struct message_size *body_size);
/* Get the any of the "special" fields. */
enum mail_fetch_field field);
/* Update message flags. */
const struct mail_full_flags *flags,
enum modify_type modify_type);
/* Expunge this message. Sequence numbers don't change until commit. */
};
#endif