mail-storage-private.h revision 00aaafa8619b4e6aaf23f15d30c36f06ccb820bc
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef MAIL_STORAGE_PRIVATE_H
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define MAIL_STORAGE_PRIVATE_H
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "module-context.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "file-lock.h"
dfa2201c6ac8ddb2d2798dee15662cfe774e644eMartti Rannanjärvi#include "mail-storage.h"
d39a04db2f4d0599cb9b5f03a9aa10a3c234453cTimo Sirainen#include "mail-storage-hooks.h"
f7423cbbd9dea363a5df18ebb96da055a977ae79Timo Sirainen#include "mail-storage-settings.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "mail-index-private.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen/* Block size when read()ing message header. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define MAIL_READ_HDR_BLOCK_SIZE (1024*4)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Block size when read()ing message (header and) body. */
c99fe55d4535d839a6ad0735c4719e076a1adb2cTimo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainenstruct mail_storage_module_register {
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen unsigned int id;
5a6343181a5183b1ae1c39d40fc5a1deb3b840d9Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mail_module_register {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int id;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mail_storage_vfuncs {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(void);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_storage *(*alloc)(void);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int (*create)(struct mail_storage *storage, struct mail_namespace *ns,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char **error_r);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen void (*destroy)(struct mail_storage *storage);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen void (*add_list)(struct mail_storage *storage,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mailbox_list *list);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen void (*get_list_settings)(const struct mail_namespace *ns,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mailbox_list_settings *set);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mailbox_list_settings *set);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen struct mailbox_list *list,
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen const char *vname,
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen enum mailbox_flags flags);
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen int (*purge)(struct mail_storage *storage);
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen};
bd20ef9d5c639faf470912ab94e6e6627d3eaebaTimo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenunion mail_storage_module_context {
2f94ca6b0f70641fe31c8e1f93404ca0df8bb289Timo Sirainen struct mail_storage_vfuncs super;
2f94ca6b0f70641fe31c8e1f93404ca0df8bb289Timo Sirainen struct mail_storage_module_register *reg;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenenum mail_storage_class_flags {
104318260228780a5c6b3181b3401e8e504e2776Timo Sirainen /* mailboxes are files, not directories */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE = 0x01,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* root_dir points to a unique directory */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT = 0x02,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* mailbox_open_stream() is supported */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS = 0x04,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* never use quota for this storage (e.g. virtual mailboxes) */
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen MAIL_STORAGE_CLASS_FLAG_NOQUOTA = 0x08,
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen /* Storage doesn't need a mail root directory */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MAIL_STORAGE_CLASS_FLAG_NO_ROOT = 0x10,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* Storage uses one file per message */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MAIL_STORAGE_CLASS_FLAG_FILE_PER_MSG = 0x20
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
f46363f428d8f2784146d36692b21936a48a7006Timo Sirainenstruct mail_storage {
f46363f428d8f2784146d36692b21936a48a7006Timo Sirainen const char *name;
f46363f428d8f2784146d36692b21936a48a7006Timo Sirainen enum mail_storage_class_flags class_flags;
f46363f428d8f2784146d36692b21936a48a7006Timo Sirainen
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen struct mail_storage_vfuncs v, *vlast;
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen/* private: */
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen pool_t pool;
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen struct mail_storage *prev, *next;
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen /* counting number of times mail_storage_create() has returned this
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen same storage. */
2f94ca6b0f70641fe31c8e1f93404ca0df8bb289Timo Sirainen int refcount;
2f94ca6b0f70641fe31c8e1f93404ca0df8bb289Timo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
2f94ca6b0f70641fe31c8e1f93404ca0df8bb289Timo Sirainen to this storage. */
2f94ca6b0f70641fe31c8e1f93404ca0df8bb289Timo Sirainen int obj_refcount;
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen /* Linked list of all mailboxes in the storage */
2f94ca6b0f70641fe31c8e1f93404ca0df8bb289Timo Sirainen struct mailbox *mailboxes;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *unique_root_dir;
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen char *error_string;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen enum mail_error error;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const struct mail_storage *storage_class;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen struct mail_user *user;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen const char *temp_path_prefix;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen const struct mail_storage_settings *set;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen enum mail_storage_flags flags;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen struct mail_storage_callbacks callbacks;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen void *callback_context;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainen};
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainen
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainenstruct mail_attachment_part {
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen struct message_part *part;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen const char *content_type, *content_disposition;
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen};
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainen
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainenstruct mailbox_vfuncs {
04a6e51325d52a8f6046389406b2f606159a61e3Timo Sirainen bool (*is_readonly)(struct mailbox *box);
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen int (*exists)(struct mailbox *box, bool auto_boxes,
4cbe2b4ee234317331eadd1768d9ce433adb60e1Timo Sirainen enum mailbox_existence *existence_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen int (*open)(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen void (*close)(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen void (*free)(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen int (*create)(struct mailbox *box, const struct mailbox_update *update,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen bool directory);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen int (*update)(struct mailbox *box, const struct mailbox_update *update);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen int (*delete)(struct mailbox *box);
f158d9a303bb15a6848ca276c9391c7ca52e452bTimo Sirainen int (*rename)(struct mailbox *src, struct mailbox *dest,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen bool rename_children);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mailbox_status *status_r);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int (*get_metadata)(struct mailbox *box,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen enum mailbox_metadata_items items,
7fe37c2b0e4cd2a39896ab16e47eb418a59e3934Timo Sirainen struct mailbox_metadata *metadata_r);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int (*set_subscribed)(struct mailbox *box, bool set);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* Lookup sync extension record and figure out if it mailbox has
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen changed since. Returns 1 = yes, 0 = no, -1 = error. */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen int (*list_index_has_changed)(struct mailbox *box,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mail_index_view *list_view,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen uint32_t seq);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen /* Update the sync extension record. */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen void (*list_index_update_sync)(struct mailbox *box,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mail_index_transaction *trans,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen uint32_t seq);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mailbox_sync_context *
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen (*sync_init)(struct mailbox *box,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen enum mailbox_sync_flags flags);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mailbox_sync_rec *sync_rec_r);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mailbox_sync_status *status_r);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen /* Called once for each expunge. Called one or more times for
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen flag/keyword changes. Once the sync is finished, called with
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen uid=0 and sync_type=0. */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen void (*sync_notify)(struct mailbox *box, uint32_t uid,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen enum mailbox_sync_type sync_type);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen void (*notify_changes)(struct mailbox *box);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mailbox_transaction_context *
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen (*transaction_begin)(struct mailbox *box,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen enum mailbox_transaction_flags flags);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mail_transaction_commit_changes *changes_r);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
8761992b5aa05862e7ec3a460cdc17af41a4a0f5Timo Sirainen
8761992b5aa05862e7ec3a460cdc17af41a4a0f5Timo Sirainen enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mail *
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen enum mail_fetch_field wanted_fields,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mail_search_context *
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen (*search_init)(struct mailbox_transaction_context *t,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen struct mail_search_args *args,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const enum mail_sort_type *sort_program,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen enum mail_fetch_field wanted_fields,
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen bool (*search_next_nonblock)(struct mail_search_context *ctx,
28bf8f762fcd21c57bf71822cf818447babce9a0Timo Sirainen struct mail **mail_r, bool *tryagain_r);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen /* Internal search function which updates ctx->seq */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_save_context *
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen (*save_alloc)(struct mailbox_transaction_context *t);
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen int (*save_begin)(struct mail_save_context *ctx, struct istream *input);
0c22bef8f5b35c645de8affd8746307fc53bd222Timo Sirainen int (*save_continue)(struct mail_save_context *ctx);
0c22bef8f5b35c645de8affd8746307fc53bd222Timo Sirainen int (*save_finish)(struct mail_save_context *ctx);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch int (*copy)(struct mail_save_context *ctx, struct mail *mail);
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen /* Called during transaction commit/rollback if saving was done */
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen int (*transaction_save_commit_pre)(struct mail_save_context *save_ctx);
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen void (*transaction_save_commit_post)
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen (struct mail_save_context *save_ctx,
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen struct mail_index_transaction_commit_result *result_r);
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen void (*transaction_save_rollback)(struct mail_save_context *save_ctx);
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen bool (*is_inconsistent)(struct mailbox *box);
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen};
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainenunion mailbox_module_context {
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen struct mailbox_vfuncs super;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_storage_module_register *reg;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mailbox {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *name;
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen /* mailbox's virtual name (from mail_namespace_get_vname()) */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *vname;
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen struct mail_storage *storage;
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen struct mailbox_list *list;
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen struct mailbox_vfuncs v, *vlast;
28bf8f762fcd21c57bf71822cf818447babce9a0Timo Sirainen/* private: */
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen pool_t pool;
40a8e6948d662339c0c5e2c7abfb84ae7c1803fdTimo Sirainen /* Linked list of all mailboxes in this storage */
d6b3cfd855c0eebed68be50d3111de1b5a6afeb0Timo Sirainen struct mailbox *prev, *next;
40a8e6948d662339c0c5e2c7abfb84ae7c1803fdTimo Sirainen
40a8e6948d662339c0c5e2c7abfb84ae7c1803fdTimo Sirainen /* these won't be set until mailbox is opened: */
40a8e6948d662339c0c5e2c7abfb84ae7c1803fdTimo Sirainen struct mail_index *index;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct mail_index_view *view;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_cache *cache;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* Filled lazily by mailbox_get_permissions() */
1904e2fc786dbc037039d284b371730777277fc5Aki Tuomi struct mailbox_permissions _perm;
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen /* Filled lazily by mailbox_get_path() */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *_path;
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen /* default vfuncs for new struct mails. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const struct mail_vfuncs *mail_vfuncs;
e6b4168ba670d9e51ea7877661def039ae6b53c3Timo Sirainen /* Mailbox settings, or NULL if defaults */
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen const struct mailbox_settings *set;
e6b4168ba670d9e51ea7877661def039ae6b53c3Timo Sirainen
e6b4168ba670d9e51ea7877661def039ae6b53c3Timo Sirainen /* If non-zero, fail mailbox_open() with this error. mailbox_alloc()
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen can set this to force open to fail. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen enum mail_error open_error;
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainen struct istream *input;
28bf8f762fcd21c57bf71822cf818447babce9a0Timo Sirainen const char *index_prefix;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen enum mailbox_flags flags;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen unsigned int transaction_count;
6efdbeab167483597bef087f70ea852d1256a082Timo Sirainen enum mailbox_feature enabled_features;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen
6efdbeab167483597bef087f70ea852d1256a082Timo Sirainen /* Mailbox notification settings: */
6efdbeab167483597bef087f70ea852d1256a082Timo Sirainen unsigned int notify_min_interval;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen mailbox_notify_callback_t *notify_callback;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen void *notify_context;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* Increased by one for each new struct mailbox. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int generation_sequence;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* Saved search results */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen ARRAY_DEFINE(search_results, struct mail_search_result *);
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen it's synced for the first time. */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen unsigned int opened:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* Mailbox was deleted while we had it open. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int mailbox_deleted:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* Mailbox is being created */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int creating:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* Mailbox is being deleted */
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen unsigned int deleting:1;
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen /* Mailbox was already marked as deleted within this allocation. */
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen unsigned int marked_deleted:1;
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen /* TRUE if this is an INBOX for this user */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int inbox_user:1;
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen /* TRUE if this is an INBOX for this namespace (user or shared) */
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen unsigned int inbox_any:1;
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen /* When copying to this mailbox, require that mailbox_copy() uses
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen mailbox_save_*() to actually save a new physical copy rather than
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen simply incrementing a reference count (e.g. via hard link) */
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen unsigned int disable_reflink_copy_to:1;
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen /* Don't allow creating any new keywords */
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen unsigned int disallow_new_keywords:1;
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen};
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainenstruct mail_vfuncs {
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen void (*close)(struct mail *mail);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen void (*free)(struct mail *mail);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen void (*set_seq)(struct mail *mail, uint32_t seq, bool saving);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen bool (*set_uid)(struct mail *mail, uint32_t uid);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen void (*set_uid_cache_updates)(struct mail *mail, bool set);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen bool (*prefetch)(struct mail *mail);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen void (*precache)(struct mail *mail);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen void (*add_temp_wanted_fields)(struct mail *mail,
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen enum mail_fetch_field fields,
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen struct mailbox_header_lookup_ctx *headers);
d4845c4245638fd6f02dc0cb92c3465fae763cbbTimo Sirainen
d4845c4245638fd6f02dc0cb92c3465fae763cbbTimo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
d4845c4245638fd6f02dc0cb92c3465fae763cbbTimo Sirainen const char *const *(*get_keywords)(struct mail *mail);
d4845c4245638fd6f02dc0cb92c3465fae763cbbTimo Sirainen const ARRAY_TYPE(keyword_indexes) *
d4845c4245638fd6f02dc0cb92c3465fae763cbbTimo Sirainen (*get_keyword_indexes)(struct mail *mail);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen uint64_t (*get_modseq)(struct mail *mail);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen int (*get_parts)(struct mail *mail,
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen struct message_part **parts_r);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen int (*get_date)(struct mail *mail, time_t *date_r, int *timezone_r);
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainen int (*get_received_date)(struct mail *mail, time_t *date_r);
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainen int (*get_save_date)(struct mail *mail, time_t *date_r);
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainen int (*get_virtual_size)(struct mail *mail, uoff_t *size_r);
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainen int (*get_physical_size)(struct mail *mail, uoff_t *size_r);
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainen
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen int (*get_first_header)(struct mail *mail, const char *field,
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen bool decode_to_utf8, const char **value_r);
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen int (*get_headers)(struct mail *mail, const char *field,
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen bool decode_to_utf8, const char *const **value_r);
b7b9d4be2a1ff399026a5d6feeffd3a048f22be0Timo Sirainen int (*get_header_stream)(struct mail *mail,
b7b9d4be2a1ff399026a5d6feeffd3a048f22be0Timo Sirainen struct mailbox_header_lookup_ctx *headers,
b7b9d4be2a1ff399026a5d6feeffd3a048f22be0Timo Sirainen struct istream **stream_r);
b7b9d4be2a1ff399026a5d6feeffd3a048f22be0Timo Sirainen int (*get_stream)(struct mail *mail, bool get_body,
b7b9d4be2a1ff399026a5d6feeffd3a048f22be0Timo Sirainen struct message_size *hdr_size,
b7b9d4be2a1ff399026a5d6feeffd3a048f22be0Timo Sirainen struct message_size *body_size,
c444eeaa2866152cf62652698aa11b125e8454bcTimo Sirainen struct istream **stream_r);
f158d9a303bb15a6848ca276c9391c7ca52e452bTimo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int (*get_special)(struct mail *mail, enum mail_fetch_field field,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char **value_r);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail *(*get_real_mail)(struct mail *mail);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen void (*update_flags)(struct mail *mail, enum modify_type modify_type,
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen enum mail_flags flags);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen struct mail_keywords *keywords);
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen void (*update_modseq)(struct mail *mail, uint64_t min_modseq);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen void (*update_pop3_uidl)(struct mail *mail, const char *uidl);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen void (*expunge)(struct mail *mail);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen void (*set_cache_corrupted)(struct mail *mail,
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen enum mail_fetch_field field);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen int (*istream_opened)(struct mail *mail, struct istream **input);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen};
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainenunion mail_module_context {
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen struct mail_vfuncs super;
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen struct mail_module_register *reg;
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen};
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainenstruct mail_private {
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen struct mail mail;
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen struct mail_vfuncs v, *vlast;
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen /* initial wanted fields/headers, set by mail_alloc(): */
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen enum mail_fetch_field wanted_fields;
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen pool_t pool;
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_module_context *);
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen};
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainen
9b0f6b90ff8d1d6efd718b0d7cbe01b2454e9fd6Timo Sirainenstruct mailbox_list_context {
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen struct mail_storage *storage;
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen enum mailbox_list_flags flags;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen bool failed;
e52f55c08f6f1b4fbc5765bf6aa9c7daee0785c3Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainenunion mailbox_transaction_module_context {
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen struct mail_storage_module_register *reg;
e52f55c08f6f1b4fbc5765bf6aa9c7daee0785c3Timo Sirainen};
e52f55c08f6f1b4fbc5765bf6aa9c7daee0785c3Timo Sirainen
e52f55c08f6f1b4fbc5765bf6aa9c7daee0785c3Timo Sirainenstruct mailbox_transaction_stats {
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen unsigned long open_lookup_count;
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen unsigned long stat_lookup_count;
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen unsigned long fstat_lookup_count;
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen /* number of files we've opened and read */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned long files_read_count;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* number of bytes we've had to read from files */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned long long files_read_bytes;
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen /* number of cache lookup hits */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned long cache_hit_count;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstruct mailbox_transaction_context {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct mailbox *box;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen enum mailbox_transaction_flags flags;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen union mail_index_transaction_module_context module_ctx;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mail_index_transaction_vfuncs super;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen int mail_ref_count;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mail_index_transaction *itrans;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen /* view contains all changes done within this transaction */
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mail_index_view *view;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mail_cache_view *cache_view;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mail_cache_transaction_ctx *cache_trans;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_transaction_commit_changes *changes;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen ARRAY_DEFINE(module_contexts,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen union mailbox_transaction_module_context *);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_save_context *save_ctx;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen /* these statistics are never reset by mail-storage API: */
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mailbox_transaction_stats stats;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen /* Set to TRUE to update stats_* fields */
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen unsigned int stats_track:1;
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen};
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainenunion mail_search_module_context {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_storage_module_register *reg;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainenstruct mail_search_context {
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mailbox_transaction_context *transaction;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mail_search_args *args;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mail_search_sort_program *sort_program;
f5e1d3d6b34ec152aa1ff15c7bd3d3552e9227eaTimo Sirainen enum mail_fetch_field wanted_fields;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen /* if non-NULL, specifies that a search resulting is being updated.
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen this can be used as a search optimization: if searched message
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen already exists in search result, it's not necessary to check if
deb06d37292d9112d74bdf80cfebb92ab5151679Timo Sirainen static data matches. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_search_result *update_result;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* add matches to these search results */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen ARRAY_DEFINE(results, struct mail_search_result *);
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen uint32_t seq;
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen uint32_t progress_cur, progress_max;
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen unsigned int seen_lost_data:1;
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen unsigned int progress_hidden:1;
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen};
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenstruct mail_save_context {
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen struct mailbox_transaction_context *transaction;
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen struct mail *dest_mail;
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen enum mail_flags flags;
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen struct mail_keywords *keywords;
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen uint64_t min_modseq;
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen time_t received_date, save_date;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen int received_tz_offset;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen uint32_t uid;
2e533fb1283b5f06a4063b519e47f1861c910386Timo Sirainen char *guid, *pop3_uidl, *from_envelope;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen struct ostream *output;
d9515a2eaa94c8287188c38fc28028727671e729Timo Sirainen
d9515a2eaa94c8287188c38fc28028727671e729Timo Sirainen struct mail_save_attachment *attach;
d9515a2eaa94c8287188c38fc28028727671e729Timo Sirainen
d9515a2eaa94c8287188c38fc28028727671e729Timo Sirainen /* returns TRUE if message part is an attachment. */
2e533fb1283b5f06a4063b519e47f1861c910386Timo Sirainen bool (*part_is_attachment)(struct mail_save_context *ctx,
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen const struct mail_attachment_part *part);
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen /* mail was copied using saving */
dd645357a6b851a3a9527d16e2bced731e46dcaaMartti Rannanjärvi unsigned int copying_via_save:1;
dd645357a6b851a3a9527d16e2bced731e46dcaaMartti Rannanjärvi /* mail is being saved, not copied */
dd645357a6b851a3a9527d16e2bced731e46dcaaMartti Rannanjärvi unsigned int saving:1;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen};
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainenstruct mailbox_sync_context {
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen struct mailbox *box;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen enum mailbox_sync_flags flags;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mailbox_header_lookup_ctx {
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen struct mailbox *box;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen pool_t pool;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen int refcount;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
85b4143f07c504294dd4e5b168e9bfb293515c31Josef 'Jeff' Sipek unsigned int count;
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen const char *const *name;
6efdbeab167483597bef087f70ea852d1256a082Timo Sirainen unsigned int *idx;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen/* Modules should use do "my_id = mail_storage_module_id++" and
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen use objects' module_contexts[id] for their own purposes. */
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainenextern struct mail_storage_module_register mail_storage_module_register;
6efdbeab167483597bef087f70ea852d1256a082Timo Sirainen
96d19229e5f322411eb84446e5477d8170cfa5afTimo Sirainen/* Storage's module_id for mail_index. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct mail_module_register mail_module_register;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define MAIL_STORAGE_CONTEXT(obj) \
d39a04db2f4d0599cb9b5f03a9aa10a3c234453cTimo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
d39a04db2f4d0599cb9b5f03a9aa10a3c234453cTimo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
d39a04db2f4d0599cb9b5f03a9aa10a3c234453cTimo Sirainen &mail_index_module_register);
d39a04db2f4d0599cb9b5f03a9aa10a3c234453cTimo Sirainen
d39a04db2f4d0599cb9b5f03a9aa10a3c234453cTimo Sirainenvoid mail_storage_obj_ref(struct mail_storage *storage);
17fe695b985e9d6e9dc39c05b24e6b3c3b7e1ba1Timo Sirainenvoid mail_storage_obj_unref(struct mail_storage *storage);
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen
17fe695b985e9d6e9dc39c05b24e6b3c3b7e1ba1Timo Sirainen/* Set error message in storage. Critical errors are logged with i_error(),
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen but user sees only "internal error" message. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mail_storage_clear_error(struct mail_storage *storage);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mail_storage_set_error(struct mail_storage *storage,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen enum mail_error error, const char *string);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *fmt, ...) ATTR_FORMAT(2, 3);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mail_storage_set_internal_error(struct mail_storage *storage);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mail_storage_set_index_error(struct mailbox *box);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenbool mail_storage_set_error_from_errno(struct mail_storage *storage);
8d7eb4104707c60ca7e9d0228b37c5133476907bTimo Sirainenvoid mail_storage_copy_list_error(struct mail_storage *storage,
8d7eb4104707c60ca7e9d0228b37c5133476907bTimo Sirainen struct mailbox_list *list);
275385a2ecc58e41dc7df3ce3cd943caaa58c4d1Timo Sirainen
8d7eb4104707c60ca7e9d0228b37c5133476907bTimo Sirainen/* Returns TRUE if everything should already be in memory after this call. */
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenbool mail_prefetch(struct mail *mail);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenint mail_set_aborted(struct mail *mail);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenvoid mail_set_expunged(struct mail *mail);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenvoid mail_set_seq_saving(struct mail *mail, uint32_t seq);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenvoid mailbox_set_deleted(struct mailbox *box);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenint mailbox_mark_index_deleted(struct mailbox *box, bool del);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen/* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX */
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenconst char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen/* Get mailbox permissions. */
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenconst struct mailbox_permissions *mailbox_get_permissions(struct mailbox *box);
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen/* Force permissions to be refreshed on next lookup */
8d7eb4104707c60ca7e9d0228b37c5133476907bTimo Sirainenvoid mailbox_refresh_permissions(struct mailbox *box);
8d7eb4104707c60ca7e9d0228b37c5133476907bTimo Sirainen
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenint mailbox_create_fd(struct mailbox *box, const char *path, int flags,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen int *fd_r);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenunsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int secs);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen#endif
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen