changeset 9358:dc66872f1856 HEAD

dbox: Allow getting streams to messages being saved.
author Timo Sirainen <tss@iki.fi>
date Sun, 06 Sep 2009 18:32:03 -0400
parents 56e619176787
children 6debbb31df39
files src/lib-storage/index/dbox/dbox-mail.c src/lib-storage/index/dbox/dbox-save.c src/lib-storage/index/dbox/dbox-storage.h
diffstat 3 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-mail.c	Sun Sep 06 17:19:00 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Sun Sep 06 18:32:03 2009 -0400
@@ -47,16 +47,25 @@
 			    uoff_t *offset_r, struct dbox_file **file_r)
 {
 	struct dbox_mailbox *mbox = (struct dbox_mailbox *)mail->imail.ibox;
+	struct mail *_mail = &mail->imail.mail.mail;
 	unsigned int file_id;
 
-	if (mail->open_file == NULL) {
-		if (!dbox_file_lookup(mbox, mbox->ibox.view,
-				      mail->imail.mail.mail.seq,
+	if (mail->open_file != NULL) {
+		/* already open */
+	} else if (_mail->uid != 0) {
+		if (!dbox_file_lookup(mbox, mbox->ibox.view, _mail->seq,
 				      &file_id, &mail->offset)) {
-			mail_set_expunged(&mail->imail.mail.mail);
+			mail_set_expunged(_mail);
 			return -1;
 		}
 		mail->open_file = dbox_file_init(mbox, file_id);
+	} else {
+		/* mail is being saved in this transaction */
+		mail->open_file = dbox_save_file_get_file(_mail->transaction,
+							  _mail->seq,
+							  &mail->offset);
+		mail->open_file->refcount++;
+
 	}
 
 	*file_r = mail->open_file;
--- a/src/lib-storage/index/dbox/dbox-save.c	Sun Sep 06 17:19:00 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-save.c	Sun Sep 06 18:32:03 2009 -0400
@@ -48,6 +48,27 @@
 	unsigned int finished:1;
 };
 
+struct dbox_file *
+dbox_save_file_get_file(struct mailbox_transaction_context *_t,
+			uint32_t seq, uoff_t *offset_r)
+{
+	struct dbox_transaction_context *t =
+		(struct dbox_transaction_context *)_t;
+	struct dbox_save_context *ctx = t->save_ctx;
+	const struct dbox_save_mail *mails, *mail;
+	unsigned int count;
+
+	mails = array_get(&ctx->mails, &count);
+	i_assert(count > 0);
+	i_assert(seq >= mails[0].seq);
+
+	mail = &mails[mails[0].seq - seq];
+	i_assert(mail->seq == seq);
+
+	*offset_r = mail->append_offset;
+	return mail->file;
+}
+
 static void dbox_save_keywords(struct dbox_save_context *ctx,
 			       struct mail_keywords *keywords)
 {
--- a/src/lib-storage/index/dbox/dbox-storage.h	Sun Sep 06 17:19:00 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-storage.h	Sun Sep 06 18:32:03 2009 -0400
@@ -93,6 +93,10 @@
 int dbox_save_finish(struct mail_save_context *ctx);
 void dbox_save_cancel(struct mail_save_context *ctx);
 
+struct dbox_file *
+dbox_save_file_get_file(struct mailbox_transaction_context *_t,
+			uint32_t seq, uoff_t *offset_r);
+
 int dbox_transaction_save_commit_pre(struct dbox_save_context *ctx);
 void dbox_transaction_save_commit_post(struct dbox_save_context *ctx);
 void dbox_transaction_save_rollback(struct dbox_save_context *ctx);