WeFixIT

Mailcow change Dovecot mail directory layout

Here you find a solution to change the default behavior of Dovecot to store folders in a different way to reduce problems when clients use Microsoft Outlook. Yes there are still people out there who use Outlook instead of Thunderbird or the Webinterface … but that’s another story.

Before
  • Folder
  • Folder.Subfolder
  • Folder.Subfolder.Subfolder
After
  • Folder
    • Subfolder
      • Subfolder

Problem

With older versions of Outlook you have the problem with folders which contain a dot/period. When you create a folder like “1.1_abc” it will create exactly this folder in Dovecot, which leads to an error because Dovecot and Outlook think “1_abc” is a subfolder of “1”. This leads to broken folders, you find the terms “phantom folder” and “ghost folder” on different boards.

Solution

Append “LAYOUT=fs:DIRNAME=DOVECOT.dir” to the maildir/mail_locatixon setting. This was not that easy because mailcow stores this setting, not as usual, in the configuration file, instead it is saved into the database. Therefore the query has to be changed. See below:

cp helper-scripts/docker-compose.override.yml.d/BUILD_FLAGS/docker-compose.override.yml docker-compose.override.yml

vim docker-compose.override.yml

version: '2.1'
services:

  dovecot-mailcow:
    build: ./data/Dockerfiles/dovecot
vim data/Dockerfiles/dovecot/docker-entrypoint.sh
Before:
cat <<EOF > /etc/dovecot/sql/dovecot-dict-sql-userdb.conf
# Autogenerated by mailcow
driver = mysql
connect = "host=/var/run/mysqld/mysqld.sock dbname=${DBNAME} user=${DBUSER} password=${DBPASS}"
user_query = SELECT CONCAT(JSON_UNQUOTE(JSON_VALUE(attributes, '$.mailbox_format')), mailbox_path_prefix, '%d/%n/${MAILDIR_SUB}:VOLATILEDIR=/var/volatile/%u:INDEX=/var/vmail_index/%u') AS mail, '%s' AS protocol, 5000 AS uid, 5000 AS gid, concat('*:bytes=', quota) AS quota_rule FROM mailbox WHERE username = '%u' AND (active = '1' OR active = '2')
iterate_query = SELECT username FROM mailbox WHERE active = '1' OR active = '2';
EOF
After:
cat <<EOF > /etc/dovecot/sql/dovecot-dict-sql-userdb.conf
# Autogenerated by mailcow
driver = mysql
connect = "host=/var/run/mysqld/mysqld.sock dbname=${DBNAME} user=${DBUSER} password=${DBPASS}"
user_query = SELECT CONCAT(JSON_UNQUOTE(JSON_VALUE(attributes, '$.mailbox_format')), mailbox_path_prefix, '%d/%n/${MAILDIR_SUB}:VOLATILEDIR=/var/volatile/%u:INDEX=/var/vmail_index/%u:LAYOUT=fs:DIRNAME=DOVECOT.dir') AS mail, '%s' AS protocol, 5000 AS uid, 5000 AS gid, concat('*:bytes=', quota) AS quota_rule FROM mailbox WHERE username = '%u' AND (active = '1' OR active = '2')
iterate_query = SELECT username FROM mailbox WHERE active = '1' OR active = '2';
EOF

Reload the changes and check if the new files were replaced in the container:

docker-compose up -d --build dovecot-mailcow

docker-compose exec dovecot-mailcow cat /etc/dovecot/sql/dovecot-dict-sql-userdb.conf

Now you can log into SOGO and create a new folder. Don’t forget to check the filestructure afterwards.

ls -alh /var/lib/docker/volumes/mailcowdockerized_vmail-vol-1/_data/<DOMAIN>/<USER>/Maildir/

This solution should survive an update.

Scroll to Top