]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Set FETCH transactions hidden only when \Seen flags are implicitly set
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 5 May 2017 09:35:23 +0000 (12:35 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 5 May 2017 09:35:23 +0000 (12:35 +0300)
This simplifies implementing some plugins and has no downsides to core
functionality.

src/imap/imap-fetch.c

index e17c6c7e35ffd8b0ee1588cbfb981394348c1d3a..901cf82a276c5ab629523d84297380b7ba8c0b74 100644 (file)
@@ -351,6 +351,8 @@ static void imap_fetch_init(struct imap_fetch_context *ctx)
 void imap_fetch_begin(struct imap_fetch_context *ctx, struct mailbox *box,
                      struct mail_search_args *search_args)
 {
+       enum mailbox_transaction_flags trans_flags =
+               MAILBOX_TRANSACTION_FLAG_REFRESH;
        struct mailbox_header_lookup_ctx *wanted_headers = NULL;
        const char *const *headers;
 
@@ -370,9 +372,18 @@ void imap_fetch_begin(struct imap_fetch_context *ctx, struct mailbox *box,
                             array_count(&ctx->all_headers)-1, 1);
        }
 
-       ctx->state.trans = mailbox_transaction_begin(box,
-               MAILBOX_TRANSACTION_FLAG_HIDE |
-               MAILBOX_TRANSACTION_FLAG_REFRESH);
+       if (ctx->flags_update_seen) {
+               /* Hide the implicit \Seen flag addition. Otherwise a separate
+                  untagged FETCH FLAGS (\Seen) would be sent on top of the
+                  one FLAGS (\Seen) already added in the main FETCH reply.
+
+                  We don't set this always, because some plugins might want
+                  to do their own flag changes which we don't want hidden.
+                  (Of course this isn't perfect since if implicit \Seen flags
+                  are added, other flag changes are also hidden.) */
+               trans_flags |= MAILBOX_TRANSACTION_FLAG_HIDE;
+       }
+       ctx->state.trans = mailbox_transaction_begin(box, trans_flags);
        mailbox_transaction_set_reason(ctx->state.trans, ctx->reason);
 
        mail_search_args_init(search_args, box, TRUE,