Dovecot: Email clients and duplicated folders
So in my server I'm usually going against a problem, different emails clients call some special folders like Sent
and Trash
different names like Sent Items
and Deleted Items
.
My question is, can I in some way "alias" all those names and internally map them to a same Sent
folder on the server?
I managed to change my dovecot.conf
an include sections like:
mailbox Sent {
special_use = \Sent
auto=subscribe
}
mailbox "Sent Messages" {
special_use = \Sent
}
mailbox "Sent Items" {
special_use = \Sent
}
Is this the right way to "fix" this annoying issue? It seems to work, at least there's no actually duplication on the server, but some emails clients may pick all the folders duplicated.
Thank you.
You can use the Mailbox alias plugin requiring Dovecot 2.1.10+ which creates symlinks on the filesystem level to provide one directory with more than one name. The both directories have the same content.
Example configuration where Sent and Trash are the real mailboxes for the aliases "Sent Items" and "Deleted Items":
mail_plugins = $mail_plugins mailbox_alias
plugin {
mailbox_alias_old = Trash
mailbox_alias_new = Deleted Items
mailbox_alias_old2 = Sent
mailbox_alias_new2 = Sent Items
}
Don't forget to create the mailboxes:
namespace inbox {
mailbox Sent {
auto = create # or subscribe
special_use = \Sent
}
mailbox Trash {
auto = create
special_use = \Trash
}
}
The other possibility is to create two different mailboxes as you mentioned, I copied a part of conf.d/15-mailboxes.conf
namespace inbox {
# For \Sent mailboxes there are two widely used names. We'll mark both of
# them as \Sent. User typically deletes one of them if duplicates are created.
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
}
Using this method, you have two different Sent-boxes. When the user deletes one of them, the other still exists unchanged.
There is no need to use the plugin. Go to your vmail directory, example:
cd /var/vmail/example.com/exampleUser/
then, if you want for example to have all messages stored into the "Sent Messages"
folder to be stored into the "Sent"
folder instead, just move the files of "Sent Messages"
into "Sent"
through your client as first step.
Then, in the /var/vmail/example.com/exampleUser/mail
folder, remove the "Sent Messages"
hidden folder:
rm -r /var/vmail/example.com/exampleUser/mail/.Sent\ Messages
Before sending any other email, proceed adding a symlink to the hidden folder "Sent"
from "Sent Messages"
(long line here, if you copy and paste do it carefully):
ln -s /var/vmail/example.com/exampleUser/mail/.Sent /var/vmail/example.com/exampleUser/mail/.Sent\ Messages
This should be working fine. Just repeat the same procedure if you want to have the "Sent Items"
or "Mail Sent"
or any other folder symlinked to the "Sent"
one, or if you want any other solution with other folders pointing to other folders and keep the mails in just one of them.
If you need to make dovecot and the client to use "INBOX"
as the "Sent"
folder, you should create the symbolic link from the mail folder with the username (long line again):
ln -s /var/vmail/example.com/exampleUser/mail/ /var/vmail/example.com/exampleUser/mail/.Sent\ Messages
unless you didn't change it. Then edit in the /etc/dovecot/conf.d/15-mailboxes.conf
the lines:
namespace inbox {
# For \Sent mailboxes there are two widely used names. We'll mark both of
# them as \Sent. User typically deletes one of them if duplicates are created.
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
}
or other equivalent to make them become:
namespace inbox {
# For \Sent mailboxes there are two widely used names. We'll mark both of
# them as \Sent. User typically deletes one of them if duplicates are created.
mailbox INBOX {
special_use = \Sent
}
mailbox INBOX {
special_use = \Sent
}
}
As you can notice, two are the same now, so you can just delete one:
namespace inbox {
# For \Sent mailboxes there are two widely used names. We'll mark both of
# them as \Sent. User typically deletes one of them if duplicates are created.
mailbox INBOX {
special_use = \Sent
}
}
Then it should work fine.
I've gone through this process because I wanted my sent emails to be in my inbox folder both from my laptop and my phone. The dovecot hack was enough for the laptop, but the phone kept using the "Sent Messages"
folder, so I had to use the symlink trick. Be very careful in selecting the right "Sent"
or "Sent Messages"
or whatever folder to make the symlink to and from!
I guess the plugin simply does a symlink itself, so you're just making similar stuff. With this technique you may merge all the folders you want and keep your clients work with no changes. :-)