Skip to content

Message and mailbox limits

A message with a huge header, or a message filed in hundreds of mailboxes, is costly for the server to parse, index and synchronise to every client. Stalwart therefore bounds the size and shape of the messages and mailboxes it stores, so that a single client or sender cannot create such objects.

The limits apply to every access protocol. A message appended over IMAP, created or imported over JMAP, or received over SMTP is checked against the same values. They are set on the Email singleton, found in the WebUI under Settings › Email › Defaults, Settings › Email › Encryption, Settings › Email › Limits, Settings › Email › Storage.

Two fields bound the size of what is stored, one for the whole message and one for each attachment:

FieldDefaultLimit
maxMessageSize75 MBSize of a whole message stored in a mailbox.
maxAttachmentSize50 MBSize of a single attachment.

Mail received over SMTP meets another limit first. The SMTP server applies its own message size limit before a message reaches a mailbox, and that limit is configured on the DATA stage.

A related limit lives elsewhere. The number of messages that a single JMAP Email/parse request may parse is a JMAP protocol limit, parseLimitEmail on the Jmap singleton, described with the other JMAP limits.

The top-level header section has limits of its own:

FieldDefaultLimit
maxHeaderSize512 KiB, minimum 1 KiBSize in bytes of the top-level header section.
maxHeaderCount5000, minimum 100Number of header fields in the top-level header section.

Both limits apply to the header section of the message itself, not to the headers of its MIME parts. A third limit is fixed: independently of these settings, a message may not carry more than 65534 header fields across all of its parts. A message that exceeds any of the three limits is refused, in the way of the protocol that carried it:

  • JMAP Email/set and Email/import return a tooLarge error.
  • IMAP APPEND fails with a tagged NO [LIMIT] response.
  • SMTP refuses the message at the end of DATA, on both the MX and the submission ports, with the reply listed in Message limits. Messages that Stalwart generates itself are not checked.

The description of the error names the limit that was exceeded, for example An email header cannot exceed <n> bytes. or An email header cannot have more than <n> fields.

A message can carry metadata of its own: the mailboxes it belongs to and the flags set on it. Each is bounded:

FieldDefaultLimit
maxMailboxesPerEmail100Number of mailboxes a single message can belong to. JMAP allows a message to be in several mailboxes at once; IMAP clients see each membership as a copy.
maxFlagsPerEmail100Number of flags on a single message. JMAP keywords and IMAP flags are the same values, so the limit covers both.
maxFlagLength128 bytes, maximum 1024Length of a single flag or keyword name. System flags such as \Seen are exempt from this check.

These limits prevent growth only. An operation that leaves a message with fewer mailboxes or flags than before is always accepted. A message that already exceeds a lowered limit can therefore still be cleaned up. An operation that would push a message over a limit fails as follows:

LimitJMAP Email/setIMAP
Mailboxes per messagetooManyMailboxes on mailboxIdsNO [LIMIT] An email cannot belong to more than <n> mailboxes.
Flags per messagetooManyKeywords on keywordsNO [LIMIT] An email cannot have more than <n> keywords.
Flag lengthinvalidProperties on keywordsNO [LIMIT] Keywords cannot be longer than <n> bytes.

Mailboxes themselves are bounded in depth and in the length of their names:

FieldDefaultLimit
maxMailboxDepth10Nesting depth of a mailbox below the account’s top level.
maxMailboxNameLength255Length of a single mailbox name.

The following object body lowers the mailbox depth and the number of mailboxes a message may belong to:

{
"maxMailboxDepth": 6,
"maxMailboxesPerEmail": 20
}

Besides the shape of individual objects, the server bounds how many objects an account can create. The Email singleton holds the default number of objects of each type. Each default applies to accounts that have no value of their own in their quotas map. Quotas describes how the per-account values override them.

FieldDefaultObjects counted
maxMessagesunlimitedMessages
maxMailboxes250Mailboxes
maxIdentities20JMAP sending identities
maxSubmissions500JMAP email submissions
maxMaskedAddresses5Masked addresses (Enterprise edition)
maxPublicKeys5Public keys for encryption at rest

The remaining fields of the singleton control how messages are stored. compressionAlgorithm selects the compression applied to stored message data. encryptAtRest and encryptOnAppend are described in Encryption at rest. The default folders created for new accounts are described in IMAP and POP3.