dovecot-2.0: Mailbox saving: Allow setting IMAP UID, POP3 UIDL a...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jun 30 05:04:31 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/49f736dce881
changeset: 9554:49f736dce881
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 29 21:54:16 2009 -0400
description:
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Most of them aren't yet implemented by backends.

diffstat:

6 files changed, 42 insertions(+), 4 deletions(-)
src/lib-storage/index/dbox/dbox-save.c       |    2 +-
src/lib-storage/index/index-storage.c        |    3 ++-
src/lib-storage/index/maildir/maildir-save.c |    8 ++++++++
src/lib-storage/mail-storage-private.h       |    5 +++--
src/lib-storage/mail-storage.c               |   18 ++++++++++++++++++
src/lib-storage/mail-storage.h               |   10 ++++++++++

diffs (133 lines):

diff -r be220a26fc5e -r 49f736dce881 src/lib-storage/index/dbox/dbox-save.c
--- a/src/lib-storage/index/dbox/dbox-save.c	Mon Jun 29 21:53:16 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-save.c	Mon Jun 29 21:54:16 2009 -0400
@@ -83,7 +83,7 @@ static void dbox_save_add_to_index(struc
 	enum mail_flags save_flags;
 
 	save_flags = ctx->ctx.flags & ~MAIL_RECENT;
-	mail_index_append(ctx->trans, 0, &ctx->seq);
+	mail_index_append(ctx->trans, ctx->ctx.uid, &ctx->seq);
 	mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE,
 				save_flags);
 	if (ctx->ctx.keywords != NULL) {
diff -r be220a26fc5e -r 49f736dce881 src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Mon Jun 29 21:53:16 2009 -0400
+++ b/src/lib-storage/index/index-storage.c	Mon Jun 29 21:54:16 2009 -0400
@@ -663,4 +663,5 @@ void index_save_context_free(struct mail
 {
 	i_free_and_null(ctx->from_envelope);
 	i_free_and_null(ctx->guid);
-}
+	i_free_and_null(ctx->pop3_uidl);
+}
diff -r be220a26fc5e -r 49f736dce881 src/lib-storage/index/maildir/maildir-save.c
--- a/src/lib-storage/index/maildir/maildir-save.c	Mon Jun 29 21:53:16 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-save.c	Mon Jun 29 21:54:16 2009 -0400
@@ -455,6 +455,14 @@ static int maildir_save_finish_real(stru
 				"o_stream_flush(%s) failed: %m", path);
 		}
 		ctx->failed = TRUE;
+	}
+
+	if (_ctx->save_date != (time_t)-1) {
+		/* we can't change ctime, but we can add the date to cache */
+		struct index_mail *mail = (struct index_mail *)_ctx->dest_mail;
+		uint32_t t = _ctx->save_date;
+
+		index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
 	}
 
 	if (ctx->ctx.received_date != (time_t)-1) {
diff -r be220a26fc5e -r 49f736dce881 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Mon Jun 29 21:53:16 2009 -0400
+++ b/src/lib-storage/mail-storage-private.h	Mon Jun 29 21:54:16 2009 -0400
@@ -385,10 +385,11 @@ struct mail_save_context {
 	enum mail_flags flags;
 	struct mail_keywords *keywords;
 
-	time_t received_date;
+	time_t received_date, save_date;
 	int received_tz_offset;
 
-	char *guid, *from_envelope;
+	uint32_t uid;
+	char *guid, *pop3_uidl, *from_envelope;
 	struct ostream *output;
 };
 
diff -r be220a26fc5e -r 49f736dce881 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Mon Jun 29 21:53:16 2009 -0400
+++ b/src/lib-storage/mail-storage.c	Mon Jun 29 21:54:16 2009 -0400
@@ -920,6 +920,7 @@ mailbox_save_alloc(struct mailbox_transa
 
 	ctx = t->box->v.save_alloc(t);
 	ctx->received_date = (time_t)-1;
+	ctx->save_date = (time_t)-1;
 	return ctx;
 }
 
@@ -951,6 +952,12 @@ void mailbox_save_set_received_date(stru
 	ctx->received_tz_offset = timezone_offset;
 }
 
+void mailbox_save_set_save_date(struct mail_save_context *ctx,
+				time_t save_date)
+{
+	ctx->save_date = save_date;
+}
+
 void mailbox_save_set_from_envelope(struct mail_save_context *ctx,
 				    const char *envelope)
 {
@@ -958,12 +965,23 @@ void mailbox_save_set_from_envelope(stru
 	ctx->from_envelope = i_strdup(envelope);
 }
 
+void mailbox_save_set_uid(struct mail_save_context *ctx, uint32_t uid)
+{
+	ctx->uid = uid;
+}
+
 void mailbox_save_set_guid(struct mail_save_context *ctx, const char *guid)
 {
 	i_assert(guid == NULL || *guid != '\0');
 
 	i_free(ctx->guid);
 	ctx->guid = i_strdup(guid);
+}
+
+void mailbox_save_set_pop3_uidl(struct mail_save_context *ctx, const char *uidl)
+{
+	i_free(ctx->pop3_uidl);
+	ctx->pop3_uidl = i_strdup(uidl);
 }
 
 void mailbox_save_set_dest_mail(struct mail_save_context *ctx,
diff -r be220a26fc5e -r 49f736dce881 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h	Mon Jun 29 21:53:16 2009 -0400
+++ b/src/lib-storage/mail-storage.h	Mon Jun 29 21:54:16 2009 -0400
@@ -508,14 +508,24 @@ void mailbox_save_copy_flags(struct mail
    backend doesn't support storing it. */
 void mailbox_save_set_received_date(struct mail_save_context *ctx,
 				    time_t received_date, int timezone_offset);
+/* Set the "message saved" date. This should be set only when you're
+   replicating/restoring an existing mailbox. */
+void mailbox_save_set_save_date(struct mail_save_context *ctx,
+				time_t save_date);
 /* Set the envelope sender. This is currently used only with mbox files to
    specify the address in From_-line. */
 void mailbox_save_set_from_envelope(struct mail_save_context *ctx,
 				    const char *envelope);
+/* Set message's UID. If UID is smaller than the current next_uid, it's given
+   a new UID anyway. */
+void mailbox_save_set_uid(struct mail_save_context *ctx, uint32_t uid);
 /* Set globally unique ID for the saved mail. A new GUID is generated by
    default. This function should usually be called only when copying an
    existing mail (or restoring a mail from backup). */
 void mailbox_save_set_guid(struct mail_save_context *ctx, const char *guid);
+/* Set message's POP3 UIDL, if the backend supports it. */
+void mailbox_save_set_pop3_uidl(struct mail_save_context *ctx,
+				const char *uidl);
 /* If dest_mail is set, the saved message can be accessed using it. Note that
    setting it may require mailbox syncing, so don't set it unless you need
    it. Also you shouldn't try to access it before mailbox_save_finish() is


More information about the dovecot-cvs mailing list