Mailsorting

From SME Server
Jump to navigationJump to search


see UserManager, as this is part of a collection of contribs







mailsorting
NeedImage.svg
mailsorting logo
Source: smeserver-mailsorting
Licenceopen source
Category

Mail

Tags Mailsorting Proton Procmail


Sorting mail with Maildrop or Procmail or Dovecot-Sieve

Version

smecontribs-testing 11:
smecontribs 10:
smecontribs 9:
smeserver-mailsorting
The latest version of smeserver-mailsorting is available in the SME repository, click on the version number(s) for more information.


Installation

  • For sme9 and sme10
yum install smeserver-mailsorting --enablerepo=smecontribs

for sme11

dnf install smeserver-mailsorting --enablerepo=smecontribs

Allows a user to configure mail rules either as an individual user (login to server-manager as such) or as admin, giving access to filters for all users.

Procmail or maildrop or dovecot-sieve is used to process your email on the server. It follows user defined rules. Common uses are to sort mail into folders or forward selected email on to other email addresses. The rules that you define are executed as email arrives in your mailbox on the server, and are independent of your email client. If you sort to folders you will need to use a IMAP mail client to read them.

Related Contribs

See https://wiki.koozali.org/Email-Management

Rule List

The panel shows a table of active rules and the order they are executed in. Each rule has links to modify or remove them.

A yes* in 'copy to' copies the email to your inbox

To forward an email to multiple addresses, place a space between them.

Other information on the main panel

If the sieve filter is in use, then a button is shown to apply the current set of filters to the INBOX. This runs "sieve-filter" in the background and will adjust the email count if some are deleted or moved.

The panel also shows

  • the filter type in use
  • the number of emails currently in the INBOX
  • the number of emails affected by a test run of the filter (only after the test has been run)


Create Rules

A user defines a pattern for emails that if matched, an action occurs.


Important.png Note:
Defining a mail rule that includes characters such as "[ $ . , ' | " \{ ^ + ? ( \ " breaks the sort rules and standard mail delivery in general. It is necessary to escape these special characters in the mail rules so that the sort rules work correctly. Special characters can be entered but you must verify they do not break mail deliver and work as expected. It is recommended you only use alphanumeric, @ and spaces.


The rule fields are in fact regular expressions compatible with egrep. As a result the above cited characters are interpreted as structure of the language. Refer to "man egrep" for correct syntax. As an example if you want to catch mails with the subject including "[mymailinglist]", your rule will be :

\[mymailinglist\]

Also please note that that character "|" (pipe) is the default character used to separate fields in the internal database, so it is forbidden.

Configuration

Enable mailsorting

Use either procmail or maildrop or dovecot-sieve

db configuration setprop qmail FilterType procmail
db configuration setprop qmail FilterType maildrop
db configuration setprop qmail FilterType sieve
db configuration delprop qmail FilterType [delete to disable]

If you want to bypass filtering for an individual user

db accounts setprop user MailFilter bypass
db accounts delprop user MailFilter [delete to disable]

after any command

signal-event mailsorting-conf

Any mail that passes through procmail or maildrop or dovecot-sieve without matching a rule is delivered according to the existing user setting.
ie. deliver locally, forward or both.


Important.png Note:
you can force the creation and the validation of rules of a user by this command line
signal-event mailsorting-conf user

where user has to match a real user name on your server


Sieve compatibility

Only for SME9+

On SME 11 and above, sieve is enabled by default and dovecot-extras has been merged to core. Once Sieve enabled by the Contrib smeserver-dovecot-extras, filter rules defined in a user's ~/.procmailrc or ~/.mailfilter or ~/.sievefilter file are applied prior to the mail getting passed to dovecot-lda and Sieve. If you want to prohibit the use of Sieve for a determined User

db accounts  setprop USERNAME Sieve disabled
signal-event mailsorting-conf

Deleting duplicates

Procmail will automatically delete duplicate email.

Maildrop has to be enabled at the command line

Procmail will automatically delete duplicate email.

Individually

db processmail setprop USERNAME deldups yes 
signal-event mailsorting-conf 

To enable for all users

db processmail setprop maildrop deldups yes
signal-event mailsorting-conf 

Create a global rule

db commands

It's possible just to use db commands, here is a subset of options

db processmail setprop 50001 pmGlobalRule action delete basis subject criterion xyz

50001: is the rule precedence

action: is either - sort delete forward

basis: match against this - headers Subject To From

criterion: using the text entered here - 'xyz'


Fragments

For more flexibility create a fragment in templates-user, expand template as above.


Geekmode Rules

By design the mail user .procmailrc, .mailfilter or .seivefilter file are built from SME templates whenever a system update is performed. You can disable that action by enabling "geekmode", using the command below. With that done, you may write your own .procmailrc, .mailfilter or .sievefilter file and place it in the appropriate mail directory.

db accounts setprop USERNAME geekmode enabled

Geekmode implies you know what you are doing when creating a custom filter file.

Testing

Create a simple rule, eg Subject = xyz > forward to USER2

Send an email to USERNAME to match, check in USER2's inbox

View the logs

  • For Maildrop
tail -50 /home/e-smith/files/users/USERNAME/mailfilter.log
  • For Procmail
tail -50 /home/e-smith/files/users/USERNAME/procmail.log
  • For dovecot-sieve
    tail -f /var/log/dovecot/dovecot.log
    

View the rules

  • For Maildrop
less /home/e-smith/files/users/USERNAME/.mailfilter
  • For Procmail
less /home/e-smith/files/users/USERNAME/.procmailrc
  • For Sieve
    less /home/e-smith/files/users/USERNAME/.sievefilter
    Note that the individual filter rule is displayed on the "modify" panel according to which filter programme is in use.

Bugs

Please raise bugs under the SME-Contribs section in bugzilla and select the smeserver-mailsorting component or use this link


IDProductVersionStatusSummary (13 tasks)
13267SME ContribsFuturRESOLVEDQmail/FilterType DB entry not got a default.
13264SME ContribsFuturCONFIRMEDAdd Body and ListID to options for sieve variant and add duplicate rule command
13255SME ContribsFuturRESOLVEDApply to inbox with user selected from admin reverts to admin
13251SME Contribs11.0RESOLVEDHeaders basic type only takes domain to be matched in sieve generation
13245SME Contribs11.0RESOLVEDMake Global rule processing the same as User rule processing
13244SME ContribsFuturCONFIRMEDEnhancements after Sieve implementation
13232SME Contribs11.0RESOLVEDAdd Dovecot Sieve generation and application
13190SME Contribs11.0CONFIRMEDTable extends past right margin of window
13000SME Contribs11.0RESOLVEDAdd an SM2 panel to mailsorting
11338SME ContribsFuturUNCONFIRMEDCopy rules from one user account to another
10517SME Contribs9.2CONFIRMEDEmailForward and ForwardAddress properties are used in mailfilter rules but not in procmail
8572SME Contribs8.1UNCONFIRMEDmaildrop: delivery deferred
4662SME Contribs7.3CONFIRMEDSpecial characters input in match criterion breaks mail sort rules

Changelog

Only versions released in smecontrib are listed here.

smeserver-mailsorting Changelog: SME 10 (smecontribs)
2024/09/06 Terry Fage 1.4-15.sme
- apply locale locale-2024-09-06.patch
2021/08/23 Terry Fage 1.4-14.sme
- apply locale 2021-08-22 patch
2021/04/25 Jean-Philippe Pialasse 1.4-13.sme
- add requirement for maildrop and procmail [SME: 11578]
2021/02/22 Jean-Philipe Pialasse 1.4-12.sme
- add update event to avoid need of reboot [SME: 10952]
2020/11/24 Brian Read 1.4-11.sme
- First import to SME10 [SME: 10952]