Skip to main content

Command Palette

Search for a command to run...

Plus Addressing In Stalwart

Updated
2 min read

What Is Plus Addressing?

Plus addressing (also known as sub-addressing) lets you receive messages into one email account from multiple sub-addresses, such as user+tag@example.org. For example, your main email might be user@example.org, but you can also use user+work@example.org for work-related apps and still receive all messages in the same inbox. This way, you’ll know which messages are work-related based on the address used.

Another bonus is when all such messages are automatically moved to a sub-folder named after the used tag (in this case work).

How To Achieve It In Stalwart

Good news — plus addressing works by default in Stalwart except for the bonus case, when you want to also move messages into appropriate folders. To achieve it, we need Sieve scripts.

Your first idea might be to add Sieve scripts into System scripts or User scripts in the Stalwart admin web UI. This will not work because you can’t use the fileinto directive in those scripts. We need to use something else.

Use ManageSieve

ManageSieve is a protocol (RFC 5804) for users to add and manage their own Sieve scripts on the mail server. You need a ManageSieve client to do it. I recommend SieveEditor.

This Sieve script detects the “tag” part of the email address, creates a folder if necessary, and moves the message into the folder.

require ["envelope", "fileinto", "mailbox", "subaddress", "variables"];

# Check if the mail recipient address has a tag (:detail)
if envelope :detail :matches "to" "*" {
  # Create a variable `tag`, with the the captured `to` value normalized
  set :lower "tag" "${1}";

  # Store the mail into a folder with the tag name:
  if mailboxexists "${tag}" {
    fileinto "${tag}";
  } else {
    fileinto :create "${tag}";
  }
}