--- dovecot-2.1.6/src/lib-storage/mail-storage.c.orig 2012-05-23 11:45:55.000000000 +0100 +++ dovecot-2.1.6/src/lib-storage/mail-storage.c 2012-05-23 12:11:28.000000000 +0100 @@ -22,12 +22,13 @@ #include "mailbox-guid-cache.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 }; @@ -1620,22 +1621,28 @@ 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 (!(*ctx)->copying_via_save) (*ctx)->saving = TRUE; - 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); } @@ -1685,23 +1692,31 @@ 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(&keywords); return ret; } int mailbox_save_using_mail(struct mail_save_context **ctx, struct mail *mail)