]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add and use mail_stream_access_start()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 29 Nov 2021 17:32:09 +0000 (18:32 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 21 Dec 2021 10:06:58 +0000 (10:06 +0000)
This replaces setting mail_stream_accessed directly.

src/lib-storage/index/dbox-multi/mdbox-mail.c
src/lib-storage/index/dbox-single/sdbox-mail.c
src/lib-storage/index/imapc/imapc-mail-fetch.c
src/lib-storage/index/imapc/imapc-save.c
src/lib-storage/index/index-mail.c
src/lib-storage/index/maildir/maildir-mail.c
src/lib-storage/index/mbox/mbox-mail.c
src/lib-storage/index/pop3c/pop3c-mail.c
src/lib-storage/index/raw/raw-mail.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail.c

index 22f46427bbda06520b972e910671d8eff21a281c..ed3fe064fe56787068d0c05e0ed0e03b8eef2781 100644 (file)
@@ -99,11 +99,8 @@ int mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
        uint32_t prev_file_id = 0, map_uid = 0;
        bool deleted;
 
-       if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
-               mail_set_aborted(_mail);
+       if (!mail_stream_access_start(_mail))
                return -1;
-       }
-       _mail->mail_stream_accessed = TRUE;
 
        do {
                if (mail->open_file != NULL) {
index 380fddf28626ca49bdf8ba57a309bcfd9f1ce84f..3b0352ca99b4d0e38ab5a6b0a2507f647c42e96d 100644 (file)
@@ -121,11 +121,8 @@ int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
        bool deleted;
        int ret;
 
-       if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
-               mail_set_aborted(_mail);
+       if (!mail_stream_access_start(_mail))
                return -1;
-       }
-       _mail->mail_stream_accessed = TRUE;
 
        ret = sdbox_mail_file_set(mail);
        if (ret < 0)
index 1aaa4f58e3d45b68c237c67c4f3ca0d6ebc1e372..222237829adf07df8a0f6fcadfd071d45d3fba62 100644 (file)
@@ -213,11 +213,8 @@ imapc_mail_send_fetch(struct mail *_mail, enum mail_fetch_field fields,
        i_assert(headers == NULL ||
                 IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_FETCH_HEADERS));
 
-       if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
-               mail_set_aborted(_mail);
+       if (!mail_stream_access_start(_mail))
                return -1;
-       }
-       _mail->mail_stream_accessed = TRUE;
 
        /* drop any fields that we may already be fetching currently */
        fields &= ENUM_NEGATE(mail->fetching_fields);
@@ -328,6 +325,9 @@ static void imapc_mail_cache_get(struct imapc_mail *mail,
        }
        mail->header_fetched = TRUE;
        mail->body_fetched = TRUE;
+       /* The stream was already accessed and now it's cached.
+          It still needs to be set accessed to avoid assert-crash. */
+       mail->imail.mail.mail.mail_stream_accessed = TRUE;
        imapc_mail_init_stream(mail);
 }
 
index 4d15b0cdcd097a1ccbd0df603cfcee7ffb0e02db..4971dd53cc4859f8c5f92d2d6340ba91e1389370 100644 (file)
@@ -152,6 +152,9 @@ imapc_save_add_to_index(struct imapc_save_context *ctx, uint32_t uid)
                imail->data.stream = i_stream_create_fd_autoclose(&ctx->fd, 0);
                imapc_mail->header_fetched = TRUE;
                imapc_mail->body_fetched = TRUE;
+               /* The saved stream wasn't actually read, but it needs to be
+                  set accessed to avoid assert-crash. */
+               _mail->mail_stream_accessed = TRUE;
                imapc_mail_init_stream(imapc_mail);
        }
 
index d62ff4a7cfc498d76beaef8be16a325ef8be340b..9902cd148cf0e727c0639ba2be1ac404f24290d4 100644 (file)
@@ -1350,7 +1350,7 @@ int index_mail_init_stream(struct index_mail *mail,
        bool has_nuls, body_size_from_stream = FALSE;
        int ret;
 
-       _mail->mail_stream_accessed = TRUE;
+       i_assert(_mail->mail_stream_accessed);
 
        if (!data->initialized_wrapper_stream &&
            _mail->transaction->stats_track) {
index ed20f8656f9f8ec04cbb89b4b5fe8f397983cd18..bdc8adf4fe692e298c7d16e381a213fe3f9c7d33 100644 (file)
@@ -68,11 +68,8 @@ maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail,
 
        *deleted_r = FALSE;
 
-       if (mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
-               mail_set_aborted(mail);
+       if (!mail_stream_access_start(mail))
                return NULL;
-       }
-       mail->mail_stream_accessed = TRUE;
 
        ctx.fd = -1;
        ctx.path = NULL;
index 53e1499309da1c524c3ebd94e166fb6216e5b2e0..09223b018140c650f2adc6ee27790305f0be1969 100644 (file)
@@ -41,11 +41,8 @@ static int mbox_mail_seek(struct index_mail *mail)
        if (_mail->expunged || mbox->syncing)
                return -1;
 
-       if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
-               mail_set_aborted(_mail);
+       if (!mail_stream_access_start(_mail))
                return -1;
-       }
-       _mail->mail_stream_accessed = TRUE;
 
        if (mbox->mbox_stream != NULL &&
            istream_raw_mbox_is_corrupted(mbox->mbox_stream)) {
index 3b660745dcd21f3bb0c5efbf4a6932199f5757f3..27a842758d8c0d1d44c8589cbf539d030850bd79 100644 (file)
@@ -146,8 +146,8 @@ static bool pop3c_mail_prefetch(struct mail *_mail)
        const char *cmd;
 
        if (pmail->imail.data.access_part != 0 &&
-           pmail->imail.data.stream == NULL) {
-               _mail->mail_stream_accessed = TRUE;
+           pmail->imail.data.stream == NULL &&
+           mail_stream_access_start(_mail)) {
                capa = pop3c_client_get_capabilities(mbox->client);
                pmail->prefetching_body = (capa & POP3C_CAPABILITY_TOP) == 0 ||
                        (pmail->imail.data.access_part & (READ_BODY | PARSE_BODY)) != 0;
@@ -207,11 +207,8 @@ pop3c_mail_get_stream(struct mail *_mail, bool get_body,
        }
 
        if (mail->data.stream == NULL) {
-               if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
-                       mail_set_aborted(_mail);
+               if (!mail_stream_access_start(_mail))
                        return -1;
-               }
-               _mail->mail_stream_accessed = TRUE;
                capa = pop3c_client_get_capabilities(mbox->client);
                if (get_body || (capa & POP3C_CAPABILITY_TOP) == 0) {
                        cmd = t_strdup_printf("RETR %u\r\n", _mail->seq);
index 2e9033ae3100561e4cbf651c08fa6265a2a058d1..b388023a234e870e374dcfea31e425ff1e4bd5ba 100644 (file)
@@ -85,11 +85,8 @@ raw_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED,
        struct index_mail *mail = INDEX_MAIL(_mail);
 
        if (mail->data.stream == NULL) {
-               if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
-                       mail_set_aborted(_mail);
+               if (!mail_stream_access_start(_mail))
                        return -1;
-               }
-               _mail->mail_stream_accessed = TRUE;
                /* we can't just reference mbox->input, because
                   index_mail_close() expects to be able to free the stream */
                mail->data.stream =
index 846e2b155b13cefe8a2b99590374239a64285991..32369b0c3dfc09543edad04974fbbec3bb4bbd73 100644 (file)
@@ -827,6 +827,9 @@ bool mail_has_attachment_keywords(struct mail *mail);
    and 1 if attachment was found. */
 int mail_set_attachment_keywords(struct mail *mail);
 
+/* Attempt to start accessing the mail stream. Returns TRUE is ok, FALSE if
+   prevented by mail->lookup_abort. */
+bool mail_stream_access_start(struct mail *mail);
 /* Emit mail opened events */
 void mail_opened_event(struct mail *mail);
 
index dcc404d30a3f5b27e7c9038cf02ef91ffc1da0fb..4ae559cdb5926259f70c7839d697ca80c0b2aec2 100644 (file)
@@ -639,6 +639,16 @@ int mail_set_attachment_keywords(struct mail *mail)
        return ret;
 }
 
+bool mail_stream_access_start(struct mail *mail)
+{
+       if (mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
+               mail_set_aborted(mail);
+               return FALSE;
+       }
+       mail->mail_stream_accessed = TRUE;
+       return TRUE;
+}
+
 void mail_opened_event(struct mail *mail)
 {
        struct mail_private *pmail =