mail-storage.h revision d23c747de9d33966483fbdd41f08ad7766da7c5c
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen#ifndef MAIL_STORAGE_H
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#define MAIL_STORAGE_H
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct message_size;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "seq-range-array.h"
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "file-lock.h"
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "mail-types.h"
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen#include "mail-error.h"
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen#include "mailbox-list.h"
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* If some operation is taking long, call notify_ok every n seconds. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#define MAIL_STORAGE_STAYALIVE_SECS 15
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mail_storage_flags {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Print debugging information while initializing the storage */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_DEBUG = 0x01,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Allow full filesystem access with absolute or relative paths. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo 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
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen (currently OpenBSD <= 3.5) */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo 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 CRLF linefeeds when saving mails. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_SAVE_CRLF = 0x40,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Don't try to autodetect anything, require that the given data
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen contains all the necessary information. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_FLAG_NO_AUTODETECTION = 0x100,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Don't autocreate any directories. If they don't exist,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen fail to create the storage. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_FLAG_NO_AUTOCREATE = 0x200,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Rely on O_EXCL when creating dotlocks */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL = 0x400,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Flush NFS caches for mail storage / index */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE = 0x800,
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen MAIL_STORAGE_FLAG_NFS_FLUSH_INDEX = 0x1000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't use fsync() or fdatasync() */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_STORAGE_FLAG_FSYNC_DISABLE = 0x2000
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenenum mailbox_open_flags {
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen /* Mailbox must not be modified even if asked */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_READONLY = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Only saving/copying mails to mailbox works. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_SAVEONLY = 0x02,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo 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,
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen /* Don't reset MAIL_RECENT flags when syncing */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAILBOX_OPEN_KEEP_RECENT = 0x08,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't create index files for the mailbox */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_NO_INDEX_FILES = 0x10,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Keep mailbox exclusively locked all the time while it's open */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_OPEN_KEEP_LOCKED = 0x20,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_feature {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Enable tracking modsequences */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAILBOX_FEATURE_CONDSTORE = 0x01,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen /* Enable tracking expunge modsequences */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen MAILBOX_FEATURE_QRESYNC = 0x02
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen};
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_status_items {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_MESSAGES = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_RECENT = 0x02,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_UIDNEXT = 0x04,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_UIDVALIDITY = 0x08,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_UNSEEN = 0x10,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_FIRST_UNSEEN_SEQ = 0x20,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen STATUS_KEYWORDS = 0x40,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen STATUS_HIGHESTMODSEQ = 0x80
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen};
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenenum mailbox_search_result_flags {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Update search results whenever the mailbox view is synced.
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen Expunged messages are removed even without this flag. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SEARCH_RESULT_FLAG_UPDATE = 0x01,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Queue changes so _sync() can be used. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_SEARCH_RESULT_FLAG_QUEUE_SYNC = 0x02
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo 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 (8 + 1)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_ARRIVAL = 0x0001,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_CC = 0x0002,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_DATE = 0x0004,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_FROM = 0x0008,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_SIZE = 0x0010,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_SUBJECT = 0x0020,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_TO = 0x0040,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_SEARCH_SCORE = 0x0080,
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 */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo 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 /* Set has_nuls / has_no_nuls fields */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_NUL_STATE = 0x00000200,
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 MAIL_FETCH_UIDL_BACKEND = 0x00040000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_MAILBOX_NAME = 0x00080000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_SEARCH_SCORE = 0x00100000,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_FETCH_GUID = 0x00200000
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 /* Always assign UIDs to messages when saving/copying. Normally this
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen is done only if the mailbox is synced, or if dest_mail parameter
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen was non-NULL to mailbox_save_init() or mailbox_copy() */
47f1c273dfaea552c034ffbecdec096f7cbaef35Timo Sirainen MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS = 0x04,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Refresh the index so lookups return latest flags/modseqs */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_TRANSACTION_FLAG_REFRESH = 0x08
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 */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen MAILBOX_SYNC_FLAG_FAST = 0x04,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Don't sync expunges from our view */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen MAILBOX_SYNC_FLAG_NO_EXPUNGES = 0x08,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Stop auto syncing */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen MAILBOX_SYNC_AUTO_STOP = 0x20,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* If mailbox is currently inconsistent, fix it instead of failing. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen MAILBOX_SYNC_FLAG_FIX_INCONSISTENT = 0x40,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Syncing after an EXPUNGE command. This is just an informational
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen flag for plugins. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen MAILBOX_SYNC_FLAG_EXPUNGE = 0x80
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen};
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenenum mailbox_sync_type {
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAILBOX_SYNC_TYPE_EXPUNGE = 0x01,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAILBOX_SYNC_TYPE_FLAGS = 0x02,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen MAILBOX_SYNC_TYPE_MODSEQ = 0x04
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen};
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenstruct message_part;
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenstruct mail_namespace;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_storage;
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenstruct mail_search_args;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_search_result;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_keywords;
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenstruct mail_save_context;
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenstruct mailbox;
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenstruct mailbox_transaction_context;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenstruct mailbox_status {
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen uint32_t messages;
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen uint32_t recent;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen uint32_t unseen;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen uint32_t uidvalidity;
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen uint32_t uidnext;
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen uint32_t first_unseen_seq;
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen uint64_t highest_modseq;
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen const ARRAY_TYPE(keywords) *keywords;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* There are expunges that haven't been synced yet */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen unsigned int sync_delayed_expunges:1;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Modseqs aren't permanent (index is in memory) */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen unsigned int nonpermanent_modseqs:1;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen};
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mailbox_sync_rec {
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen uint32_t seq1, seq2;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mailbox_sync_type type;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen};
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail {
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* always set */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct mailbox *box;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct mailbox_transaction_context *transaction;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo 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 */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen};
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_storage_callbacks {
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* "* OK <text>" */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void (*notify_ok)(struct mailbox *mailbox, const char *text,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* "* NO <text>" */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void (*notify_no)(struct mailbox *mailbox, const char *text,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen};
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainentypedef void mailbox_notify_callback_t(struct mailbox *box, void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_init(void);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_deinit(void);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* register all mail storages */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_register_all(void);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo 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
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo 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 file_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 driver is NULL, it's tried to be autodetected
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen from data. If data is NULL, it uses the first storage that exists.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen The storage is put into ns->storage. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mail_storage_create(struct mail_namespace *ns, const char *driver,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *data, enum mail_storage_flags flags,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum file_lock_method lock_method,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char **error_r);
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 *
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmail_storage_get_list(const struct mail_storage *storage) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_namespace *
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmail_storage_get_namespace(const struct mail_storage *storage) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Set storage callback functions to use. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo 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
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns the error message of last occurred error. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_last_error(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen enum mail_error *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,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *name);
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/* Enable the given feature for the mailbox. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_enable(struct mailbox *box, enum mailbox_feature features);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenenum mailbox_feature mailbox_get_enabled_features(struct mailbox *box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns storage of given mailbox */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_storage *mailbox_get_storage(const struct mailbox *box) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns name of given mailbox */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mailbox_get_name(const struct mailbox *box) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns TRUE if mailbox is read-only. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenbool mailbox_is_readonly(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns TRUE if mailbox currently supports adding keywords. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenbool mailbox_allow_new_keywords(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Gets the mailbox status information. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mailbox_status *status_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Synchronize the mailbox. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mailbox_sync_context *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenbool mailbox_sync_next(struct mailbox_sync_context *ctx,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mailbox_sync_rec *sync_rec_r);
b71f152acb8a197d20b709ca74366e6d765bd200Timo Sirainenint mailbox_sync_deinit(struct mailbox_sync_context **ctx,
b71f152acb8a197d20b709ca74366e6d765bd200Timo Sirainen enum mailbox_status_items status_items,
b71f152acb8a197d20b709ca74366e6d765bd200Timo Sirainen struct mailbox_status *status_r);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* One-step mailbox synchronization. Use this if you don't care about
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen changes. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_sync(struct mailbox *box, enum mailbox_sync_flags flags,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen enum mailbox_status_items status_items,
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen struct mailbox_status *status_r);
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen/* Call given callback function when something changes in the mailbox. */
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainenvoid mailbox_notify_changes(struct mailbox *box, unsigned int min_interval,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen mailbox_notify_callback_t *callback, void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen#ifdef CONTEXT_TYPE_SAFETY
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen ({(void)(1 ? 0 : callback((struct mailbox *)NULL, context)); \
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen mailbox_notify_changes(box, min_interval, \
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen (mailbox_notify_callback_t *)callback, context); })
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen#else
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen mailbox_notify_changes(box, min_interval, \
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen (mailbox_notify_callback_t *)callback, context)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#endif
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_notify_changes_stop(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mailbox_transaction_context *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_transaction_begin(struct mailbox *box,
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen enum mailbox_transaction_flags flags);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_transaction_commit(struct mailbox_transaction_context **t);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* If no messages were saved/copied, first/last_saved_uid_r are 0. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_transaction_commit_get_uids(struct mailbox_transaction_context **t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t *uid_validity_r,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t *first_saved_uid_r,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t *last_saved_uid_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_transaction_rollback(struct mailbox_transaction_context **t);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Return the number of active transactions for the mailbox. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenunsigned int mailbox_transaction_get_count(const struct mailbox *box) ATTR_PURE;
47f1c273dfaea552c034ffbecdec096f7cbaef35Timo Sirainen/* When committing transaction, drop flag/keyword updates for messages whose
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen mdoseq is larger than max_modseq. Save those messages' sequences to the
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen given array. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_transaction_set_max_modseq(struct mailbox_transaction_context *t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint64_t max_modseq,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen ARRAY_TYPE(seq_range) *seqs);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mailbox *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_transaction_get_mailbox(const struct mailbox_transaction_context *t)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen ATTR_PURE;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Build mail_keywords from NULL-terminated keywords list.
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen Returns 0 if successful, -1 if there are invalid keywords (error is set). */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_keywords_create(struct mailbox *box, const char *const keywords[],
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen struct mail_keywords **keywords_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Like mailbox_keywords_create(), except ignore invalid keywords. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mail_keywords *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_keywords_create_valid(struct mailbox *box,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen const char *const keywords[]);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_keywords_free(struct mailbox *box,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mail_keywords **keywords);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns TRUE if keyword is valid, FALSE and error if not. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenbool mailbox_keyword_is_valid(struct mailbox *box, const char *keyword,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen const char **error_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Convert uid range to sequence range. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_get_seq_range(struct mailbox *box, uint32_t uid1, uint32_t uid2,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen uint32_t *seq1_r, uint32_t *seq2_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Convert sequence range to uid range. If sequences contain
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen (uint32_t)-1 to specify "*", they're preserved. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenvoid mailbox_get_uid_range(struct mailbox *box,
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen const ARRAY_TYPE(seq_range) *seqs,
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen ARRAY_TYPE(seq_range) *uids);
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen/* Get list of UIDs expunged after modseq and within the given range.
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen UIDs that have been expunged after the last mailbox sync aren't returned.
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen Returns TRUE if ok, FALSE if modseq is lower than we can check for. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenbool mailbox_get_expunged_uids(struct mailbox *box, uint64_t modseq,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen const ARRAY_TYPE(seq_range) *uids,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen ARRAY_TYPE(seq_range) *expunged_uids);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Initialize header lookup for given headers. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstruct mailbox_header_lookup_ctx *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_header_lookup_init(struct mailbox *box, const char *const headers[]);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **ctx);
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen/* Initialize new search request. charset specifies the character set used in
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen the search argument strings. If sort_program is non-NULL, the messages are
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen returned in the requested order, otherwise from first to last. */
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainenstruct mail_search_context *
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_search_init(struct mailbox_transaction_context *t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mail_search_args *args,
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen const enum mail_sort_type *sort_program);
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen/* Deinitialize search request. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_search_deinit(struct mail_search_context **ctx);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Search the next message. Returns 1 if found, 0 if not, -1 if failure. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_search_next(struct mail_search_context *ctx, struct mail *mail);
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen/* Like mailbox_search_next(), but don't spend too much time searching.
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen Returns 1 if found, -1 if failure or 0 with tryagain_r=FALSE if
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen finished, and TRUE if more results will by calling the function again. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenint mailbox_search_next_nonblock(struct mail_search_context *ctx,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen struct mail *mail, bool *tryagain_r);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Remember the search result for future use. This must be called before the
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen first mailbox_search_next*() call. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenstruct mail_search_result *
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenmailbox_search_result_save(struct mail_search_context *ctx,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen enum mailbox_search_result_flags flags);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Free memory used by search result. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenvoid mailbox_search_result_free(struct mail_search_result **result);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* A simplified API for searching and saving the result. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenint mailbox_search_result_build(struct mailbox_transaction_context *t,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen struct mail_search_args *args,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen enum mailbox_search_result_flags flags,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mail_search_result **result_r);
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen/* Return all messages' UIDs in the search result. */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenconst ARRAY_TYPE(seq_range) *
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenmailbox_search_result_get(struct mail_search_result *result);
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen/* Return messages that have been removed and added since the last sync call.
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen This function must not be called if search result wasn't saved with
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen _QUEUE_SYNC flag. */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenvoid mailbox_search_result_sync(struct mail_search_result *result,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen ARRAY_TYPE(seq_range) *removed_uids,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen ARRAY_TYPE(seq_range) *added_uids);
/* Initialize saving a new mail. You must not try to save more than one mail
at a time. */
struct mail_save_context *
mailbox_save_alloc(struct mailbox_transaction_context *t);
/* Set the flags and keywords. Nothing is set by default. */
void mailbox_save_set_flags(struct mail_save_context *ctx,
enum mail_flags flags,
struct mail_keywords *keywords);
/* If received date isn't specified the current time is used. timezone_offset
specifies the preferred timezone in minutes, but it may be ignored if
backend doesn't support storing it. */
void mailbox_save_set_received_date(struct mail_save_context *ctx,
time_t received_date, int timezone_offset);
/* Set the envelope sender. This is currently used only with mbox files to
specify the address in From_-line. */
void mailbox_save_set_from_envelope(struct mail_save_context *ctx,
const char *envelope);
/* Set globally unique ID for the saved mail. A new GUID is generated by
default. This function should usually be called only when copying an
existing mail (or restoring a mail from backup). */
void mailbox_save_set_guid(struct mail_save_context *ctx, const char *guid);
/* If dest_mail is set, the saved message can be accessed using it. Note that
setting it may require mailbox syncing, so don't set it unless you need
it. Also you shouldn't try to access it before mailbox_save_finish() is
called. */
void mailbox_save_set_dest_mail(struct mail_save_context *ctx,
struct mail *mail);
/* Begin saving the message. All mail_save_set_*() calls must have been called
before this function. If the save initialization fails, the context is freed
and -1 is returned. After beginning the save you should keep calling
i_stream_read() and calling mailbox_save_continue() as long as there's
more input. */
int mailbox_save_begin(struct mail_save_context **ctx, struct istream *input);
int mailbox_save_continue(struct mail_save_context *ctx);
int mailbox_save_finish(struct mail_save_context **ctx);
void mailbox_save_cancel(struct mail_save_context **ctx);
/* Copy given message. If dest_mail is non-NULL, the copied message can be
accessed using it. Note that setting it non-NULL may require mailbox
syncing, so don't give give it unless you need it. */
int mailbox_copy(struct mailbox_transaction_context *t, struct mail *mail,
enum mail_flags flags, struct mail_keywords *keywords,
struct mail *dest_mail);
/* 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. */
bool mailbox_is_inconsistent(struct mailbox *box);
struct mail *mail_alloc(struct mailbox_transaction_context *t,
enum mail_fetch_field wanted_fields,
struct mailbox_header_lookup_ctx *wanted_headers);
void mail_free(struct mail **mail);
void mail_set_seq(struct mail *mail, uint32_t seq);
/* Returns TRUE if successful, FALSE if message doesn't exist.
mail_*() functions shouldn't be called if FALSE is returned. */
bool mail_set_uid(struct mail *mail, uint32_t uid);
/* Returns message's flags */
enum mail_flags mail_get_flags(struct mail *mail);
/* Returns message's keywords */
const char *const *mail_get_keywords(struct mail *mail);
/* Returns message's keywords */
const ARRAY_TYPE(keyword_indexes) *mail_get_keyword_indexes(struct mail *mail);
/* Returns message's modseq */
uint64_t mail_get_modseq(struct mail *mail);
/* Returns message's MIME parts */
int mail_get_parts(struct mail *mail, const struct message_part **parts_r);
/* Get the Date-header of the mail. Timezone is in minutes. date=0 if it
wasn't found or it was invalid. */
int mail_get_date(struct mail *mail, time_t *date_r, int *timezone_r);
/* Get the time when the mail was received (IMAP INTERNALDATE). */
int mail_get_received_date(struct mail *mail, time_t *date_r);
/* Get the time when the mail was saved into this mailbox. This time may not
always be entirely reliable. */
int mail_get_save_date(struct mail *mail, time_t *date_r);
/* Get the space used by the mail as seen by the reader. Linefeeds are always
counted as being CR+LF. */
int mail_get_virtual_size(struct mail *mail, uoff_t *size_r);
/* Get the size of the stream returned by mail_get_stream(). */
int mail_get_physical_size(struct mail *mail, uoff_t *size_r);
/* Get value for single header field, or NULL if header wasn't found.
Returns 1 if header was found, 0 if not, -1 if error. */
int mail_get_first_header(struct mail *mail, const char *field,
const char **value_r);
/* Like mail_get_first_header(), but decode MIME encoded words to UTF-8 */
int mail_get_first_header_utf8(struct mail *mail, const char *field,
const char **value_r);
/* Return a NULL-terminated list of values for each found field. */
int mail_get_headers(struct mail *mail, const char *field,
const char *const **value_r);
/* Like mail_get_headers(), but decode MIME encoded words to UTF-8 */
int mail_get_headers_utf8(struct mail *mail, const char *field,
const char *const **value_r);
/* Returns stream containing specified headers. */
int mail_get_header_stream(struct mail *mail,
struct mailbox_header_lookup_ctx *headers,
struct istream **stream_r);
/* Returns input stream pointing to beginning of message header.
hdr_size and body_size are updated unless they're NULL. */
int mail_get_stream(struct mail *mail, struct message_size *hdr_size,
struct message_size *body_size, struct istream **stream_r);
/* Get any of the "special" fields. */
int mail_get_special(struct mail *mail, enum mail_fetch_field field,
const char **value_r);
/* Update message flags. */
void mail_update_flags(struct mail *mail, enum modify_type modify_type,
enum mail_flags flags);
/* Update message keywords. */
void mail_update_keywords(struct mail *mail, enum modify_type modify_type,
struct mail_keywords *keywords);
/* Expunge this message. Sequence numbers don't change until commit. */
void mail_expunge(struct mail *mail);
/* Mark a cached field corrupted and have it recalculated. */
void mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field);
#endif