mail-storage.h revision 6acaa359928215b48e97373fb96a3dc326bbd65b
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#ifndef MAIL_STORAGE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MAIL_STORAGE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainenstruct message_size;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen#include "seq-range-array.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "file-lock.h"
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen#include "mail-types.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "mail-error.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "mailbox-list.h"
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* If some operation is taking long, call notify_ok every n seconds. */
da5d50534cfca45d0aaaf0bdac17b287b4588809Timo Sirainen#define MAIL_STORAGE_STAYALIVE_SECS 15
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenenum mail_storage_flags {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Remember message headers' MD5 sum */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_STORAGE_FLAG_KEEP_HEADER_MD5 = 0x01,
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen /* Don't try to autodetect anything, require that the given data
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen contains all the necessary information. */
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen MAIL_STORAGE_FLAG_NO_AUTODETECTION = 0x02,
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen /* Don't autocreate any directories. If they don't exist,
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen fail to create the storage. */
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen MAIL_STORAGE_FLAG_NO_AUTOCREATE = 0x04
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenenum mailbox_flags {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Mailbox must not be modified even if asked */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_FLAG_READONLY = 0x01,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Only saving/copying mails to mailbox works. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_FLAG_SAVEONLY = 0x02,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Don't reset MAIL_RECENT flags when syncing */
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen MAILBOX_FLAG_KEEP_RECENT = 0x08,
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen /* Don't create index files for the mailbox */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen MAILBOX_FLAG_NO_INDEX_FILES = 0x10,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* Keep mailbox exclusively locked all the time while it's open */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen MAILBOX_FLAG_KEEP_LOCKED = 0x20,
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* Enable if mailbox is used for serving POP3. This allows making
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen better caching decisions. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_FLAG_POP3_SESSION = 0x40,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Enable if mailbox is used for saving a mail delivery using MDA.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen This causes ACL plugin to use POST right rather than INSERT. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen MAILBOX_FLAG_POST_SESSION = 0x80,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen /* Force opening mailbox and ignoring any ACLs */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen MAILBOX_FLAG_IGNORE_ACLS = 0x100
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen};
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenenum mailbox_feature {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Enable tracking modsequences */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen MAILBOX_FEATURE_CONDSTORE = 0x01,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Enable tracking expunge modsequences */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_FEATURE_QRESYNC = 0x02
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenenum mailbox_status_items {
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen STATUS_MESSAGES = 0x01,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen STATUS_RECENT = 0x02,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen STATUS_UIDNEXT = 0x04,
ee246b46953e4b94b2f22e093373674fa9155500Timo Sirainen STATUS_UIDVALIDITY = 0x08,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen STATUS_UNSEEN = 0x10,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen STATUS_FIRST_UNSEEN_SEQ = 0x20,
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen STATUS_KEYWORDS = 0x40,
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen STATUS_HIGHESTMODSEQ = 0x80,
ee246b46953e4b94b2f22e093373674fa9155500Timo Sirainen STATUS_GUID = 0x100
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen};
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenenum mailbox_search_result_flags {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Update search results whenever the mailbox view is synced.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Expunged messages are removed even without this flag. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_SEARCH_RESULT_FLAG_UPDATE = 0x01,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Queue changes so _sync() can be used. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_SEARCH_RESULT_FLAG_QUEUE_SYNC = 0x02
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainenenum mail_sort_type {
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen/* Maximum size for sort program (each one separately + END) */
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen#define MAX_SORT_PROGRAM_SIZE (8 + 1)
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen MAIL_SORT_ARRIVAL = 0x0001,
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen MAIL_SORT_CC = 0x0002,
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen MAIL_SORT_DATE = 0x0004,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen MAIL_SORT_FROM = 0x0008,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen MAIL_SORT_SIZE = 0x0010,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen MAIL_SORT_SUBJECT = 0x0020,
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen MAIL_SORT_TO = 0x0040,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAIL_SORT_SEARCH_SCORE = 0x0080,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen MAIL_SORT_MASK = 0x0fff,
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen MAIL_SORT_FLAG_REVERSE = 0x1000, /* reverse this mask type */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen MAIL_SORT_END = 0x0000 /* ends sort program */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen};
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenenum mail_fetch_field {
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen MAIL_FETCH_FLAGS = 0x00000001,
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen MAIL_FETCH_MESSAGE_PARTS = 0x00000002,
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAIL_FETCH_STREAM_HEADER = 0x00000004,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAIL_FETCH_STREAM_BODY = 0x00000008,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAIL_FETCH_DATE = 0x00000010,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAIL_FETCH_RECEIVED_DATE = 0x00000020,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAIL_FETCH_SAVE_DATE = 0x00000040,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen MAIL_FETCH_PHYSICAL_SIZE = 0x00000080,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAIL_FETCH_VIRTUAL_SIZE = 0x00000100,
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* Set has_nuls / has_no_nuls fields */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen MAIL_FETCH_NUL_STATE = 0x00000200,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* specials: */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen MAIL_FETCH_IMAP_BODY = 0x00001000,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen MAIL_FETCH_IMAP_BODYSTRUCTURE = 0x00002000,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen MAIL_FETCH_IMAP_ENVELOPE = 0x00004000,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAIL_FETCH_FROM_ENVELOPE = 0x00008000,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen MAIL_FETCH_HEADER_MD5 = 0x00010000,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen MAIL_FETCH_UIDL_FILE_NAME = 0x00020000,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAIL_FETCH_UIDL_BACKEND = 0x00040000,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen MAIL_FETCH_MAILBOX_NAME = 0x00080000,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAIL_FETCH_SEARCH_SCORE = 0x00100000,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAIL_FETCH_GUID = 0x00200000
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen};
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenenum mailbox_transaction_flags {
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen /* Hide changes done in this transaction from next view sync */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAILBOX_TRANSACTION_FLAG_HIDE = 0x01,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen /* External transaction. Should be used for copying and appends,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen but nothing else. */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAILBOX_TRANSACTION_FLAG_EXTERNAL = 0x02,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen /* Always assign UIDs to messages when saving/copying. Normally this
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen is done only if the mailbox is synced, or if dest_mail parameter
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen was non-NULL to mailbox_save_init() or mailbox_copy() */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS = 0x04,
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen /* Refresh the index so lookups return latest flags/modseqs */
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen MAILBOX_TRANSACTION_FLAG_REFRESH = 0x08
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen};
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainenenum mailbox_sync_flags {
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* Make sure we sync all external changes done to mailbox */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAILBOX_SYNC_FLAG_FULL_READ = 0x01,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* Make sure we write all our internal changes into the mailbox */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAILBOX_SYNC_FLAG_FULL_WRITE = 0x02,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* If it's not too much trouble, check if there are some changes */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen MAILBOX_SYNC_FLAG_FAST = 0x04,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* Don't sync expunges from our view */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAILBOX_SYNC_FLAG_NO_EXPUNGES = 0x08,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* Stop auto syncing */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAILBOX_SYNC_AUTO_STOP = 0x20,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* If mailbox is currently inconsistent, fix it instead of failing. */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAILBOX_SYNC_FLAG_FIX_INCONSISTENT = 0x40,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* Syncing after an EXPUNGE command. This is just an informational
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen flag for plugins. */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen MAILBOX_SYNC_FLAG_EXPUNGE = 0x80,
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen /* Force doing a full resync of indexes. */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MAILBOX_SYNC_FLAG_FORCE_RESYNC = 0x100
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen};
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainenenum mailbox_sync_type {
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen MAILBOX_SYNC_TYPE_EXPUNGE = 0x01,
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen MAILBOX_SYNC_TYPE_FLAGS = 0x02,
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen MAILBOX_SYNC_TYPE_MODSEQ = 0x04
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen};
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct message_part;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mail_namespace;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mail_storage;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mail_search_args;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mail_search_result;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mail_keywords;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mail_save_context;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mailbox;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mailbox_transaction_context;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen#define MAILBOX_GUID_SIZE MAIL_GUID_128_SIZE
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenstruct mailbox_status {
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen uint32_t messages;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen uint32_t recent;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen uint32_t unseen;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen uint32_t uidvalidity;
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen uint32_t uidnext;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen uint32_t first_unseen_seq;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen uint64_t highest_modseq;
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen uint8_t mailbox_guid[MAILBOX_GUID_SIZE];
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen const ARRAY_TYPE(keywords) *keywords;
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen /* There are expunges that haven't been synced yet */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen unsigned int sync_delayed_expunges:1;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* Modseqs aren't permanent (index is in memory) */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen unsigned int nonpermanent_modseqs:1;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen};
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenstruct mailbox_update {
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* All non-zero fields are changed. */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen uint8_t mailbox_guid[MAILBOX_GUID_SIZE];
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen uint32_t uid_validity;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen uint32_t min_next_uid;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen uint64_t min_highest_modseq;
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen};
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenstruct mail_transaction_commit_changes {
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* Unreference the pool to free memory used by these changes. */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen pool_t pool;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* UIDVALIDITY for assigned UIDs. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen uint32_t uid_validity;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* UIDs assigned to saved messages. Not necessarily ascending. */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen ARRAY_TYPE(seq_range) saved_uids;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen};
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenstruct mailbox_sync_rec {
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen uint32_t seq1, seq2;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen enum mailbox_sync_type type;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen};
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenstruct mailbox_expunge_rec {
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* IMAP UID */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen uint32_t uid;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen /* 128 bit GUID. If the actual GUID has a different size, this
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen contains last bits of its SHA1 sum. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen uint8_t guid_128[MAIL_GUID_128_SIZE];
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen};
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo SirainenARRAY_DEFINE_TYPE(mailbox_expunge_rec, struct mailbox_expunge_rec);
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenenum mail_lookup_abort {
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* Perform everything no matter what it takes */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen MAIL_LOOKUP_ABORT_NEVER = 0,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* Abort if the operation would require reading message header/body */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen MAIL_LOOKUP_ABORT_READ_MAIL,
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* Abort if the operation can't be done fully using cache file */
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen MAIL_LOOKUP_ABORT_NOT_IN_CACHE
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen};
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen
053843989f13d9013b265fb401a4bde7e0e6568eTimo Sirainenstruct mail {
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen /* always set */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen struct mailbox *box;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen struct mailbox_transaction_context *transaction;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen uint32_t seq, uid;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen unsigned int expunged:1;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen unsigned int has_nuls:1; /* message data is known to contain NULs */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen unsigned int has_no_nuls:1; /* -''- known to not contain NULs */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen enum mail_lookup_abort lookup_abort;
ab286a8b58306eb8d22fc18342b6c199fd428e1eTimo Sirainen};
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenstruct mail_storage_callbacks {
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen /* "* OK <text>" */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen void (*notify_ok)(struct mailbox *mailbox, const char *text,
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen void *context);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* "* NO <text>" */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen void (*notify_no)(struct mailbox *mailbox, const char *text,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen void *context);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen};
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenstruct mailbox_virtual_pattern {
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen struct mail_namespace *ns;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen const char *pattern;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen};
bbf796c17f02538058d7559bfe96d677e5b55015Timo SirainenARRAY_DEFINE_TYPE(mailbox_virtual_patterns, struct mailbox_virtual_pattern);
bbf796c17f02538058d7559bfe96d677e5b55015Timo SirainenARRAY_DEFINE_TYPE(mail_storage, struct mail_storage *);
bbf796c17f02538058d7559bfe96d677e5b55015Timo SirainenARRAY_DEFINE_TYPE(mailboxes, struct mailbox *);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenextern ARRAY_TYPE(mail_storage) mail_storage_classes;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainentypedef void mailbox_notify_callback_t(struct mailbox *box, void *context);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenvoid mail_storage_init(void);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenvoid mail_storage_deinit(void);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen/* register all mail storages */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenvoid mail_storage_register_all(void);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Register mail storage class with given name - all methods that are NULL
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen are set to default methods */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid mail_storage_class_register(struct mail_storage *storage_class);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid mail_storage_class_unregister(struct mail_storage *storage_class);
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen/* Find mail storage class by name */
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainenstruct mail_storage *mail_storage_find_class(const char *name);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen/* Create a new instance of registered mail storage class with given
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen storage-specific data. If driver is NULL, it's tried to be autodetected
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen from ns location. If ns location is NULL, it uses the first storage that
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen exists. The storage is put into ns->storage. */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenint mail_storage_create(struct mail_namespace *ns, const char *driver,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen enum mail_storage_flags flags, const char **error_r);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenvoid mail_storage_ref(struct mail_storage *storage);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenvoid mail_storage_unref(struct mail_storage **storage);
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen/* Returns the mail storage settings. */
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainenconst struct mail_storage_settings *
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenmail_storage_get_settings(struct mail_storage *storage) ATTR_PURE;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen/* Set storage callback functions to use. */
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenvoid mail_storage_set_callbacks(struct mail_storage *storage,
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen struct mail_storage_callbacks *callbacks,
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen void *context);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen/* Purge storage's mailboxes (freeing disk space from expunged mails),
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen if supported by the storage. Otherwise just a no-op. */
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainenint mail_storage_purge(struct mail_storage *storage);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Returns the error message of last occurred error. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenconst char *mail_storage_get_last_error(struct mail_storage *storage,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen enum mail_error *error_r);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen/* Returns TRUE if mailboxes are files. */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenbool mail_storage_is_mailbox_file(struct mail_storage *storage) ATTR_PURE;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen/* Initialize mailbox without actually opening any files or verifying that
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen it exists. If input stream is given, mailbox is opened read-only
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen using it as a backend.
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen Note that append and copy may open the selected mailbox again
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen with possibly different readonly-state. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenstruct mailbox *mailbox_alloc(struct mailbox_list *list, const char *name,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen struct istream *input, enum mailbox_flags flags);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Open the mailbox. If this function isn't called explicitly, it's also called
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen internally by lib-storage when necessary. */
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainenint mailbox_open(struct mailbox *box);
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen/* Close the box. */
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainenvoid mailbox_close(struct mailbox **box);
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen/* Create a mailbox. Returns failure if it already exists. Mailbox name is
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen allowed to contain multiple new non-existing hierarchy levels. If directory
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen is TRUE, the mailbox should be created so that it can contain children. The
b79ec51bdeef6ef950eb5e890e65cc0491cf5fe9Timo Sirainen mailbox itself doesn't have to be created as long as it shows up in LIST.
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainen If update is non-NULL, its contents are used to set initial mailbox
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainen metadata. */
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainenint mailbox_create(struct mailbox *box, const struct mailbox_update *update,
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainen bool directory);
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainen/* Update existing mailbox's metadata. */
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainenint mailbox_update(struct mailbox *box, const struct mailbox_update *update);
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainen
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainen/* Enable the given feature for the mailbox. */
64541374b58e4c702b1926e87df421d180ffa006Timo Sirainenint mailbox_enable(struct mailbox *box, enum mailbox_feature features);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Returns all enabled features. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenenum mailbox_feature
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenmailbox_get_enabled_features(struct mailbox *box) ATTR_PURE;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen/* Returns storage of given mailbox */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenstruct mail_storage *mailbox_get_storage(const struct mailbox *box) ATTR_PURE;
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Return namespace of given mailbox. */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenstruct mail_namespace *
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenmailbox_get_namespace(const struct mailbox *box) ATTR_PURE;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen/* Returns the storage's settings. */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenconst struct mail_storage_settings *
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainenmailbox_get_settings(struct mailbox *box) ATTR_PURE;
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen/* Returns name of given mailbox */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenconst char *mailbox_get_name(const struct mailbox *box) ATTR_PURE;
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen/* Returns the virtual name of the given mailbox. This is the same as using
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen mail_namespace_get_vname(). */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenconst char *mailbox_get_vname(const struct mailbox *box) ATTR_PURE;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Returns TRUE if mailbox is read-only. */
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenbool mailbox_is_readonly(struct mailbox *box);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen/* Returns TRUE if mailbox currently supports adding keywords. */
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenbool mailbox_allow_new_keywords(struct mailbox *box);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Returns TRUE if two mailboxes point to the same physical mailbox. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenbool mailbox_backends_equal(const struct mailbox *box1,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen const struct mailbox *box2);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Gets the mailbox status information. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mailbox_status *status_r);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Synchronize the mailbox. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mailbox_sync_context *
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenmailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenbool mailbox_sync_next(struct mailbox_sync_context *ctx,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mailbox_sync_rec *sync_rec_r);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenint mailbox_sync_deinit(struct mailbox_sync_context **ctx,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen enum mailbox_status_items status_items,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mailbox_status *status_r);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* One-step mailbox synchronization. Use this if you don't care about
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen changes. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenint mailbox_sync(struct mailbox *box, enum mailbox_sync_flags flags,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen enum mailbox_status_items status_items,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen struct mailbox_status *status_r);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Call given callback function when something changes in the mailbox. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid mailbox_notify_changes(struct mailbox *box, unsigned int min_interval,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen mailbox_notify_callback_t *callback, void *context);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen#ifdef CONTEXT_TYPE_SAFETY
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen ({(void)(1 ? 0 : callback((struct mailbox *)NULL, context)); \
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen mailbox_notify_changes(box, min_interval, \
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen (mailbox_notify_callback_t *)callback, context); })
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen#else
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen mailbox_notify_changes(box, min_interval, \
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen (mailbox_notify_callback_t *)callback, context)
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen#endif
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainenvoid mailbox_notify_changes_stop(struct mailbox *box);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenstruct mailbox_transaction_context *
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenmailbox_transaction_begin(struct mailbox *box,
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen enum mailbox_transaction_flags flags);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenint mailbox_transaction_commit(struct mailbox_transaction_context **t);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenint mailbox_transaction_commit_get_changes(
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen struct mailbox_transaction_context **t,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen struct mail_transaction_commit_changes *changes_r);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid mailbox_transaction_rollback(struct mailbox_transaction_context **t);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Return the number of active transactions for the mailbox. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenunsigned int mailbox_transaction_get_count(const struct mailbox *box) ATTR_PURE;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* When committing transaction, drop flag/keyword updates for messages whose
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen modseq is larger than max_modseq. Save those messages' sequences to the
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen given array. */
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenvoid mailbox_transaction_set_max_modseq(struct mailbox_transaction_context *t,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen uint64_t max_modseq,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ARRAY_TYPE(seq_range) *seqs);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mailbox *
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenmailbox_transaction_get_mailbox(const struct mailbox_transaction_context *t)
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ATTR_PURE;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Build mail_keywords from NULL-terminated keywords list.
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen Returns 0 if successful, -1 if there are invalid keywords (error is set). */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenint mailbox_keywords_create(struct mailbox *box, const char *const keywords[],
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mail_keywords **keywords_r);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Like mailbox_keywords_create(), except ignore invalid keywords. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mail_keywords *
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenmailbox_keywords_create_valid(struct mailbox *box,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const char *const keywords[]);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenstruct mail_keywords *
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenmailbox_keywords_create_from_indexes(struct mailbox *box,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const ARRAY_TYPE(keyword_indexes) *idx);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid mailbox_keywords_ref(struct mailbox *box, struct mail_keywords *keywords);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid mailbox_keywords_unref(struct mailbox *box,
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen struct mail_keywords **keywords);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Returns TRUE if keyword is valid, FALSE and error if not. */
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenbool mailbox_keyword_is_valid(struct mailbox *box, const char *keyword,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const char **error_r);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Convert uid range to sequence range. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid mailbox_get_seq_range(struct mailbox *box, uint32_t uid1, uint32_t uid2,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen uint32_t *seq1_r, uint32_t *seq2_r);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Convert sequence range to uid range. If sequences contain
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen (uint32_t)-1 to specify "*", they're preserved. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid mailbox_get_uid_range(struct mailbox *box,
871c7b8969e8627dc4c8b3e56fd126f948e6bce6Timo Sirainen const ARRAY_TYPE(seq_range) *seqs,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen ARRAY_TYPE(seq_range) *uids);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Get list of messages' that have been expunged after prev_modseq and that
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen exist in uids_filter range. UIDs that have been expunged after the last
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen mailbox sync aren't returned. Returns TRUE if ok, FALSE if modseq is lower
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen than we can check for (but expunged_uids is still set as best as it can). */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenbool mailbox_get_expunges(struct mailbox *box, uint64_t prev_modseq,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen const ARRAY_TYPE(seq_range) *uids_filter,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ARRAY_TYPE(mailbox_expunge_rec) *expunges);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* If box is a virtual mailbox, look up UID for the given backend message.
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen Returns TRUE if found, FALSE if not. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenbool mailbox_get_virtual_uid(struct mailbox *box, const char *backend_mailbox,
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen uint32_t backend_uidvalidity,
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen uint32_t backend_uid, uint32_t *uid_r);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* If box is a virtual mailbox, return all backend mailboxes. If
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen only_with_msgs=TRUE, return only those mailboxes that have at least one
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen message existing in the virtual mailbox. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mailbox_get_virtual_backend_boxes(struct mailbox *box,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ARRAY_TYPE(mailboxes) *mailboxes,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen bool only_with_msgs);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* If mailbox is a virtual mailbox, return all mailbox list patterns that
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen are used to figure out which mailboxes belong to the virtual mailbox. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mailbox_get_virtual_box_patterns(struct mailbox *box,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ARRAY_TYPE(mailbox_virtual_patterns) *includes,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ARRAY_TYPE(mailbox_virtual_patterns) *excludes);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Initialize header lookup for given headers. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mailbox_header_lookup_ctx *
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenmailbox_header_lookup_init(struct mailbox *box, const char *const headers[]);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenvoid mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **ctx);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Initialize new search request. charset specifies the character set used in
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen the search argument strings. If sort_program is non-NULL, the messages are
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen returned in the requested order, otherwise from first to last. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mail_search_context *
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenmailbox_search_init(struct mailbox_transaction_context *t,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen struct mail_search_args *args,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const enum mail_sort_type *sort_program);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Deinitialize search request. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenint mailbox_search_deinit(struct mail_search_context **ctx);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Search the next message. Returns 1 if found, 0 if not, -1 if failure. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenint mailbox_search_next(struct mail_search_context *ctx, struct mail *mail);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen/* Like mailbox_search_next(), but don't spend too much time searching.
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen Returns 1 if found, -1 if failure or 0 with tryagain_r=FALSE if
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen finished, and TRUE if more results will by calling the function again. */
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainenint mailbox_search_next_nonblock(struct mail_search_context *ctx,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mail *mail, bool *tryagain_r);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Returns TRUE if some messages were already expunged and we couldn't
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen determine correctly if those messages should have been returned in this
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen search. */
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenbool mailbox_search_seen_lost_data(struct mail_search_context *ctx);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen/* Remember the search result for future use. This must be called before the
811f2e26d9782d9cb99fdf82e18ffa0a77564fe2Timo Sirainen first mailbox_search_next*() call. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_search_result *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmailbox_search_result_save(struct mail_search_context *ctx,
811f2e26d9782d9cb99fdf82e18ffa0a77564fe2Timo Sirainen enum mailbox_search_result_flags flags);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Free memory used by search result. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mailbox_search_result_free(struct mail_search_result **result);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* A simplified API for searching and saving the result. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mailbox_search_result_build(struct mailbox_transaction_context *t,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail_search_args *args,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen enum mailbox_search_result_flags flags,
811f2e26d9782d9cb99fdf82e18ffa0a77564fe2Timo Sirainen struct mail_search_result **result_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Return all messages' UIDs in the search result. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst ARRAY_TYPE(seq_range) *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmailbox_search_result_get(struct mail_search_result *result);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Return messages that have been removed and added since the last sync call.
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen This function must not be called if search result wasn't saved with
8830fab191cab8440281eb641dfdd93974b2933bTimo Sirainen _QUEUE_SYNC flag. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenvoid mailbox_search_result_sync(struct mail_search_result *result,
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen ARRAY_TYPE(seq_range) *removed_uids,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ARRAY_TYPE(seq_range) *added_uids);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
92888ef30960c30ccc9e030fe7eab5d4d04a7d1cTimo Sirainen/* Initialize saving a new mail. You must not try to save more than one mail
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen at a time. */
92888ef30960c30ccc9e030fe7eab5d4d04a7d1cTimo Sirainenstruct mail_save_context *
92888ef30960c30ccc9e030fe7eab5d4d04a7d1cTimo Sirainenmailbox_save_alloc(struct mailbox_transaction_context *t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Set the flags and keywords. Nothing is set by default. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mailbox_save_set_flags(struct mail_save_context *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen enum mail_flags flags,
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainen struct mail_keywords *keywords);
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen/* Copy flags and keywords from given mail. */
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainenvoid mailbox_save_copy_flags(struct mail_save_context *ctx, struct mail *mail);
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen/* If received date isn't specified the current time is used. timezone_offset
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainen specifies the preferred timezone in minutes, but it may be ignored if
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen backend doesn't support storing it. */
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainenvoid mailbox_save_set_received_date(struct mail_save_context *ctx,
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen time_t received_date, int timezone_offset);
e12648867876aaec17e06ee4caef0bb60363449dTimo Sirainen/* Set the "message saved" date. This should be set only when you're
e12648867876aaec17e06ee4caef0bb60363449dTimo Sirainen replicating/restoring an existing mailbox. */
e12648867876aaec17e06ee4caef0bb60363449dTimo Sirainenvoid mailbox_save_set_save_date(struct mail_save_context *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen time_t save_date);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Set the envelope sender. This is currently used only with mbox files to
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen specify the address in From_-line. */
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainenvoid mailbox_save_set_from_envelope(struct mail_save_context *ctx,
d482b35af87f5fd872bad007da0475813a401a49Timo Sirainen const char *envelope);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Set message's UID. If UID is smaller than the current next_uid, it's given
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen a new UID anyway. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mailbox_save_set_uid(struct mail_save_context *ctx, uint32_t uid);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Set globally unique ID for the saved mail. A new GUID is generated by
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen default. This function should usually be called only when copying an
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen existing mail (or restoring a mail from backup). */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mailbox_save_set_guid(struct mail_save_context *ctx, const char *guid);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen/* Set message's POP3 UIDL, if the backend supports it. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mailbox_save_set_pop3_uidl(struct mail_save_context *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *uidl);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen/* If dest_mail is set, the saved message can be accessed using it. Note that
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen setting it may require mailbox syncing, so don't set it unless you need
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen it. Also you shouldn't try to access it before mailbox_save_finish() is
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen called. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mailbox_save_set_dest_mail(struct mail_save_context *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail *mail);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen/* Begin saving the message. All mail_save_set_*() calls must have been called
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen before this function. If the save initialization fails, the context is freed
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen and -1 is returned. After beginning the save you should keep calling
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen i_stream_read() and calling mailbox_save_continue() as long as there's
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen more input. */
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenint mailbox_save_begin(struct mail_save_context **ctx, struct istream *input);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenint mailbox_save_continue(struct mail_save_context *ctx);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenint mailbox_save_finish(struct mail_save_context **ctx);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenvoid mailbox_save_cancel(struct mail_save_context **ctx);
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Copy the given message. You'll need to specify the flags etc. using the
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen mailbox_save_*() functions. */
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenint mailbox_copy(struct mail_save_context **ctx, struct mail *mail);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns TRUE if mailbox is now in inconsistent state, meaning that
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen the message IDs etc. may have changed - only way to recover this
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen would be to fully close the mailbox and reopen it. With IMAP
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen connection this would mean a forced disconnection since we can't
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen do forced CLOSE. */
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenbool mailbox_is_inconsistent(struct mailbox *box);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenstruct mail *mail_alloc(struct mailbox_transaction_context *t,
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen enum mail_fetch_field wanted_fields,
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenvoid mail_free(struct mail **mail);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenvoid mail_set_seq(struct mail *mail, uint32_t seq);
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen/* Returns TRUE if successful, FALSE if message doesn't exist.
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen mail_*() functions shouldn't be called if FALSE is returned. */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenbool mail_set_uid(struct mail *mail, uint32_t uid);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Returns message's flags */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenenum mail_flags mail_get_flags(struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns message's keywords */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst char *const *mail_get_keywords(struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns message's keywords */
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainenconst ARRAY_TYPE(keyword_indexes) *mail_get_keyword_indexes(struct mail *mail);
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen/* Returns message's modseq */
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainenuint64_t mail_get_modseq(struct mail *mail);
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen/* Returns message's MIME parts */
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainenint mail_get_parts(struct mail *mail, const struct message_part **parts_r);
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen/* Get the Date-header of the mail. Timezone is in minutes. date=0 if it
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen wasn't found or it was invalid. */
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainenint mail_get_date(struct mail *mail, time_t *date_r, int *timezone_r);
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen/* Get the time when the mail was received (IMAP INTERNALDATE). */
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainenint mail_get_received_date(struct mail *mail, time_t *date_r);
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen/* Get the time when the mail was saved into this mailbox. This time may not
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen always be entirely reliable. */
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainenint mail_get_save_date(struct mail *mail, time_t *date_r);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Get the space used by the mail as seen by the reader. Linefeeds are always
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen counted as being CR+LF. */
3c24d47ad5ff02ea00684233bef314ef2eefda4aTimo Sirainenint mail_get_virtual_size(struct mail *mail, uoff_t *size_r);
3c24d47ad5ff02ea00684233bef314ef2eefda4aTimo Sirainen/* Get the size of the stream returned by mail_get_stream(). */
3c24d47ad5ff02ea00684233bef314ef2eefda4aTimo Sirainenint mail_get_physical_size(struct mail *mail, uoff_t *size_r);
3c24d47ad5ff02ea00684233bef314ef2eefda4aTimo Sirainen
3c24d47ad5ff02ea00684233bef314ef2eefda4aTimo Sirainen/* Get value for single header field, or NULL if header wasn't found.
3c24d47ad5ff02ea00684233bef314ef2eefda4aTimo Sirainen Returns 1 if header was found, 0 if not, -1 if error. */
3c24d47ad5ff02ea00684233bef314ef2eefda4aTimo Sirainenint mail_get_first_header(struct mail *mail, const char *field,
4c1827d5d718d6f610df3209a2eb95a6591698afTimo Sirainen const char **value_r);
5a4ab3d6e108a899c8b51bebd0094a37b738d5a1Timo Sirainen/* Like mail_get_first_header(), but decode MIME encoded words to UTF-8.
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen Also multiline headers are returned unfolded. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenint mail_get_first_header_utf8(struct mail *mail, const char *field,
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen const char **value_r);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Return a NULL-terminated list of values for each found field. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenint mail_get_headers(struct mail *mail, const char *field,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *const **value_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Like mail_get_headers(), but decode MIME encoded words to UTF-8.
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen Also multiline headers are returned unfolded. */
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainenint mail_get_headers_utf8(struct mail *mail, const char *field,
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen const char *const **value_r);
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen/* Returns stream containing specified headers. */
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainenint mail_get_header_stream(struct mail *mail,
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen struct mailbox_header_lookup_ctx *headers,
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen struct istream **stream_r);
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen/* Returns input stream pointing to beginning of message header.
91b5eae18db48ebb70eee5407a7ab52bf798ee12Timo Sirainen hdr_size and body_size are updated unless they're NULL. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenint mail_get_stream(struct mail *mail, struct message_size *hdr_size,
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen struct message_size *body_size, struct istream **stream_r);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Get any of the "special" fields. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenint mail_get_special(struct mail *mail, enum mail_fetch_field field,
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen const char **value_r);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Update message flags. */
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainenvoid mail_update_flags(struct mail *mail, enum modify_type modify_type,
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen enum mail_flags flags);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Update message keywords. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenvoid mail_update_keywords(struct mail *mail, enum modify_type modify_type,
7e94cf9d70ce9fdeccb7a85ff400b899e6386f36Timo Sirainen struct mail_keywords *keywords);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Expunge this message. Sequence numbers don't change until commit. */
cd65dfcedc603fabbf644be793efb09096f6c1b5Timo Sirainenvoid mail_expunge(struct mail *mail);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Mark a cached field corrupted and have it recalculated. */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenvoid mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen/* Return 128 bit GUID using input string. If guid is already 128 bit hex
0ce3bbb0f03fb0ee99258b41b5a1d689c1158a75Timo Sirainen encoded, it's returned as-is. Otherwise SHA1 sum is taken and its last
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen 128 bits are returned. */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenvoid mail_generate_guid_128_hash(const char *guid,
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen uint8_t guid_128[MAIL_GUID_128_SIZE]);
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen/* Returns TRUE if GUID is empty (not set / unknown). */
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainenbool mail_guid_128_is_empty(const uint8_t guid_128[MAIL_GUID_128_SIZE]);
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen
b2105c78f0fd58281317e6d777ded860f33153a3Timo Sirainen#endif
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen