PDA

View Full Version : IMAP folders



ZipperZapper
04-18-2017, 07:57 AM
I've got a problem with IMAP and I can't seem to find the right answer (or the right search term? :p).

I'm using Directadmin as my mail server, with Dovecot and Roundcube webmail. I use the IMAP-protocol to get my mail on all my devices and I keep running into a problem around folders: it's a mess.

It looks like every mailclient (Gmail on Android, Thunderbird on Windows, sometimes Windows Mail on Windows) adds its own Concepts, Sent and Trash folders to the server. At the moment one account of mine shows one inbox, 2 'Concepts'-folders, Trash, Deleted Items, Deleted Mail and INBOX.Trash, Sent, Sent Items, INBOX.Sent.

Is there a way to force every mailclient to use the same folder for sent/trash/concepts? I sometimes use Gmail over IMAP and it seems to work there, but I can't find the right place/way to set this up in Directadmin/Dovecot.

zEitEr
04-18-2017, 09:17 AM
Hello,

Yes, it's possible, you need to define special folders at the server level in Dovecot. Check this:

https://wiki.dovecot.org/MailboxSettings

ZipperZapper
04-18-2017, 09:47 AM
That was quick, thanks! Weird I didn't find that, seems logic.

It's not completely clear to me where to put it in the config. /usr/local/directadmin/custombuild/custom/dovecot/dovecot.conf? Or a seperate file? Will it automaticly apply to all currently active mailusers?

zEitEr
04-18-2017, 09:53 AM
Better something like 90-special-folders.conf in /usr/local/directadmin/custombuild/configure/dovecot/conf.d/.

This will let you have the original version of dovecot.conf

Mailusers will or won't have new folders, depending on:

auto: Autocreate/subscribe mailbox?

no: Neither
create: Autocreate, but don't autosubscribe
subscribe: Autocreate and autosubscribe



They will probably need to re-read folders from the server.

ZipperZapper
04-18-2017, 10:26 AM
Ah, thanks.

Won't it overwrite any already existing folders? I would like to use 'subscribe' to make sure every mailclient uses the same folders anytime, but won't have users lose their mail.

"webapps_inbox_prefix" is turned on in Custombuild, does that have any effect on the config-file? And do I have to rebuild Dovecot?

I'm sorry, don't have that much experience with Dovecot so I'm a bit scared to screw it up.

zEitEr
04-18-2017, 10:58 AM
No need to rebuild dovecot. After re-defining special folders the current emails might get inaccessible via a regular way (it means you won't see them in new special folders). The old folders with emails won't get removed (though they might become invisible until you re-sync folders), they will become regular folders available for removing, hiding, showing, etc.

I did such an installation for my clients. So there is actually little risk, if any exists at all.

If you are unsure on consequences, you'd better test it in a dev environment. You can even use a testing server with Dovecot without Directadmin for this. If you don't have a testing server use a VPS from hosting companies which offer free-trial.

ZipperZapper
04-18-2017, 11:11 AM
Thank you so much for your time. I want to make use of the default folders ''Verzonden", "Concepten", "Spam" en "Prullenbak" (Dutch). I created names that didn't exist yet, to prevent problems. I saved the following 90-special-folders.conf in /usr/local/directadmin/custombuild/configure/dovecot/conf.d/ :



namespace inbox {
prefix = INBOX.
inbox = yes

mailbox Prullenbak {
auto = subscribe
special_use = \Trash
}
mailbox Concepten {
auto = subscribe
special_use = \Drafts
}
mailbox Verzonden {
auto = subscribe
special_use = \Sent
}

mailbox Spam {
auto = subscribe
special_use = \Junk
}
}


After deleting my mailaccount and connecting to it again from Windows mailclient, I don't see any of these folders created in /home/user/Maildir or added to the subscriptions file in there. Is there a step I'm missing here? I only did a restart of the Dovecot-service.

zEitEr
04-18-2017, 11:14 AM
Yes, you need to run:


./build dovecot_conf

My setup has these lines:



namespace {
separator = .
#prefix = INBOX.
inbox = yes
type = private
list = yes
subscriptions = yes

... skipped...


Then you might need to update



$config['default_folders'] = array(...);


in /var/www/html/roundcube/config/config.inc.php and save it to /usr/local/directadmin/custombuild/custom/roundcube/config.inc.php

ZipperZapper
04-18-2017, 03:32 PM
I'm completely lost now. The 90-special-folders.conf did not seem to work, maybe because I already had a custom Dovecot config file, so I added it to that file:


namespace inbox {
prefix = INBOX.
separator = .
inbox = yes
type = private
list = yes
subscriptions = yes

mailbox Prullenbak {
auto = subscribe
special_use = \Trash
}
mailbox Concepten {
auto = subscribe
special_use = \Drafts
}
mailbox Verzonden {
auto = subscribe
special_use = \Sent
}

mailbox Spam {
auto = subscribe
special_use = \Junk
}
}


Then I used https://help.directadmin.com/item.php?id=228 to create default folders for new users:


#!/bin/sh
DIR=/home/$username/imap/$domain/$user/Maildir
mkdir -p $DIR/.INBOX.Concepten
mkdir -p $DIR/.INBOX.Verzonden
mkdir -p $DIR/.INBOX.Prullenbak
echo ".INBOX.Concepten" >> $DIR/subscriptions
echo ".INBOX.Verzonden" >> $DIR/subscriptions
echo ".INBOX.Prullenbak" >> $DIR/subscriptions
chown -R $username:mail $DIR
exit 0;


And in /usr/local/directadmin/custombuild/custom/roundcube/config.inc.php I changed the values to my new folder names and turned 'create_default_folders' to false.



$config['drafts_mbox'] = 'INBOX.Concepten';
$config['junk_mbox'] = 'INBOX.Spam';
$config['sent_mbox'] = 'INBOX.Verzonden';
$config['trash_mbox'] = 'INBOX.Prullenbak';
$config['default_folders'] = array('INBOX', 'INBOX.Concepten', 'INBOX.Verzonden', 'INBOX.Spam', 'INBOX.Prullenbak');
$config['smtp_helo_host'] = 'xxxxxxxxxxx';
$config['smtp_auth_type'] = 'LOGIN';
$config['create_default_folders'] = false;
$config['protect_default_folders'] = true;
$config['login_autocomplete'] = 2;
$config['quota_zero_as_unlimited'] = true;
$config['enable_spellcheck'] = false;
$config['email_dns_check'] = true;
$config['mime_types'] = '/var/www/html/roundcube/config/mime.types';


If I create a new mailuser under a domain now, the folders 'INBOX.Concepten', 'INBOX.Verzonden', 'INBOX.Spam' and 'INBOX.Prullenbak' are created in Maildir, which I would expect from the email_create_post.sh.

But AS SOON as I login that new mailbox with Roundcube, '.Verzonden', '.Prullenbak', '.Spam' and '.Concepten' are also creatied in Maildir and added to the subscriptions file.

What is going wrong? I did a rebuild of the Dovecot-config and a rebuild of Roundcube after every change I made.

zEitEr
04-18-2017, 09:08 PM
auto = subscribe - autocreate and autosubscribe, should be no then.

ZipperZapper
04-19-2017, 02:01 AM
Alex, so much thanks for your help. I deleted the email_create_post.sh and now use the following settings:

dovecot.conf

namespace inbox {
inbox = yes
separator = .
type = private
list = yes
subscriptions = yes

mailbox Concepten {
auto = subscribe
special_use = \Drafts
}
mailbox Prullenbak {
auto = subscribe
special_use = \Trash
}
mailbox Verzonden {
auto = subscribe
special_use = \Sent
}

mailbox INBOX.spam {
auto = subscribe
special_use = \Junk
}
}


Roundcube config

$config['drafts_mbox'] = '.Concepten';
$config['trash_mbox'] = '.Prullenbak';
$config['sent_mbox'] = '.Verzonden';
$config['junk_mbox'] = '.INBOX.spam';
$config['default_folders'] = array('INBOX', '.Concepten', '.Prullenbak', '.Verzonden', '.INBOX.spam');


Now when I create a new mailaccount and login to Roundcube, the right folders are created and registered, so it seems to work. Apart from one thing: I can't delete files. Roundcube gives me this error:


UID MOVE: Invalid mailbox name: Begins with hierarchy separator

Weird? I tried switching around the order in 'default_folders' and adding/deleting the 'seperator = .' statement in dovecot (what does it do exactly? Doesn't seem to make any difference?), and I always end up with one folder giving me that error. Trash or Drafts mostly.

The subscriptions file seems right to me, the right folders exist in the Maildir. Puzzled.

zEitEr
04-19-2017, 07:56 AM
I believe the roundcube config should be modified on your side. I see these in defaults.inc.php:



$config['drafts_mbox'] = 'Drafts';
$config['junk_mbox'] = 'Junk';
$config['sent_mbox'] = 'Sent';
$config['trash_mbox'] = 'Trash';

no leading dots in the folders' names.

ZipperZapper
04-19-2017, 02:38 PM
Thanks Alex, it works!

One thing though: everything works as expected when creating a new account. the folders are created and used by Roundcube and other mail clients.

I also tried to make it work for my already existing account too, so I deleted the old ".INBOX.Sent Items" and others from Maildir and from the subscriptions-file.

After logging in with Roundcube I see the new folders are created and added to subscriptions, but after sending/deleting a mail as test, I see the old folders appear again too and Roundcube gets confused about the folder-tree.

Is there a way I have to 'reset' any existing account to make it work? Without deleting the mail inside it, if possible (I moved the things I like to keep to a temporary folder with a different name).

zEitEr
04-19-2017, 10:31 PM
The issue happened when you tried to delete emails in Roundcube? Try and check then your preferences in Roundcube, as it allows to re-define special folders per email-account in its interface.

ZipperZapper
04-20-2017, 04:00 AM
That did the trick. Thank you for your time Alex.

zEitEr
04-20-2017, 04:19 AM
Good. The other user might need to reset the settings in Roundcube too. Probably it can be changed in MySQL DB directly or in phpmyadmin. I did not study this moment yet.

Raymonds
10-10-2018, 06:00 AM
Good. The other user might need to reset the settings in Roundcube too. Probably it can be changed in MySQL DB directly or in phpmyadmin. I did not study this moment yet.

This has been very helpful indeed!!!. Will adding \Trash folders this way also mean they get purged as such when the option to Auto Purge Emails is set in the Administrator Settings ?

I know this thread is a bit older, but can't find anything to solve the auto purge of trash folders other than starting with the above.

Cheers,

Ray

zEitEr
10-16-2018, 09:16 AM
Ray,

According to this https://www.directadmin.com/features.php?id=868 .INBOX.Trash and .Trash are to be cleared by Directadmin crontask. So, yes, they should get purged.