sdbox_copy_hardlink(struct mail_save_context *_ctx, struct mail *mail)
{
struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
- struct sdbox_mailbox *dest_mbox =
- (struct sdbox_mailbox *)_ctx->transaction->box;
+ struct sdbox_mailbox *dest_mbox = SDBOX_MAILBOX(_ctx->transaction->box);
struct sdbox_mailbox *src_mbox;
struct dbox_file *src_file, *dest_file;
const char *src_path, *dest_path;
int ret;
if (strcmp(mail->box->storage->name, SDBOX_STORAGE_NAME) == 0)
- src_mbox = (struct sdbox_mailbox *)mail->box;
+ src_mbox = SDBOX_MAILBOX(mail->box);
else {
/* Source storage isn't sdbox, can't hard link */
return 0;
static int sdbox_mail_file_set(struct dbox_mail *mail)
{
struct mail *_mail = &mail->imail.mail.mail;
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)_mail->box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(_mail->box);
bool deleted;
int ret;
sdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
const char **value_r)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)_mail->box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(_mail->box);
struct dbox_mail *mail = DBOX_MAIL(_mail);
struct stat st;
ARRAY(struct dbox_file *) files;
};
+#define SDBOX_SAVECTX(s) container_of(DBOX_SAVECTX(s), struct sdbox_save_context, ctx)
+
struct dbox_file *
sdbox_save_file_get_file(struct mailbox_transaction_context *t, uint32_t seq)
{
- struct sdbox_save_context *ctx =
- (struct sdbox_save_context *)t->save_ctx;
+ struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);
struct dbox_file *const *files, *file;
unsigned int count;
struct mail_save_context *
sdbox_save_alloc(struct mailbox_transaction_context *t)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)t->box;
- struct sdbox_save_context *ctx =
- (struct sdbox_save_context *)t->save_ctx;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(t->box);
+ struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);
i_assert((t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
void sdbox_save_add_file(struct mail_save_context *_ctx, struct dbox_file *file)
{
- struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+ struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct dbox_file *const *files;
unsigned int count;
int sdbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
{
- struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+ struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct dbox_file *file;
int ret;
int sdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
{
- struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+ struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct mailbox_transaction_context *_t = _ctx->transaction;
const struct mail_index_header *hdr;
void sdbox_transaction_save_commit_post(struct mail_save_context *_ctx,
struct mail_index_transaction_commit_result *result)
{
- struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+ struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
struct mail_storage *storage = _ctx->transaction->box->storage;
_ctx->transaction = NULL; /* transaction is already freed */
void sdbox_transaction_save_rollback(struct mail_save_context *_ctx)
{
- struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
+ struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
if (!ctx->ctx.finished)
sdbox_save_cancel(_ctx);
ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS |
MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY;
- mbox->storage = (struct sdbox_storage *)storage;
+ mbox->storage = SDBOX_STORAGE(storage);
return &mbox->box;
}
const struct mailbox_update *update,
struct mail_index_transaction *trans)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct mail_index_transaction *new_trans = NULL;
const struct mail_index_header *hdr;
uint32_t uid_validity, uid_next;
void sdbox_set_mailbox_corrupted(struct mailbox *box)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct sdbox_index_header hdr;
bool need_resize;
static int sdbox_mailbox_open(struct mailbox *box)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct sdbox_index_header hdr;
bool need_resize;
time_t path_ctime;
static void sdbox_mailbox_close(struct mailbox *box)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
if (mbox->corrupted_rebuild_count != 0)
(void)sdbox_sync(mbox, 0);
sdbox_mailbox_create(struct mailbox *box,
const struct mailbox_update *update, bool directory)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
struct sdbox_index_header hdr;
bool need_resize;
enum mailbox_metadata_items items,
struct mailbox_metadata *metadata_r)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
if (index_mailbox_get_metadata(box, items, metadata_r) < 0)
return -1;
guid_128_t mailbox_guid;
};
+#define SDBOX_STORAGE(s) container_of(DBOX_STORAGE(s), struct sdbox_storage, storage)
+#define SDBOX_MAILBOX(s) container_of(s, struct sdbox_mailbox, box)
+
extern struct mail_vfuncs sdbox_mail_vfuncs;
int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
sdbox_sync_add_file(struct index_rebuild_context *ctx,
const char *fname, bool primary)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(ctx->box);
struct dbox_file *file;
uint32_t uid;
int ret;
static void sdbox_sync_update_header(struct index_rebuild_context *ctx)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(ctx->box);
struct sdbox_index_header hdr;
bool need_resize;
struct mailbox_sync_context *
sdbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
{
- struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+ struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
enum sdbox_sync_flags sdbox_sync_flags = 0;
int ret = 0;