I like to be able to use Dovecot's doveadm to expunge spam automatically for all mail accounts, but i-MSCP does not define an iterate query. From what i read on the forum that is because of incompatibility with Dovecot <v2.x.
Since Dovecot on my system is >v2.x i decided to write a listener for this (well, adapted an existing listener tbh ).
With this listener in place i can use a cronjob to clear out messages older than 30 days from the .Junk folder for all mail accounts with this command:
doveadm expunge -A mailbox INBOX.Junk savedbefore 30d
My actual cronjob also learns spam/ham for all accounts before expunging spam:
This script is saved as an executable file: /etc/cron.daily/spamjob
Here is the Listener file. If you want to use it then save as /etc/imscp/listeners.d/10_dovecot_iterate.pl:
- #!/usr/bin/perl
- package Listener::Dovecot::Iterate;
- use strict;
- use warnings;
- use iMSCP::EventManager;
- iMSCP::EventManager->getInstance()->register(
- 'beforePoBuildConf',
- sub {
- my ($cfgTpl, $tplName) = @_;
- return 0 unless index( $tplName, 'dovecot-sql.conf' ) != -1;
- $$cfgTpl.= <<'EOF';
- # Added by Listener::Dovecot::Iterate listener
- iterate_query = SELECT `mail_addr` AS 'user' FROM `mail_users` WHERE `mail_type` LIKE '%%_mail%%'
- EOF
- 0;
- }
- );
- 1;
- __END__
Nuxwin : Maybe it is possible to add the iterate query back into i-MSCP repository and make i-MSCP only install this for systems where Dovecot version is >2.x?