mail-storage-private.h revision 4b41116563110d00330896a568eff1078c382827
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#ifndef __MAIL_STORAGE_PRIVATE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define __MAIL_STORAGE_PRIVATE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "module-context.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "file-lock.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "mail-storage.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "mail-index-private.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Called after mail storage has been created */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenextern void (*hook_mail_storage_created)(struct mail_storage *storage);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Called after mailbox has been opened */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenextern void (*hook_mailbox_opened)(struct mailbox *box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenstruct mail_storage_module_register {
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen unsigned int id;
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen};
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenstruct mail_module_register {
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen unsigned int id;
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen};
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenstruct mail_storage_vfuncs {
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen void (*class_init)(void);
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen void (*class_deinit)(void);
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen struct mail_storage *(*alloc)(void);
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen int (*create)(struct mail_storage *storage, const char *data);
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen void (*destroy)(struct mail_storage *storage);
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen bool (*autodetect)(const char *data, enum mail_storage_flags flags);
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mailbox *(*mailbox_open)(struct mail_storage *storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *name,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct istream *input,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen enum mailbox_open_flags flags);
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*mailbox_create)(struct mail_storage *storage, const char *name,
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen bool directory);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenunion mail_storage_module_context {
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen struct mail_storage_vfuncs super;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail_storage_module_register *reg;
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstruct mail_storage {
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen const char *name;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen bool mailbox_is_file;
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail_storage_vfuncs v;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen/* private: */
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen pool_t pool;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen char *error;
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen struct mail_namespace *ns;
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen struct mailbox_list *list;
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen const char *user; /* name of user accessing the storage */
f7d43647acc6dc80064c8c4cacf5bf86f754c530Timo Sirainen enum mail_storage_flags flags;
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen enum file_lock_method lock_method;
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen struct mail_storage_callbacks *callbacks;
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen void *callback_context;
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
8153fdec343e40e2a78f5c12353e89b994b28f74Timo Sirainen /* IMAP: Give a BAD reply instead of NO */
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen unsigned int syntax_error:1;
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen /* Internal temporary error, as opposed to visible user errors like
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen "permission denied" or "out of disk space" */
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen unsigned int temporary_error:1;
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen};
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainenstruct mailbox_vfuncs {
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen bool (*is_readonly)(struct mailbox *box);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen bool (*allow_new_keywords)(struct mailbox *box);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen int (*close)(struct mailbox *box);
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mailbox_status *status);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mailbox_sync_context *
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen (*sync_init)(struct mailbox *box,
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen enum mailbox_sync_flags flags);
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen int (*sync_next)(struct mailbox_sync_context *ctx,
445f9e31c6c3aa6c0a72be8565da8f6e594d24fbTimo Sirainen struct mailbox_sync_rec *sync_rec_r);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen enum mailbox_status_items status_items,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mailbox_status *status_r);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* Called once for each expunge. Called one or more times for
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen flag/keyword changes. Once the sync is finished, called with
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen uid=0 and sync_type=0. */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen void (*sync_notify)(struct mailbox *box, uint32_t uid,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen enum mailbox_sync_type sync_type);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen void (*notify_changes)(struct mailbox *box);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mailbox_transaction_context *
9e59a1f3f095b3099478562cf3f3970a24736970Timo Sirainen (*transaction_begin)(struct mailbox *box,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen enum mailbox_transaction_flags flags);
178511b57faa7c3f8203dd8b7e4059d00cbfc23aTimo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen enum mailbox_sync_flags flags);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
2e937ed8585299b2e879a28314902a5f644813d2Timo Sirainen
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mail_keywords *
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen (*keywords_create)(struct mailbox_transaction_context *t,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen const char *const keywords[]);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen void (*keywords_free)(struct mailbox_transaction_context *t,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mail_keywords *keywords);
4d25408732be27e91f0430f71e87242760c2517cTimo Sirainen
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen int (*get_uids)(struct mailbox *box, uint32_t uid1, uint32_t uid2,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen uint32_t *seq1_r, uint32_t *seq2_r);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mail *
e5c08648676d1989f6e70b95e5990c26b3e8b96bTimo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
4d25408732be27e91f0430f71e87242760c2517cTimo Sirainen enum mail_fetch_field wanted_fields,
c3412ddeb9abc13f99d3caf50faf76cd99f7e9d2Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen struct mailbox_header_lookup_ctx *
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen (*header_lookup_init)(struct mailbox *box,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen const char *const headers[]);
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen void (*header_lookup_deinit)(struct mailbox_header_lookup_ctx *ctx);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen
d0d7fcf3ce44f26fdf34c1542a25cec644c5c4c7Timo Sirainen struct mail_search_context *
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen (*search_init)(struct mailbox_transaction_context *t,
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen const char *charset, struct mail_search_arg *args,
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen const enum mail_sort_type *sort_program);
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
e8a35266a5ceacdfafeeffd6bddae77931ff97ebTimo Sirainen int (*search_next_nonblock)(struct mail_search_context *ctx,
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen struct mail *mail, bool *tryagain_r);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen /* Internal search function which updates ctx->seq */
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen int (*search_next_update_seq)(struct mail_search_context *ctx);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen int (*save_init)(struct mailbox_transaction_context *t,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen enum mail_flags flags,
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen struct mail_keywords *keywords,
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen time_t received_date, int timezone_offset,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen const char *from_envelope, struct istream *input,
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen struct mail *dest_mail,
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen struct mail_save_context **ctx_r);
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen int (*save_continue)(struct mail_save_context *ctx);
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen int (*save_finish)(struct mail_save_context *ctx);
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen int (*copy)(struct mailbox_transaction_context *t, struct mail *mail,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen enum mail_flags flags, struct mail_keywords *keywords,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen struct mail *dest_mail);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen bool (*is_inconsistent)(struct mailbox *box);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen};
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenunion mailbox_module_context {
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen struct mailbox_vfuncs super;
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen struct mail_storage_module_register *reg;
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen};
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenstruct mailbox {
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen char *name;
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen struct mail_storage *storage;
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen struct mailbox_vfuncs v;
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen/* private: */
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen pool_t pool;
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
755fe6da51ab7f54aa1d86913cb344bffef60e79Timo Sirainen unsigned int transaction_count;
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen /* Mailbox notification settings: */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen unsigned int notify_min_interval;
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen mailbox_notify_callback_t *notify_callback;
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen void *notify_context;
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
36e2fa21c22452470c1509cc63de20f7415c7b5eTimo Sirainen it's synced for the first time. */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen unsigned int opened:1;
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen};
36e2fa21c22452470c1509cc63de20f7415c7b5eTimo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenstruct mail_vfuncs {
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen void (*free)(struct mail *mail);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen int (*set_seq)(struct mail *mail, uint32_t seq);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen int (*set_uid)(struct mail *mail, uint32_t uid);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen const char *const *(*get_keywords)(struct mail *mail);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen const struct message_part *(*get_parts)(struct mail *mail);
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen time_t (*get_date)(struct mail *mail, int *timezone);
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen time_t (*get_received_date)(struct mail *mail);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen time_t (*get_save_date)(struct mail *mail);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen uoff_t (*get_virtual_size)(struct mail *mail);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen uoff_t (*get_physical_size)(struct mail *mail);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen const char *(*get_first_header)(struct mail *mail, const char *field);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen const char *const *(*get_headers)(struct mail *mail, const char *field);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen struct istream *
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen (*get_header_stream)(struct mail *mail,
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen struct mailbox_header_lookup_ctx *headers);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen struct istream *(*get_stream)(struct mail *mail,
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen struct message_size *hdr_size,
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen struct message_size *body_size);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen const char *(*get_special)(struct mail *mail,
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen enum mail_fetch_field field);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen int (*update_flags)(struct mail *mail, enum modify_type modify_type,
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen enum mail_flags flags);
43d504fb5b23e14878e9777cdebff9c623f0b52cTimo Sirainen int (*update_keywords)(struct mail *mail, enum modify_type modify_type,
43d504fb5b23e14878e9777cdebff9c623f0b52cTimo Sirainen struct mail_keywords *keywords);
43d504fb5b23e14878e9777cdebff9c623f0b52cTimo Sirainen
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen int (*expunge)(struct mail *mail);
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen};
43d504fb5b23e14878e9777cdebff9c623f0b52cTimo Sirainen
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainenunion mail_module_context {
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen struct mail_vfuncs super;
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen struct mail_module_register *reg;
ccb70ccfd9a25e490aab46d15d9b8323ad9ea3bfTimo Sirainen};
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenstruct mail_private {
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen struct mail mail;
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen struct mail_vfuncs v;
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen pool_t pool;
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_module_context *);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen};
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mailbox_list_context {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mail_storage *storage;
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen enum mailbox_list_flags flags;
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen bool failed;
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen};
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainen
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainenunion mailbox_transaction_module_context {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mail_storage_module_register *reg;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen};
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
39775ad03c459efe64cce924658da5094ba417e1Timo Sirainenstruct mailbox_transaction_context {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mailbox *box;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ARRAY_DEFINE(module_contexts,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen union mailbox_transaction_module_context *);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen};
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenunion mail_search_module_context {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mail_storage_module_register *reg;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen};
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mail_search_context {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mailbox_transaction_context *transaction;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen char *charset;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mail_search_arg *args;
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen struct mail_search_sort_program *sort_program;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen uint32_t seq;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen};
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mail_save_context {
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mailbox_transaction_context *transaction;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct mail *dest_mail;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen};
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen
db7c9201c88e3d9bee10485194ee5b0c67249916Timo Sirainenstruct mailbox_sync_context {
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen struct mailbox *box;
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen};
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenstruct mailbox_header_lookup_ctx {
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen struct mailbox *box;
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen};
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen/* Modules should use do "my_id = mail_storage_module_id++" and
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen use objects' module_contexts[id] for their own purposes. */
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenextern struct mail_storage_module_register mail_storage_module_register;
df4018ae2f0a95be602f724ca70df7e0e3bd6a7dTimo Sirainen
df4018ae2f0a95be602f724ca70df7e0e3bd6a7dTimo Sirainen/* Storage's module_id for mail_index. */
a393d9d6dabdc46cf724f8cb004a652b4036d53dTimo Sirainenextern struct mail_module_register mail_module_register;
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen
a393d9d6dabdc46cf724f8cb004a652b4036d53dTimo Sirainen#define MAIL_STORAGE_CONTEXT(obj) \
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen &mail_index_module_register);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainen/* Set error message in storage. Critical errors are logged with i_error(),
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen but user sees only "internal error" message. */
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenvoid mail_storage_clear_error(struct mail_storage *storage);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenvoid mail_storage_set_error(struct mail_storage *storage,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen const char *fmt, ...) __attr_format__(2, 3);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenvoid mail_storage_set_syntax_error(struct mail_storage *storage,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen const char *fmt, ...) __attr_format__(2, 3);
a393d9d6dabdc46cf724f8cb004a652b4036d53dTimo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen const char *fmt, ...) __attr_format__(2, 3);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenvoid mail_storage_set_internal_error(struct mail_storage *storage);
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainenconst char *mail_storage_class_get_last_error(struct mail_storage *storage,
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen bool *syntax_error_r);
8153fdec343e40e2a78f5c12353e89b994b28f74Timo Sirainen
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainenenum mailbox_list_flags
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainenmail_storage_get_list_flags(enum mail_storage_flags storage_flags);
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainenbool mail_storage_errno2str(const char **error_r);
2bf7bb14894faf721518e2122a14a2389ef94078Timo Sirainen
2ae575a66f2a302f047f6de062a70b75f8bebc7bTimo Sirainen#endif
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen