Start with the mechanism, not the score

Google’s Gmail IMAP extensions expose X-GM-MSGID as a unique message identifier and X-GM-LABELS for labels. Gmail presents labels using IMAP folder semantics, so the same logical message can be reachable through more than one label view.

Gmail’s IMAP model exposes labels in a way that can make one underlying message appear through multiple mailbox views. If a collector walks several labels and deduplicates only by IMAP sequence number or by folder-local UID, it can process the same Gmail message more than once. Gmail’s `X-GM-MSGID` extension provides a provider-specific message identifier that remains the same for that Gmail message across labels, which makes it useful for deduplication inside a Gmail connector. Keep it as a Gmail optimization, though: a portable IMAP client still needs a standards-based identity strategy for providers that do not advertise the extension.

Where operators commonly misclassify the result

An IMAP UID is unique only within its mailbox and UIDVALIDITY context. Treating UID alone as a global message ID across Gmail labels can make one message look like several independent events.

Another trap is deleting or moving a message under the assumption that Gmail folders behave exactly like independent traditional IMAP mailboxes. Labels can change which views expose a message without creating a brand-new email. If your reply detector scans Inbox and All Mail, duplicate events are especially easy to create. Do not “fix” this by scanning only one label unless you have defined what replies or archived messages that choice can miss. Instead, model provider message identity separately from mailbox location and make processing idempotent so a second sighting is harmless.

How to reproduce it without adding volume

Fetch X-GM-MSGID together with UID and labels for messages discovered in each watched mailbox. In a test account, apply two labels to one message and confirm your event pipeline emits only one logical-message record.

On connection, inspect CAPABILITY for Gmail extensions. Fetch `X-GM-MSGID`, relevant UIDs, Message-ID, labels, and the minimal headers your reply logic needs for a controlled mailbox. Apply two labels to the same test message and confirm the connector sees the same Gmail message ID in both views while folder-local identifiers may differ. Then disable the Gmail-specific path and verify the fallback strategy still prevents destructive double actions. This test proves the extension improves identity resolution without becoming a hidden requirement for the entire IMAP subsystem.

A narrow remediation path

Key Gmail-level deduplication on account plus X-GM-MSGID while still preserving per-mailbox UID state for incremental sync. Keep the abstraction provider-specific so non-Gmail IMAP accounts can use their own correlation rules.

Store a provider namespace with the identifier: `gmail:x-gm-msgid` is not interchangeable with RFC Message-ID or an Outlook-specific value. Use it as one strong dedupe key within Gmail, while also retaining Message-ID and thread headers for cross-system correlation. If a message is processed from a second label, update location/label metadata rather than firing the reply handler again. This design lets the connector exploit Gmail’s extension without leaking Gmail assumptions into every provider and makes mailbox migrations less likely to create duplicated replies or canceled follow-ups.

What this looks like in a small stack

The reply may have UID 412 in INBOX and a different UID in another selected mailbox, yet both FETCH responses can report the same X-GM-MSGID. That is the signal the two views refer to one Gmail message.

A good Gmail adapter can expose a normalized message object while retaining provider extras. For example, the core layer stores mailbox UID/UIDVALIDITY, RFC Message-ID, From, References, and received time; the Gmail extension layer adds X-GM-MSGID, X-GM-THRID, and labels. Deduplication can then prefer the Gmail message ID when present but fall back safely when the connector moves to another provider. Keep label changes as metadata events rather than new-message events. This is particularly important if a user archives a reply: the message may disappear from Inbox and remain in All Mail without becoming a second reply. By separating message identity from current label membership, the sequence engine sees one durable reply event even while the mailbox UI representation changes several times.

Evidence worth saving for the next incident

Store account, mailbox, UIDVALIDITY, UID, X-GM-MSGID, X-GM-THRID if used, labels, and the canonical event ID chosen by your application.

When to stop changing things

Do not replace RFC identifiers everywhere with Gmail extensions. X-GM-MSGID is useful inside Gmail integration code, while Message-ID and other standard headers still matter for cross-provider threading.

Field checklist

  • Capture the raw evidence for Gmail IMAP labels duplicate processing X-GM-MSGID before editing DNS, queue state, or mailbox metadata.
  • Confirm the cited mechanism using gmail-imap-ext, imap-rfc rather than a generic deliverability score.
  • Keep a known-good control case so the failing layer can be compared without changing several variables at once.
  • Apply the narrow repair described for Gmail labels over IMAP: use X-GM-MSGID to avoid processing the same message as if it were two emails and preserve a rollback or retry path.
  • Repeat the original failing test after the change; do not substitute a different checker as proof of recovery.
  • Store timestamp, affected identity, raw result, action taken, and the post-change result in the operator log.

Primary sources

Standards and provider policies can change. These links are the reference points used for this field note.

  1. Gmail IMAP extensionsGoogle for DevelopersGmail-specific IMAP identifiers and label behavior, including X-GM-MSGID, X-GM-THRID, and X-GM-LABELS.
  2. RFC 9051 — IMAP4rev2IETF / RFC EditorMailbox flags, UIDs, BODY.PEEK and IMAP4rev2 behavior.