Skip to content

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

Type: String · required · max length: 255

Name of the rule

Type: Boolean · default: true

Whether the rule runs when mail is delivered

Type: UnsignedInt · default: 0

Order in which the rule runs; lower runs first

Type: MailRuleConditions · required

Which messages the rule applies to; a rule without conditions applies to every message

Type: MailRuleActions · required

What 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.

The MailRule object is available via the urn:stalwart:jmap capability.

This is a standard Foo/get method as defined in RFC 8620, Section 5.1.

This method requires the sysMailRuleGet permission.

Terminal window
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"
]
}'

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.

This operation requires the sysMailRuleCreate permission.

Terminal window
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"
]
}'

This operation requires the sysMailRuleUpdate permission.

Terminal window
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"
]
}'

This operation requires the sysMailRuleDestroy permission.

Terminal window
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"
]
}'

This is a standard Foo/query method as defined in RFC 8620, Section 5.5.

This method requires the sysMailRuleQuery permission.

Terminal window
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.

Terminal window
stalwart-cli get MailRule id1
Terminal window
stalwart-cli create MailRule \
--field name=Example \
--field 'conditions={"matchAll":{},"matchAny":{},"matchNone":{}}' \
--field 'actions={"addKeywords":{},"copyTo":{},"moveTo":{},"removeKeywords":{}}'
Terminal window
stalwart-cli query MailRule
Terminal window
stalwart-cli update MailRule id1 --field name='updated value'
Terminal window
stalwart-cli delete MailRule --ids id1

The tests of a rule: all of matchAll, at least one of matchAny unless it is empty, and none of matchNone

Type: List<MailRuleCondition> · max items: 32

Tests that must all match

Type: List<MailRuleCondition> · max items: 32

Tests of which at least one must match; ignored when empty

Type: List<MailRuleCondition> · max items: 32

Tests of which none may match

A test applied to a delivered message

  • From: Sender address (From). Carries the fields of MailRuleAddressTest.
  • To: To address. Carries the fields of MailRuleAddressTest.
  • Cc: Cc address. Carries the fields of MailRuleAddressTest.
  • ToOrCc: To or Cc address. Carries the fields of MailRuleAddressTest.
  • SentToMe: Addressed to the account itself. Carries the fields of MailRuleSentToMe.
  • Subject: Subject. Carries the fields of MailRuleTextTest.
  • Body: Body text. Carries the fields of MailRuleTextTest.
  • Header: Any header. Carries the fields of MailRuleHeaderTest.
  • SizeOver: Larger than a size. Carries the fields of MailRuleSize.
  • SizeUnder: Smaller than a size. Carries the fields of MailRuleSize.
  • HasAttachment: Has attachments. No additional fields.
  • Importance: Importance. Carries the fields of MailRuleImportance.
  • Sensitivity: Sensitivity. Carries the fields of MailRuleSensitivity.
  • MessageType: Message type. Carries the fields of MailRuleMessageType.
  • HeaderExists: Header is present. Carries the fields of MailRuleHeaderName.
  • AttachmentName: Attachment file name. Carries the fields of MailRuleTextTest.
  • AttachmentType: Attachment media type. Carries the fields of MailRuleTextTest.
  • MailingList: Sent by a mailing list. No additional fields.
  • RecipientAddress: Delivered to address (envelope recipient). Carries the fields of MailRuleAddressTest.
  • RecipientDetail: Plus-address detail of the envelope recipient. Carries the fields of MailRuleTextTest.
  • SpamScore: Spam score at or above a threshold (50 or more is spam). Carries the fields of MailRuleSpamScore.
  • SubjectOrBody: Subject or body text. Carries the fields of MailRuleTextTest.
  • ReceivedAfter: Received on or after a date. Carries the fields of MailRuleDate.
  • ReceivedBefore: Received on or before a date. Carries the fields of MailRuleDate.
  • Schedule: Received within weekly time slots. Carries the fields of MailRuleSchedule.
  • PrivateEvent: Calendar event is private. No additional fields.
  • Keyword: Has any of the keywords. Carries the fields of MailRuleKeywordTest.
  • AnyKeyword: Has any keyword. No additional fields.
  • Flagged: Is flagged. No additional fields.
  • IsAway: The vacation response is in effect. No additional fields.

Compares an address field with a list of values

Type: MailRuleAddressOperator · default: "is"

How the addresses are compared

Type: Set<String> · min items: 1 · max items: 64

Values compared with the addresses; the test matches when any value matches

How the message is addressed to the account

Type: MailRuleSentToMePlacement · default: "toOrCc"

Where the account’s address appears

Compares a text field with a list of values

Type: MailRuleTextOperator · default: "contains"

How the text is compared

Type: Set<String> · min items: 1 · max items: 64 · max length: 255

Values compared with the text; the test matches when any value matches

Compares a named header with a list of values

Type: String · required · max length: 255

Header name

Type: MailRuleTextOperator · default: "contains"

How the header is compared

Type: Set<String> · min items: 1 · max items: 64 · max length: 255

Values compared with the header; the test matches when any value matches

A message size limit

Type: UnsignedInt · default: 100 · min: 1

Size in kilobytes

Importance of the message

Type: MailRuleImportanceLevel · default: "high"

Importance level

Sensitivity of the message

Type: MailRuleSensitivityLevel · default: "confidential"

Sensitivity level

Type of the message

Type: MailRuleMessageKind · default: "meetingRequest"

Message type

A named header

Type: String · required · max length: 255

Header name

A spam score threshold

Type: UnsignedInt · default: 50 · min: 1 · max: 100

Spam score on a scale of 0 to 100; the test matches at or above it

A point in time

Type: UTCDateTime · required

Date and time, in UTC

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: 14

Days and times of the week; an end earlier than the start spans midnight into the next day

Type: TimeZone?

Time zone of the slots. When empty, the account time zone at the time the rules were last saved is used.

A working interval on one or more days of the week.

Type: Set<Weekday> · min items: 1 · max items: 7

Days 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

Keywords tested on the message

Type: Set<String> · min items: 1 · max items: 64

Keywords (IMAP flags) set by an earlier rule or listed in the Keywords header; the test matches when any of them is present

What a rule does to a matching message; each action is given at most once

Type: Set<String> · max items: 128

Keywords added to the message; $seen marks it as read, $flagged flags it and $notjunk keeps it out of Junk

Type: Set<String> · max items: 128

Keywords removed from the message, before addKeywords is applied; $flagged clears the flag

Type: Boolean · default: false

Whether the keywords added by earlier rules are removed first

Type: MailRuleImportanceLevel?

Importance the message is given

Type: MailRuleRedirect?

Other addresses the message is redirected to

Type: MailRuleReply?

Template the sender is answered with

Type: Set<Id> · max items: 16

Mailboxes the message is copied to; the rule keeps working when a mailbox is renamed

Type: Set<Id> · max items: 16

Mailboxes the message is moved to; moving to Junk also marks it as spam. The rule keeps working when a mailbox is renamed

Type: Boolean · default: false

Whether the message is deleted permanently

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

Type: Boolean · default: false

Whether later rules are skipped after this rule matches

Redirect target of a rule action

Type: Set<EmailAddress> · min items: 1 · max items: 64

Addresses the message is redirected to

Type: Boolean · default: true

Whether a copy is also delivered to the account

Automatic reply sent to the sender of a matching message

Type: String? · max length: 255

Subject of the reply; when empty, the original subject with a prefix is used

Type: Text · required · max length: 2048

Plain text body of the reply

Type: Html? · max length: 2048

HTML body of the reply

Type: UnsignedInt · default: 7 · max: 365

Minimum number of days between two replies to the same sender; 0 replies to every message

Rejection returned to the sender of a matching message

Type: String · required · max length: 1024

Text returned to the sender

ValueLabel
isIs exactly the address
containsContains
domainIs in the domain
matchesMatches a wildcard pattern
ValueLabel
toIn To
ccIn Cc
toOrCcIn To or Cc
notToNot in To
onlyToThe account is the only recipient
ValueLabel
containsContains
isIs exactly
matchesMatches a wildcard pattern
ValueLabel
lowLow
normalNormal
highHigh
ValueLabel
normalNormal
personalPersonal
privatePrivate
confidentialConfidential
ValueLabel
meetingRequestMeeting request
meetingResponseMeeting response
meetingCancellationMeeting cancellation
nonDeliveryReportNon-delivery report
readReceiptRead receipt
automaticReplyAutomatic reply
signedSigned
encryptedEncrypted
automaticForwardAutomatically forwarded
voicemailVoicemail
ValueLabel
mondayMonday
tuesdayTuesday
wednesdayWednesday
thursdayThursday
fridayFriday
saturdaySaturday
sundaySunday