mail-storage-private.h revision 8a13b020f90e080570658b18c042e7e352c8b14f
#ifndef MAIL_STORAGE_PRIVATE_H
#define MAIL_STORAGE_PRIVATE_H
#include "module-context.h"
#include "file-lock.h"
#include "mail-storage.h"
#include "mail-storage-hooks.h"
#include "mail-storage-settings.h"
#include "mail-index-private.h"
/* Block size when read()ing message header. */
/* Block size when read()ing message (header and) body. */
struct mail_storage_module_register {
unsigned int id;
};
struct mail_module_register {
unsigned int id;
};
struct mail_storage_vfuncs {
const struct setting_parser_info *(*get_setting_parser_info)(void);
struct mail_storage *(*alloc)(void);
const char **error_r);
struct mailbox_list *list);
struct mailbox_list_settings *set);
struct mailbox_list_settings *set);
struct mailbox_list *list,
const char *name,
enum mailbox_flags flags);
};
union mail_storage_module_context {
struct mail_storage_vfuncs super;
struct mail_storage_module_register *reg;
};
enum mail_storage_class_flags {
/* mailboxes are files, not directories */
/* root_dir points to a unique directory */
/* mailbox_open_stream() is supported */
/* never use quota for this storage (e.g. virtual mailboxes) */
};
struct mail_storage {
const char *name;
struct mail_storage_vfuncs v, *vlast;
/* private: */
/* counting number of times mail_storage_create() has returned this
same storage. */
int refcount;
/* counting number of objects (e.g. mailbox) that have a pointer
to this storage. */
int obj_refcount;
const char *unique_root_dir;
char *error_string;
enum mail_error error;
const struct mail_storage *storage_class;
const char *temp_path_prefix;
const struct mail_storage_settings *set;
enum mail_storage_flags flags;
struct mail_storage_callbacks callbacks;
void *callback_context;
/* Module-specific contexts. See mail_storage_module_id. */
};
struct mail_attachment_part {
struct message_part *part;
const char *content_type, *content_disposition;
};
struct mailbox_vfuncs {
bool directory);
bool rename_children);
struct mailbox_status *status_r);
/* Lookup sync extension record and figure out if it mailbox has
changed since. Returns 1 = yes, 0 = no, -1 = error. */
struct mail_index_view *list_view,
/* Update the sync extension record. Returns 0 = ok, -1 = error. */
struct mail_index_transaction *trans,
struct mailbox_sync_context *
enum mailbox_sync_flags flags);
struct mailbox_sync_rec *sync_rec_r);
struct mailbox_sync_status *status_r);
/* Called once for each expunge. Called one or more times for
uid=0 and sync_type=0. */
enum mailbox_sync_type sync_type);
struct mailbox_transaction_context *
enum mailbox_transaction_flags flags);
int (*transaction_commit)(struct mailbox_transaction_context *t,
struct mail_transaction_commit_changes *changes_r);
void (*transaction_rollback)(struct mailbox_transaction_context *t);
void (*transaction_set_max_modseq)(struct mailbox_transaction_context *t,
const char *const keywords[],
struct mail_keywords **keywords_r,
bool skip_invalid);
struct mail_keywords *
const char **error_r);
const char *backend_mailbox,
bool only_with_msgs);
struct mail *
(*mail_alloc)(struct mailbox_transaction_context *t,
struct mailbox_header_lookup_ctx *wanted_headers);
struct mailbox_header_lookup_ctx *
const char *const headers[]);
struct mail_search_context *
(*search_init)(struct mailbox_transaction_context *t,
struct mail_search_args *args,
const enum mail_sort_type *sort_program);
/* Internal search function which updates ctx->seq */
struct mail_save_context *
(*save_alloc)(struct mailbox_transaction_context *t);
/* returns TRUE if message part is an attachment. */
const struct mail_attachment_part *part);
};
union mailbox_module_context {
struct mailbox_vfuncs super;
struct mail_storage_module_register *reg;
};
struct mailbox_permissions {
/* origin (e.g. path) where the file_create_gid was got from */
const char *file_create_gid_origin;
};
struct mailbox {
const char *name;
/* mailbox's virtual name (from mail_namespace_get_vname()) */
const char *vname;
struct mail_storage *storage;
struct mailbox_list *list;
struct mailbox_vfuncs v, *vlast;
/* private: */
/* these won't be set until mailbox is opened: */
struct mail_index *index;
struct mail_index_view *view;
struct mail_cache *cache;
/* Filled lazily by mailbox_get_permissions() */
struct mailbox_permissions _perm;
/* Filled lazily by mailbox_get_path() */
const char *_path;
/* default vfuncs for new struct mails. */
const struct mail_vfuncs *mail_vfuncs;
const char *index_prefix;
enum mailbox_flags flags;
unsigned int transaction_count;
/* Mailbox notification settings: */
unsigned int notify_min_interval;
void *notify_context;
/* Saved search results */
/* Module-specific contexts. See mail_storage_module_id. */
/* When FAST open flag is used, the mailbox isn't actually opened until
it's synced for the first time. */
unsigned int opened:1;
/* Mailbox was deleted while we had it open. */
unsigned int mailbox_deleted:1;
/* we've discovered there aren't enough permissions to modify mailbox */
unsigned int backend_readonly:1;
/* Mailbox is being deleted */
unsigned int deleting:1;
/* Mailbox was already marked as deleted within this allocation. */
unsigned int marked_deleted:1;
/* TRUE if this is an INBOX for this user */
unsigned int inbox_user:1;
/* TRUE if this is an INBOX for this namespace (user or shared) */
unsigned int inbox_any:1;
/* When copying to this mailbox, require that mailbox_copy() uses
mailbox_save_*() to actually save a new physical copy rather than
simply incrementing a reference count (e.g. via hard link) */
unsigned int disable_reflink_copy_to:1;
};
struct mail_vfuncs {
const ARRAY_TYPE(keyword_indexes) *
struct message_part **parts_r);
bool decode_to_utf8, const char **value_r);
bool decode_to_utf8, const char *const **value_r);
struct mailbox_header_lookup_ctx *headers,
struct message_size *body_size,
const char **value_r);
enum mail_flags flags);
struct mail_keywords *keywords);
enum mail_fetch_field field);
};
union mail_module_context {
struct mail_vfuncs super;
struct mail_module_register *reg;
};
struct mail_private {
struct mail_vfuncs v, *vlast;
struct mailbox_header_lookup_ctx *wanted_headers;
/* these statistics are never reset by mail-storage API: */
unsigned long stats_open_lookup_count;
unsigned long stats_stat_lookup_count;
unsigned long stats_fstat_lookup_count;
/* number of files we've opened and read */
unsigned long stats_files_read_count;
/* number of bytes we've had to read from files */
unsigned long long stats_files_read_bytes;
/* number of cache lookup hits */
unsigned long stats_cache_hit_count;
/* Set to TRUE to update stats_* fields */
unsigned int stats_track:1;
};
struct mailbox_list_context {
struct mail_storage *storage;
enum mailbox_list_flags flags;
bool failed;
};
struct mail_storage_module_register *reg;
};
struct mailbox_transaction_context {
struct mail_index_transaction_vfuncs super;
int mail_ref_count;
struct mail_index_transaction *itrans;
/* view contains all changes done within this transaction */
struct mail_index_view *view;
struct mail_cache_view *cache_view;
struct mail_cache_transaction_ctx *cache_trans;
struct mail_transaction_commit_changes *changes;
union mailbox_transaction_module_context *);
struct mail_save_context *save_ctx;
};
union mail_search_module_context {
struct mail_storage_module_register *reg;
};
struct mail_search_context {
struct mailbox_transaction_context *transaction;
struct mail_search_args *args;
struct mail_search_sort_program *sort_program;
/* if non-NULL, specifies that a search resulting is being updated.
this can be used as a search optimization: if searched message
already exists in search result, it's not necessary to check if
static data matches. */
struct mail_search_result *update_result;
/* add matches to these search results */
unsigned int seen_lost_data:1;
unsigned int progress_hidden:1;
};
struct mail_save_context {
struct mailbox_transaction_context *transaction;
enum mail_flags flags;
struct mail_keywords *keywords;
int received_tz_offset;
struct mail_save_attachment *attach;
/* we came here from mailbox_copy() */
unsigned int copying:1;
};
struct mailbox_sync_context {
};
struct mailbox_header_lookup_ctx {
const char *const *headers;
int refcount;
};
/* Modules should use do "my_id = mail_storage_module_id++" and
use objects' module_contexts[id] for their own purposes. */
extern struct mail_storage_module_register mail_storage_module_register;
/* Storage's module_id for mail_index. */
extern struct mail_module_register mail_module_register;
#define MAIL_STORAGE_CONTEXT(obj) \
/* Set error message in storage. Critical errors are logged with i_error(),
but user sees only "internal error" message. */
struct mailbox_list *list);
/* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX */
/* Get mailbox permissions. */
/* Force permissions to be refreshed on next lookup */
/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
int *fd_r);
unsigned int secs);
#endif