index-storage.h revision bf661a542d17273066e720b4f75868a1ff975a4c
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#ifndef __INDEX_STORAGE_H
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#define __INDEX_STORAGE_H
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#include "file-dotlock.h"
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#include "mail-storage-private.h"
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#include "mail-index.h"
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* Max. mmap()ed size for a message */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#define MAIL_MMAP_BLOCK_SIZE (1024*256)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* Block size when read()ing message. */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#define MAIL_READ_BLOCK_SIZE (1024*8)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny#define MAILBOX_FULL_SYNC_INTERVAL 5
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenyenum mailbox_lock_notify_type {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny MAILBOX_LOCK_NOTIFY_NONE,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Mailbox is locked, will abort in secs_left */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* Mailbox lock looks stale, will override in secs_left */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny MAILBOX_LOCK_NOTIFY_MAILBOX_OVERRIDE
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny};
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystruct index_storage {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mail_storage storage;
3ee411625aee19afda7477bb10b52c3da378b6fbPetr Čech
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *dir; /* root directory */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *index_dir;
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher const char *control_dir;
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce const char *inbox_path; /* INBOX location */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *temp_prefix; /* prefix for temporary files */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose const char *user; /* name of user accessing the storage */
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose struct mail_storage_callbacks *callbacks;
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek void *callback_context;
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose};
d81d8d3dc151ebc95cd0e3f3b14c1cdaa48980f1Sumit Bose
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystruct index_mailbox {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mailbox box;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct index_storage *storage;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const char *path, *control_dir;
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mail_index *index;
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek struct mail_index_view *view;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mail_cache *cache;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mail_vfuncs *mail_vfuncs;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek int (*is_recent)(struct index_mailbox *ibox, uint32_t uid);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct timeout *notify_to;
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina struct index_notify_file *notify_files;
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose struct index_notify_io *notify_ios;
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose time_t notify_last_check, notify_last_sent;
b9fbeb75e7a4f50f98d979a70a710f9221892483Lukas Slebodnik unsigned int min_notify_interval;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny mailbox_notify_callback_t *notify_callback;
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz void *notify_context;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny time_t next_lock_notify; /* temporary */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny enum mailbox_lock_notify_type last_notify_type;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny uint32_t commit_log_file_seq;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny uoff_t commit_log_file_offset;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny const array_t *ARRAY_DEFINE_PTR(keyword_names, const char *);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek struct mail_cache_field *cache_fields;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny buffer_t *recent_flags;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny uint32_t recent_flags_start_seq, recent_flags_count;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny uint32_t synced_recent_count;
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek time_t sync_last_check;
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek /* mbox: */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int mbox_fd;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct istream *mbox_stream, *mbox_file_stream;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int mbox_lock_type;
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek dev_t mbox_dev;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov ino_t mbox_ino;
15b5d885e28afcd6c3c19f900eea2a8e00c3e6d3Sumit Bose unsigned int mbox_excl_locks, mbox_shared_locks;
c03214d427ea43e7bf8255ccc79faa905c89f7f6Jakub Hrozek struct dotlock *mbox_dotlock;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny unsigned int mbox_lock_id;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny int mbox_readonly, mbox_writeonly;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny time_t mbox_dirty_stamp;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov off_t mbox_dirty_size;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek uint32_t mbox_ext_idx, md5hdr_ext_idx;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* maildir sync: */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct maildir_uidlist *uidlist;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny time_t last_new_mtime, last_cur_mtime, last_new_sync_time;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny time_t dirty_cur_time;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
326f4fc3125e155ee2d484fe921aafddd6b5a49dPavel Březina mode_t mail_create_mode;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny unsigned int private_flags_mask;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny unsigned int readonly:1;
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose unsigned int keep_recent:1;
fdda4b659fa3be3027df91a2b053835186ec2c59Sumit Bose unsigned int recent_flags_synced:1;
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose unsigned int sent_diskspace_warning:1;
b56b06e199f15a8a840b36bc7cb8010e39ae761dSumit Bose unsigned int sent_readonly_flags_warning:1;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek unsigned int notify_pending:1;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek unsigned int mail_read_mmaped:1;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek unsigned int syncing_commit:1;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov unsigned int mbox_sync_dirty:1;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov unsigned int mbox_do_dirty_syncs:1;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek unsigned int mbox_very_dirty_syncs:1;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek unsigned int mbox_save_md5:1;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek unsigned int mbox_dotlocked:1;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek};
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březinastruct index_transaction_context {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mailbox_transaction_context mailbox_ctx;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct index_mailbox *ibox;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny enum mailbox_transaction_flags flags;
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek struct mail_index_transaction *trans;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mail_index_view *trans_view;
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek struct mail_cache_view *cache_view;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov struct mail_cache_transaction_ctx *cache_trans;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny unsigned int cache_trans_failed:1;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny};
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenyint mail_storage_set_index_error(struct index_mailbox *ibox);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bosevoid index_storage_lock_notify(struct index_mailbox *ibox,
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose enum mailbox_lock_notify_type notify_type,
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose unsigned int secs_left);
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bosevoid index_storage_lock_notify_reset(struct index_mailbox *ibox);
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bosestruct mail_index *
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagherindex_storage_alloc(const char *index_dir, const char *mailbox_path,
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose const char *prefix);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovvoid index_storage_unref(struct mail_index *index);
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bosevoid index_storage_destroy_unrefed(void);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bosevoid index_storage_init(struct index_storage *storage,
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose enum mail_storage_flags flags,
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bose enum mail_storage_lock_method lock_method);
75dd4b05e1dacc76dc9d5f16be31978f84a71dc5Sumit Bosevoid index_storage_deinit(struct index_storage *storage);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovint index_storage_mailbox_init(struct index_mailbox *ibox,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher struct mail_index *index, const char *name,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher enum mailbox_open_flags flags);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovvoid index_storage_mailbox_free(struct mailbox *box);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagherint index_storage_is_readonly(struct mailbox *box);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagherint index_storage_allow_new_keywords(struct mailbox *box);
8be5e4497e5008f7807178acdfcbf97365ec4e73Stephen Gallagherint index_storage_is_inconsistent(struct mailbox *box);
8be5e4497e5008f7807178acdfcbf97365ec4e73Stephen Gallagher
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagherstruct mail_keywords *
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagherindex_keywords_create(struct mailbox_transaction_context *t,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov const char *const keywords[]);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovvoid index_keywords_free(struct mailbox_transaction_context *t,
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher struct mail_keywords *keywords);
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallaghervoid index_mailbox_set_recent(struct index_mailbox *ibox, uint32_t seq);
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagherint index_mailbox_is_recent(struct index_mailbox *ibox, uint32_t seq);
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovunsigned int index_storage_get_recent_count(struct mail_index_view *view);
c20a339d54b39120b4051f690ca759e6d079f177Stephen Gallagher
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovvoid index_mailbox_check_add(struct index_mailbox *ibox,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher const char *path, int dir);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallaghervoid index_mailbox_check_remove_all(struct index_mailbox *ibox);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagherstruct mailbox_sync_context *
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagherindex_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher int failed);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagherint index_mailbox_sync_next(struct mailbox_sync_context *ctx,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov struct mailbox_sync_rec *sync_rec_r);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovint index_mailbox_sync_deinit(struct mailbox_sync_context *ctx,
bfd59d1a2d0d45125e5164ef12c425690d519f61Jakub Hrozek struct mailbox_status *status_r);
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovint index_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallaghervoid index_storage_set_callbacks(struct mail_storage *storage,
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagher struct mail_storage_callbacks *callbacks,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov void *context);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashovconst char *index_storage_get_last_error(struct mail_storage *storage,
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek int *syntax_error_r);
58d02e0d3d6d48c97fccdb2ad7212e065671ad6dStephen Gallagherint index_storage_get_status(struct mailbox *box,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny enum mailbox_status_items items,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mailbox_status *status);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenyint index_storage_get_status_locked(struct index_mailbox *ibox,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny enum mailbox_status_items items,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny struct mailbox_status *status_r);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashovint index_storage_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek uint32_t *seq1_r, uint32_t *seq2_r);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenystruct mailbox_header_lookup_ctx *
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenyindex_header_lookup_init(struct mailbox *box, const char *const headers[]);
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bosevoid index_header_lookup_deinit(struct mailbox_header_lookup_ctx *ctx);
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose
1d93029624d708119bbf803e6647a2cbb271f001Sumit Boseint index_storage_search_get_sorting(struct mailbox *box,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose enum mail_sort_type *sort_program);
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bosestruct mail_search_context *
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnikindex_storage_search_init(struct mailbox_transaction_context *t,
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik const char *charset, struct mail_search_arg *args,
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik const enum mail_sort_type *sort_program);
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnikint index_storage_search_deinit(struct mail_search_context *ctx);
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnikint index_storage_search_next(struct mail_search_context *ctx,
56e88cd5f3501566778b138e4934ee8e7f3fa674Lukas Slebodnik struct mail *mail);
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bosevoid index_transaction_init(struct index_transaction_context *t,
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek struct index_mailbox *ibox,
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek enum mailbox_transaction_flags flags);
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozekint index_transaction_commit(struct mailbox_transaction_context *t);
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozekvoid index_transaction_rollback(struct mailbox_transaction_context *t);
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek#endif
108db0e3b9e06e530364ef8228634f5e3f6bd3b5Jakub Hrozek