Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4324:36587f382562 HEAD
If mail's size is known beforehand, select the dbox file so that the saving
won't grow file larger than dbox_rotate_size.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 Jun 2006 21:21:12 +0300 |
parents | af09f5b2ce04 |
children | 95b0ce55fa4b |
files | src/lib-storage/index/dbox/dbox-save.c src/lib-storage/index/dbox/dbox-uidlist.c src/lib-storage/index/dbox/dbox-uidlist.h |
diffstat | 3 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-save.c Thu Jun 08 20:14:27 2006 +0300 +++ b/src/lib-storage/index/dbox/dbox-save.c Thu Jun 08 21:21:12 2006 +0300 @@ -3,6 +3,7 @@ #include "lib.h" #include "array.h" #include "ioloop.h" +#include "istream.h" #include "hex-dec.h" #include "write-full.h" #include "ostream.h" @@ -108,6 +109,7 @@ struct dbox_mailbox *mbox = (struct dbox_mailbox *)t->ictx.ibox; struct dbox_save_context *ctx = t->save_ctx; struct dbox_mail_header hdr; + const struct stat *st; buffer_t *file_keywords = NULL; enum mail_flags save_flags; unsigned int i, pos, left; @@ -139,7 +141,13 @@ } ctx->input = input; - if (dbox_uidlist_append_locked(ctx->append_ctx, &ctx->file) < 0) { + /* get the size of the mail to be saved, if possible */ + st = i_stream_stat(input, TRUE); + if (st != NULL && st->st_size == -1) + st = NULL; + + if (dbox_uidlist_append_locked(ctx->append_ctx, &ctx->file, + st != NULL ? st->st_size : 0) < 0) { ctx->failed = TRUE; return -1; }
--- a/src/lib-storage/index/dbox/dbox-uidlist.c Thu Jun 08 20:14:27 2006 +0300 +++ b/src/lib-storage/index/dbox/dbox-uidlist.c Thu Jun 08 21:21:12 2006 +0300 @@ -973,7 +973,8 @@ static int dbox_file_append_lock(struct dbox_uidlist_append_ctx *ctx, string_t *path, - uint32_t *file_seq_r, struct dbox_uidlist_entry **entry_r, + uoff_t mail_size, uint32_t *file_seq_r, + struct dbox_uidlist_entry **entry_r, struct dotlock **dotlock_r, bool *existing_r) { struct dbox_mailbox *mbox = ctx->uidlist->mbox; @@ -988,7 +989,8 @@ *existing_r = FALSE; for (; i < count; i++) { if (DBOX_CAN_APPEND(ctx, entries[i]->create_time, - entries[i]->file_size) && + entries[i]->file_size + + mail_size) && !dbox_uidlist_files_lookup(ctx, entries[i]->file_seq)) { *existing_r = TRUE; @@ -1054,7 +1056,7 @@ } int dbox_uidlist_append_locked(struct dbox_uidlist_append_ctx *ctx, - struct dbox_file **file_r) + struct dbox_file **file_r, uoff_t mail_size) { struct dbox_save_file *const *files, *save_file; struct dbox_uidlist_entry *entry; @@ -1072,7 +1074,8 @@ files = array_get(&ctx->files, &count); for (i = 0; i < count; i++) { if (DBOX_CAN_APPEND(ctx, files[i]->file->create_time, - files[i]->file->append_offset)) { + files[i]->file->append_offset + + mail_size)) { if (dbox_reopen_file(ctx, files[i]) < 0) return -1; @@ -1088,7 +1091,7 @@ do { if (dotlock != NULL) file_dotlock_delete(&dotlock); - if (dbox_file_append_lock(ctx, path, &file_seq, + if (dbox_file_append_lock(ctx, path, mail_size, &file_seq, &entry, &dotlock, &existing) < 0) return -1; } while ((ret = dbox_file_append(ctx, str_c(path), entry,
--- a/src/lib-storage/index/dbox/dbox-uidlist.h Thu Jun 08 20:14:27 2006 +0300 +++ b/src/lib-storage/index/dbox/dbox-uidlist.h Thu Jun 08 21:21:12 2006 +0300 @@ -31,7 +31,7 @@ Returns -1 if failed, 0 if ok. If new file is created, the file's header is already appended. */ int dbox_uidlist_append_locked(struct dbox_uidlist_append_ctx *ctx, - struct dbox_file **file_r); + struct dbox_file **file_r, uoff_t mail_size); void dbox_uidlist_append_finish_mail(struct dbox_uidlist_append_ctx *ctx, struct dbox_file *file);