mail-storage.h revision 20eafc2a848865ce7bf5e8c609e3b0bbd9077ec2
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen#ifndef MAIL_STORAGE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define MAIL_STORAGE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct message_size;
8363f50d7b5d605912e55c34f7f28e9f4ce01341Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "seq-range-array.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "file-lock.h"
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen#include "mail-types.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "mail-error.h"
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen#include "mailbox-list.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* If some operation is taking long, call notify_ok every n seconds. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo 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,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen /* Don't try to autodetect anything, require that the given data
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen contains all the necessary information. */
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen MAIL_STORAGE_FLAG_NO_AUTODETECTION = 0x02,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen /* Don't autocreate any directories. If they don't exist,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen fail to create the storage. */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen MAIL_STORAGE_FLAG_NO_AUTOCREATE = 0x04,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen /* Don't verify existence or accessibility of any directories.
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen Create the storage in any case. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_STORAGE_FLAG_NO_AUTOVERIFY = 0x08
8363f50d7b5d605912e55c34f7f28e9f4ce01341Timo Sirainen};
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainenenum mailbox_flags {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Mailbox must not be modified even if asked */
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo 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 */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen MAILBOX_FLAG_KEEP_RECENT = 0x08,
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen /* Don't create index files for the mailbox */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen MAILBOX_FLAG_NO_INDEX_FILES = 0x10,
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen /* Keep mailbox exclusively locked all the time while it's open */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen MAILBOX_FLAG_KEEP_LOCKED = 0x20,
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen /* Enable if mailbox is used for serving POP3. This allows making
98922c5675bbbfadc84d58768bef867fe82256c2Timo 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. */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen MAILBOX_FLAG_POST_SESSION = 0x80,
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainen /* Force opening mailbox and ignoring any ACLs */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_FLAG_IGNORE_ACLS = 0x100,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Open mailbox even if it's already marked as deleted */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_FLAG_OPEN_DELETED = 0x200
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenenum mailbox_feature {
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen /* Enable tracking modsequences */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen MAILBOX_FEATURE_CONDSTORE = 0x01,
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen /* Enable tracking expunge modsequences */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen MAILBOX_FEATURE_QRESYNC = 0x02
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen};
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainenenum mailbox_existence {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_EXISTENCE_NONE,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_EXISTENCE_NOSELECT,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_EXISTENCE_SELECT
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainenenum mailbox_status_items {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen STATUS_MESSAGES = 0x01,
d42eb03b3a4e79a2da22a1be2de59b95660af2beTimo Sirainen STATUS_RECENT = 0x02,
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen STATUS_UIDNEXT = 0x04,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen STATUS_UIDVALIDITY = 0x08,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen STATUS_UNSEEN = 0x10,
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen STATUS_FIRST_UNSEEN_SEQ = 0x20,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen STATUS_KEYWORDS = 0x40,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen STATUS_HIGHESTMODSEQ = 0x80,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen STATUS_PERMANENT_FLAGS = 0x200,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen STATUS_FIRST_RECENT_UID = 0x400
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen};
fc40a9a002458e372ff4b9f6f4e15239520c0bcdTimo Sirainen
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainenenum mailbox_metadata_items {
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen MAILBOX_METADATA_GUID = 0x01,
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen MAILBOX_METADATA_VIRTUAL_SIZE = 0x02,
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen MAILBOX_METADATA_CACHE_FIELDS = 0x04
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen};
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainenenum mailbox_search_result_flags {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Update search results whenever the mailbox view is synced.
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen Expunged messages are removed even without this flag. */
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo 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};
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen
c60d1eda4df179d83d531647732d5e3e45064219Timo Sirainenenum mail_sort_type {
c60d1eda4df179d83d531647732d5e3e45064219Timo Sirainen/* Maximum size for sort program (each one separately + END) */
f6f021c133f680cf3d559187524fd9abcbaae9b9Timo Sirainen#define MAX_SORT_PROGRAM_SIZE (8 + 1)
f6f021c133f680cf3d559187524fd9abcbaae9b9Timo Sirainen
c60d1eda4df179d83d531647732d5e3e45064219Timo Sirainen MAIL_SORT_ARRIVAL = 0x0001,
c60d1eda4df179d83d531647732d5e3e45064219Timo Sirainen MAIL_SORT_CC = 0x0002,
c60d1eda4df179d83d531647732d5e3e45064219Timo Sirainen MAIL_SORT_DATE = 0x0004,
c60d1eda4df179d83d531647732d5e3e45064219Timo Sirainen MAIL_SORT_FROM = 0x0008,
c60d1eda4df179d83d531647732d5e3e45064219Timo Sirainen MAIL_SORT_SIZE = 0x0010,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen MAIL_SORT_SUBJECT = 0x0020,
d42eb03b3a4e79a2da22a1be2de59b95660af2beTimo Sirainen MAIL_SORT_TO = 0x0040,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_SORT_RELEVANCY = 0x0080,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_SORT_DISPLAYFROM = 0x0100,
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen MAIL_SORT_DISPLAYTO = 0x0200,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_SORT_POP3_ORDER = 0x0400,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen MAIL_SORT_MASK = 0x0fff,
ee1a3e217279dcd0f1cccbd3442e481b7dc90f05Timo Sirainen MAIL_SORT_FLAG_REVERSE = 0x1000, /* reverse this mask type */
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen
ee1a3e217279dcd0f1cccbd3442e481b7dc90f05Timo Sirainen MAIL_SORT_END = 0x0000 /* ends sort program */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainenenum mail_fetch_field {
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen MAIL_FETCH_FLAGS = 0x00000001,
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen MAIL_FETCH_MESSAGE_PARTS = 0x00000002,
ebe6df72f1309135f02b6a4d2aef1e81a073f91cTimo Sirainen
bc6ef0b01b99c43ee46aa796420516e89a744c30Timo Sirainen MAIL_FETCH_STREAM_HEADER = 0x00000004,
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen MAIL_FETCH_STREAM_BODY = 0x00000008,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAIL_FETCH_DATE = 0x00000010,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAIL_FETCH_RECEIVED_DATE = 0x00000020,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAIL_FETCH_SAVE_DATE = 0x00000040,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen MAIL_FETCH_PHYSICAL_SIZE = 0x00000080,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen MAIL_FETCH_VIRTUAL_SIZE = 0x00000100,
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen /* Set has_nuls / has_no_nuls fields */
ee1a3e217279dcd0f1cccbd3442e481b7dc90f05Timo Sirainen MAIL_FETCH_NUL_STATE = 0x00000200,
ee1a3e217279dcd0f1cccbd3442e481b7dc90f05Timo Sirainen
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* specials: */
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen MAIL_FETCH_IMAP_BODY = 0x00001000,
3eb63515855f386449c22233d1f1baf1ddfe8a2dTimo Sirainen MAIL_FETCH_IMAP_BODYSTRUCTURE = 0x00002000,
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen MAIL_FETCH_IMAP_ENVELOPE = 0x00004000,
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen MAIL_FETCH_FROM_ENVELOPE = 0x00008000,
e9d29ae46d435aee85514decfe6ee27399ebf794Timo Sirainen MAIL_FETCH_HEADER_MD5 = 0x00010000,
e9d29ae46d435aee85514decfe6ee27399ebf794Timo Sirainen MAIL_FETCH_UIDL_FILE_NAME = 0x00020000,
e9d29ae46d435aee85514decfe6ee27399ebf794Timo Sirainen MAIL_FETCH_UIDL_BACKEND = 0x00040000,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAIL_FETCH_MAILBOX_NAME = 0x00080000,
e9d29ae46d435aee85514decfe6ee27399ebf794Timo Sirainen MAIL_FETCH_SEARCH_RELEVANCY = 0x00100000,
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen MAIL_FETCH_GUID = 0x00200000,
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen MAIL_FETCH_POP3_ORDER = 0x00400000
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen};
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenenum mailbox_transaction_flags {
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen /* Hide changes done in this transaction from next view sync */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_TRANSACTION_FLAG_HIDE = 0x01,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen /* External transaction. Should be used for copying and appends,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen but nothing else. */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_TRANSACTION_FLAG_EXTERNAL = 0x02,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* Always assign UIDs to messages when saving/copying. Normally this
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen is done only if it can be done easily. */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS = 0x04,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* Refresh the index so lookups return latest flags/modseqs */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_TRANSACTION_FLAG_REFRESH = 0x08
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen};
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainenenum mailbox_sync_flags {
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen /* Make sure we sync all external changes done to mailbox */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAILBOX_SYNC_FLAG_FULL_READ = 0x01,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* Make sure we write all our internal changes into the mailbox */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_SYNC_FLAG_FULL_WRITE = 0x02,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen /* If it's not too much trouble, check if there are some changes */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_SYNC_FLAG_FAST = 0x04,
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen /* Don't sync expunges from our view */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAILBOX_SYNC_FLAG_NO_EXPUNGES = 0x08,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* If mailbox is currently inconsistent, fix it instead of failing. */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAILBOX_SYNC_FLAG_FIX_INCONSISTENT = 0x40,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* Syncing after an EXPUNGE command. This is just an informational
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen flag for plugins. */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_SYNC_FLAG_EXPUNGE = 0x80,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* Force doing a full resync of indexes. */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_SYNC_FLAG_FORCE_RESYNC = 0x100,
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen /* Add all missing data to cache and fts index ("doveadm index") */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAILBOX_SYNC_FLAG_PRECACHE = 0x200,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* FIXME: kludge until something better comes along:
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen Request full text search index optimization */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen MAILBOX_SYNC_FLAG_OPTIMIZE = 0x400
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen};
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen
51078c3413b7ed4811bc725acbb1289723361ba9Timo Sirainenenum mailbox_sync_type {
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_SYNC_TYPE_EXPUNGE = 0x01,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAILBOX_SYNC_TYPE_FLAGS = 0x02,
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen MAILBOX_SYNC_TYPE_MODSEQ = 0x04
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen};
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainenstruct message_part;
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainenstruct mail_namespace;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainenstruct mail_storage;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainenstruct mail_search_args;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainenstruct mail_search_result;
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainenstruct mail_keywords;
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainenstruct mail_save_context;
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo Sirainenstruct mailbox;
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainenstruct mailbox_transaction_context;
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainenstruct mailbox_status {
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen uint32_t messages;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen uint32_t recent;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen uint32_t unseen;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen uint32_t uidvalidity;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen uint32_t uidnext;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen
d22301419109ed4a38351715e6760011421dadecTimo Sirainen uint32_t first_unseen_seq;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen uint32_t first_recent_uid;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen uint64_t highest_modseq;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen /* NULL-terminated array of keywords */
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen const ARRAY_TYPE(keywords) *keywords;
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen /* These flags can be permanently modified */
9334fbad0aabb2fed88f40b2205d0d6f80bdffa2Timo Sirainen enum mail_flags permanent_flags;
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen /* Modseqs aren't permanent (index is in memory) */
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen unsigned int nonpermanent_modseqs:1;
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen /* All keywords can be permanently modified */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen unsigned int permanent_keywords:1;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* More keywords can be created */
d22301419109ed4a38351715e6760011421dadecTimo Sirainen unsigned int allow_new_keywords:1;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen};
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenstruct mailbox_metadata {
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint8_t guid[MAIL_GUID_128_SIZE];
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* sum of virtual size of all messages in mailbox */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint64_t virtual_size;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* Fields that have "temp" or "yes" caching decision. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen const ARRAY_TYPE(const_string) *cache_fields;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen};
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainenstruct mailbox_update {
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* All non-zero fields are changed. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint32_t uid_validity;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint32_t min_next_uid;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint32_t min_first_recent_uid;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen uint64_t min_highest_modseq;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen /* Add these fields to be temporarily cached, if they aren't already. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen const char *const *cache_fields;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen};
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
d22301419109ed4a38351715e6760011421dadecTimo Sirainenstruct mail_transaction_commit_changes {
d22301419109ed4a38351715e6760011421dadecTimo Sirainen /* Unreference the pool to free memory used by these changes. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen pool_t pool;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* UIDVALIDITY for assigned UIDs. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint32_t uid_validity;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* UIDs assigned to saved messages. Not necessarily ascending. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen ARRAY_TYPE(seq_range) saved_uids;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
d22301419109ed4a38351715e6760011421dadecTimo Sirainen /* number of modseq changes that couldn't be changed as requested */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen unsigned int ignored_modseq_changes;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen};
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainenstruct mailbox_sync_rec {
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint32_t seq1, seq2;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen enum mailbox_sync_type type;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen};
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenstruct mailbox_sync_status {
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* There are expunges that haven't been synced yet */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen unsigned int sync_delayed_expunges:1;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen};
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainenstruct mailbox_expunge_rec {
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* IMAP UID */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint32_t uid;
236bedf76e31651ea9fca63fbdc25be673819526Timo Sirainen /* 128 bit GUID. If the actual GUID has a different size, this
d22301419109ed4a38351715e6760011421dadecTimo Sirainen contains last bits of its SHA1 sum. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint8_t guid_128[MAIL_GUID_128_SIZE];
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen};
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo SirainenARRAY_DEFINE_TYPE(mailbox_expunge_rec, struct mailbox_expunge_rec);
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainenenum mail_lookup_abort {
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* Perform everything no matter what it takes */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen MAIL_LOOKUP_ABORT_NEVER = 0,
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* Abort if the operation would require reading message header/body */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen MAIL_LOOKUP_ABORT_READ_MAIL,
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* Abort if the operation can't be done fully using cache file */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen MAIL_LOOKUP_ABORT_NOT_IN_CACHE
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen};
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail {
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen /* always set */
d22301419109ed4a38351715e6760011421dadecTimo Sirainen struct mailbox *box;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen struct mailbox_transaction_context *transaction;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen uint32_t seq, uid;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
3eb63515855f386449c22233d1f1baf1ddfe8a2dTimo Sirainen unsigned int expunged:1;
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen unsigned int saving:1; /* This mail is still being saved */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen unsigned int has_nuls:1; /* message data is known to contain NULs */
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen unsigned int has_no_nuls:1; /* -''- known to not contain NULs */
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen /* If the lookup is aborted, error is set to MAIL_ERROR_NOTPOSSIBLE */
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen enum mail_lookup_abort lookup_abort;
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen};
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_storage_callbacks {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* "* OK <text>" */
80bcc6caa317a52bddcafe74fede886247dbba5bTimo Sirainen void (*notify_ok)(struct mailbox *mailbox, const char *text,
80bcc6caa317a52bddcafe74fede886247dbba5bTimo Sirainen void *context);
80bcc6caa317a52bddcafe74fede886247dbba5bTimo Sirainen /* "* NO <text>" */
80bcc6caa317a52bddcafe74fede886247dbba5bTimo Sirainen void (*notify_no)(struct mailbox *mailbox, const char *text,
80bcc6caa317a52bddcafe74fede886247dbba5bTimo Sirainen void *context);
80bcc6caa317a52bddcafe74fede886247dbba5bTimo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen};
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
3eb63515855f386449c22233d1f1baf1ddfe8a2dTimo Sirainenstruct mailbox_virtual_pattern {
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen struct mail_namespace *ns;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen const char *pattern;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen};
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo SirainenARRAY_DEFINE_TYPE(mailbox_virtual_patterns, struct mailbox_virtual_pattern);
9261dbf0675204898c6557591c7aa376e23a52b2Timo SirainenARRAY_DEFINE_TYPE(mail_storage, struct mail_storage *);
9261dbf0675204898c6557591c7aa376e23a52b2Timo SirainenARRAY_DEFINE_TYPE(mailboxes, struct mailbox *);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenextern ARRAY_TYPE(mail_storage) mail_storage_classes;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentypedef void mailbox_notify_callback_t(struct mailbox *box, void *context);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenvoid mail_storage_init(void);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenvoid mail_storage_deinit(void);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen
d22301419109ed4a38351715e6760011421dadecTimo Sirainen/* register all mail storages */
d22301419109ed4a38351715e6760011421dadecTimo Sirainenvoid mail_storage_register_all(void);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Register mail storage class with given name - all methods that are NULL
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen are set to default methods */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenvoid mail_storage_class_register(struct mail_storage *storage_class);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenvoid mail_storage_class_unregister(struct mail_storage *storage_class);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Find mail storage class by name */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenstruct mail_storage *mail_storage_find_class(const char *name);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen
55b6e3105184ad6a2f987346380966f556300055Timo Sirainen/* Create a new instance of registered mail storage class with given
7aeaf23f760d86aad525d831efcac9f860a55a39Timo Sirainen storage-specific data. If driver is NULL, it's tried to be autodetected
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainen from ns location. If ns location is NULL, it uses the first storage that
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainen exists. The storage is put into ns->storage. */
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainenint mail_storage_create(struct mail_namespace *ns, const char *driver,
d22301419109ed4a38351715e6760011421dadecTimo Sirainen enum mail_storage_flags flags, const char **error_r);
63aaafe7e6b201d6633f8c25610ecd30c9cda99cTimo Sirainenvoid mail_storage_unref(struct mail_storage **storage);
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainen
63aaafe7e6b201d6633f8c25610ecd30c9cda99cTimo Sirainen/* Returns the mail storage settings. */
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainenconst struct mail_storage_settings *
2ff23d6fb7e2ff85aa23b7f4769aeac1d0316a1bTimo Sirainenmail_storage_get_settings(struct mail_storage *storage) ATTR_PURE;
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainenstruct mail_user *mail_storage_get_user(struct mail_storage *storage) ATTR_PURE;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen
63aaafe7e6b201d6633f8c25610ecd30c9cda99cTimo Sirainen/* Set storage callback functions to use. */
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainenvoid mail_storage_set_callbacks(struct mail_storage *storage,
63aaafe7e6b201d6633f8c25610ecd30c9cda99cTimo Sirainen struct mail_storage_callbacks *callbacks,
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainen void *context);
2ff23d6fb7e2ff85aa23b7f4769aeac1d0316a1bTimo Sirainen
cf49fc07f541c0f74578ac6c3b334ddade143aa1Timo Sirainen/* Purge storage's mailboxes (freeing disk space from expunged mails),
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen if supported by the storage. Otherwise just a no-op. */
7aeaf23f760d86aad525d831efcac9f860a55a39Timo Sirainenint mail_storage_purge(struct mail_storage *storage);
7aeaf23f760d86aad525d831efcac9f860a55a39Timo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen/* Returns the error message of last occurred error. */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainenconst char *mail_storage_get_last_error(struct mail_storage *storage,
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen enum mail_error *error_r);
18065635d4e79dd96eb3b3215718abd12f6a6808Timo Sirainen/* Wrapper for mail_storage_get_last_error(); */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenconst char *mailbox_get_last_error(struct mailbox *box,
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen enum mail_error *error_r);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Wrapper for mail_storage_get_last_error(); */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenenum mail_error mailbox_get_last_mail_error(struct mailbox *box);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Returns TRUE if mailboxes are files. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenbool mail_storage_is_mailbox_file(struct mail_storage *storage) ATTR_PURE;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Initialize mailbox without actually opening any files or verifying that
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen it exists. Note that append and copy may open the selected mailbox again
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen with possibly different readonly-state. */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenstruct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname,
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen enum mailbox_flags flags);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Like mailbox_alloc(), but use mailbox GUID. */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainenstruct mailbox *mailbox_alloc_guid(struct mailbox_list *list,
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen uint8_t guid[MAIL_GUID_128_SIZE],
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen enum mailbox_flags flags);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Get mailbox existence state. If auto_boxes=FALSE, return
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen MAILBOX_EXISTENCE_NONE for autocreated mailboxes that haven't been
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen physically created yet */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenint mailbox_exists(struct mailbox *box, bool auto_boxes,
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen enum mailbox_existence *existence_r);
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen/* Open the mailbox. If this function isn't called explicitly, it's also called
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen internally by lib-storage when necessary. */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainenint mailbox_open(struct mailbox *box);
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen/* Open mailbox as read-only using the given stream as input. */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainenint mailbox_open_stream(struct mailbox *box, struct istream *input);
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen/* Close mailbox. Same as if mailbox was freed and re-allocated. */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenvoid mailbox_close(struct mailbox *box);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Close and free the mailbox. */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainenvoid mailbox_free(struct mailbox **box);
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen/* Create a mailbox. Returns failure if it already exists. Mailbox name is
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen allowed to contain multiple new nonexistent hierarchy levels. If directory
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen is TRUE, the mailbox should be created so that it can contain children. The
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen mailbox itself doesn't have to be created as long as it shows up in LIST.
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen If update is non-NULL, its contents are used to set initial mailbox
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen metadata. */
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainenint mailbox_create(struct mailbox *box, const struct mailbox_update *update,
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainen bool directory);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Update existing mailbox's metadata. */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenint mailbox_update(struct mailbox *box, const struct mailbox_update *update);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Delete mailbox (and its parent directory, if it has no siblings) */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenint mailbox_delete(struct mailbox *box);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Rename mailbox. Renaming across different mailbox lists is possible only
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen between private namespaces and storages of the same type. If the rename
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen fails, the error is set to src's storage. */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenint mailbox_rename(struct mailbox *src, struct mailbox *dest,
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen bool rename_children);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen/* Subscribe/unsubscribe mailbox. Subscribing to
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen nonexistent mailboxes is optional. */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenint mailbox_set_subscribed(struct mailbox *box, bool set);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen/* Enable the given feature for the mailbox. */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint mailbox_enable(struct mailbox *box, enum mailbox_feature features);
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen/* Returns all enabled features. */
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainenenum mailbox_feature
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenmailbox_get_enabled_features(struct mailbox *box) ATTR_PURE;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Returns storage of given mailbox */
d22301419109ed4a38351715e6760011421dadecTimo Sirainenstruct mail_storage *mailbox_get_storage(const struct mailbox *box) ATTR_PURE;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Return namespace of given mailbox. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenstruct mail_namespace *
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenmailbox_get_namespace(const struct mailbox *box) ATTR_PURE;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Returns the storage's settings. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenconst struct mail_storage_settings *
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainenmailbox_get_settings(struct mailbox *box) ATTR_PURE;
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen/* Returns name of given mailbox */
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainenconst char *mailbox_get_name(const struct mailbox *box) ATTR_PURE;
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen/* Returns the virtual name of the given mailbox. This is the same as using
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen mail_namespace_get_vname(). */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenconst char *mailbox_get_vname(const struct mailbox *box) ATTR_PURE;
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen/* Returns TRUE if mailbox is read-only. */
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainenbool mailbox_is_readonly(struct mailbox *box);
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen/* Returns TRUE if two mailboxes point to the same physical mailbox. */
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainenbool mailbox_backends_equal(const struct mailbox *box1,
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen const struct mailbox *box2);
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen/* Returns TRUE if mailbox is now in inconsistent state, meaning that
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen the message IDs etc. may have changed - only way to recover this
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen would be to fully close the mailbox and reopen it. With IMAP
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen connection this would mean a forced disconnection since we can't
6d50c4d875bb05f9076e9e0ecbacb8beb2e9ae42Timo Sirainen do forced CLOSE. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenbool mailbox_is_inconsistent(struct mailbox *box);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Gets the mailbox status information, opening the mailbox if necessary. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenint mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen struct mailbox_status *status_r);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Gets the mailbox status, requires that mailbox is already opened. */
3eb63515855f386449c22233d1f1baf1ddfe8a2dTimo Sirainenvoid mailbox_get_open_status(struct mailbox *box,
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen enum mailbox_status_items items,
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen struct mailbox_status *status_r);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Gets mailbox metadata */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenint mailbox_get_metadata(struct mailbox *box, enum mailbox_metadata_items items,
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen struct mailbox_metadata *metadata_r);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Returns a mask of flags that are private to user in this mailbox
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen (as opposed to flags shared between users). */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenenum mail_flags mailbox_get_private_flags_mask(struct mailbox *box);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Synchronize the mailbox. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenstruct mailbox_sync_context *
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenmailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenbool mailbox_sync_next(struct mailbox_sync_context *ctx,
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen struct mailbox_sync_rec *sync_rec_r);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenint mailbox_sync_deinit(struct mailbox_sync_context **ctx,
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen struct mailbox_sync_status *status_r);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* One-step mailbox synchronization. Use this if you don't care about
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen changes. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenint mailbox_sync(struct mailbox *box, enum mailbox_sync_flags flags);
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen/* Call given callback function when something changes in the mailbox. */
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainenvoid mailbox_notify_changes(struct mailbox *box, unsigned int min_interval,
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen mailbox_notify_callback_t *callback, void *context);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen#ifdef CONTEXT_TYPE_SAFETY
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen ({(void)(1 ? 0 : callback((struct mailbox *)NULL, context)); \
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen mailbox_notify_changes(box, min_interval, \
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen (mailbox_notify_callback_t *)callback, context); })
d22301419109ed4a38351715e6760011421dadecTimo Sirainen#else
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen mailbox_notify_changes(box, min_interval, \
b19a1420da0618a10edf67c2cfd13c8c8633057aTimo Sirainen (mailbox_notify_callback_t *)callback, context)
b19a1420da0618a10edf67c2cfd13c8c8633057aTimo Sirainen#endif
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainenvoid mailbox_notify_changes_stop(struct mailbox *box);
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainen
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainenstruct mailbox_transaction_context *
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainenmailbox_transaction_begin(struct mailbox *box,
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainen enum mailbox_transaction_flags flags);
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainenint mailbox_transaction_commit(struct mailbox_transaction_context **t);
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainenint mailbox_transaction_commit_get_changes(
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainen struct mailbox_transaction_context **t,
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainen struct mail_transaction_commit_changes *changes_r);
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainenvoid mailbox_transaction_rollback(struct mailbox_transaction_context **t);
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainen/* Return the number of active transactions for the mailbox. */
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainenunsigned int mailbox_transaction_get_count(const struct mailbox *box) ATTR_PURE;
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainen/* When committing transaction, drop flag/keyword updates for messages whose
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainen modseq is larger than max_modseq. Save those messages' sequences to the
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainen given array. */
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainenvoid mailbox_transaction_set_max_modseq(struct mailbox_transaction_context *t,
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainen uint64_t max_modseq,
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainen ARRAY_TYPE(seq_range) *seqs);
3df398a463e931b63586726adb3309c9692208c1Timo Sirainen
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainenstruct mailbox *
ed34a210eff7707787ee154e5581528b8f4b2daaTimo Sirainenmailbox_transaction_get_mailbox(const struct mailbox_transaction_context *t)
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainen ATTR_PURE;
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainen
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainen/* Convert uid range to sequence range. */
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainenvoid mailbox_get_seq_range(struct mailbox *box, uint32_t uid1, uint32_t uid2,
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainen uint32_t *seq1_r, uint32_t *seq2_r);
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainen/* Convert sequence range to uid range. If sequences contain
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainen (uint32_t)-1 to specify "*", they're preserved. */
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainenvoid mailbox_get_uid_range(struct mailbox *box,
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainen const ARRAY_TYPE(seq_range) *seqs,
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainen ARRAY_TYPE(seq_range) *uids);
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainen/* Get list of messages' that have been expunged after prev_modseq and that
24cd47a2c8f7507e555459b7e841de771ba3c318Timo Sirainen exist in uids_filter range. UIDs that have been expunged after the last
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen mailbox sync aren't returned. Returns TRUE if ok, FALSE if modseq is lower
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen than we can check for (but expunged_uids is still set as best as it can). */
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainenbool mailbox_get_expunges(struct mailbox *box, uint64_t prev_modseq,
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen const ARRAY_TYPE(seq_range) *uids_filter,
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen ARRAY_TYPE(mailbox_expunge_rec) *expunges);
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen/* Same as mailbox_get_expunges(), but return only list of UIDs. Not caring
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen about GUIDs is slightly faster. */
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainenbool mailbox_get_expunged_uids(struct mailbox *box, uint64_t prev_modseq,
8754bb7a1f24705ffa5434f9e10d57e0b3b88d6eTimo Sirainen const ARRAY_TYPE(seq_range) *uids_filter,
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainen ARRAY_TYPE(seq_range) *expunged_uids);
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainen
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainen/* Initialize header lookup for given headers. */
129cc29ae6d8ad64d6d2b72f18da18fa134d0f3eTimo Sirainenstruct mailbox_header_lookup_ctx *
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenmailbox_header_lookup_init(struct mailbox *box, const char *const headers[]);
b19a1420da0618a10edf67c2cfd13c8c8633057aTimo Sirainenvoid mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx);
e76c494ad6535d3de314cc0d3ac7a44b06e53c4bTimo Sirainenvoid mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **ctx);
e76c494ad6535d3de314cc0d3ac7a44b06e53c4bTimo Sirainen
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainen/* Initialize new search request. If sort_program is non-NULL, the messages are
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainen returned in the requested order, otherwise from first to last. */
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainenstruct mail_search_context *
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainenmailbox_search_init(struct mailbox_transaction_context *t,
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainen struct mail_search_args *args,
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainen const enum mail_sort_type *sort_program,
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainen enum mail_fetch_field wanted_fields,
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
c991c182b019bd85427a4ace2485683b50ea1b83Timo Sirainen/* Deinitialize search request. */
89fb98e9eb7e95255a579c8e9d865383c2334a74Timo Sirainenint mailbox_search_deinit(struct mail_search_context **ctx);
0d73d91d1a1809f173d433023ccf97e6ec5ba629Timo Sirainen/* Search the next message. Returns TRUE if found, FALSE if not. */
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainenbool mailbox_search_next(struct mail_search_context *ctx, struct mail **mail_r);
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen/* Like mailbox_search_next(), but don't spend too much time searching.
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen Returns FALSE with tryagain_r=FALSE if finished, and tryagain_r=TRUE if
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen more results will be returned by calling the function again. */
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainenbool mailbox_search_next_nonblock(struct mail_search_context *ctx,
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen struct mail **mail_r, bool *tryagain_r);
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen/* Returns TRUE if some messages were already expunged and we couldn't
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen determine correctly if those messages should have been returned in this
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen search. */
b19a1420da0618a10edf67c2cfd13c8c8633057aTimo Sirainenbool mailbox_search_seen_lost_data(struct mail_search_context *ctx);
b19a1420da0618a10edf67c2cfd13c8c8633057aTimo Sirainen
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen/* Remember the search result for future use. This must be called before the
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen first mailbox_search_next*() call. */
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainenstruct mail_search_result *
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainenmailbox_search_result_save(struct mail_search_context *ctx,
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen enum mailbox_search_result_flags flags);
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen/* Free memory used by search result. */
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainenvoid mailbox_search_result_free(struct mail_search_result **result);
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen/* A simplified API for searching and saving the result. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mailbox_search_result_build(struct mailbox_transaction_context *t,
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct mail_search_args *args,
d22301419109ed4a38351715e6760011421dadecTimo Sirainen enum mailbox_search_result_flags flags,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail_search_result **result_r);
6ef7e31619edfaa17ed044b45861d106a86191efTimo 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);
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen/* Return messages that have been removed and added since the last sync call.
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen This function must not be called if search result wasn't saved with
910fa4e4204a73d3d24c03f3059dd24e727ca057Timo Sirainen _QUEUE_SYNC flag. */
910fa4e4204a73d3d24c03f3059dd24e727ca057Timo Sirainenvoid mailbox_search_result_sync(struct mail_search_result *result,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen ARRAY_TYPE(seq_range) *removed_uids,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen ARRAY_TYPE(seq_range) *added_uids);
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen/* Build mail_keywords from NULL-terminated keywords list.
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen Returns 0 if successful, -1 if there are invalid keywords (error is set). */
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainenint mailbox_keywords_create(struct mailbox *box, const char *const keywords[],
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen struct mail_keywords **keywords_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Like mailbox_keywords_create(), except ignore invalid keywords. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_keywords *
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenmailbox_keywords_create_valid(struct mailbox *box,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *const keywords[]);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_keywords *
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenmailbox_keywords_create_from_indexes(struct mailbox *box,
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen const ARRAY_TYPE(keyword_indexes) *idx);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenvoid mailbox_keywords_ref(struct mail_keywords *keywords);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenvoid mailbox_keywords_unref(struct mail_keywords **keywords);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen/* Returns TRUE if keyword is valid, FALSE and error if not. */
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenbool mailbox_keyword_is_valid(struct mailbox *box, const char *keyword,
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen const char **error_r);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen/* Initialize saving a new mail. You must not try to save more than one mail
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen at a time. */
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenstruct mail_save_context *
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenmailbox_save_alloc(struct mailbox_transaction_context *t);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen/* Set the flags and keywords. Nothing is set by default. */
900bb5e316d030cdebff7ee128ce65881dfb27f7Timo Sirainenvoid mailbox_save_set_flags(struct mail_save_context *ctx,
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen enum mail_flags flags,
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen struct mail_keywords *keywords);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen/* Copy flags and keywords from given mail. */
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenvoid mailbox_save_copy_flags(struct mail_save_context *ctx, struct mail *mail);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Set message's modseq to be at least min_modseq. */
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainenvoid mailbox_save_set_min_modseq(struct mail_save_context *ctx,
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen uint64_t min_modseq);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* If received date isn't specified the current time is used. timezone_offset
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen specifies the preferred timezone in minutes, but it may be ignored if
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen backend doesn't support storing it. */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenvoid mailbox_save_set_received_date(struct mail_save_context *ctx,
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen time_t received_date, int timezone_offset);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Set the "message saved" date. This should be set only when you're
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen replicating/restoring an existing mailbox. */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenvoid mailbox_save_set_save_date(struct mail_save_context *ctx,
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen time_t save_date);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Set the envelope sender. This is currently used only with mbox files to
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen specify the address in From_-line. */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenvoid mailbox_save_set_from_envelope(struct mail_save_context *ctx,
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen const char *envelope);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen/* Set message's UID. If UID is smaller than the current next_uid, it's given
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen a new UID anyway. */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenvoid mailbox_save_set_uid(struct mail_save_context *ctx, uint32_t uid);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen/* Set globally unique ID for the saved mail. A new GUID is generated by
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen default. This function should usually be called only when copying an
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainen existing mail (or restoring a mail from backup). */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenvoid mailbox_save_set_guid(struct mail_save_context *ctx, const char *guid);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen/* Set message's POP3 UIDL, if the backend supports it. */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenvoid mailbox_save_set_pop3_uidl(struct mail_save_context *ctx,
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen const char *uidl);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen/* If dest_mail is set, the saved message can be accessed using it. Note that
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen setting it may require mailbox syncing, so don't set it unless you need
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen it. Also you shouldn't try to access it before mailbox_save_finish() is
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen called. */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenvoid mailbox_save_set_dest_mail(struct mail_save_context *ctx,
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen struct mail *mail);
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainen/* Begin saving the message. All mail_save_set_*() calls must have been called
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainen before this function. If the save initialization fails, the context is freed
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainen and -1 is returned. After beginning the save you should keep calling
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainen i_stream_read() and calling mailbox_save_continue() as long as there's
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainen more input. */
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainenint mailbox_save_begin(struct mail_save_context **ctx, struct istream *input);
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainenint mailbox_save_continue(struct mail_save_context *ctx);
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainenint mailbox_save_finish(struct mail_save_context **ctx);
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainenvoid mailbox_save_cancel(struct mail_save_context **ctx);
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainen
3ec3632e12638396944e854a8f7a2bc6c67b981dTimo Sirainenstruct mailbox_transaction_context *
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenmailbox_save_get_transaction(struct mail_save_context *ctx);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen/* Copy the given message. You'll need to specify the flags etc. using the
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen mailbox_save_*() functions. */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenint mailbox_copy(struct mail_save_context **ctx, struct mail *mail);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenstruct mail *mail_alloc(struct mailbox_transaction_context *t,
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen enum mail_fetch_field wanted_fields,
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenvoid mail_free(struct mail **mail);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenvoid mail_set_seq(struct mail *mail, uint32_t seq);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen/* Returns TRUE if successful, FALSE if message doesn't exist.
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen mail_*() functions shouldn't be called if FALSE is returned. */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenbool mail_set_uid(struct mail *mail, uint32_t uid);
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen/* Returns message's flags */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenenum mail_flags mail_get_flags(struct mail *mail);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Returns message's keywords */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenconst char *const *mail_get_keywords(struct mail *mail);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Returns message's keywords */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenconst ARRAY_TYPE(keyword_indexes) *mail_get_keyword_indexes(struct mail *mail);
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainen/* Returns message's modseq */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenuint64_t mail_get_modseq(struct mail *mail);
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainen
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen/* Returns message's MIME parts */
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainenint mail_get_parts(struct mail *mail, struct message_part **parts_r);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Get the Date-header of the mail. Timezone is in minutes. date=0 if it
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainen wasn't found or it was invalid. */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenint mail_get_date(struct mail *mail, time_t *date_r, int *timezone_r);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Get the time when the mail was received (IMAP INTERNALDATE). */
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainenint mail_get_received_date(struct mail *mail, time_t *date_r);
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen/* Get the time when the mail was saved into this mailbox. This time may not
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen always be entirely reliable. */
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainenint mail_get_save_date(struct mail *mail, time_t *date_r);
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen/* Get the space used by the mail as seen by the reader. Linefeeds are always
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen counted as being CR+LF. */
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainenint mail_get_virtual_size(struct mail *mail, uoff_t *size_r);
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen/* Get the size of the stream returned by mail_get_stream(). */
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainenint mail_get_physical_size(struct mail *mail, uoff_t *size_r);
45799f8340fdcddfb077c1d44ad1d2014d7db31cTimo Sirainen
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Get value for single header field, or NULL if header wasn't found.
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen Returns 1 if header was found, 0 if not, -1 if error. */
b12b6da6f084212d42421a28ae329eae79751c42Timo Sirainenint mail_get_first_header(struct mail *mail, const char *field,
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen const char **value_r);
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen/* Like mail_get_first_header(), but decode MIME encoded words to UTF-8.
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen Also multiline headers are returned unfolded.
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen Do not use this function for getting structured fields (e.g. address fields),
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen because decoding may break the structuring. Instead parse them first and
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen only afterwards decode the encoded words. */
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainenint mail_get_first_header_utf8(struct mail *mail, const char *field,
de4e3a2e1e8f82b2d3226c090b71b518b43bf9cfTimo Sirainen const char **value_r);
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainen/* Return a NULL-terminated list of values for each found field.
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainen Returns -1 if error, 0 otherwise (with or without headers found). */
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainenint mail_get_headers(struct mail *mail, const char *field,
8c9e48cd6de80da0fa32b9c0dee003472c9a7c0dTimo Sirainen const char *const **value_r);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen/* Like mail_get_headers(), but decode MIME encoded words to UTF-8.
0d86aa0d47f7393c669c084b34c0537b193688adTimo Sirainen Also multiline headers are returned unfolded.
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen Do not use for structured fields (see mail_get_first_header_utf8()). */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenint mail_get_headers_utf8(struct mail *mail, const char *field,
a12399903f415a7e14c2816cffa2f7a09dcbb097Timo Sirainen const char *const **value_r);
aa247243412a49f9bdebf7255e131dc6ece4ed46Timo Sirainen/* Returns stream containing specified headers. */
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainenint mail_get_header_stream(struct mail *mail,
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen struct mailbox_header_lookup_ctx *headers,
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen struct istream **stream_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns input stream pointing to beginning of message header.
439980f88f421039dea8335e92d3fa82b3f470a1Timo Sirainen hdr_size and body_size are updated unless they're NULL. The returned stream
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen is destroyed automatically, don't unreference it. */
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainenint mail_get_stream(struct mail *mail, struct message_size *hdr_size,
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen struct message_size *body_size, struct istream **stream_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Get any of the "special" fields. Unhandled specials are returned as "". */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainenint mail_get_special(struct mail *mail, enum mail_fetch_field field,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen const char **value_r);
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen/* Returns the mail for the physical message. Normally this is the mail itself,
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen but in virtual mailboxes it points to the backend mailbox. */
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainenstruct mail *mail_get_real_mail(struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen/* Update message flags. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_update_flags(struct mail *mail, enum modify_type modify_type,
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen enum mail_flags flags);
9af6cc9ebc9986c1275ebdfa29c39e152af1557eTimo Sirainen/* Update message keywords. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_update_keywords(struct mail *mail, enum modify_type modify_type,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen struct mail_keywords *keywords);
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen/* Update message's modseq to be at least min_modseq. */
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainenvoid mail_update_modseq(struct mail *mail, uint64_t min_modseq);
838e367716bbd5e44b4a1691db9cbf72af53e9f0Timo Sirainen
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen/* Update message's POP3 UIDL (if possible). */
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainenvoid mail_update_pop3_uidl(struct mail *mail, const char *uidl);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Expunge this message. Sequence numbers don't change until commit. */
void mail_expunge(struct mail *mail);
/* Returns TRUE if anything is cached for the mail, FALSE if not. */
bool mail_is_cached(struct mail *mail);
/* Parse mail's header and optionally body so that fields using them get
cached. */
void mail_parse(struct mail *mail, bool parse_body);
/* Mark a cached field corrupted and have it recalculated. */
void mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field);
/* Generate a GUID (contains host name) */
const char *mail_generate_guid_string(void);
/* Generate 128 bit GUID */
void mail_generate_guid_128(uint8_t guid[MAIL_GUID_128_SIZE]);
/* Return 128 bit GUID using input string. If guid is already 128 bit hex
encoded, it's returned as-is. Otherwise SHA1 sum is taken and its last
128 bits are returned. */
void mail_generate_guid_128_hash(const char *guid,
uint8_t guid_128[MAIL_GUID_128_SIZE]);
/* Returns TRUE if GUID is empty (not set / unknown). */
bool mail_guid_128_is_empty(const uint8_t guid_128[MAIL_GUID_128_SIZE]);
/* Returns GUID as a hex string. */
const char *mail_guid_128_to_string(const uint8_t guid_128[MAIL_GUID_128_SIZE]);
/* guid_128 hash/cmp functions for hash.h */
unsigned int mail_guid_128_hash(const void *p);
int mail_guid_128_cmp(const void *p1, const void *p2);
#endif