--- dovecot-2.0.7/src/lib-storage/mail-storage.c.ORIG 2010-11-11 19:46:14.000000000 +0000 +++ dovecot-2.0.7/src/lib-storage/mail-storage.c 2010-11-11 19:46:19.000000000 +0000 @@ -15,20 +15,21 @@ #include "mail-storage-settings.h" #include "mail-namespace.h" #include "mail-search.h" #include "mail-search-register.h" #include "mailbox-search-result-private.h" #include #include #define MAILBOX_DELETE_RETRY_SECS (60*5) +#define MAX_MSGS_PER_MAILBOX 4000 extern struct mail_search_register *mail_search_register_imap; extern struct mail_search_register *mail_search_register_human; struct mail_storage_module_register mail_storage_module_register = { 0 }; struct mail_module_register mail_module_register = { 0 }; struct mail_storage_mail_index_module mail_storage_mail_index_module = MODULE_CONTEXT_INIT(&mail_index_module_register); ARRAY_TYPE(mail_storage) mail_storage_classes; @@ -1365,28 +1366,34 @@ void mailbox_save_set_pop3_uidl(struct m void mailbox_save_set_dest_mail(struct mail_save_context *ctx, struct mail *mail) { ctx->dest_mail = mail; } int mailbox_save_begin(struct mail_save_context **ctx, struct istream *input) { struct mailbox *box = (*ctx)->transaction->box; + struct mailbox_status status; int ret; if (mail_index_is_deleted(box->index)) { mailbox_set_deleted(box); return -1; } - if (box->v.save_begin == NULL) { + mailbox_get_status(box, STATUS_MESSAGES, &status); + if (status.messages >= MAX_MSGS_PER_MAILBOX) { + mail_storage_set_error(box->storage, MAIL_ERROR_NOSPACE, + "Mailbox full: Too many messages"); + ret = -1; + } else if (box->v.save_begin == NULL) { mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE, "Saving messages not supported"); ret = -1; } else { ret = box->v.save_begin(*ctx, input); } if (ret < 0) { mailbox_save_cancel(ctx); return -1; @@ -1423,31 +1430,39 @@ void mailbox_save_cancel(struct mail_sav ctx->transaction->box->v.save_cancel(ctx); if (keywords != NULL) mailbox_keywords_unref(box, &keywords); } int mailbox_copy(struct mail_save_context **_ctx, struct mail *mail) { struct mail_save_context *ctx = *_ctx; struct mailbox *box = ctx->transaction->box; struct mail_keywords *keywords = ctx->keywords; + struct mailbox_status status; int ret; *_ctx = NULL; if (mail_index_is_deleted(box->index)) { mailbox_set_deleted(box); mailbox_save_cancel(_ctx); return -1; } - ret = ctx->transaction->box->v.copy(ctx, mail); + mailbox_get_status(box, STATUS_MESSAGES, &status); + if (status.messages >= MAX_MSGS_PER_MAILBOX) { + mail_storage_set_error(box->storage, MAIL_ERROR_NOSPACE, + "Mailbox full: Too many messages"); + ret = -1; + } else { + ret = ctx->transaction->box->v.copy(ctx, mail); + } if (keywords != NULL) mailbox_keywords_unref(box, &keywords); return ret; } bool mailbox_is_inconsistent(struct mailbox *box) { return box->mailbox_deleted || box->v.is_inconsistent(box); }