MailRule
A rule applied to mail delivered to the account: when a message matches its conditions, the rule’s actions run.
This object can be configured from the WebUI under Account › Filters & Auto-Replies › Mail Rules
Fields
Section titled “Fields”Type:
String· required · max length: 255Name of the rule
isEnabled
Section titled “isEnabled”Type:
Boolean· default:trueWhether the rule runs when mail is delivered
position
Section titled “position”Type:
UnsignedInt· default:0Order in which the rule runs; lower runs first
conditions
Section titled “conditions”Type:
MailRuleConditions· requiredWhich messages the rule applies to; a rule without conditions applies to every message
actions
Section titled “actions”Type:
MailRuleActions· requiredWhat happens to a matching message; at least one action is required. The order is fixed: keywords are cleared, removed and added, the importance is set, then the message is redirected, replied to, copied, moved, discarded or rejected, and processing stops last.
JMAP API
Section titled “JMAP API”The MailRule object is available via the urn:stalwart:jmap capability.
x:MailRule/get
Section titled “x:MailRule/get”This is a standard Foo/get method as defined in RFC 8620, Section 5.1.
This method requires the sysMailRuleGet permission.
curl -X POST https://mail.example.com/jmap/ \ -H 'Authorization: Bearer $TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "methodCalls": [ [ "x:MailRule/get", { "ids": [ "id1" ] }, "c1" ] ], "using": [ "urn:ietf:params:jmap:core", "urn:stalwart:jmap" ] }'x:MailRule/set
Section titled “x:MailRule/set”This is a standard Foo/set method as defined in RFC 8620, Section 5.3.
Supports the following operations in a single call: create, update, destroy.
Create
Section titled “Create”This operation requires the sysMailRuleCreate permission.
curl -X POST https://mail.example.com/jmap/ \ -H 'Authorization: Bearer $TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "methodCalls": [ [ "x:MailRule/set", { "create": { "new1": { "actions": { "addKeywords": {}, "copyTo": {}, "moveTo": {}, "removeKeywords": {} }, "conditions": { "matchAll": {}, "matchAny": {}, "matchNone": {} }, "name": "Example" } } }, "c1" ] ], "using": [ "urn:ietf:params:jmap:core", "urn:stalwart:jmap" ] }'Update
Section titled “Update”This operation requires the sysMailRuleUpdate permission.
curl -X POST https://mail.example.com/jmap/ \ -H 'Authorization: Bearer $TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "methodCalls": [ [ "x:MailRule/set", { "update": { "id1": { "name": "updated value" } } }, "c1" ] ], "using": [ "urn:ietf:params:jmap:core", "urn:stalwart:jmap" ] }'Destroy
Section titled “Destroy”This operation requires the sysMailRuleDestroy permission.
curl -X POST https://mail.example.com/jmap/ \ -H 'Authorization: Bearer $TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "methodCalls": [ [ "x:MailRule/set", { "destroy": [ "id1" ] }, "c1" ] ], "using": [ "urn:ietf:params:jmap:core", "urn:stalwart:jmap" ] }'x:MailRule/query
Section titled “x:MailRule/query”This is a standard Foo/query method as defined in RFC 8620, Section 5.5.
This method requires the sysMailRuleQuery permission.
curl -X POST https://mail.example.com/jmap/ \ -H 'Authorization: Bearer $TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "methodCalls": [ [ "x:MailRule/query", { "filter": {} }, "c1" ] ], "using": [ "urn:ietf:params:jmap:core", "urn:stalwart:jmap" ] }'stalwart-cli wraps the same JMAP calls. See the CLI reference for installation, authentication, and general usage.
stalwart-cli get MailRule id1Create
Section titled “Create”stalwart-cli create MailRule \ --field name=Example \ --field 'conditions={"matchAll":{},"matchAny":{},"matchNone":{}}' \ --field 'actions={"addKeywords":{},"copyTo":{},"moveTo":{},"removeKeywords":{}}'stalwart-cli query MailRuleUpdate
Section titled “Update”stalwart-cli update MailRule id1 --field name='updated value'Delete
Section titled “Delete”stalwart-cli delete MailRule --ids id1Nested types
Section titled “Nested types”MailRuleConditions
Section titled “MailRuleConditions”The tests of a rule: all of matchAll, at least one of matchAny unless it is empty, and none of matchNone
matchAll
Section titled “matchAll”Type:
List<MailRuleCondition>· max items: 32Tests that must all match
matchAny
Section titled “matchAny”Type:
List<MailRuleCondition>· max items: 32Tests of which at least one must match; ignored when empty
matchNone
Section titled “matchNone”Type:
List<MailRuleCondition>· max items: 32Tests of which none may match
MailRuleCondition
Section titled “MailRuleCondition”A test applied to a delivered message
From: Sender address (From). Carries the fields ofMailRuleAddressTest.To: To address. Carries the fields ofMailRuleAddressTest.Cc: Cc address. Carries the fields ofMailRuleAddressTest.ToOrCc: To or Cc address. Carries the fields ofMailRuleAddressTest.SentToMe: Addressed to the account itself. Carries the fields ofMailRuleSentToMe.Subject: Subject. Carries the fields ofMailRuleTextTest.Body: Body text. Carries the fields ofMailRuleTextTest.Header: Any header. Carries the fields ofMailRuleHeaderTest.SizeOver: Larger than a size. Carries the fields ofMailRuleSize.SizeUnder: Smaller than a size. Carries the fields ofMailRuleSize.HasAttachment: Has attachments. No additional fields.Importance: Importance. Carries the fields ofMailRuleImportance.Sensitivity: Sensitivity. Carries the fields ofMailRuleSensitivity.MessageType: Message type. Carries the fields ofMailRuleMessageType.HeaderExists: Header is present. Carries the fields ofMailRuleHeaderName.AttachmentName: Attachment file name. Carries the fields ofMailRuleTextTest.AttachmentType: Attachment media type. Carries the fields ofMailRuleTextTest.MailingList: Sent by a mailing list. No additional fields.RecipientAddress: Delivered to address (envelope recipient). Carries the fields ofMailRuleAddressTest.RecipientDetail: Plus-address detail of the envelope recipient. Carries the fields ofMailRuleTextTest.SpamScore: Spam score at or above a threshold (50 or more is spam). Carries the fields ofMailRuleSpamScore.SubjectOrBody: Subject or body text. Carries the fields ofMailRuleTextTest.ReceivedAfter: Received on or after a date. Carries the fields ofMailRuleDate.ReceivedBefore: Received on or before a date. Carries the fields ofMailRuleDate.Schedule: Received within weekly time slots. Carries the fields ofMailRuleSchedule.PrivateEvent: Calendar event is private. No additional fields.Keyword: Has any of the keywords. Carries the fields ofMailRuleKeywordTest.AnyKeyword: Has any keyword. No additional fields.Flagged: Is flagged. No additional fields.IsAway: The vacation response is in effect. No additional fields.
MailRuleAddressTest
Section titled “MailRuleAddressTest”Compares an address field with a list of values
operator
Section titled “operator”Type:
MailRuleAddressOperator· default:"is"How the addresses are compared
values
Section titled “values”Type:
Set<String>· min items: 1 · max items: 64Values compared with the addresses; the test matches when any value matches
MailRuleSentToMe
Section titled “MailRuleSentToMe”How the message is addressed to the account
placement
Section titled “placement”Type:
MailRuleSentToMePlacement· default:"toOrCc"Where the account’s address appears
MailRuleTextTest
Section titled “MailRuleTextTest”Compares a text field with a list of values
operator
Section titled “operator”Type:
MailRuleTextOperator· default:"contains"How the text is compared
values
Section titled “values”Type:
Set<String>· min items: 1 · max items: 64 · max length: 255Values compared with the text; the test matches when any value matches
MailRuleHeaderTest
Section titled “MailRuleHeaderTest”Compares a named header with a list of values
header
Section titled “header”Type:
String· required · max length: 255Header name
operator
Section titled “operator”Type:
MailRuleTextOperator· default:"contains"How the header is compared
values
Section titled “values”Type:
Set<String>· min items: 1 · max items: 64 · max length: 255Values compared with the header; the test matches when any value matches
MailRuleSize
Section titled “MailRuleSize”A message size limit
kilobytes
Section titled “kilobytes”Type:
UnsignedInt· default:100· min: 1Size in kilobytes
MailRuleImportance
Section titled “MailRuleImportance”Importance of the message
Type:
MailRuleImportanceLevel· default:"high"Importance level
MailRuleSensitivity
Section titled “MailRuleSensitivity”Sensitivity of the message
Type:
MailRuleSensitivityLevel· default:"confidential"Sensitivity level
MailRuleMessageType
Section titled “MailRuleMessageType”Type of the message
Type:
MailRuleMessageKind· default:"meetingRequest"Message type
MailRuleHeaderName
Section titled “MailRuleHeaderName”A named header
header
Section titled “header”Type:
String· required · max length: 255Header name
MailRuleSpamScore
Section titled “MailRuleSpamScore”A spam score threshold
percent
Section titled “percent”Type:
UnsignedInt· default:50· min: 1 · max: 100Spam score on a scale of 0 to 100; the test matches at or above it
MailRuleDate
Section titled “MailRuleDate”A point in time
Type:
UTCDateTime· requiredDate and time, in UTC
MailRuleSchedule
Section titled “MailRuleSchedule”Weekly time slots in a time zone; the condition matches when the message arrives within any of them
Type:
List<WorkingHoursSlot>· min items: 1 · max items: 14Days and times of the week; an end earlier than the start spans midnight into the next day
timeZone
Section titled “timeZone”Type:
TimeZone?Time zone of the slots. When empty, the account time zone at the time the rules were last saved is used.
WorkingHoursSlot
Section titled “WorkingHoursSlot”A working interval on one or more days of the week.
Type:
Set<Weekday>· min items: 1 · max items: 7Days of the week the interval applies to
Type:
LocalTime· default:"09:00"Start of the interval
Type:
LocalTime· default:"17:00"End of the interval; 24:00 is the end of the day
MailRuleKeywordTest
Section titled “MailRuleKeywordTest”Keywords tested on the message
keywords
Section titled “keywords”Type:
Set<String>· min items: 1 · max items: 64Keywords (IMAP flags) set by an earlier rule or listed in the Keywords header; the test matches when any of them is present
MailRuleActions
Section titled “MailRuleActions”What a rule does to a matching message; each action is given at most once
addKeywords
Section titled “addKeywords”Type:
Set<String>· max items: 128Keywords added to the message; $seen marks it as read, $flagged flags it and $notjunk keeps it out of Junk
removeKeywords
Section titled “removeKeywords”Type:
Set<String>· max items: 128Keywords removed from the message, before addKeywords is applied; $flagged clears the flag
clearKeywords
Section titled “clearKeywords”Type:
Boolean· default:falseWhether the keywords added by earlier rules are removed first
setImportance
Section titled “setImportance”Type:
MailRuleImportanceLevel?Importance the message is given
redirect
Section titled “redirect”Type:
MailRuleRedirect?Other addresses the message is redirected to
Type:
MailRuleReply?Template the sender is answered with
copyTo
Section titled “copyTo”Type:
Set<Id>· max items: 16Mailboxes the message is copied to; the rule keeps working when a mailbox is renamed
moveTo
Section titled “moveTo”Type:
Set<Id>· max items: 16Mailboxes the message is moved to; moving to Junk also marks it as spam. The rule keeps working when a mailbox is renamed
discard
Section titled “discard”Type:
Boolean· default:falseWhether the message is deleted permanently
reject
Section titled “reject”Type:
MailRuleReject?Rejection returned to the sender when their return path is verified, otherwise the message is discarded silently; only alone, and it always stops processing
stopProcessing
Section titled “stopProcessing”Type:
Boolean· default:falseWhether later rules are skipped after this rule matches
MailRuleRedirect
Section titled “MailRuleRedirect”Redirect target of a rule action
addresses
Section titled “addresses”Type:
Set<EmailAddress>· min items: 1 · max items: 64Addresses the message is redirected to
keepCopy
Section titled “keepCopy”Type:
Boolean· default:trueWhether a copy is also delivered to the account
MailRuleReply
Section titled “MailRuleReply”Automatic reply sent to the sender of a matching message
subject
Section titled “subject”Type:
String?· max length: 255Subject of the reply; when empty, the original subject with a prefix is used
textBody
Section titled “textBody”Type:
Text· required · max length: 2048Plain text body of the reply
htmlBody
Section titled “htmlBody”Type:
Html?· max length: 2048HTML body of the reply
Type:
UnsignedInt· default:7· max: 365Minimum number of days between two replies to the same sender; 0 replies to every message
MailRuleReject
Section titled “MailRuleReject”Rejection returned to the sender of a matching message
reason
Section titled “reason”Type:
String· required · max length: 1024Text returned to the sender
MailRuleAddressOperator
Section titled “MailRuleAddressOperator”| Value | Label |
|---|---|
is | Is exactly the address |
contains | Contains |
domain | Is in the domain |
matches | Matches a wildcard pattern |
MailRuleSentToMePlacement
Section titled “MailRuleSentToMePlacement”| Value | Label |
|---|---|
to | In To |
cc | In Cc |
toOrCc | In To or Cc |
notTo | Not in To |
onlyTo | The account is the only recipient |
MailRuleTextOperator
Section titled “MailRuleTextOperator”| Value | Label |
|---|---|
contains | Contains |
is | Is exactly |
matches | Matches a wildcard pattern |
MailRuleImportanceLevel
Section titled “MailRuleImportanceLevel”| Value | Label |
|---|---|
low | Low |
normal | Normal |
high | High |
MailRuleSensitivityLevel
Section titled “MailRuleSensitivityLevel”| Value | Label |
|---|---|
normal | Normal |
personal | Personal |
private | Private |
confidential | Confidential |
MailRuleMessageKind
Section titled “MailRuleMessageKind”| Value | Label |
|---|---|
meetingRequest | Meeting request |
meetingResponse | Meeting response |
meetingCancellation | Meeting cancellation |
nonDeliveryReport | Non-delivery report |
readReceipt | Read receipt |
automaticReply | Automatic reply |
signed | Signed |
encrypted | Encrypted |
automaticForward | Automatically forwarded |
voicemail | Voicemail |
Weekday
Section titled “Weekday”| Value | Label |
|---|---|
monday | Monday |
tuesday | Tuesday |
wednesday | Wednesday |
thursday | Thursday |
friday | Friday |
saturday | Saturday |
sunday | Sunday |