]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mail.access_type
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Feb 2017 17:29:03 +0000 (19:29 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 19 Feb 2017 20:07:40 +0000 (22:07 +0200)
src/lib-storage/index/index-search.c
src/lib-storage/index/index-sort.c
src/lib-storage/mail-storage.h

index fef38dd8bade8c7308e4c5335781755a74390a23..cfb52170cc70fe4dc2d35b96da280ed46426417c 100644 (file)
@@ -1591,9 +1591,14 @@ static int search_more_with_mail(struct index_search_context *ctx,
                mail_set_seq(mail, _ctx->seq);
 
                ctx->cur_mail = mail;
+               /* mail's access_type is SEARCH only while using it to process
+                  the search query. afterwards the mail can still be accessed
+                  for fetching. */
+               ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_SEARCH;
                T_BEGIN {
                        match = search_match_next(ctx);
                } T_END;
+               ctx->cur_mail->access_type = MAIL_ACCESS_TYPE_DEFAULT;
                ctx->cur_mail = NULL;
 
                i_assert(imail->data.search_results == NULL);
index 452395a6185efb7d8b59999f0c10ab05965085b3..2f0df428874bd478eb04ef395f05a228d5df7e01 100644 (file)
@@ -170,6 +170,7 @@ void index_sort_list_add(struct mail_search_sort_program *program,
                         struct mail *mail)
 {
        enum mail_lookup_abort orig_abort = mail->lookup_abort;
+       enum mail_access_type orig_access_type = mail->access_type;
        bool prev_slow = mail->mail_stream_opened ||
                mail->mail_metadata_accessed;
 
@@ -177,9 +178,13 @@ void index_sort_list_add(struct mail_search_sort_program *program,
 
        if (program->slow_mails_left == 0)
                mail->lookup_abort = MAIL_LOOKUP_ABORT_NOT_IN_CACHE;
+
+       mail->access_type = MAIL_ACCESS_TYPE_SORT;
        T_BEGIN {
                program->sort_list_add(program, mail);
        } T_END;
+       mail->access_type = orig_access_type;
+
        if (!prev_slow && (mail->mail_stream_opened ||
                           mail->mail_metadata_accessed)) {
                i_assert(program->slow_mails_left > 0);
@@ -308,6 +313,7 @@ index_sort_program_init(struct mailbox_transaction_context *t,
        program = i_new(struct mail_search_sort_program, 1);
        program->t = t;
        program->temp_mail = mail_alloc(t, 0, NULL);
+       program->temp_mail->access_type = MAIL_ACCESS_TYPE_SORT;
 
        program->slow_mails_left =
                program->t->box->storage->set->mail_sort_max_read_count;
index 0d8f05b09ada50dc20cb64846d06501c9aa00874..06207e8dcf826e74324220c30eec6ee1a672d65d 100644 (file)
@@ -373,6 +373,14 @@ enum mail_lookup_abort {
        MAIL_LOOKUP_ABORT_NOT_IN_CACHE
 };
 
+enum mail_access_type {
+       MAIL_ACCESS_TYPE_DEFAULT = 0,
+       /* Mail is being used for searching */
+       MAIL_ACCESS_TYPE_SEARCH,
+       /* Mail is being used for sorting results */
+       MAIL_ACCESS_TYPE_SORT,
+};
+
 struct mail {
        /* always set */
        struct mailbox *box;
@@ -394,6 +402,8 @@ struct mail {
           MAIL_LOOKUP_ABORT_NOT_IN_CACHE, this can't become TRUE. */
        bool mail_metadata_accessed:1;
 
+       enum mail_access_type access_type;
+
        /* If the lookup is aborted, error is set to MAIL_ERROR_NOTPOSSIBLE */
        enum mail_lookup_abort lookup_abort;
 };