mail-storage-private.h revision 51327f2489a4e0e615eb9f7d921473cf8512bb79
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen/* Block size when read()ing message header. */
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen/* Block size when read()ing message (header and) body. */
3ed2d0f6b5e67e2663d44489d9da3176823789a8Timo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen unsigned int id;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen unsigned int id;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(void);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen int (*create)(struct mail_storage *storage, struct mail_namespace *ns,
2dd39e478269d6fb0bb26d12b394aa30ee965e38Timo Sirainen const char **error_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*destroy)(struct mail_storage *storage);
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen void (*add_list)(struct mail_storage *storage,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen void (*get_list_settings)(const struct mail_namespace *ns,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen /* mailboxes are files, not directories */
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE = 0x01,
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen /* root_dir points to a unique directory */
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen /* mailbox_open_stream() is supported */
4ba9a1d3facc515b3feb5238a16bcf91f76fac61Timo Sirainen /* never use quota for this storage (e.g. virtual mailboxes) */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* private: */
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen /* counting number of times mail_storage_create() has returned this
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen same storage. */
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen to this storage. */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char *content_type, *content_disposition;
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen bool (*allow_new_keywords)(struct mailbox *box);
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen int (*create)(struct mailbox *box, const struct mailbox_update *update,
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen int (*update)(struct mailbox *box, const struct mailbox_update *update);
2649b237dd4690575e75a30b2bf3b39ebd37b835Timo Sirainen int (*rename)(struct mailbox *src, struct mailbox *dest,
d3280fe317a4598c0868cc440e7a1191c06d0db3Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen /* Lookup sync extension record and figure out if it mailbox has
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen changed since. Returns 1 = yes, 0 = no, -1 = error. */
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen int (*list_index_has_changed)(struct mailbox *box,
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen /* Update the sync extension record. Returns 0 = ok, -1 = error. */
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen int (*list_index_update_sync)(struct mailbox *box,
c979eeda1f46483d9c963e265786b701d7683d77Timo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
4b41116563110d00330896a568eff1078c382827Timo Sirainen /* Called once for each expunge. Called one or more times for
4b41116563110d00330896a568eff1078c382827Timo Sirainen flag/keyword changes. Once the sync is finished, called with
4b41116563110d00330896a568eff1078c382827Timo Sirainen uid=0 and sync_type=0. */
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen void (*sync_notify)(struct mailbox *box, uint32_t uid,
b2c1349cf07410aefab0f5b17153af9e5cfcf48fTimo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen struct mail_transaction_commit_changes *changes_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
8a13b020f90e080570658b18c042e7e352c8b14fTimo Sirainen enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen (*search_init)(struct mailbox_transaction_context *t,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
f3bb2fbe87425dc89a839908985af496f7f65702Timo Sirainen bool (*search_next_nonblock)(struct mail_search_context *ctx,
a3ee5ce6ecc8e228ee69300fdd562d7ac8be89a7Timo Sirainen /* Internal search function which updates ctx->seq */
bd1b2615928a1e8be190cb0405754f0aec8cac2fTimo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen (*save_alloc)(struct mailbox_transaction_context *t);
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen int (*save_begin)(struct mail_save_context *ctx, struct istream *input);
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen int (*save_continue)(struct mail_save_context *ctx);
2ebeb22b9a8a8bb7fbe2f2e2908478a220792b87Timo Sirainen int (*save_finish)(struct mail_save_context *ctx);
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
bd4d0a1a7c0626452b8d82f37e3ec07267ac9896Timo Sirainen int (*copy)(struct mail_save_context *ctx, struct mail *mail);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* mode and GID to use for newly created files/dirs */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* origin (e.g. path) where the file_create_gid was got from */
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen /* mailbox's virtual name (from mail_namespace_get_vname()) */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen/* private: */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* these won't be set until mailbox is opened: */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* Filled lazily by mailbox_get_permissions() */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* Filled lazily by mailbox_get_path() */
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen /* default vfuncs for new struct mails. */
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen /* Mailbox notification settings: */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* Saved search results */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen ARRAY_DEFINE(search_results, struct mail_search_result *);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen it's synced for the first time. */
4bbd396aa6198c84f3f7763b6e8a63a26e97e141Timo Sirainen /* Mailbox was deleted while we had it open. */
3f91e60401495a4046c73992fabaa5e77200a451Timo Sirainen /* Mailbox is being deleted */
6b0d8106ae51ffc6ce45636b34d2e21cbefca7fdTimo Sirainen /* Mailbox was already marked as deleted within this allocation. */
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen /* TRUE if this is an INBOX for this user */
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen /* TRUE if this is an INBOX for this namespace (user or shared) */
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen /* When copying to this mailbox, require that mailbox_copy() uses
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen mailbox_save_*() to actually save a new physical copy rather than
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen simply incrementing a reference count (e.g. via hard link) */
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*set_seq)(struct mail *mail, uint32_t seq);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen bool (*set_uid)(struct mail *mail, uint32_t uid);
aa247243412a49f9bdebf7255e131dc6ece4ed46Timo Sirainen void (*set_uid_cache_updates)(struct mail *mail, bool set);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen const char *const *(*get_keywords)(struct mail *mail);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_date)(struct mail *mail, time_t *date_r, int *timezone_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_received_date)(struct mail *mail, time_t *date_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_save_date)(struct mail *mail, time_t *date_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_virtual_size)(struct mail *mail, uoff_t *size_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_physical_size)(struct mail *mail, uoff_t *size_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_first_header)(struct mail *mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_headers)(struct mail *mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen bool decode_to_utf8, const char *const **value_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_stream)(struct mail *mail, struct message_size *hdr_size,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_special)(struct mail *mail, enum mail_fetch_field field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen const char **value_r);
9af6cc9ebc9986c1275ebdfa29c39e152af1557eTimo Sirainen struct mail *(*get_real_mail)(struct mail *mail);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*update_flags)(struct mail *mail, enum modify_type modify_type,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen void (*update_modseq)(struct mail *mail, uint64_t min_modseq);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen void (*update_pop3_uidl)(struct mail *mail, const char *uidl);
838e367716bbd5e44b4a1691db9cbf72af53e9f0Timo Sirainen void (*set_cache_corrupted)(struct mail *mail,
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen int (*istream_opened)(struct mail *mail, struct istream **input);
310767ca33e7636d40ec45dee68a2c319a5fa3c0Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_module_context *);
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen /* these statistics are never reset by mail-storage API: */
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen /* number of files we've opened and read */
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen /* number of bytes we've had to read from files */
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen unsigned long long stats_files_read_bytes;
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen /* number of cache lookup hits */
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen /* Set to TRUE to update stats_* fields */
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen union mail_index_transaction_module_context module_ctx;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen /* view contains all changes done within this transaction */
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mail_cache_transaction_ctx *cache_trans;
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen struct mail_transaction_commit_changes *changes;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_transaction_context *transaction;
e63bdfedcf61e1a9ee21990140cbd0d0638da7e1Timo Sirainen struct mail_search_sort_program *sort_program;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* if non-NULL, specifies that a search resulting is being updated.
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen this can be used as a search optimization: if searched message
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen already exists in search result, it's not necessary to check if
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen static data matches. */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* add matches to these search results */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen ARRAY_DEFINE(results, struct mail_search_result *);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_transaction_context *transaction;
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen /* returns TRUE if message part is an attachment. */
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen bool (*part_is_attachment)(struct mail_save_context *ctx,
4d527c363482be2b65dd0573d878ecda86cbb0bbTimo Sirainen /* we came here from mailbox_copy() */
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen unsigned int count;
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen const char *const *name;
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen unsigned int *idx;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen/* Modules should use do "my_id = mail_storage_module_id++" and
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen use objects' module_contexts[id] for their own purposes. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern struct mail_storage_module_register mail_storage_module_register;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen/* Storage's module_id for mail_index. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern struct mail_module_register mail_module_register;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainenvoid mail_storage_obj_ref(struct mail_storage *storage);
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainenvoid mail_storage_obj_unref(struct mail_storage *storage);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Set error message in storage. Critical errors are logged with i_error(),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen but user sees only "internal error" message. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_clear_error(struct mail_storage *storage);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_set_error(struct mail_storage *storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_set_internal_error(struct mail_storage *storage);
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainenvoid mail_storage_set_index_error(struct mailbox *box);
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainenbool mail_storage_set_error_from_errno(struct mail_storage *storage);
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenvoid mail_storage_copy_list_error(struct mail_storage *storage,
b83deefd2cf1e293373673eefb4d5cf60907978cTimo Sirainenint mailbox_mark_index_deleted(struct mailbox *box, bool del);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen/* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainenconst char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen/* Get mailbox permissions. */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainenconst struct mailbox_permissions *mailbox_get_permissions(struct mailbox *box);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen/* Force permissions to be refreshed on next lookup */
3c493c276f599d9b9cd10764876d648003046954Timo Sirainenvoid mailbox_refresh_permissions(struct mailbox *box);
3c493c276f599d9b9cd10764876d648003046954Timo Sirainen/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
3c493c276f599d9b9cd10764876d648003046954Timo Sirainenint mailbox_create_fd(struct mailbox *box, const char *path, int flags,
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainenunsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen unsigned int secs);