Skip to content

Keep personal sieve scripts in the user's home with SQL (#109) - #112

Merged
AndrewSav merged 1 commit into
mailserver2:masterfrom
AndrewSav:sieve-home-path
Dec 4, 2026
Merged

AndrewSav merged 1 commit into
mailserver2:masterfrom
AndrewSav:sieve-home-path

Conversation

@AndrewSav

Copy link
Copy Markdown
Collaborator

Description

Fixes #109

  • What is the current behavior (you can also link to an open issue here) ?

    The SQL userdb sets each user's home and mail_path from the maildir column (auth-sql.conf.ext: CONCAT('/var/mail/vhosts/',maildir)), but 90-sieve.conf fixes the personal sieve storage at /var/mail/vhosts/<domain>/<localpart>/. That only matches when maildir is <domain>/<localpart>/, which is what PostfixAdmin writes with domain_path = 'YES'. With domain_path = 'NO', maildir is user@domain/, so mail goes to /var/mail/vhosts/user@domain/ while filters are read from and written to /var/mail/vhosts/<domain>/<localpart>/. Scripts copied in with the mail from another server are ignored.

  • What is the new behavior (if this is a feature change) ?

    • With SQL (MySQL/MariaDB or PostgreSQL), path = ~/sieve and active_path = ~/.dovecot.sieve, as the issue proposes. For a mailbox whose maildir is <domain>/<localpart>/ this is the same directory as before, so nothing moves.
    • With LDAP, the fixed path stays. An LDAP userdb only has a home when LDAP_DOVECOT_USER_ATTRS sets one, so ~ is not safe to rely on there.
    • 90-sieve.conf is now rendered by setup.sh (_envtpl) to choose between the two.

    Upgrade notes.

    Who is not affected: setups using LDAP, and setups whose mailboxes were all created through the PostfixAdmin image (mailserver2/postfixadmin, as in docker-compose.sample.yml). That image writes domain_path = 'YES' and domain_in_mailbox = 'NO' into its configuration on every start, and no environment variable changes them, so every mailbox it creates has maildir = <domain>/<localpart>/. For those mailboxes the new path is the same directory as the old one.

    Who may be affected: setups with mailboxes created some other way, for example a database imported from another PostfixAdmin installation, a different PostfixAdmin image or configuration, or rows written by a script. If such a mailbox's maildir is not <domain>/<localpart>/ and its user saved filters on this server (ManageSieve, Rainloop, doveadm sieve), those filters are still at the old path, and Dovecot no longer reads them. The container does not move them.

    To check: run this from the directory with your docker-compose.yml, before or after upgrading. It asks Dovecot for every mailbox's home, so it works with MySQL/MariaDB and PostgreSQL alike and needs no database password:

    docker compose exec -T mailserver sh -c 'doveadm user "*" | while read -r u; do old=/var/mail/vhosts/${u#*@}/${u%@*}; [ -e "$old/sieve" ] || [ -e "$old/.dovecot.sieve" ] || [ -L "$old/.dovecot.sieve" ] || continue; home=$(doveadm user -f home "$u" 2>/dev/null) || { echo "$u: inactive, has filters in $old"; continue; }; home=${home%/}; [ "$home" = "$old" ] && continue; echo "$u: move filters from $old to $home"; [ -e "$home/sieve" ] && echo "  $home/sieve already exists, merge by hand"; done; echo "check finished"'

    (Without Compose: docker exec -i <mailserver container> sh -c '...', with the same script.)

    If it prints only check finished, nothing needs doing. For each mailbox it lists, move sieve/ and .dovecot.sieve together from the first directory into the second. .dovecot.sieve is a link into sieve/: a relative link keeps working after the move, an absolute one has to be re-pointed. An inactive mailbox is listed with its old directory only, because Dovecot does not look up its home; its new directory is /var/mail/vhosts/ followed by its maildir.

    I left out an automatic move on startup. When the home already holds scripts, for example ones copied in with the mail as in Paths for personal sieve scripts should be based on the virtual users home directory #109, the container would have to pick which set wins. The check flags that case for a person to decide.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Test (adding missing tests or correcting existing ones)

Not breaking for mailboxes created by the PostfixAdmin image. It is a one-time manual step for mailboxes with a different maildir that already have filters here, as above.

Status

  • Ready

Todo List

  • Implementation
  • Tests
  • Documentation: the upgrade note above, for the release notes

How has this been tested ?

Two tests added to test/sieve.bats. They insert a mailbox with maildir = sieve.home@domain.tld/, as domain_path = 'NO' would, then:

  • upload a script with doveadm sieve put -a and check it lands in /var/mail/vhosts/sieve.home@domain.tld/sieve/, .dovecot.sieve points at it, and nothing is created under /var/mail/vhosts/domain.tld/sieve.home;
  • send that mailbox a message and check the script filed it into Filtered.

On this branch (rebased on master 32a7ef9), fresh build, TEST_DNS=9.9.9.9:

  • All nine suites: 364/364 (default 140, reverse 88, ldap 66, ldap2 30, sieve 4, ecdsa 4, traefik_acmev1 11, traefik_acmev2 12, traefik_v3 9).

  • The new tests against an image built from master (32a7ef9): the storage test fails, because the script is not written under the mailbox's maildir (test -f /var/mail/vhosts/sieve.home@domain.tld/sieve/filter.sieve, status 1). The delivery test passes there, because on master both the upload and the delivery use the old path, so they agree. It confirms the uploaded script actually filters mail, and leaves the location to the storage test.

  • The upgrade check, run in a sieve-suite container (MariaDB), with five mailboxes set up by hand:

    • default maildir, with filters: not listed
    • different maildir, no filters: not listed
    • different maildir, filters at the old path: listed with both directories
    • the same, with sieve/ also present in its home: listed, plus the merge warning
    • inactive, filters at the old path: listed as inactive

    With the old-path filters removed, it printed only check finished. It ran through docker exec -i, not docker compose exec -T.

)

The SQL userdb builds each user's home and mail_path from the mailbox's
maildir column, but the personal sieve storage was fixed at
/var/mail/vhosts/<domain>/<localpart>/. A mailbox whose maildir differs,
such as one imported from a PostfixAdmin installation with
domain_path = NO, kept its mail in one place and its filters in another,
and scripts copied in with the mail were ignored.

With SQL the storage is now ~/sieve and ~/.dovecot.sieve. Mailboxes
created by the PostfixAdmin image have maildir = <domain>/<localpart>/,
so their scripts stay where they are. LDAP keeps the fixed path, since an
LDAP userdb only has a home when LDAP_DOVECOT_USER_ATTRS sets one.

90-sieve.conf is now rendered as a template.
@AndrewSav
AndrewSav merged commit cf6c344 into mailserver2:master Dec 4, 2026
9 checks passed
@AndrewSav
AndrewSav deleted the sieve-home-path branch December 4, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paths for personal sieve scripts should be based on the virtual users home directory

2 participants