Overview
Modifies message flags (e.g.,\Seen, \Flagged, \Draft, custom flags) by adding or removing flags from a message. This is a non-destructive write operation that changes message metadata without affecting the message content.
Common use cases
- Mark messages as read/unread (
\Seen) - Flag messages for follow-up (
\Flagged) - Mark messages as drafts (
\Draft) - Add custom labels or tags
- Remove incorrect or outdated flags
Input parameters
Account identifier. Must match pattern
^[A-Za-z0-9_-]{1,64}$.Message identifier in format
imap:{account_id}:{mailbox}:{uidvalidity}:{uid}.The account_id in the message_id must match the account_id parameter.Array of flags to add (1-20 flags). At least one of
add_flags or remove_flags is required.Common system flags:\Seen- Message has been read\Answered- Message has been replied to\Flagged- Message is flagged for urgent/special attention\Deleted- Message is marked for deletion\Draft- Message is a draft\Recent- Message is recent (read-only, cannot be set)
Array of flags to remove (1-20 flags). At least one of
add_flags or remove_flags is required.Uses the same flag format as add_flags.Response
Human-readable one-line outcome:
"Flags updated"Example request
Example response
Error responses
Implementation notes
- Flag operations use the
+FLAGS.SILENTand-FLAGS.SILENTIMAP commands to avoid unnecessary server notifications - The server attempts to add flags first, then remove flags
- Each operation is tracked separately with
applied_add_flagsandapplied_remove_flagsboolean indicators - After flag modifications, the server fetches the current flag list to return in the response
- Flag validation prevents IMAP command injection by rejecting flags with special characters
- The mailbox is selected in read-write mode, and uidvalidity is verified to ensure the message still exists
See also
- imap_get_message - Retrieve message details including current flags
- Write operations configuration - Enable write operations
- Message IDs - Understanding message identifier format