Don't update a folder's unread email count during normalisation

Updating the unread count after opening a folder and finding email that
has an unexpected unread status messes up the count obtained from the
server, which has already taken these messages into account.

Here, both the main normalisation process and the email flag updater are
prevented from adjusting the unread count for a folder when they
encounter email that are new and unread, or have an unread status
different from what was last seen by the engine.

See #213
13 jobs for wip/email-flag-refinement-redux in 8 minutes and 57 seconds (queued for 1 second)
Status Job ID Name Coverage
  Build
failed #216118
fedora

00:02:56

failed #216117
ubuntu

00:06:00

failed #216101
fedora

00:03:16

failed #216107
fedora

00:11:17

failed #216095
fedora

00:09:23

failed #216116
fedora

00:02:56

failed #216102
ubuntu

00:07:58

failed #216112
ubuntu

00:02:06

failed #216096
ubuntu

00:09:43

 
  Test
skipped #216097
deb-package
skipped #216098
flatpak
 
  Deploy
skipped #216099
review
skipped #216100
allowed to fail manual
stop_review
 
Name Stage Failure
failed
fedora Build
../src/engine/imap-engine/imap-engine-batch-operations.vala:34.25-34.79: error: 1 missing arguments for `Gee.Map<Geary.Email,bool> Geary.ImapDB.Folder.create_or_merge_email_async (Gee.Collection<Geary.Email>, bool, GLib.Cancellable?)'
created = yield folder.create_or_merge_email_async(emails, cancellable);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../src/engine/util/util-js.vala:46.55-46.64: warning: JS has been deprecated since 2.22
../src/engine/util/util-js.vala:138.41-138.50: warning: JS has been deprecated since 2.22
Command-line option `--thread` is deprecated and will be ignored
Compilation failed: 2 error(s), 2 warning(s)
ninja: build stopped: subcommand failed.
ERROR: Job failed: exit code 1
failed
ubuntu Build
valac -C --debug --vapidir /builds/GNOME/geary/bindings/vapi --metadatadir /builds/GNOME/geary/bindings/metadata --pkg sqlite3 --pkg posix --pkg libxml-2.0 /builds/GNOME/geary/bindings/vapi/libunwind.vapi --pkg javascriptcoregtk-4.0 --pkg gmime-2.6 --target-glib 2.54 --pkg glib-2.0 --pkg gio-2.0 --pkg gee-0.8 --color=always --directory src/engine/src@engine@@geary-engine@sta --basedir ../src/engine --library geary-engine --header src/engine/geary-engine.h --vapi ../geary-engine.vapi --target-glib=2.54 --thread --enable-checking --internal-header=/builds/GNOME/geary/build/src/engine/geary-engine-internal.h --internal-vapi=/builds/GNOME/geary/build/src/engine/geary-engine-internal.vapi ../src/engine/api/geary.vala ../src/engine/api/geary-abstract-local-folder.vala ../src/engine/api/geary-account.vala ../src/engine/api/geary-account-information.vala ../src/engine/api/geary-aggregated-folder-properties.vala ../src/engine/api/geary-attachment.vala ../src/engine/api/geary-base-object.vala ../src/engine/api/geary-client-service.vala ../src/engine/api/geary-composed-email.vala ../src/engine/api/geary-contact.vala ../src/engine/api/geary-contact-flags.vala ../src/engine/api/geary-contact-importance.vala ../src/engine/api/geary-contact-store.vala ../src/engine/api/geary-credentials.vala ../src/engine/api/geary-credentials-mediator.vala ../src/engine/api/geary-email-flags.vala ../src/engine/api/geary-email-identifier.vala ../src/engine/api/geary-email-properties.vala ../src/engine/api/geary-email.vala ../src/engine/api/geary-endpoint.vala ../src/engine/api/geary-engine-error.vala ../src/engine/api/geary-engine.vala ../src/engine/api/geary-folder.vala ../src/engine/api/geary-folder-path.vala ../src/engine/api/geary-folder-properties.vala ../src/engine/api/geary-folder-supports-archive.vala ../src/engine/api/geary-folder-supports-copy.vala ../src/engine/api/geary-folder-supports-create.vala ../src/engine/api/geary-folder-supports-empty.vala ../src/engine/api/geary-folder-supports-mark.vala ../src/engine/api/geary-folder-supports-move.vala ../src/engine/api/geary-folder-supports-remove.vala ../src/engine/api/geary-logging.vala ../src/engine/api/geary-named-flag.vala ../src/engine/api/geary-named-flags.vala ../src/engine/api/geary-problem-report.vala ../src/engine/api/geary-progress-monitor.vala ../src/engine/api/geary-revokable.vala ../src/engine/api/geary-search-folder.vala ../src/engine/api/geary-search-query.vala ../src/engine/api/geary-service-information.vala ../src/engine/api/geary-service-provider.vala ../src/engine/api/geary-special-folder-type.vala ../src/engine/app/app-conversation.vala ../src/engine/app/app-conversation-monitor.vala ../src/engine/app/app-draft-manager.vala ../src/engine/app/app-email-store.vala ../src/engine/app/conversation-monitor/app-append-operation.vala ../src/engine/app/conversation-monitor/app-conversation-operation-queue.vala ../src/engine/app/conversation-monitor/app-conversation-operation.vala ../src/engine/app/conversation-monitor/app-conversation-set.vala ../src/engine/app/conversation-monitor/app-external-append-operation.vala ../src/engine/app/conversation-monitor/app-fill-window-operation.vala ../src/engine/app/conversation-monitor/app-insert-operation.vala ../src/engine/app/conversation-monitor/app-local-search-operation.vala ../src/engine/app/conversation-monitor/app-remove-operation.vala ../src/engine/app/conversation-monitor/app-reseed-operation.vala ../src/engine/app/conversation-monitor/app-terminate-operation.vala ../src/engine/app/email-store/app-async-folder-operation.vala ../src/engine/app/email-store/app-copy-operation.vala ../src/engine/app/email-store/app-fetch-operation.vala ../src/engine/app/email-store/app-list-operation.vala ../src/engine/app/email-store/app-mark-operation.vala ../src/engine/common/common-message-data.vala ../src/engine/db/db.vala ../src/engine/db/db-connection.vala ../src/engine/db/db-context.vala ../src/engine/db/db-database.vala ../src/engine/db/db-database-error.vala ../src/engine/db/db-result.vala ../src/engine/db/db-statement.vala ../src/engine/db/db-synchronous-mode.vala ../src/engine/db/db-transaction-async-job.vala ../src/engine/db/db-transaction-outcome.vala ../src/engine/db/db-transaction-type.vala ../src/engine/db/db-versioned-database.vala ../src/engine/imap/imap.vala ../src/engine/imap/imap-error.vala ../src/engine/imap/api/imap-account-session.vala ../src/engine/imap/api/imap-client-service.vala ../src/engine/imap/api/imap-email-flags.vala ../src/engine/imap/api/imap-email-properties.vala ../src/engine/imap/api/imap-folder.vala ../src/engine/imap/api/imap-folder-properties.vala ../src/engine/imap/api/imap-folder-root.vala ../src/engine/imap/api/imap-folder-session.vala ../src/engine/imap/api/imap-session-object.vala ../src/engine/imap/command/imap-append-command.vala ../src/engine/imap/command/imap-authenticate-command.vala ../src/engine/imap/command/imap-capability-command.vala ../src/engine/imap/command/imap-close-command.vala ../src/engine/imap/command/imap-command.vala ../src/engine/imap/command/imap-compress-command.vala ../src/engine/imap/command/imap-copy-command.vala ../src/engine/imap/command/imap-create-command.vala ../src/engine/imap/command/imap-delete-command.vala ../src/engine/imap/command/imap-examine-command.vala ../src/engine/imap/command/imap-expunge-command.vala ../src/engine/imap/command/imap-fetch-command.vala ../src/engine/imap/command/imap-id-command.vala ../src/engine/imap/command/imap-idle-command.vala ../src/engine/imap/command/imap-list-command.vala ../src/engine/imap/command/imap-list-return-parameter.vala ../src/engine/imap/command/imap-login-command.vala ../src/engine/imap/command/imap-logout-command.vala ../src/engine/imap/command/imap-message-set.vala ../src/engine/imap/command/imap-namespace-command.vala ../src/engine/imap/command/imap-noop-command.vala ../src/engine/imap/command/imap-search-command.vala ../src/engine/imap/command/imap-search-criteria.vala ../src/engine/imap/command/imap-search-criterion.vala ../src/engine/imap/command/imap-select-command.vala ../src/engine/imap/command/imap-starttls-command.vala ../src/engine/imap/command/imap-status-command.vala ../src/engine/imap/command/imap-store-command.vala ../src/engine/imap/message/imap-data-format.vala ../src/engine/imap/message/imap-envelope.vala ../src/engine/imap/message/imap-fetch-body-data-specifier.vala ../src/engine/imap/message/imap-fetch-data-specifier.vala ../src/engine/imap/message/imap-flag.vala ../src/engine/imap/message/imap-flags.vala ../src/engine/imap/message/imap-internal-date.vala ../src/engine/imap/message/imap-mailbox-specifier.vala ../src/engine/imap/message/imap-message-data.vala ../src/engine/imap/message/imap-message-flag.vala ../src/engine/imap/message/imap-message-flags.vala ../src/engine/imap/message/imap-namespace.vala ../src/engine/imap/message/imap-sequence-number.vala ../src/engine/imap/message/imap-status-data-type.vala ../src/engine/imap/message/imap-tag.vala ../src/engine/imap/message/imap-uid.vala ../src/engine/imap/message/imap-uid-validity.vala ../src/engine/imap/parameter/imap-atom-parameter.vala ../src/engine/imap/parameter/imap-list-parameter.vala ../src/engine/imap/parameter/imap-literal-parameter.vala ../src/engine/imap/parameter/imap-nil-parameter.vala ../src/engine/imap/parameter/imap-number-parameter.vala ../src/engine/imap/parameter/imap-parameter.vala ../src/engine/imap/parameter/imap-quoted-string-parameter.vala ../src/engine/imap/parameter/imap-root-parameters.vala ../src/engine/imap/parameter/imap-string-parameter.vala ../src/engine/imap/parameter/imap-unquoted-string-parameter.vala ../src/engine/imap/response/imap-capabilities.vala ../src/engine/imap/response/imap-continuation-response.vala ../src/engine/imap/response/imap-fetch-data-decoder.vala ../src/engine/imap/response/imap-fetched-data.vala ../src/engine/imap/response/imap-mailbox-attribute.vala ../src/engine/imap/response/imap-mailbox-attributes.vala ../src/engine/imap/response/imap-mailbox-information.vala ../src/engine/imap/response/imap-namespace-response.vala ../src/engine/imap/response/imap-response-code.vala ../src/engine/imap/response/imap-response-code-type.vala ../src/engine/imap/response/imap-server-data.vala ../src/engine/imap/response/imap-server-data-type.vala ../src/engine/imap/response/imap-server-response.vala ../src/engine/imap/response/imap-status.vala ../src/engine/imap/response/imap-status-data.vala ../src/engine/imap/response/imap-status-response.vala ../src/engine/imap/transport/imap-client-connection.vala ../src/engine/imap/transport/imap-client-session.vala ../src/engine/imap/transport/imap-deserializer.vala ../src/engine/imap/transport/imap-serializer.vala ../src/engine/imap-db/imap-db-account.vala ../src/engine/imap-db/imap-db-attachment.vala ../src/engine/imap-db/imap-db-contact.vala ../src/engine/imap-db/imap-db-database.vala ../src/engine/imap-db/imap-db-email-identifier.vala ../src/engine/imap-db/imap-db-folder.vala ../src/engine/imap-db/imap-db-gc.vala ../src/engine/imap-db/imap-db-message-addresses.vala ../src/engine/imap-db/imap-db-message-row.vala ../src/engine/imap-db/search/imap-db-search-email-identifier.vala ../src/engine/imap-db/search/imap-db-search-folder.vala ../src/engine/imap-db/search/imap-db-search-folder-properties.vala ../src/engine/imap-db/search/imap-db-search-query.vala ../src/engine/imap-db/search/imap-db-search-term.vala ../src/engine/imap-engine/imap-engine.vala ../src/engine/imap-engine/imap-engine-account-operation.vala ../src/engine/imap-engine/imap-engine-account-processor.vala ../src/engine/imap-engine/imap-engine-account-synchronizer.vala ../src/engine/imap-engine/imap-engine-batch-operations.vala ../src/engine/imap-engine/imap-engine-contact-store.vala ../src/engine/imap-engine/imap-engine-email-prefetcher.vala ../src/engine/imap-engine/imap-engine-generic-account.vala ../src/engine/imap-engine/imap-engine-generic-folder.vala ../src/engine/imap-engine/imap-engine-minimal-folder.vala ../src/engine/imap-engine/imap-engine-replay-operation.vala ../src/engine/imap-engine/imap-engine-replay-queue.vala ../src/engine/imap-engine/imap-engine-revokable-move.vala ../src/engine/imap-engine/imap-engine-revokable-committed-move.vala ../src/engine/imap-engine/imap-engine-send-replay-operation.vala ../src/engine/imap-engine/gmail/imap-engine-gmail-account.vala ../src/engine/imap-engine/gmail/imap-engine-gmail-all-mail-folder.vala ../src/engine/imap-engine/gmail/imap-engine-gmail-drafts-folder.vala ../src/engine/imap-engine/gmail/imap-engine-gmail-folder.vala ../src/engine/imap-engine/gmail/imap-engine-gmail-search-folder.vala ../src/engine/imap-engine/gmail/imap-engine-gmail-spam-trash-folder.vala ../src/engine/imap-engine/other/imap-engine-other-account.vala ../src/engine/imap-engine/other/imap-engine-other-folder.vala ../src/engine/imap-engine/outlook/imap-engine-outlook-account.vala ../src/engine/imap-engine/outlook/imap-engine-outlook-folder.vala ../src/engine/imap-engine/outlook/imap-engine-outlook-drafts-folder.vala ../src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala ../src/engine/imap-engine/replay-ops/imap-engine-copy-email.vala ../src/engine/imap-engine/replay-ops/imap-engine-create-email.vala ../src/engine/imap-engine/replay-ops/imap-engine-empty-folder.vala ../src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala ../src/engine/imap-engine/replay-ops/imap-engine-list-email-by-id.vala ../src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala ../src/engine/imap-engine/replay-ops/imap-engine-mark-email.vala ../src/engine/imap-engine/replay-ops/imap-engine-move-email-commit.vala ../src/engine/imap-engine/replay-ops/imap-engine-move-email-prepare.vala ../src/engine/imap-engine/replay-ops/imap-engine-move-email-revoke.vala ../src/engine/imap-engine/replay-ops/imap-engine-remove-email.vala ../src/engine/imap-engine/replay-ops/imap-engine-replay-append.vala ../src/engine/imap-engine/replay-ops/imap-engine-replay-removal.vala ../src/engine/imap-engine/replay-ops/imap-engine-replay-update.vala ../src/engine/imap-engine/replay-ops/imap-engine-server-search-email.vala ../src/engine/imap-engine/replay-ops/imap-engine-user-close.vala ../src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala ../src/engine/imap-engine/yahoo/imap-engine-yahoo-folder.vala ../src/engine/memory/memory-buffer.vala ../src/engine/memory/memory-byte-buffer.vala ../src/engine/memory/memory-empty-buffer.vala ../src/engine/memory/memory-file-buffer.vala ../src/engine/memory/memory-growable-buffer.vala ../src/engine/memory/memory-offset-buffer.vala ../src/engine/memory/memory-string-buffer.vala ../src/engine/memory/memory-unowned-byte-array-buffer.vala ../src/engine/memory/memory-unowned-bytes-buffer.vala ../src/engine/memory/memory-unowned-string-buffer.vala ../src/engine/mime/mime-content-disposition.vala ../src/engine/mime/mime-content-parameters.vala ../src/engine/mime/mime-content-type.vala ../src/engine/mime/mime-data-format.vala ../src/engine/mime/mime-disposition-type.vala ../src/engine/mime/mime-error.vala ../src/engine/mime/mime-multipart-subtype.vala ../src/engine/nonblocking/nonblocking-batch.vala ../src/engine/nonblocking/nonblocking-concurrent.vala ../src/engine/nonblocking/nonblocking-counting-semaphore.vala ../src/engine/nonblocking/nonblocking-error.vala ../src/engine/nonblocking/nonblocking-lock.vala ../src/engine/nonblocking/nonblocking-mutex.vala ../src/engine/nonblocking/nonblocking-queue.vala ../src/engine/nonblocking/nonblocking-reporting-semaphore.vala ../src/engine/nonblocking/nonblocking-variants.vala ../src/engine/outbox/outbox-email-identifier.vala ../src/engine/outbox/outbox-email-properties.vala ../src/engine/outbox/outbox-folder.vala ../src/engine/outbox/outbox-folder-properties.vala ../src/engine/rfc822/rfc822.vala ../src/engine/rfc822/rfc822-error.vala ../src/engine/rfc822/rfc822-gmime-filter-flowed.vala ../src/engine/rfc822/rfc822-gmime-filter-blockquotes.vala ../src/engine/rfc822/rfc822-gmime-filter-plain.vala ../src/engine/rfc822/rfc822-mailbox-addresses.vala ../src/engine/rfc822/rfc822-mailbox-address.vala ../src/engine/rfc822/rfc822-message.vala ../src/engine/rfc822/rfc822-message-data.vala ../src/engine/rfc822/rfc822-part.vala ../src/engine/rfc822/rfc822-utils.vala ../src/engine/smtp/smtp-authenticator.vala ../src/engine/smtp/smtp-capabilities.vala ../src/engine/smtp/smtp-client-connection.vala ../src/engine/smtp/smtp-client-service.vala ../src/engine/smtp/smtp-client-session.vala ../src/engine/smtp/smtp-command.vala ../src/engine/smtp/smtp-data-format.vala ../src/engine/smtp/smtp-error.vala ../src/engine/smtp/smtp-greeting.vala ../src/engine/smtp/smtp-login-authenticator.vala ../src/engine/smtp/smtp-oauth2-authenticator.vala ../src/engine/smtp/smtp-plain-authenticator.vala ../src/engine/smtp/smtp-request.vala ../src/engine/smtp/smtp-response.vala ../src/engine/smtp/smtp-response-code.vala ../src/engine/smtp/smtp-response-line.vala ../src/engine/state/state-machine-descriptor.vala ../src/engine/state/state-machine.vala ../src/engine/state/state-mapping.vala ../src/engine/util/util-ascii.vala ../src/engine/util/util-collection.vala ../src/engine/util/util-config-file.vala ../src/engine/util/util-connectivity-manager.vala ../src/engine/util/util-error-context.vala ../src/engine/util/util-files.vala ../src/engine/util/util-generic-capabilities.vala ../src/engine/util/util-html.vala ../src/engine/util/util-idle-manager.vala ../src/engine/util/util-imap-utf7.vala ../src/engine/util/util-inet.vala ../src/engine/util/util-iterable.vala ../src/engine/util/util-js.vala ../src/engine/util/util-numeric.vala ../src/engine/util/util-object.vala ../src/engine/util/util-reference-semantics.vala ../src/engine/util/util-scheduler.vala ../src/engine/util/util-stream.vala ../src/engine/util/util-string.vala ../src/engine/util/util-synchronization.vala ../src/engine/util/util-time.vala ../src/engine/util/util-timeout-manager.vala ../src/engine/util/util-trillian.vala src/geary-version.vala
../src/engine/imap-engine/imap-engine-batch-operations.vala:34.68-34.78: error: Argument 2: Cannot convert from `unowned GLib.Cancellable?' to `bool'
created = yield folder.create_or_merge_email_async(emails, cancellable);
^^^^^^^^^^^
../src/engine/util/util-js.vala:46.55-46.64: warning: JS has been deprecated since 2.22
../src/engine/util/util-js.vala:138.41-138.50: warning: JS has been deprecated since 2.22
Compilation failed: 1 error(s), 2 warning(s)
ninja: build stopped: subcommand failed.
ERROR: Job failed: exit code 1