]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Remove unnecessary mail_save_context.dest_mail==NULL checks
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 9 Feb 2017 15:14:57 +0000 (17:14 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Feb 2017 09:32:31 +0000 (11:32 +0200)
It can never be NULL after the previous change: "lib-storage: Always create
mail_save_context.dest_mail".

The code removal in maildir_transaction_save_commit_pre() seemed
potentially dangerous, but I don't think such code path is possible
anymore. Also even if it is, it's probably fine since the mail_free()
is called even earlier than before (although that itself might have
been a problem).

This also removes last traces of code that made it possible to save mails to
mbox without assigning UID to the mail. The previous commit already caused
this, so this is just removing dead code.

13 files changed:
src/lib-storage/index/cydir/cydir-save.c
src/lib-storage/index/dbox-common/dbox-save.c
src/lib-storage/index/dbox-common/dbox-save.h
src/lib-storage/index/dbox-multi/mdbox-save.c
src/lib-storage/index/dbox-single/sdbox-copy.c
src/lib-storage/index/dbox-single/sdbox-save.c
src/lib-storage/index/imapc/imapc-save.c
src/lib-storage/index/index-mail.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/maildir/maildir-save.c
src/lib-storage/index/mbox/mbox-save.c
src/lib-storage/index/mbox/mbox-sync-private.h
src/lib-storage/index/mbox/mbox-sync.c

index 93970c9996b76bf618762315f7d4e22b63890ea4..63307f7ac4afa0e1adedbefeade381a66ba15103 100644 (file)
@@ -28,7 +28,6 @@ struct cydir_save_context {
        /* updated for each appended mail: */
        uint32_t seq;
        struct istream *input;
-       struct mail *mail;
        int fd;
 
        unsigned int failed:1;
@@ -115,11 +114,6 @@ int cydir_save_begin(struct mail_save_context *_ctx, struct istream *input)
                                         _ctx->data.min_modseq);
        }
 
-       if (_ctx->dest_mail == NULL) {
-               if (ctx->mail == NULL)
-                       ctx->mail = mail_alloc(trans, 0, NULL);
-               _ctx->dest_mail = ctx->mail;
-       }
        mail_set_seq_saving(_ctx->dest_mail, ctx->seq);
 
        crlf_input = i_stream_create_crlf(input);
@@ -291,9 +285,6 @@ int cydir_transaction_save_commit_pre(struct mail_save_context *_ctx)
                        return -1;
                }
        }
-
-       if (ctx->mail != NULL)
-               mail_free(&ctx->mail);
        return 0;
 }
 
@@ -321,8 +312,6 @@ void cydir_transaction_save_rollback(struct mail_save_context *_ctx)
        if (ctx->sync_ctx != NULL)
                (void)cydir_sync_finish(&ctx->sync_ctx, FALSE);
 
-       if (ctx->mail != NULL)
-               mail_free(&ctx->mail);
        i_free(ctx->tmp_basename);
        i_free(ctx);
 }
index 89927bd2878bc8d042b94d6e742f5879de8dffda..3647a1e0c93f4b86d34e15204f03247ce634235a 100644 (file)
@@ -44,11 +44,6 @@ void dbox_save_begin(struct dbox_save_context *ctx, struct istream *input)
 
        dbox_save_add_to_index(ctx);
 
-       if (_ctx->dest_mail == NULL) {
-               if (ctx->mail == NULL)
-                       ctx->mail = mail_alloc(_ctx->transaction, 0, NULL);
-               _ctx->dest_mail = ctx->mail;
-       }
        mail_set_seq_saving(_ctx->dest_mail, ctx->seq);
 
        crlf_input = i_stream_create_lf(input);
index 9d5f17333c939c36b24d446ecb11a33995bc9c7c..09a0e33da1467fcd88ae7f98b7c1b178e8f1f939 100644 (file)
@@ -10,7 +10,6 @@ struct dbox_save_context {
        /* updated for each appended mail: */
        uint32_t seq;
        struct istream *input;
-       struct mail *mail;
 
        struct ostream *dbox_output;
 
index caa0ff6da9383bdd921469e1549ea841dfeaa943..db50757cdd269b6025af9c84a3441276d91029e5 100644 (file)
@@ -361,9 +361,6 @@ int mdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
                mail_index_sync_set_reason(ctx->sync_ctx->index_sync_ctx, "saving");
        }
 
-       if (ctx->ctx.mail != NULL)
-               mail_free(&ctx->ctx.mail);
-
        _t->changes->uid_validity = hdr->uid_validity;
        return 0;
 }
@@ -424,8 +421,6 @@ void mdbox_transaction_save_rollback(struct mail_save_context *_ctx)
        if (ctx->sync_ctx != NULL)
                (void)mdbox_sync_finish(&ctx->sync_ctx, FALSE);
 
-       if (ctx->ctx.mail != NULL)
-               mail_free(&ctx->ctx.mail);
        array_free(&ctx->mails);
        i_free(ctx);
 }
@@ -485,8 +480,7 @@ int mdbox_copy(struct mail_save_context *_ctx, struct mail *mail)
        save_mail = array_append_space(&ctx->mails);
        save_mail->seq = ctx->ctx.seq;
 
-       if (_ctx->dest_mail != NULL)
-               mail_set_seq_saving(_ctx->dest_mail, ctx->ctx.seq);
+       mail_set_seq_saving(_ctx->dest_mail, ctx->ctx.seq);
        index_save_context_free(_ctx);
        return 0;
 }
index ea76b30d256526843b3b68ef9ede1566c91ba246..e03a0a868d336dc870103573ce50511730239054 100644 (file)
@@ -155,8 +155,7 @@ sdbox_copy_hardlink(struct mail_save_context *_ctx, struct mail *mail)
        index_copy_cache_fields(_ctx, mail, ctx->seq);
 
        sdbox_save_add_file(_ctx, dest_file);
-       if (_ctx->dest_mail != NULL)
-               mail_set_seq_saving(_ctx->dest_mail, ctx->seq);
+       mail_set_seq_saving(_ctx->dest_mail, ctx->seq);
        dbox_file_unref(&src_file);
        return 1;
 }
index 6f46161ece6aa4ef362db8597dfb9cac5a92d04e..95ff5c256c9df729261267c6cea2c10941063c77 100644 (file)
@@ -307,8 +307,6 @@ int sdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
 
        if (array_count(&ctx->files) == 0) {
                /* the mail must be freed in the commit_pre() */
-               if (ctx->ctx.mail != NULL)
-                       mail_free(&ctx->ctx.mail);
                return 0;
        }
 
@@ -340,9 +338,6 @@ int sdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
                }
        }
 
-       if (ctx->ctx.mail != NULL)
-               mail_free(&ctx->ctx.mail);
-
        _t->changes->uid_validity = hdr->uid_validity;
        return 0;
 }
@@ -387,8 +382,5 @@ void sdbox_transaction_save_rollback(struct mail_save_context *_ctx)
 
        if (ctx->sync_ctx != NULL)
                (void)sdbox_sync_finish(&ctx->sync_ctx, FALSE);
-
-       if (ctx->ctx.mail != NULL)
-               mail_free(&ctx->ctx.mail);
        i_free(ctx);
 }
index 577419c908a1b9e392b34e50298ba5652b96cecd..888a0fd3dbc250ce3efea1963dd9e9010bf2a5f7 100644 (file)
@@ -141,9 +141,6 @@ imapc_save_add_to_index(struct imapc_save_context *ctx, uint32_t uid)
        struct index_mail *imail = (struct index_mail *)_mail;
        uint32_t seq;
 
-       if (_mail == NULL)
-               return;
-
        /* we'll temporarily append messages and at commit time expunge
           them all, since we can't guarantee that no one else has saved
           messages to remote server during our transaction */
index 4a62ca7603d1ad31e410bf35c8c4c48d03362101..3a1b477ffbe9985e15eaf3603beb97e41a98a846 100644 (file)
@@ -2307,9 +2307,6 @@ void index_mail_save_finish(struct mail_save_context *ctx)
 {
        struct index_mail *imail = (struct index_mail *)ctx->dest_mail;
 
-       if (imail == NULL)
-               return;
-
        if (ctx->data.from_envelope != NULL &&
            imail->data.from_envelope == NULL) {
                imail->data.from_envelope =
index 9b808e60142336140c24c5b33a8d7793ebd7c947..1f0c070858d1299a0b45cfc666bc3ccab3083f2c 100644 (file)
@@ -878,9 +878,8 @@ mail_copy_cache_field(struct mail_save_context *ctx, struct mail *src_mail,
                if (mail_cache_lookup_field(src_mail->transaction->cache_view, buf,
                                            src_mail->seq, src_field_idx) <= 0)
                        buffer_set_used_size(buf, 0);
-               else if (ctx->dest_mail != NULL &&
-                        (strcmp(name, "size.physical") == 0 ||
-                         strcmp(name, "size.virtual") == 0)) {
+               else if (strcmp(name, "size.physical") == 0 ||
+                        strcmp(name, "size.virtual") == 0) {
                        /* FIXME: until mail_cache_lookup() can read unwritten
                           cached data from buffer, we'll do this optimization
                           to make quota plugin's work faster */
index 0da1d0cac545f6db2fdca1ae3f4989c7e04aea98..92c958c32a2d8d81c55047af908343b592e4bcce 100644 (file)
@@ -48,7 +48,7 @@ struct maildir_save_context {
        struct maildir_uidlist_sync_ctx *uidlist_sync_ctx;
        struct maildir_keywords_sync_ctx *keywords_sync_ctx;
        struct maildir_index_sync_context *sync_ctx;
-       struct mail *mail, *cur_dest_mail;
+       struct mail *cur_dest_mail;
 
        const char *tmpdir, *newdir, *curdir;
        struct maildir_filename *files, **files_tail, *file_last;
@@ -208,11 +208,6 @@ maildir_save_add(struct mail_save_context *_ctx, const char *tmp_fname,
                i_assert(ctx->files->next == NULL);
        }
 
-       if (_ctx->dest_mail == NULL) {
-               if (ctx->mail == NULL)
-                       ctx->mail = mail_alloc(_ctx->transaction, 0, NULL);
-               _ctx->dest_mail = ctx->mail;
-       }
        mail_set_seq_saving(_ctx->dest_mail, ctx->seq);
 
        if (ctx->input == NULL) {
@@ -981,12 +976,8 @@ int maildir_transaction_save_commit_pre(struct mail_save_context *_ctx)
        i_assert(_ctx->data.output == NULL);
        i_assert(ctx->last_save_finished);
 
-       if (ctx->files_count == 0) {
-               /* the mail must be freed in the commit_pre() */
-               if (ctx->mail != NULL)
-                       mail_free(&ctx->mail);
+       if (ctx->files_count == 0)
                return 0;
-       }
 
        sync_flags = MAILDIR_UIDLIST_SYNC_PARTIAL |
                MAILDIR_UIDLIST_SYNC_NOREFRESH;
@@ -1041,13 +1032,6 @@ int maildir_transaction_save_commit_pre(struct mail_save_context *_ctx)
        _t->changes->uid_validity =
                maildir_uidlist_get_uid_validity(ctx->mbox->uidlist);
 
-       if (ctx->mail != NULL) {
-               /* Mail freeing may trigger cache updates and a call to
-                  maildir_save_file_get_path(). Do this before finishing index
-                  sync so we still have keywords_sync_ctx. */
-               mail_free(&ctx->mail);
-       }
-
        if (ctx->locked) {
                /* It doesn't matter if index syncing fails */
                ctx->keywords_sync_ctx = NULL;
@@ -1109,7 +1093,5 @@ void maildir_transaction_save_rollback(struct mail_save_context *_ctx)
        if (ctx->locked)
                maildir_uidlist_unlock(ctx->mbox->uidlist);
 
-       if (ctx->mail != NULL)
-               mail_free(&ctx->mail);
        pool_unref(&ctx->pool);
 }
index 6bcdf81c4b75c6378b2ff2541a048b8171f89627..95e33e829df720becf6df2f1f30b2a45cd029670 100644 (file)
@@ -36,7 +36,6 @@ struct mbox_save_context {
 
        struct mbox_mailbox *mbox;
        struct mail_index_transaction *trans;
-       struct mail *mail;
        uoff_t append_offset, mail_offset;
        time_t orig_atime;
 
@@ -269,12 +268,11 @@ mbox_save_append_keyword_headers(struct mbox_save_context *ctx,
 
 static int
 mbox_save_init_file(struct mbox_save_context *ctx,
-                   struct mbox_transaction_context *t, bool want_mail)
+                   struct mbox_transaction_context *t)
 {
        struct mailbox_transaction_context *_t = &t->t;
        struct mbox_mailbox *mbox = ctx->mbox;
        struct mail_storage *storage = &mbox->storage->storage;
-       bool empty = FALSE;
        int ret;
 
        if (mbox_is_backend_readonly(ctx->mbox)) {
@@ -283,10 +281,6 @@ mbox_save_init_file(struct mbox_save_context *ctx,
                return -1;
        }
 
-       if ((_t->flags & MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS) != 0 ||
-           ctx->ctx.data.uid != 0)
-               want_mail = TRUE;
-
        if (ctx->append_offset == (uoff_t)-1) {
                /* first appended mail in this transaction */
                if (t->write_lock_id == 0) {
@@ -300,18 +294,12 @@ mbox_save_init_file(struct mbox_save_context *ctx,
                }
 
                /* update mbox_sync_dirty state */
-               ret = mbox_sync_has_changed_full(mbox, TRUE, &empty);
+               ret = mbox_sync_has_changed(mbox, TRUE);
                if (ret < 0)
                        return -1;
-               if (!want_mail && ret == 0) {
-                       /* we're not required to assign UIDs for the appended
-                          mails immediately. do it only if it doesn't require
-                          syncing. */
-                       mbox_save_init_sync(_t);
-               }
        }
 
-       if (!ctx->synced && (want_mail || empty)) {
+       if (!ctx->synced) {
                /* we'll need to assign UID for the mail immediately. */
                if (mbox_sync(mbox, 0) < 0)
                        return -1;
@@ -416,13 +404,10 @@ mbox_save_get_input_stream(struct mbox_save_context *ctx, struct istream *input)
                i_stream_create_crlf(filter) : i_stream_create_lf(filter);
        i_stream_unref(&filter);
 
-       if (ctx->ctx.dest_mail != NULL) {
-               /* caching creates a tee stream */
-               cache_input =
-                       index_mail_cache_parse_init(ctx->ctx.dest_mail, ret);
-               i_stream_unref(&ret);
-               ret = cache_input;
-       }
+       /* caching creates a tee stream */
+       cache_input = index_mail_cache_parse_init(ctx->ctx.dest_mail, ret);
+       i_stream_unref(&ret);
+       ret = cache_input;
        return ret;
 }
 
@@ -463,7 +448,7 @@ int mbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
        ctx->failed = FALSE;
        ctx->seq = 0;
 
-       if (mbox_save_init_file(ctx, t, _ctx->dest_mail != NULL) < 0) {
+       if (mbox_save_init_file(ctx, t) < 0) {
                ctx->failed = TRUE;
                return -1;
        }
@@ -506,13 +491,6 @@ int mbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
                ctx->next_uid++;
 
                /* parse and cache the mail headers as we read it */
-               if (_ctx->dest_mail == NULL) {
-                       if (ctx->mail == NULL) {
-                               ctx->mail = mail_alloc(_ctx->transaction,
-                                                      0, NULL);
-                       }
-                       _ctx->dest_mail = ctx->mail;
-               }
                mail_set_seq_saving(_ctx->dest_mail, ctx->seq);
        }
        mbox_save_append_flag_headers(ctx->headers, save_flags);
@@ -556,11 +534,9 @@ static int mbox_save_body(struct mbox_save_context *ctx)
        while ((ret = i_stream_read(ctx->input)) != -1) {
                if (mbox_save_body_input(ctx) < 0)
                        return -1;
-               if (ctx->ctx.dest_mail != NULL) {
-                       /* i_stream_read() may have returned 0 at EOF
-                          because of this parser */
-                       index_mail_cache_parse_continue(ctx->ctx.dest_mail);
-               }
+               /* i_stream_read() may have returned 0 at EOF
+                  because of this parser */
+               index_mail_cache_parse_continue(ctx->ctx.dest_mail);
                if (ret == 0)
                        return 0;
        }
@@ -628,8 +604,7 @@ int mbox_save_continue(struct mail_save_context *_ctx)
                i_assert(size > 0);
                ctx->last_char = data[size-1];
                i_stream_skip(ctx->input, size);
-               if (ctx->ctx.dest_mail != NULL)
-                       index_mail_cache_parse_continue(ctx->ctx.dest_mail);
+               index_mail_cache_parse_continue(ctx->ctx.dest_mail);
        }
        if (ret == 0)
                return 0;
@@ -697,11 +672,9 @@ int mbox_save_finish(struct mail_save_context *_ctx)
                } T_END;
        }
 
-       if (ctx->ctx.dest_mail != NULL) {
-               index_mail_cache_parse_deinit(ctx->ctx.dest_mail,
-                                             ctx->ctx.data.received_date,
-                                             !ctx->failed);
-       }
+       index_mail_cache_parse_deinit(ctx->ctx.dest_mail,
+                                     ctx->ctx.data.received_date,
+                                     !ctx->failed);
        if (ctx->input != NULL)
                i_stream_destroy(&ctx->input);
 
@@ -737,8 +710,6 @@ static void mbox_transaction_save_deinit(struct mbox_save_context *ctx)
 {
        if (ctx->output != NULL)
                o_stream_destroy(&ctx->output);
-       if (ctx->mail != NULL)
-               mail_free(&ctx->mail);
        str_free(&ctx->headers);
 }
 
index 275afe9d7b411ac25f7180baa65c808940aa80db..38f4b545a05d33f954077a0626a3ecdea5a1e803 100644 (file)
@@ -153,8 +153,6 @@ struct mbox_sync_context {
 int mbox_sync_header_refresh(struct mbox_mailbox *mbox);
 int mbox_sync(struct mbox_mailbox *mbox, enum mbox_sync_flags flags);
 int mbox_sync_has_changed(struct mbox_mailbox *mbox, bool leave_dirty);
-int mbox_sync_has_changed_full(struct mbox_mailbox *mbox, bool leave_dirty,
-                              bool *empty_r);
 void mbox_sync_set_critical(struct mbox_sync_context *sync_ctx,
                            const char *fmt, ...) ATTR_FORMAT(2, 3);
 
index b1ef113f0bde3968e94a54f04d75d4af7a353e68..9c29734b63795e5ec6e00b5e0c434a22b8cc80a2 100644 (file)
@@ -1730,14 +1730,6 @@ int mbox_sync_get_guid(struct mbox_mailbox *mbox)
 }
 
 int mbox_sync_has_changed(struct mbox_mailbox *mbox, bool leave_dirty)
-{
-       bool empty;
-
-       return mbox_sync_has_changed_full(mbox, leave_dirty, &empty);
-}
-
-int mbox_sync_has_changed_full(struct mbox_mailbox *mbox, bool leave_dirty,
-                              bool *empty_r)
 {
        const struct stat *st;
        struct stat statbuf;
@@ -1763,7 +1755,6 @@ int mbox_sync_has_changed_full(struct mbox_mailbox *mbox, bool leave_dirty,
                }
                st = &statbuf;
        }
-       *empty_r = st->st_size == 0;
 
        if (mbox_sync_header_refresh(mbox) < 0)
                return -1;