]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
authorTimo Sirainen <tss@iki.fi>
Tue, 30 Jun 2009 01:54:16 +0000 (21:54 -0400)
committerTimo Sirainen <tss@iki.fi>
Tue, 30 Jun 2009 01:54:16 +0000 (21:54 -0400)
Most of them aren't yet implemented by backends.

--HG--
branch : HEAD

src/lib-storage/index/dbox/dbox-save.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/maildir/maildir-save.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h

index acb5fa9fbf0fa5188ac2def52f2cfe08895a1a16..cf77f17fae9ba94a45f98fbda3cbefc4b943891b 100644 (file)
@@ -83,7 +83,7 @@ static void dbox_save_add_to_index(struct dbox_save_context *ctx)
        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) {
index aafa5d1da57b96d87dfa27752596404fecd07a8a..20784e66b8ac19d205ffae33ee3813a11fd69dab 100644 (file)
@@ -663,4 +663,5 @@ void index_save_context_free(struct mail_save_context *ctx)
 {
        i_free_and_null(ctx->from_envelope);
        i_free_and_null(ctx->guid);
+       i_free_and_null(ctx->pop3_uidl);
 }
index 1b15b0f3a4e46ffb27024ddd13c1dbc88a4de308..a489f4e81e60dda2a2136953b734c7d02cd187a4 100644 (file)
@@ -457,6 +457,14 @@ static int maildir_save_finish_real(struct mail_save_context *_ctx)
                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) {
                /* set the received_date by modifying mtime */
                buf.actime = ioloop_time;
index 12a2ba7b0a2950025325b5b2087f07ccf5175e4a..518925fd0eb42bc6f6e53de3ea8c5c152c6cbb96 100644 (file)
@@ -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;
 };
 
index 09b5f410b4093c69d91ea0621f147067d7e8e85f..3c09803015439be4e88cf92b78bfd42573ed34b4 100644 (file)
@@ -920,6 +920,7 @@ mailbox_save_alloc(struct mailbox_transaction_context *t)
 
        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(struct mail_save_context *ctx,
        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,6 +965,11 @@ void mailbox_save_set_from_envelope(struct mail_save_context *ctx,
        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');
@@ -966,6 +978,12 @@ void mailbox_save_set_guid(struct mail_save_context *ctx, const char *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,
                                struct mail *mail)
 {
index 6f3d6d90cc4f20936dd648677c12638fa31ba29c..14a5382a00f715c3a9f3b1e85661039b1e59fc0b 100644 (file)
@@ -508,14 +508,24 @@ void mailbox_save_copy_flags(struct mail_save_context *ctx, struct mail *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