Skip to content

fix(imap): translate virtual label names to RFC 3501 IMAP flags#5

Open
benv666 wants to merge 1 commit intojgalea:mainfrom
benv666:fix/imap-flag-label-translation
Open

fix(imap): translate virtual label names to RFC 3501 IMAP flags#5
benv666 wants to merge 1 commit intojgalea:mainfrom
benv666:fix/imap-flag-label-translation

Conversation

@benv666
Copy link
Copy Markdown

@benv666 benv666 commented Apr 20, 2026

Fixes #4

NOTE: PR claude-generated.

Problem

modify_email passes caller-supplied strings (UNREAD, FLAGGED, etc.) directly to imapflow's messageFlagsAdd/messageFlagsRemove. These are not valid IMAP flags — RFC 3501 system flags use backslash-prefixed names (\Seen, \Flagged, \Answered, \Deleted, \Draft).

As a result, remove_labels: ["UNREAD"] sends STORE -FLAGS (UNREAD) to the server. Servers may silently accept an unknown keyword removal without error, but \Seen is never touched — the message stays unread.

UNREAD has an additional wrinkle: it is the logical inverse of \Seen. Marking a message as unread means removing \Seen; marking it as read means adding \Seen. Simply renaming the flag is not enough.

Fix

Adds resolveImapFlags() which:

  • Maps UNREAD to \Seen with inversion (adding UNREAD → remove \Seen, removing UNREAD → add \Seen)
  • Maps FLAGGED\Flagged, ANSWERED\Answered, DELETED\Deleted, DRAFT\Draft
  • Passes unknown labels through unchanged, allowing custom IMAP keywords

modifyLabels now resolves both the add and remove arrays before calling imapflow, crossing the inverted flags to the opposite operation.

Notes

modify_email was passing caller-supplied strings (e.g. "UNREAD",
"FLAGGED") directly as IMAP flags. These are not valid IMAP system
flags — the correct RFC 3501 names are \Seen, \Flagged, etc.

UNREAD requires special handling: it is the logical inverse of \Seen,
so add_labels:["UNREAD"] must remove \Seen and remove_labels:["UNREAD"]
must add it.

Adds resolveImapFlags() which maps virtual names to system flags and
handles the UNREAD inversion. Unknown labels pass through unchanged
to allow custom IMAP keywords.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IMAP provider: modify_email passes label names as IMAP flags instead of RFC 3501 system flags

1 participant