mail-storage-private.h revision f81f4bc282cd1944cec187bae89c0701a416ed2a
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef __MAIL_STORAGE_PRIVATE_H
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen#define __MAIL_STORAGE_PRIVATE_H
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
8a68b403f982d0f1b2d628ea826ea5385771a787Timo Sirainen#include "module-context.h"
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen#include "file-lock.h"
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen#include "mail-storage.h"
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen#include "mail-index-private.h"
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen/* Called after mail storage has been created */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenextern void (*hook_mail_storage_created)(struct mail_storage *storage);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen/* Called after mailbox has been opened */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenextern void (*hook_mailbox_opened)(struct mailbox *box);
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainenstruct mail_storage_module_register {
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen unsigned int id;
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen};
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainenstruct mail_module_register {
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen unsigned int id;
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mail_storage_vfuncs {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*class_init)(void);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*class_deinit)(void);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
8a68b403f982d0f1b2d628ea826ea5385771a787Timo Sirainen struct mail_storage *(*alloc)(void);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*create)(struct mail_storage *storage, const char *data);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*destroy)(struct mail_storage *storage);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool (*autodetect)(const char *data, enum mail_storage_flags flags);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox *(*mailbox_open)(struct mail_storage *storage,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *name,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct istream *input,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mailbox_open_flags flags);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*mailbox_create)(struct mail_storage *storage, const char *name,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool directory);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *(*get_last_error)(struct mail_storage *storage,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool *syntax_error_r,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool *temporary_error_r);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenunion mail_storage_module_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage_vfuncs super;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage_module_register *reg;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mail_storage {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *name;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool mailbox_is_file;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage_vfuncs v;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen/* private: */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen pool_t pool;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen char *error;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_list *list;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *user; /* name of user accessing the storage */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mail_storage_flags flags;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum file_lock_method lock_method;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage_callbacks *callbacks;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void *callback_context;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen /* IMAP: Give a BAD reply instead of NO */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen unsigned int syntax_error:1;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen /* Internal temporary error, as opposed to visible user errors like
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen "permission denied" or "out of disk space" */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen unsigned int temporary_error:1;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
dedf3b46194a628cff11e6aaaedb717fa5483670Timo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mailbox_vfuncs {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool (*is_readonly)(struct mailbox *box);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool (*allow_new_keywords)(struct mailbox *box);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*close)(struct mailbox *box);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_status *status);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_sync_context *
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen (*sync_init)(struct mailbox *box,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mailbox_sync_flags flags);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*sync_next)(struct mailbox_sync_context *ctx,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_sync_rec *sync_rec_r);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mailbox_status_items status_items,
cbd6cad82e1c9ad60869ad71ae6c42e1af8b10a8Timo Sirainen struct mailbox_status *status_r);
cbd6cad82e1c9ad60869ad71ae6c42e1af8b10a8Timo Sirainen
8a68b403f982d0f1b2d628ea826ea5385771a787Timo Sirainen void (*notify_changes)(struct mailbox *box);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_transaction_context *
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen (*transaction_begin)(struct mailbox *box,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mailbox_transaction_flags flags);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mailbox_sync_flags flags);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_keywords *
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen (*keywords_create)(struct mailbox_transaction_context *t,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *const keywords[]);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*keywords_free)(struct mailbox_transaction_context *t,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_keywords *keywords);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*get_uids)(struct mailbox *box, uint32_t uid1, uint32_t uid2,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen uint32_t *seq1_r, uint32_t *seq2_r);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail *
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mail_fetch_field wanted_fields,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_header_lookup_ctx *
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen (*header_lookup_init)(struct mailbox *box,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *const headers[]);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*header_lookup_deinit)(struct mailbox_header_lookup_ctx *ctx);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_search_context *
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen (*search_init)(struct mailbox_transaction_context *t,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *charset, struct mail_search_arg *args,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const enum mail_sort_type *sort_program);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*search_next_nonblock)(struct mail_search_context *ctx,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail *mail, bool *tryagain_r);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen /* Internal search function which updates ctx->seq */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*search_next_update_seq)(struct mail_search_context *ctx);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*save_init)(struct mailbox_transaction_context *t,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mail_flags flags,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_keywords *keywords,
5e9713e7b02b2b47c339476725f9fbfd9bf78cffTimo Sirainen time_t received_date, int timezone_offset,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *from_envelope, struct istream *input,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail *dest_mail,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_save_context **ctx_r);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*save_continue)(struct mail_save_context *ctx);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*save_finish)(struct mail_save_context *ctx);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*copy)(struct mailbox_transaction_context *t, struct mail *mail,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mail_flags flags, struct mail_keywords *keywords,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail *dest_mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool (*is_inconsistent)(struct mailbox *box);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenunion mailbox_module_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_vfuncs super;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage_module_register *reg;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
f6d79884d112949fde4e7d9b7fc6a43e24a475b7Timo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mailbox {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen char *name;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage *storage;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_vfuncs v;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen/* private: */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen pool_t pool;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen unsigned int transaction_count;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen /* Mailbox notification settings: */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen unsigned int notify_min_interval;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen mailbox_notify_callback_t *notify_callback;
8a68b403f982d0f1b2d628ea826ea5385771a787Timo Sirainen void *notify_context;
8a68b403f982d0f1b2d628ea826ea5385771a787Timo Sirainen
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
b3254619187a08d0ecbdfaf4d251468158287c40Timo Sirainen ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
8a68b403f982d0f1b2d628ea826ea5385771a787Timo Sirainen
cbd6cad82e1c9ad60869ad71ae6c42e1af8b10a8Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
cbd6cad82e1c9ad60869ad71ae6c42e1af8b10a8Timo Sirainen it's synced for the first time. */
cbd6cad82e1c9ad60869ad71ae6c42e1af8b10a8Timo Sirainen unsigned int opened:1;
abb404575a238f27ea03b6049880f30f1656ddc4Timo Sirainen};
cbd6cad82e1c9ad60869ad71ae6c42e1af8b10a8Timo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mail_vfuncs {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen void (*free)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*set_seq)(struct mail *mail, uint32_t seq);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*set_uid)(struct mail *mail, uint32_t uid);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *const *(*get_keywords)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const struct message_part *(*get_parts)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen time_t (*get_date)(struct mail *mail, int *timezone);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen time_t (*get_received_date)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen time_t (*get_save_date)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen uoff_t (*get_virtual_size)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen uoff_t (*get_physical_size)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *(*get_first_header)(struct mail *mail, const char *field);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *const *(*get_headers)(struct mail *mail, const char *field);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct istream *
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen (*get_header_stream)(struct mail *mail,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_header_lookup_ctx *headers);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct istream *(*get_stream)(struct mail *mail,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct message_size *hdr_size,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct message_size *body_size);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *(*get_special)(struct mail *mail,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mail_fetch_field field);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*update_flags)(struct mail *mail, enum modify_type modify_type,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mail_flags flags);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*update_keywords)(struct mail *mail, enum modify_type modify_type,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_keywords *keywords);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen int (*expunge)(struct mail *mail);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenunion mail_module_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_vfuncs super;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_module_register *reg;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mail_private {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail mail;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_vfuncs v;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen pool_t pool;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen ARRAY_DEFINE(module_contexts, union mail_module_context *);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mailbox_list_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage *storage;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen enum mailbox_list_flags flags;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool failed;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenunion mailbox_transaction_module_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage_module_register *reg;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mailbox_transaction_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox *box;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen ARRAY_DEFINE(module_contexts,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen union mailbox_transaction_module_context *);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenunion mail_search_module_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_storage_module_register *reg;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mail_search_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_transaction_context *transaction;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen char *charset;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_search_arg *args;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail_search_sort_program *sort_program;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen uint32_t seq;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mail_save_context {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox_transaction_context *transaction;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mail *dest_mail;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenstruct mailbox_sync_context {
3d7590a656f4f746b2adc6e00fa607eba5d2412dTimo Sirainen struct mailbox *box;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
3d7590a656f4f746b2adc6e00fa607eba5d2412dTimo Sirainenstruct mailbox_header_lookup_ctx {
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen struct mailbox *box;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen};
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen/* Modules should use do "my_id = mail_storage_module_id++" and
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen use objects' module_contexts[id] for their own purposes. */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenextern struct mail_storage_module_register mail_storage_module_register;
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen/* Storage's module_id for mail_index. */
3d7590a656f4f746b2adc6e00fa607eba5d2412dTimo Sirainenextern struct mail_module_register mail_module_register;
3d7590a656f4f746b2adc6e00fa607eba5d2412dTimo Sirainen
46b823ac3bce2c0f9f0fc73911e48d3a77b04fbeTimo Sirainen#define MAIL_STORAGE_CONTEXT(obj) \
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen &mail_index_module_register);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen/* Set error message in storage. Critical errors are logged with i_error(),
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen but user sees only "internal error" message. */
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenvoid mail_storage_clear_error(struct mail_storage *storage);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenvoid mail_storage_set_error(struct mail_storage *storage,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *fmt, ...) __attr_format__(2, 3);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenvoid mail_storage_set_syntax_error(struct mail_storage *storage,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *fmt, ...) __attr_format__(2, 3);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen const char *fmt, ...) __attr_format__(2, 3);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenvoid mail_storage_set_internal_error(struct mail_storage *storage);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenconst char *mail_storage_class_get_last_error(struct mail_storage *storage,
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen bool *syntax_error_r);
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainen
fb15bb48cf8be41cd94738c868b64608b4fda1adTimo Sirainenenum mailbox_list_flags
mail_storage_get_list_flags(enum mail_storage_flags storage_flags);
bool mail_storage_errno2str(const char **error_r);
#endif