Dovecot - SpamToJunk, ImapIDLE and Expunge Junk Folder

  • Hi,

    there are some useful functions that can be implemented in i-MSCP directly

    Spam To Junk

    The i-MSCP panel already have a spam to junk implementation, but it works only if the user at the first time make a login through webmail and save the custom settings in RoundCube. To make working a default spam-to-junk filter to the users that does not make a login in webmail, here is the solution.

    1) edit the /etc/dovecot/dovecot.conf file and add the following lines:

    exit and save

    2) Create the default sieve dir, create a default sieve rule in and own it to the mail user

    mkdir /var/lib/dovecot/sieve
    nano /var/lib/dovecot/sieve/default.sieve

    chown -R vmail:mail /var/lib/dovecot/sieve

    3) reload/restart dovecot service

    service dovecot restart


    Imap IDLE

    The Imap IDLE function is very useful to increase the battery life of mobile device. Many Imap clients, like K9 mail, implement a push-to-mail function in Imap that use the Idle function of Imap server. The default idle time in dovecot is set to 2 minutes, increasing this time to 29 minutes, as the rfc2177 say, many mobile device can improve the battery life

    edit the /etc/dovecot/dovecot.conf file and add the following line:

    reload/restart dovecot service

    service dovecot restart


    Expunge Junk Folder

    This function can delete the oldest spam email received and optimize the space assigned to the mail account (edit 12/11/2014: modified cronjob and search query in DB)

    1) edit the file /etc/dovecot/dovecot-sql.conf and add this line at the end


    iterate_query = SELECT mail_addr AS user FROM mail_users

    now restart/reload dovecot service

    2) Create a new cronjob like this:

    crontab -e


    40 3 12 * * /usr/bin/doveadm expunge -A mailbox INBOX.Junk savedbefore 30d >/dev/null 2>&1


    Hope this can help many users :)

    Bye bye

  • @TheCry

    Apart the IMAP IDLE time section, all this is already included in the RoundcubePlugins plugin, right?


  • Hi,

    yes, i confirm, the sieverules are already implemented in i-MSCP through Roundcube managesieve plugins, but the spam to junk function is not enabled by default if the user does not make a login in RoundCube. The result is that the spam email are delivered in INBOX folder and not in INBOX.Junk. With my mod all the users have the spam to junk by default. See a description in 90-sieve.conf file

  • Did you take al look in the config templates of the roundcube plugin?

    1. config-templates/managesieve

    There is the config template for your solution

    1. require ["fileinto"];
    2. # rule:[Spam]
    3. if header :contains "X-Spam-Flag" "YES"
    4. {
    5. fileinto "INBOX.Junk";
    6. stop;
    7. }
  • Sure, i've used exactly your template

    The roundcube plugin with your implementation add this in /var/mail/virtual/somedomain/someuser

    dovecot.sieve -> sieve/managesieve.sieve

    But have you try if you don't use roundcube but only IMAP or POP3?

    This file/folder are not created and sieve does not have any rule to delivery the spam to INBOX.Junk folder, so, the email are delivered in INBOX with the spam definition directly

  • I will check this issue. But i think you don't had installed the plugin like we described in the wiki. You have the same problem i had on some other server. The symbolic link is created to sieve and not to managesieve!

  • For me is not a problem, now the function work correctly as i desire. I've make only 2 installation of i-MSCP in production state (1 in juni and 1 in september), i've followed the wiki for the installation and both have this problem that i've solved with this workaround.

  • Gotta pull this out again.

    I have exactly the same issue, i-mscp 1.2.2: users have to login to webmail first to get their spam rule. Now I´ve made the changes sport80 mentioned but dovecot [the user vmail] seems to have no access.

    1. Mar 5 10:46:10 mail dovecot: lda([email protected]): Error: sieve: failed to stat sieve script: stat(/var/lib/dovecot/sieve/default.sieve) failed: Permission denied (euid=999(vmail) egid=8(mail) missing +x perm: /var/lib/dovecot, we're not in group 0(root), dir owned by 0:0 mode=0750)

    Yeah sure, have to change the permissions, but the

    1. chown -R vmail:mail /var/lib/dovecot/sieve

    didn´t help -.- Dovecot says that it is not in the right group, is it enough to change the mode from 0750 to 0777? I think this would be to...dangerous.

    Thanks in advance.

    Edit: Mhm, just tried 0777 for the sieve directory, still not working. So the issue must be within the permissions for the dovecot directory. Now it is "drwxr-x--- " so I have to change it to "drwxr-x-x"?

    Just changed it, works now. But I have some doubts, that this is okay that way, regarding the security...