mail-storage-private.h revision b83deefd2cf1e293373673eefb4d5cf60907978c
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen#ifndef MAIL_STORAGE_PRIVATE_H
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#define MAIL_STORAGE_PRIVATE_H
08d6658a4e2ec8104cd1307f6baa75fdb07a24f8Mark Washenberger
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen#include "module-context.h"
eff552f5fdc275c940c4c709eeeddb833bc51b40Timo Sirainen#include "file-lock.h"
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#include "mail-storage.h"
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#include "mail-storage-hooks.h"
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#include "mail-storage-settings.h"
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen#include "mail-index-private.h"
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Block size when read()ing message header. */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen#define MAIL_READ_HDR_BLOCK_SIZE (1024*4)
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen/* Block size when read()ing message (header and) body. */
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenstruct mail_storage_module_register {
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen unsigned int id;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen};
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainenstruct mail_module_register {
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen unsigned int id;
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen};
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenstruct mail_storage_vfuncs {
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(void);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mail_storage *(*alloc)(void);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen int (*create)(struct mail_storage *storage, struct mail_namespace *ns,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen const char **error_r);
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen void (*destroy)(struct mail_storage *storage);
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen void (*add_list)(struct mail_storage *storage,
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen struct mailbox_list *list);
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen void (*get_list_settings)(const struct mail_namespace *ns,
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen struct mailbox_list_settings *set);
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mailbox_list_settings *set);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mailbox_list *list,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen const char *name,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen enum mailbox_flags flags);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen int (*purge)(struct mail_storage *storage);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen};
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainenunion mail_storage_module_context {
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mail_storage_vfuncs super;
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen struct mail_storage_module_register *reg;
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen};
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainenenum mail_storage_class_flags {
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen /* mailboxes are files, not directories */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE = 0x01,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen /* root_dir points to a unique directory */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT = 0x02,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen /* mailbox_open_stream() is supported */
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS = 0x04
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen};
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainenstruct mail_storage {
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen const char *name;
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen enum mail_storage_class_flags class_flags;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen struct mail_storage_vfuncs v;
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen/* private: */
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen pool_t pool;
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen struct mail_storage *prev, *next;
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen /* counting number of times mail_storage_create() has returned this
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen same storage. */
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen int refcount;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen to this storage. */
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen int obj_refcount;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen const char *unique_root_dir;
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen
73e19ec2d5069ea125dcd1ede5d8a70f701fd9a8Timo Sirainen char *error_string;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen enum mail_error error;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen const struct mail_storage *storage_class;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen struct mail_user *user;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen const char *temp_path_prefix;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen const struct mail_storage_settings *set;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen enum mail_storage_flags flags;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen struct mail_storage_callbacks callbacks;
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen void *callback_context;
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
ccfc6441cadb577084daeb1f0aa3dd7bdfa2a220Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen};
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainenstruct mailbox_vfuncs {
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen bool (*is_readonly)(struct mailbox *box);
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen bool (*allow_new_keywords)(struct mailbox *box);
2521482f3f897c83f7d5a2f9e17fe99fa4ba2cbeTimo Sirainen
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen int (*open)(struct mailbox *box);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen void (*close)(struct mailbox *box);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen void (*free)(struct mailbox *box);
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen
73e19ec2d5069ea125dcd1ede5d8a70f701fd9a8Timo Sirainen int (*create)(struct mailbox *box, const struct mailbox_update *update,
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen bool directory);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen int (*update)(struct mailbox *box, const struct mailbox_update *update);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen int (*delete)(struct mailbox *box);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen int (*rename)(struct mailbox *src, struct mailbox *dest,
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen bool rename_children);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen void (*get_status)(struct mailbox *box, enum mailbox_status_items items,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen struct mailbox_status *status_r);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen int (*get_guid)(struct mailbox *box, uint8_t guid[MAIL_GUID_128_SIZE]);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen /* Lookup sync extension record and figure out if it mailbox has
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen changed since. Returns 1 = yes, 0 = no, -1 = error. */
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen int (*list_index_has_changed)(struct mailbox *box,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen struct mail_index_view *list_view,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen uint32_t seq);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen /* Update the sync extension record. Returns 0 = ok, -1 = error. */
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen int (*list_index_update_sync)(struct mailbox *box,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen struct mail_index_transaction *trans,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen uint32_t seq);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen struct mailbox_sync_context *
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen (*sync_init)(struct mailbox *box,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen enum mailbox_sync_flags flags);
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen struct mailbox_sync_rec *sync_rec_r);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen struct mailbox_sync_status *status_r);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen /* Called once for each expunge. Called one or more times for
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen flag/keyword changes. Once the sync is finished, called with
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen uid=0 and sync_type=0. */
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen void (*sync_notify)(struct mailbox *box, uint32_t uid,
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen enum mailbox_sync_type sync_type);
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen void (*notify_changes)(struct mailbox *box);
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen struct mailbox_transaction_context *
747e77e3ab073a8e9e69c7a3e71b4593c5655d03Timo Sirainen (*transaction_begin)(struct mailbox *box,
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen enum mailbox_transaction_flags flags);
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
dd93aba1901a457346990f49c54a738947dc7128Timo Sirainen struct mail_transaction_commit_changes *changes_r);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen void (*transaction_set_max_modseq)(struct mailbox_transaction_context *t,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen uint64_t max_modseq,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen ARRAY_TYPE(seq_range) *seqs);
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen int (*keywords_create)(struct mailbox *box,
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen const char *const keywords[],
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen struct mail_keywords **keywords_r,
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen bool skip_invalid);
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen struct mail_keywords *
f3d506e525a720f214020ca0f989a1966b30edaeTimo Sirainen (*keywords_create_from_indexes)(struct mailbox *box,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen const ARRAY_TYPE(keyword_indexes) *idx);
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen void (*keywords_ref)(struct mail_keywords *keywords);
08aea01ef9a9d20703e0fcf8618e6195c0037a44Timo Sirainen void (*keywords_unref)(struct mail_keywords *keywords);
08aea01ef9a9d20703e0fcf8618e6195c0037a44Timo Sirainen bool (*keyword_is_valid)(struct mailbox *box, const char *keyword,
f3d506e525a720f214020ca0f989a1966b30edaeTimo Sirainen const char **error_r);
08aea01ef9a9d20703e0fcf8618e6195c0037a44Timo Sirainen
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen void (*get_seq_range)(struct mailbox *box, uint32_t uid1, uint32_t uid2,
f3d506e525a720f214020ca0f989a1966b30edaeTimo Sirainen uint32_t *seq1_r, uint32_t *seq2_r);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen void (*get_uid_range)(struct mailbox *box,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen const ARRAY_TYPE(seq_range) *seqs,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen ARRAY_TYPE(seq_range) *uids);
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainen bool (*get_expunges)(struct mailbox *box, uint64_t prev_modseq,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen const ARRAY_TYPE(seq_range) *uids_filter,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen ARRAY_TYPE(mailbox_expunge_rec) *expunges);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen bool (*get_virtual_uid)(struct mailbox *box,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen const char *backend_mailbox,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen uint32_t backend_uidvalidity,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen uint32_t backend_uid, uint32_t *uid_r);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen void (*get_virtual_backend_boxes)(struct mailbox *box,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen ARRAY_TYPE(mailboxes) *mailboxes,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen bool only_with_msgs);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen void (*get_virtual_box_patterns)(struct mailbox *box,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen ARRAY_TYPE(mailbox_virtual_patterns) *includes,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen ARRAY_TYPE(mailbox_virtual_patterns) *excludes);
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainen
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainen struct mail *
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen enum mail_fetch_field wanted_fields,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mailbox_header_lookup_ctx *
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen (*header_lookup_init)(struct mailbox *box,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen const char *const headers[]);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen void (*header_lookup_deinit)(struct mailbox_header_lookup_ctx *ctx);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mail_search_context *
51ead2f4c04ee85615d23c453924633b9ed8a4c2Timo Sirainen (*search_init)(struct mailbox_transaction_context *t,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mail_search_args *args,
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen const enum mail_sort_type *sort_program);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen bool (*search_next_nonblock)(struct mail_search_context *ctx,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen struct mail *mail, bool *tryagain_r);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen /* Internal search function which updates ctx->seq */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mail_save_context *
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen (*save_alloc)(struct mailbox_transaction_context *t);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen int (*save_begin)(struct mail_save_context *ctx, struct istream *input);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen int (*save_continue)(struct mail_save_context *ctx);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen int (*save_finish)(struct mail_save_context *ctx);
51ead2f4c04ee85615d23c453924633b9ed8a4c2Timo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen int (*copy)(struct mail_save_context *ctx, struct mail *mail);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen bool (*is_inconsistent)(struct mailbox *box);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen};
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenunion mailbox_module_context {
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct mailbox_vfuncs super;
struct mail_storage_module_register *reg;
};
struct mailbox {
const char *name;
struct mail_storage *storage;
struct mailbox_list *list;
struct mailbox_vfuncs v;
/* private: */
pool_t pool;
struct mail_index *index;
struct mail_index_view *view;
struct mail_cache *cache;
/* default vfuncs for new struct mails. */
const struct mail_vfuncs *mail_vfuncs;
/* mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX */
const char *path;
/* mailbox's virtual name (from mail_namespace_get_vname()) */
const char *vname;
struct istream *input;
enum mailbox_flags flags;
unsigned int transaction_count;
enum mailbox_feature enabled_features;
/* User's private flags if this is a shared mailbox */
enum mail_flags private_flags_mask;
/* mode and GID to use for newly created files/dirs */
mode_t file_create_mode, dir_create_mode;
gid_t file_create_gid;
/* origin (e.g. path) where the file_create_gid was got from */
const char *file_create_gid_origin;
/* Mailbox notification settings: */
unsigned int notify_min_interval;
mailbox_notify_callback_t *notify_callback;
void *notify_context;
/* Saved search results */
ARRAY_DEFINE(search_results, struct mail_search_result *);
/* Module-specific contexts. See mail_storage_module_id. */
ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
/* When FAST open flag is used, the mailbox isn't actually opened until
it's synced for the first time. */
unsigned int opened:1;
/* Mailbox was deleted while we had it open. */
unsigned int mailbox_deleted:1;
/* we've discovered there aren't enough permissions to modify mailbox */
unsigned int backend_readonly:1;
/* Mailbox is being deleted */
unsigned int deleting:1;
/* TRUE if this is the INBOX */
unsigned int inbox:1;
};
struct mail_vfuncs {
void (*close)(struct mail *mail);
void (*free)(struct mail *mail);
void (*set_seq)(struct mail *mail, uint32_t seq);
bool (*set_uid)(struct mail *mail, uint32_t uid);
void (*set_uid_cache_updates)(struct mail *mail, bool set);
enum mail_flags (*get_flags)(struct mail *mail);
const char *const *(*get_keywords)(struct mail *mail);
const ARRAY_TYPE(keyword_indexes) *
(*get_keyword_indexes)(struct mail *mail);
uint64_t (*get_modseq)(struct mail *mail);
int (*get_parts)(struct mail *mail,
struct message_part **parts_r);
int (*get_date)(struct mail *mail, time_t *date_r, int *timezone_r);
int (*get_received_date)(struct mail *mail, time_t *date_r);
int (*get_save_date)(struct mail *mail, time_t *date_r);
int (*get_virtual_size)(struct mail *mail, uoff_t *size_r);
int (*get_physical_size)(struct mail *mail, uoff_t *size_r);
int (*get_first_header)(struct mail *mail, const char *field,
bool decode_to_utf8, const char **value_r);
int (*get_headers)(struct mail *mail, const char *field,
bool decode_to_utf8, const char *const **value_r);
int (*get_header_stream)(struct mail *mail,
struct mailbox_header_lookup_ctx *headers,
struct istream **stream_r);
int (*get_stream)(struct mail *mail, struct message_size *hdr_size,
struct message_size *body_size,
struct istream **stream_r);
int (*get_special)(struct mail *mail, enum mail_fetch_field field,
const char **value_r);
struct mail *(*get_real_mail)(struct mail *mail);
void (*update_flags)(struct mail *mail, enum modify_type modify_type,
enum mail_flags flags);
void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
struct mail_keywords *keywords);
void (*update_modseq)(struct mail *mail, uint64_t min_modseq);
void (*update_uid)(struct mail *mail, uint32_t new_uid);
void (*update_pop3_uidl)(struct mail *mail, const char *uidl);
void (*expunge)(struct mail *mail);
void (*set_cache_corrupted)(struct mail *mail,
enum mail_fetch_field field);
};
union mail_module_context {
struct mail_vfuncs super;
struct mail_module_register *reg;
};
struct mail_private {
struct mail mail;
struct mail_vfuncs v;
enum mail_fetch_field wanted_fields;
struct mailbox_header_lookup_ctx *wanted_headers;
pool_t pool;
ARRAY_DEFINE(module_contexts, union mail_module_context *);
/* these statistics are never reset by mail-storage API: */
unsigned long stats_open_lookup_count;
unsigned long stats_stat_lookup_count;
unsigned long stats_fstat_lookup_count;
/* number of files we've opened and read */
unsigned long stats_files_read_count;
/* number of bytes we've had to read from files */
unsigned long long stats_files_read_bytes;
/* number of cache lookup hits */
unsigned long stats_cache_hit_count;
/* Set to TRUE to update stats_* fields */
unsigned int stats_track:1;
};
struct mailbox_list_context {
struct mail_storage *storage;
enum mailbox_list_flags flags;
bool failed;
};
union mailbox_transaction_module_context {
struct mail_storage_module_register *reg;
};
struct mailbox_transaction_context {
struct mailbox *box;
enum mailbox_transaction_flags flags;
struct mail_index_transaction *itrans;
/* view contains all changes done within this transaction */
struct mail_index_view *view;
struct mail_transaction_commit_changes *changes;
ARRAY_DEFINE(module_contexts,
union mailbox_transaction_module_context *);
struct mail_save_context *save_ctx;
};
union mail_search_module_context {
struct mail_storage_module_register *reg;
};
struct mail_search_context {
struct mailbox_transaction_context *transaction;
struct mail_search_args *args;
struct mail_search_sort_program *sort_program;
/* if non-NULL, specifies that a search resulting is being updated.
this can be used as a search optimization: if searched message
already exists in search result, it's not necessary to check if
static data matches. */
struct mail_search_result *update_result;
/* add matches to these search results */
ARRAY_DEFINE(results, struct mail_search_result *);
uint32_t seq;
uint32_t progress_cur, progress_max;
ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
unsigned int seen_lost_data:1;
unsigned int progress_hidden:1;
};
struct mail_save_context {
struct mailbox_transaction_context *transaction;
struct mail *dest_mail;
enum mail_flags flags;
struct mail_keywords *keywords;
uint64_t min_modseq;
time_t received_date, save_date;
int received_tz_offset;
uint32_t uid;
char *guid, *pop3_uidl, *from_envelope;
struct ostream *output;
/* we came here from mailbox_copy() */
unsigned int copying:1;
};
struct mailbox_sync_context {
struct mailbox *box;
};
struct mailbox_header_lookup_ctx {
struct mailbox *box;
const char *const *headers;
int refcount;
};
/* Modules should use do "my_id = mail_storage_module_id++" and
use objects' module_contexts[id] for their own purposes. */
extern struct mail_storage_module_register mail_storage_module_register;
/* Storage's module_id for mail_index. */
extern struct mail_module_register mail_module_register;
#define MAIL_STORAGE_CONTEXT(obj) \
MODULE_CONTEXT(obj, mail_storage_mail_index_module)
extern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
&mail_index_module_register);
void mail_storage_obj_ref(struct mail_storage *storage);
void mail_storage_obj_unref(struct mail_storage *storage);
/* Set error message in storage. Critical errors are logged with i_error(),
but user sees only "internal error" message. */
void mail_storage_clear_error(struct mail_storage *storage);
void mail_storage_set_error(struct mail_storage *storage,
enum mail_error error, const char *string);
void mail_storage_set_critical(struct mail_storage *storage,
const char *fmt, ...) ATTR_FORMAT(2, 3);
void mail_storage_set_internal_error(struct mail_storage *storage);
void mail_storage_set_index_error(struct mailbox *box);
bool mail_storage_set_error_from_errno(struct mail_storage *storage);
void mail_storage_copy_list_error(struct mail_storage *storage,
struct mailbox_list *list);
int mail_set_aborted(struct mail *mail);
void mail_set_expunged(struct mail *mail);
void mailbox_set_deleted(struct mailbox *box);
int mailbox_mark_index_deleted(struct mailbox *box, bool del);
void mailbox_refresh_permissions(struct mailbox *box);
/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
int mailbox_create_fd(struct mailbox *box, const char *path, int flags,
int *fd_r);
#endif