quota-storage.c revision 3ccfcf0856958cb9208a9fc51c3bdf13c58ad52a
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen/* Copyright (C) 2005 Timo Sirainen */
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen *((void **)array_idx_modifiable(&(obj)->module_contexts, \
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainenstatic unsigned int quota_storage_module_id = 0;
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainenstatic bool quota_storage_module_id_set = FALSE;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic int quota_mail_expunge(struct mail *_mail)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainen struct quota_mail *qmail = QUOTA_CONTEXT(mail);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenquota_mailbox_transaction_begin(struct mailbox *box,
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainen struct quota_mailbox *qbox = QUOTA_CONTEXT(box);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen t = qbox->super.transaction_begin(box, flags);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen array_idx_set(&t->module_contexts, quota_storage_module_id, &qt);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenquota_mailbox_transaction_commit(struct mailbox_transaction_context *ctx,
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct quota_mailbox *qbox = QUOTA_CONTEXT(ctx->box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct quota_transaction_context *qt = QUOTA_CONTEXT(ctx);
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainen if (qbox->super.transaction_commit(ctx, flags) < 0) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenquota_mailbox_transaction_rollback(struct mailbox_transaction_context *ctx)
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct quota_mailbox *qbox = QUOTA_CONTEXT(ctx->box);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct quota_transaction_context *qt = QUOTA_CONTEXT(ctx);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenstatic struct mail *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenquota_mail_alloc(struct mailbox_transaction_context *t,
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct quota_mailbox *qbox = QUOTA_CONTEXT(t->box);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen _mail = qbox->super.mail_alloc(t, wanted_fields, wanted_headers);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen qmail = p_new(mail->pool, struct quota_mail, 1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen array_idx_set(&mail->module_contexts, quota_storage_module_id, &qmail);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenstatic int quota_check(struct mailbox_transaction_context *t, struct mail *mail)
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen struct quota_transaction_context *qt = QUOTA_CONTEXT(t);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen else if (ret == 0) {
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen mail_storage_set_error(t->box->storage, "Quota exceeded");
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen "Internal quota calculation error");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenquota_copy(struct mailbox_transaction_context *t, struct mail *mail,
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen enum mail_flags flags, struct mail_keywords *keywords,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct quota_transaction_context *qt = QUOTA_CONTEXT(t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct quota_mailbox *qbox = QUOTA_CONTEXT(t->box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* we always want to know the mail size */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen qt->tmp_mail = mail_alloc(t, MAIL_FETCH_PHYSICAL_SIZE,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (qbox->super.copy(t, mail, flags, keywords, dest_mail) < 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* if copying used saving internally, we already checked the quota
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen and set qbox->save_hack = TRUE. */
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen return qbox->save_hack ? 0 : quota_check(t, dest_mail);
int ret;
bool too_large;
if (ret == 0) {
} else if (ret < 0) {
NULL);
static struct mailbox *
return NULL;
return box;
struct mailbox_transaction_context *t;
int ret;
if (ret < 0)
if (!quota_storage_module_id_set) {