index-storage.h revision 0c17af9d3f9323136a94e66605776ed4462a172d
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#ifndef __INDEX_STORAGE_H
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define __INDEX_STORAGE_H
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "mail-storage-private.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "mail-index.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#include "index-mail.h"
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Max. mmap()ed size for a message */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#define MAIL_MMAP_BLOCK_SIZE (1024*256)
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen/* Block size when read()ing message. */
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen#define MAIL_READ_BLOCK_SIZE (1024*8)
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen#define MAILBOX_FULL_SYNC_INTERVAL 5
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainen
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainenenum mailbox_lock_notify_type {
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen MAILBOX_LOCK_NOTIFY_NONE,
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen /* Mailbox is locked, will abort in secs_left */
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Mailbox lock looks stale, will override in secs_left */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAILBOX_LOCK_NOTIFY_MAILBOX_OVERRIDE
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct index_autosync_file {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct index_autosync_file *next;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen char *path;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen time_t last_stamp;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen};
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
7487ff578435377bbeefffdbfb78ca09ed1292dfTimo Sirainenstruct index_autosync_io {
89237470342ea6d4bbdf4cff9764037cfb3f6f45Timo Sirainen struct index_autosync_io *next;
89237470342ea6d4bbdf4cff9764037cfb3f6f45Timo Sirainen struct io *io;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen int fd;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen};
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstruct index_storage {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct mail_storage storage;
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen char *dir; /* root directory */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen char *index_dir;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen char *control_dir;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen char *inbox_path; /* INBOX location */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen char *user; /* name of user accessing the storage */
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen struct mail_storage_callbacks *callbacks;
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen void *callback_context;
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct index_mailbox {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mailbox box;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct index_storage *storage;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen char *path, *control_dir;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_index *index;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_index_view *view;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_cache *cache;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail_cache_view *cache_view;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mail *mail_interface;
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen uint32_t (*get_recent_count)(struct index_mailbox *ibox);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen struct timeout *autosync_to;
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen struct index_autosync_file *autosync_files;
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen struct index_autosync_io *autosync_ios;
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen enum mailbox_sync_flags autosync_flags;
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen time_t sync_last_check, sync_last_notify;
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen unsigned int min_newmail_notify_interval;
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen time_t next_lock_notify; /* temporary */
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen enum mailbox_lock_notify_type last_notify_type;
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen uint32_t commit_log_file_seq;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen uoff_t commit_log_file_offset;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* sync: */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct maildir_uidlist *uidlist;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen time_t last_new_mtime, last_cur_mtime, last_new_sync_time;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen time_t dirty_cur_time;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen mode_t mail_create_mode;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int private_flags_mask;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int readonly:1;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int sent_diskspace_warning:1;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int sent_readonly_flags_warning:1;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int autosync_pending:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int mail_read_mmaped:1;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen};
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct index_transaction_context {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct mailbox_transaction_context mailbox_ctx;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct index_mailbox *ibox;
b2d562f9c7fd13f9a16e9b3bcee904630b80b1feTimo Sirainen struct mail_index_transaction *trans;
b2d562f9c7fd13f9a16e9b3bcee904630b80b1feTimo Sirainen struct mail_cache_transaction_ctx *cache_trans;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct index_mail fetch_mail; /* for index_storage_fetch() */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen};
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenint mail_storage_set_index_error(struct index_mailbox *ibox);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid index_storage_reset_lock_notify(struct index_mailbox *ibox);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenstruct mail_index *
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenindex_storage_alloc(const char *index_dir,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen const char *mailbox_path, const char *prefix);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid index_storage_unref(struct mail_index *index);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid index_storage_destroy_unrefed(void);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid index_storage_init(struct index_storage *storage);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid index_storage_deinit(struct index_storage *storage);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
struct index_mailbox *
index_storage_mailbox_init(struct index_storage *storage, struct mailbox *box,
struct mail_index *index, const char *name,
enum mailbox_open_flags flags);
void index_storage_mailbox_free(struct mailbox *box);
int index_storage_is_readonly(struct mailbox *box);
int index_storage_allow_new_custom_flags(struct mailbox *box);
int index_storage_is_inconsistent(struct mailbox *box);
int index_mailbox_fix_custom_flags(struct index_mailbox *ibox,
enum mail_flags *flags,
const char *custom_flags[],
unsigned int custom_flags_count);
unsigned int index_storage_get_recent_count(struct mail_index_view *view);
void index_mailbox_check_add(struct index_mailbox *ibox,
const char *path, int dir);
void index_mailbox_check_remove_all(struct index_mailbox *ibox);
int index_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags);
/* mailbox methods: */
void index_storage_set_callbacks(struct mail_storage *storage,
struct mail_storage_callbacks *callbacks,
void *context);
int index_storage_get_status(struct mailbox *box,
enum mailbox_status_items items,
struct mailbox_status *status);
struct mail *
index_storage_fetch(struct mailbox_transaction_context *t, uint32_t seq,
enum mail_fetch_field wanted_fields);
int index_storage_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
uint32_t *seq1_r, uint32_t *seq2_r);
int index_storage_search_get_sorting(struct mailbox *box,
enum mail_sort_type *sort_program);
struct mail_search_context *
index_storage_search_init(struct mailbox_transaction_context *t,
const char *charset, struct mail_search_arg *args,
const enum mail_sort_type *sort_program,
enum mail_fetch_field wanted_fields,
const char *const wanted_headers[]);
int index_storage_search_deinit(struct mail_search_context *ctx);
struct mail *index_storage_search_next(struct mail_search_context *ctx);
struct mailbox_transaction_context *
index_transaction_begin(struct mailbox *box);
int index_transaction_commit(struct mailbox_transaction_context *t);
void index_transaction_rollback(struct mailbox_transaction_context *t);
#endif