mail-storage.h revision a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen#ifndef __MAIL_STORAGE_H
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#define __MAIL_STORAGE_H
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct message_size;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "mail-types.h"
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "mailbox-list.h"
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenenum mail_storage_flags {
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Print debugging information while initializing the storage */
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen MAIL_STORAGE_FLAG_DEBUG = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Allow full filesystem access with absolute or relative paths. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_FULL_FS_ACCESS = 0x02,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't try to mmap() files */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_MMAP_DISABLE = 0x04,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't try to write() to mmap()ed files. Required for the few
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen OSes that don't have unified buffer cache
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen (currently OpenBSD <= 3.5) */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_FLAG_MMAP_NO_WRITE = 0x08,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Remember message headers' MD5 sum */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_KEEP_HEADER_MD5 = 0x10,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Use mmap() for reading mail files. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_MMAP_MAILS = 0x20,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Use CRLF linefeeds when saving mails. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_SAVE_CRLF = 0x40,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* The storage points to shared namespaces */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_SHARED_NAMESPACE = 0x80,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't try to autodetect anything, require that the given data
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen contains all the necessary information. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_FLAG_NO_AUTODETECTION = 0x100,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Ths storage contains INBOX */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_FLAG_HAS_INBOX = 0x200
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen};
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenenum mail_storage_lock_method {
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_LOCK_FCNTL,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_LOCK_FLOCK,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_LOCK_DOTLOCK
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_open_flags {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Mailbox must not be modified even if asked */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_READONLY = 0x01,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Only saving/copying mails to mailbox works. */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen MAILBOX_OPEN_SAVEONLY = 0x02,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen /* Any extra time consuming operations shouldn't be performed
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen (eg. when opening mailbox just for STATUS). */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_FAST = 0x04,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't reset MAIL_RECENT flags when syncing */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen MAILBOX_OPEN_KEEP_RECENT = 0x08,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't create index files for the mailbox */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_NO_INDEX_FILES = 0x10,
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen /* Keep mailbox exclusively locked all the time while it's open */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAILBOX_OPEN_KEEP_LOCKED = 0x20,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* FIXME: Kludge for deliver: Ignore all but the first From-line */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_MBOX_ONE_MSG_ONLY = 0x40
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_status_items {
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen STATUS_MESSAGES = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_RECENT = 0x02,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_UIDNEXT = 0x04,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen STATUS_UIDVALIDITY = 0x08,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen STATUS_UNSEEN = 0x10,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen STATUS_FIRST_UNSEEN_SEQ = 0x20,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen STATUS_KEYWORDS = 0x40
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mail_sort_type {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Maximum size for sort program (each one separately + END) */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#define MAX_SORT_PROGRAM_SIZE (7 + 1)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_ARRIVAL = 0x0001,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_CC = 0x0002,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_DATE = 0x0004,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen MAIL_SORT_FROM = 0x0008,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen MAIL_SORT_SIZE = 0x0010,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen MAIL_SORT_SUBJECT = 0x0020,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_TO = 0x0040,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_MASK = 0x0fff,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_FLAG_REVERSE = 0x1000, /* reverse this mask type */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_END = 0x0000 /* ends sort program */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mail_fetch_field {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_FLAGS = 0x00000001,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_MESSAGE_PARTS = 0x00000002,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_STREAM_HEADER = 0x00000004,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_STREAM_BODY = 0x00000008,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_DATE = 0x00000010,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_RECEIVED_DATE = 0x00000020,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_SAVE_DATE = 0x00000040,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_PHYSICAL_SIZE = 0x00000080,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_VIRTUAL_SIZE = 0x00000100,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* specials: */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_IMAP_BODY = 0x00001000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_IMAP_BODYSTRUCTURE = 0x00002000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_IMAP_ENVELOPE = 0x00004000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_FROM_ENVELOPE = 0x00008000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_HEADER_MD5 = 0x00010000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_UIDL_FILE_NAME = 0x00020000
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_transaction_flags {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Hide changes done in this transaction from next view sync */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_TRANSACTION_FLAG_HIDE = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* External transaction. Should be used for copying and appends,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen but nothing else. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_TRANSACTION_FLAG_EXTERNAL = 0x02
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_sync_flags {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Make sure we sync all external changes done to mailbox */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_FLAG_FULL_READ = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Make sure we write all our internal changes into the mailbox */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_FLAG_FULL_WRITE = 0x02,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* If it's not too much trouble, check if there are some changes */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_FLAG_FAST = 0x04,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't sync expunges from our view */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_FLAG_NO_EXPUNGES = 0x08,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't show new mail */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_FLAG_NO_NEWMAIL = 0x10,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Stop auto syncing */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_AUTO_STOP = 0x20
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_sync_type {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_TYPE_EXPUNGE = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_TYPE_FLAGS = 0x02,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SYNC_TYPE_KEYWORDS = 0x04
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mail_storage;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mail_search_arg;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mail_keywords;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mail_save_context;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mailbox;
47f1c273dfaea552c034ffbecdec096f7cbaef35Timo Sirainenstruct mailbox_transaction_context;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mailbox_status {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t messages;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t recent;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t unseen;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t uidvalidity;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t uidnext;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t first_unseen_seq;
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen const ARRAY_TYPE(keywords) *keywords;
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen};
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenstruct mailbox_sync_rec {
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen uint32_t seq1, seq2;
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen enum mailbox_sync_type type;
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen};
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenstruct mail {
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* always set */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen struct mailbox *box;
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen struct mailbox_transaction_context *transaction;
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen uint32_t seq, uid;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen unsigned int expunged:1;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen unsigned int has_nuls:1; /* message data is known to contain NULs */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen unsigned int has_no_nuls:1; /* -''- known to not contain NULs */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen};
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenstruct mail_storage_callbacks {
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Alert: Not enough disk space */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen void (*alert_no_diskspace)(struct mailbox *mailbox, void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* "* OK <text>" */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void (*notify_ok)(struct mailbox *mailbox, const char *text,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen void *context);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* "* NO <text>" */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen void (*notify_no)(struct mailbox *mailbox, const char *text,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void *context);
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen};
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainentypedef void mailbox_notify_callback_t(struct mailbox *box, void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenvoid mail_storage_init(void);
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenvoid mail_storage_deinit(void);
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* register all mail storages */
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainenvoid mail_storage_register_all(void);
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen/* Register mail storage class with given name - all methods that are NULL
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen are set to default methods */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_class_register(struct mail_storage *storage_class);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_class_unregister(struct mail_storage *storage_class);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns flags and lock_method based on environment settings. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_parse_env(enum mail_storage_flags *flags_r,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mail_storage_lock_method *lock_method_r);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Create a new instance of registered mail storage class with given
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen storage-specific data. If data is NULL, it tries to autodetect defaults.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen May return NULL if anything fails. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_storage *
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmail_storage_create(const char *driver, const char *data, const char *user,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mail_storage_flags flags,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mail_storage_lock_method lock_method);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_storage *
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmail_storage_create_with_data(const char *data, const char *user,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mail_storage_flags flags,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mail_storage_lock_method lock_method);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_destroy(struct mail_storage **storage);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenchar mail_storage_get_hierarchy_sep(struct mail_storage *storage);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mailbox_list *mail_storage_get_list(struct mail_storage *storage);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_set_list_error(struct mail_storage *storage);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Set storage callback functions to use. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_set_callbacks(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct mail_storage_callbacks *callbacks,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* name is allowed to contain multiple new hierarchy levels.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen If directory is TRUE, the mailbox should be created so that it
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen can contain children. The mailbox itself doesn't have to be
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen created as long as it shows in LIST. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mail_storage_mailbox_create(struct mail_storage *storage, const char *name,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen bool directory);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Only the specified mailbox is deleted, ie. folders under the
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen specified mailbox must not be deleted. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mail_storage_mailbox_delete(struct mail_storage *storage, const char *name);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* If the name has inferior hierarchical names, then the inferior
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen hierarchical names MUST also be renamed (ie. foo -> bar renames
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen also foo/bar -> bar/bar). newname may contain multiple new
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen hierarchies.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen If oldname is case-insensitively "INBOX", the mails are moved
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen into new folder but the INBOX folder must not be deleted. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenint mail_storage_mailbox_rename(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *oldname, const char *newname);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns the error message of last occurred error. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_last_error(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen bool *syntax_error_r,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen bool *temporary_error_r);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns path to the given mailbox, or NULL if mailbox doesn't exist in
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen filesystem. is_file_r is set to TRUE if returned path points to a file,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen and FALSE if it points to a directory. If name is "", the root storage
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen directory is returned. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_mailbox_path(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *name, bool *is_file_r);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns path to the control directory of the mailbox, or NULL if mailbox
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen doesn't exist in filesystem. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_mailbox_control_dir(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *name);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns path to the index directory of the mailbox, or NULL if using
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen in-memory indexes or mailbox doesn't exist. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_mailbox_index_dir(struct mail_storage *storage,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen const char *name);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mail_storage_is_mailbox(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *dir, const char *fname,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mailbox_list_iter_flags iter_flags,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mailbox_info_flags *flags,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mailbox_list_file_type type);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Open a mailbox. If input stream is given, mailbox is opened read-only
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen using it as a backend. If storage doesn't support stream backends and its
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen tried to be used, NULL is returned.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen Note that append and copy may open the selected mailbox again
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen with possibly different readonly-state. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct istream *input,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mailbox_open_flags flags);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Close the box. Returns -1 if some cleanup errors occurred, but
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen the mailbox was closed anyway. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_close(struct mailbox **box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns storage of given mailbox */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_storage *mailbox_get_storage(struct mailbox *box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns name of given mailbox */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mailbox_get_name(struct mailbox *box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns TRUE if mailbox is read-only. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenbool mailbox_is_readonly(struct mailbox *box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns TRUE if mailbox currently supports adding keywords. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenbool mailbox_allow_new_keywords(struct mailbox *box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Gets the mailbox status information. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct mailbox_status *status);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Synchronize the mailbox. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mailbox_sync_context *
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_sync_next(struct mailbox_sync_context *ctx,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct mailbox_sync_rec *sync_rec_r);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_sync_deinit(struct mailbox_sync_context **ctx,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct mailbox_status *status_r);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Call given callback function when something changes in the mailbox.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen It's done until this function is called with callback = NULL. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mailbox_notify_changes(struct mailbox *box, unsigned int min_interval,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen mailbox_notify_callback_t *callback, void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mailbox_transaction_context *
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmailbox_transaction_begin(struct mailbox *box,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mailbox_transaction_flags flags);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_transaction_commit(struct mailbox_transaction_context **t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen enum mailbox_sync_flags flags);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_transaction_rollback(struct mailbox_transaction_context **t);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Build mail_keywords from NULL-terminated keywords list. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mail_keywords *
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmailbox_keywords_create(struct mailbox_transaction_context *t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen const char *const keywords[]);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_keywords_free(struct mailbox_transaction_context *t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mail_keywords **keywords);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Convert uid range to sequence range. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen uint32_t *seq1_r, uint32_t *seq2_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
b71f152acb8a197d20b709ca74366e6d765bd200Timo Sirainen/* Initialize header lookup for given headers. */
b71f152acb8a197d20b709ca74366e6d765bd200Timo Sirainenstruct mailbox_header_lookup_ctx *
b71f152acb8a197d20b709ca74366e6d765bd200Timo Sirainenmailbox_header_lookup_init(struct mailbox *box, const char *const headers[]);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenvoid mailbox_header_lookup_deinit(struct mailbox_header_lookup_ctx **ctx);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Initialize new search request. charset specifies the character set used in
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen the search argument strings. If sort_program is non-NULL, the messages are
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen returned in the requested order, otherwise from first to last. */
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainenstruct mail_search_context *
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainenmailbox_search_init(struct mailbox_transaction_context *t,
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen const char *charset, struct mail_search_arg *args,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const enum mail_sort_type *sort_program);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Deinitialize search request. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_search_deinit(struct mail_search_context **ctx);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Search the next message. Returns 1 if found, 0 if not, -1 if failure. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_search_next(struct mail_search_context *ctx, struct mail *mail);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Save a mail into mailbox. timezone_offset specifies the timezone in
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen minutes in which received_date was originally given with. To use
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen current time, set received_date to (time_t)-1.
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen If dest_mail is set, the saved message can be accessed using it. Note that
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen setting it may require mailbox syncing, so don't set it unless you need
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen it. Also you shouldn't try to access it before mailbox_save_finish() is
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen called.
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen The given input stream is never read in these functions, only the data
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen inside it is used. So you should call i_stream_read() yourself and then
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen call mailbox_save_continue() whenever more data is read.
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen*/
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_save_init(struct mailbox_transaction_context *t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen enum mail_flags flags, struct mail_keywords *keywords,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen time_t received_date, int timezone_offset,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen const char *from_envelope, struct istream *input,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mail *dest_mail, struct mail_save_context **ctx_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_save_continue(struct mail_save_context *ctx);
47f1c273dfaea552c034ffbecdec096f7cbaef35Timo Sirainenint mailbox_save_finish(struct mail_save_context **ctx);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_save_cancel(struct mail_save_context **ctx);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Copy given message. If dest_mail is non-NULL, the copied message can be
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen accessed using it. Note that setting it non-NULL may require mailbox
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen syncing, so don't give give it unless you need it. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_copy(struct mailbox_transaction_context *t, struct mail *mail,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen enum mail_flags flags, struct mail_keywords *keywords,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mail *dest_mail);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns TRUE if mailbox is now in inconsistent state, meaning that
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen the message IDs etc. may have changed - only way to recover this
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen would be to fully close the mailbox and reopen it. With IMAP
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen connection this would mean a forced disconnection since we can't
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen do forced CLOSE. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenbool mailbox_is_inconsistent(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns message's flags */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mail_flags mail_get_flags(struct mail *mail);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns message's keywords */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenconst char *const *mail_get_keywords(struct mail *mail);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns message's MIME parts */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenconst struct message_part *mail_get_parts(struct mail *mail);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mail *mail_alloc(struct mailbox_transaction_context *t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen enum mail_fetch_field wanted_fields,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mail_free(struct mail **mail);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mail_set_seq(struct mail *mail, uint32_t seq);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns -1 if error, 0 if UID has already been expunged, 1 if ok */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenint mail_set_uid(struct mail *mail, uint32_t uid);
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen/* Get the Date-header of the mail. Timezone is in minutes.
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen Returns (time_t)-1 if error occurred, 0 if field wasn't found or
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen couldn't be parsed. */
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainentime_t mail_get_date(struct mail *mail, int *timezone);
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen/* Get the time when the mail was received (IMAP INTERNALDATE).
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen Returns (time_t)-1 if error occurred. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainentime_t mail_get_received_date(struct mail *mail);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Get the time when the mail was saved into this mailbox. This time may not
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen always be entirely reliable. Returns (time_t)-1 if error occurred. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainentime_t mail_get_save_date(struct mail *mail);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Get the space used by the mail as seen by the reader. Linefeeds are always
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen counted as being CR+LF. Returns (uoff_t)-1 if error occurred */
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainenuoff_t mail_get_virtual_size(struct mail *mail);
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen/* Get the space used by the mail in disk.
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen Returns (uoff_t)-1 if error occurred */
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainenuoff_t mail_get_physical_size(struct mail *mail);
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Get value for single header field */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenconst char *mail_get_first_header(struct mail *mail, const char *field);
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen/* Return a NULL-terminated list of values for each found field. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenconst char *const *mail_get_headers(struct mail *mail, const char *field);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns stream containing specified headers. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct istream *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmail_get_header_stream(struct mail *mail,
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen struct mailbox_header_lookup_ctx *headers);
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen/* Returns input stream pointing to beginning of message header.
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen hdr_size and body_size are updated unless they're NULL. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenstruct istream *mail_get_stream(struct mail *mail,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen struct message_size *hdr_size,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen struct message_size *body_size);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Get any of the "special" fields. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenconst char *mail_get_special(struct mail *mail, enum mail_fetch_field field);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Update message flags. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenint mail_update_flags(struct mail *mail, enum modify_type modify_type,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen enum mail_flags flags);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Update message keywords. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenint mail_update_keywords(struct mail *mail, enum modify_type modify_type,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen struct mail_keywords *keywords);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Expunge this message. Sequence numbers don't change until commit. */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenint mail_expunge(struct mail *mail);
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen#endif
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen