1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#ifndef DBOX_STORAGE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DBOX_STORAGE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mail-storage-private.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct dbox_file;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct dbox_mail;
5b62dea2f88165f3f4d87bba9011343f3ff415ffTimo Sirainenstruct dbox_storage;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenstruct dbox_save_context;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DBOX_SUBSCRIPTION_FILE_NAME "subscriptions"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DBOX_UIDVALIDITY_FILE_NAME "dovecot-uidvalidity"
6c073ea23cd0e3760b072727cc18114860c27647Timo Sirainen#define DBOX_TEMP_FILE_PREFIX ".temp."
1fb81cb0b622cef1690c96bcc6a3e183e0b1e6ffTimo Sirainen#define DBOX_ALT_SYMLINK_NAME "dbox-alt-root"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DBOX_MAILBOX_DIR_NAME "mailboxes"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DBOX_TRASH_DIR_NAME "trash"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DBOX_MAILDIR_NAME "dbox-Mails"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Delete temp files having ctime older than this. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define DBOX_TMP_DELETE_SECS (36*60*60)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
2271d1a3dfc7191e610f039e86b9245bbc5dfb8cTimo Sirainen/* Flag specifies if the message should be in primary or alternative storage */
2271d1a3dfc7191e610f039e86b9245bbc5dfb8cTimo Sirainen#define DBOX_INDEX_FLAG_ALT MAIL_INDEX_MAIL_FLAG_BACKEND
2271d1a3dfc7191e610f039e86b9245bbc5dfb8cTimo Sirainen
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenenum dbox_index_header_flags {
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen /* messages' metadata contain POP3 UIDLs */
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen DBOX_INDEX_HEADER_FLAG_HAVE_POP3_UIDLS = 0x01,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen /* messages' metadata contain POP3 orders */
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen DBOX_INDEX_HEADER_FLAG_HAVE_POP3_ORDERS = 0x02
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen};
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct dbox_storage_vfuncs {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* dbox file has zero references now. it should be either freed or
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen left open in case it's accessed again soon */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen void (*file_unrefed)(struct dbox_file *file);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* create a new file using the same permissions as file.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if parents=TRUE, create the directory if necessary */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*file_create_fd)(struct dbox_file *file, const char *path,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool parents);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* open the mail and return its file/offset */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*mail_open)(struct dbox_mail *mail, uoff_t *offset_r,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct dbox_file **file_r);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* create/update mailbox indexes */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*mailbox_create_indexes)(struct mailbox *box,
dd4f30895ebbddd77e000472fbadcb3128ae2883Timo Sirainen const struct mailbox_update *update,
dd4f30895ebbddd77e000472fbadcb3128ae2883Timo Sirainen struct mail_index_transaction *trans);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* returns attachment path suffix. mdbox returns "", sdbox returns
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen "-<mailbox_guid>-<uid>" */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char *(*get_attachment_path_suffix)(struct dbox_file *file);
57bf90f66f393c2807b2fc543655013f61d1d9e4Timo Sirainen /* mark the mailbox corrupted */
57bf90f66f393c2807b2fc543655013f61d1d9e4Timo Sirainen void (*set_mailbox_corrupted)(struct mailbox *box);
5b62dea2f88165f3f4d87bba9011343f3ff415ffTimo Sirainen /* mark the file corrupted */
5b62dea2f88165f3f4d87bba9011343f3ff415ffTimo Sirainen void (*set_file_corrupted)(struct dbox_file *file);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct dbox_storage {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mail_storage storage;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct dbox_storage_vfuncs v;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen struct fs *attachment_fs;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char *attachment_dir;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
804fa3f03bd9170272168a5ad214053bbe3160c7Josef 'Jeff' Sipek#define DBOX_STORAGE(s) container_of(s, struct dbox_storage, storage)
804fa3f03bd9170272168a5ad214053bbe3160c7Josef 'Jeff' Sipek
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid dbox_storage_get_list_settings(const struct mail_namespace *ns,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list_settings *set);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint dbox_storage_create(struct mail_storage *storage,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen struct mail_namespace *ns,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char **error_r);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenvoid dbox_storage_destroy(struct mail_storage *storage);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenuint32_t dbox_get_uidvalidity_next(struct mailbox_list *list);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid dbox_notify_changes(struct mailbox *box);
7b15788793354ca0fd4fdb4dda8e426ca1e9e9d7Timo Sirainenint dbox_mailbox_check_existence(struct mailbox *box, time_t *path_ctime_r);
7b15788793354ca0fd4fdb4dda8e426ca1e9e9d7Timo Sirainenint dbox_mailbox_open(struct mailbox *box, time_t path_ctime);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint dbox_mailbox_create(struct mailbox *box,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mailbox_update *update, bool directory);
48d8312488089dc1a8360991f0881d91095c21eaTimo Sirainenint dbox_mailbox_create_indexes(struct mailbox *box,
48d8312488089dc1a8360991f0881d91095c21eaTimo Sirainen const struct mailbox_update *update);
755abfa2bc6c5f072519b545faa1487357046b27Timo Sirainenint dbox_verify_alt_storage(struct mailbox_list *list);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenbool dbox_header_have_flag(struct mailbox *box, uint32_t ext_id,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen unsigned int flags_offset, uint8_t flag);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#endif