• The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

Question How to prepend [EXT] to external emails (Postfix/SpamAssassin/Sieve)

tessa67

Regular Pleskian
Server operating system version
Debian 11
Plesk version and microupdate number
18.0.80 #3
Hello everyone,

using the configuration specified in my signature, I would like to prepand an "[EXT]" to the subject line of external emails, or write "EXTERNAL" at the very beginning of the email body.

All my attempts using header_checks, SpamAssassin, and Sieve have failed so far, and I am starting to wonder if this is even possible with my setup.

The domains examplea.com, exampleb.com, and examplec.com are internal email domains. Emails between these domains should remain untouched.
 
Sieve should be the right tools for this. You'll need some additional Dovecot configuration if you want the subject to be changed server wide for all mailboxes. If you want this just for one (or a couple) mailboxes than you can just apply a Sieve filter script for those specific mailboxes mailboxes. Roundcube for example let's you modify filter rules for a specific mailbox.

Sieve filter example script:
Code:
require ["editheader", "variables", "envelope"];

if allof (
    envelope :domain :is "to"
        ["examplea.com", "exampleb.com", "examplec.com"],

    not address :domain :is "From"
        ["examplea.com", "exampleb.com", "examplec.com"],

    not header :matches "Subject" "[EXT]*"
) {
    if header :matches "Subject" "*" {
        set "original_subject" "${1}";

        deleteheader "Subject";
        addheader "Subject" "[EXT] ${original_subject}";
    }
    else {
        # Handle messages without a Subject header.
        addheader "Subject" "[EXT]";
    }
}
* I've not tested this Sieve filter script, test first and use with caution.
 
Thank you very much! It works with sieve.

/etc/dovecot/sieve.d/10-external-tag.sieve
Code:
require ["editheader", "variables", "regex"];

if not header :regex "From" "@(examplea\.com|exampleb\.com|examplec\.com)" {

    if not header :contains "Subject" "[EXT]" {

        if header :matches "Subject" "*" {
            deleteheader "Subject";
            addheader :last "Subject" "[EXT] ${1}";
        }
    }
}

/etc/dovecot/conf.d/95-custom-sieve.conf
Code:
sieve_extensions {
  editheader = yes
  variables = yes
}

sieve_script custom_before {
  path = /etc/dovecot/sieve.d/10-external-tag.sieve
  type = before
}
 
However, your code is faster, more efficient, and more secure. Regex can be quite slow... ;)
 
Back
Top