[Dovecot] Automatic expire on post-login
I need to clear two folder from Maildir at login.
Exatly, delete all mails older than 30 days on Trash and 1 day on spam folder.
I'm using dovecot 2.0 and I think about use a post-login script calling doveadm -u $user expunge but post-login scripts in dovecot 2.0 are very complex
Is there possible to get the environment vars like on dovecot 1.2 ?
I think this action must be done by expire plugin, but it isn't the work method if as I understand after read wiki2.dovecot.org about expire plugin, It run only with a cronjob.
Well, I jet get a valid config for a post-login script as is shown in
http://wiki2.dovecot.org/PostLoginScripting
This is the content of dovecot.conf:
service imap { executable = imap imap-postlogin }
service imap-postlogin { executable = script-login /postlogin.sh user = root unix_listener imap-postlogin { } }
This is the content of postlogin.sh
#!/bin/bash /usr/local/bin/doveadm -D expunge -A mailbox Trash savedbefore 30d /usr/local/bin/doveadm -D expunge -A mailbox MarcaSpam savedbefore 1w exec $*
2010/11/24 Antonio Perez-Aranda aperezaranda@yaco.es:
I need to clear two folder from Maildir at login.
Exatly, delete all mails older than 30 days on Trash and 1 day on spam folder.
I'm using dovecot 2.0 and I think about use a post-login script calling doveadm -u $user expunge but post-login scripts in dovecot 2.0 are very complex
Is there possible to get the environment vars like on dovecot 1.2 ?
I think this action must be done by expire plugin, but it isn't the work method if as I understand after read wiki2.dovecot.org about expire plugin, It run only with a cronjob.
On 24.11.2010, at 9.47, Antonio Perez-Aranda wrote:
This is the content of postlogin.sh
#!/bin/bash /usr/local/bin/doveadm -D expunge -A mailbox Trash savedbefore 30d /usr/local/bin/doveadm -D expunge -A mailbox MarcaSpam savedbefore 1w exec $*
-A means it goes through all users, which most likely isn't what you want. Rather use -u $USER. Also add some check that this expunging isn't done more than once a day. Something like:
if [ ! -f expungestamp ] || [ find Makefile -mtime +1d
!= "" ]; then
touch expungestamp
doveadm ..
fi
Alternatively if this is too slow you could also build a plugin to do this (mostly copy&paste code from doveadm-mail-expunge.c).
Yes, -A is a typo error, because a I copy from cronjob. Really, I do doveadm -u $USER.
Well, I use expungestamp if the overload is very high.
When I execute doveadm -u $user many times, it's not take much time, lower than 0.1 seconds.
2010/11/24 Timo Sirainen tss@iki.fi:
On 24.11.2010, at 9.47, Antonio Perez-Aranda wrote:
This is the content of postlogin.sh
#!/bin/bash /usr/local/bin/doveadm -D expunge -A mailbox Trash savedbefore 30d /usr/local/bin/doveadm -D expunge -A mailbox MarcaSpam savedbefore 1w exec $*
-A means it goes through all users, which most likely isn't what you want. Rather use -u $USER. Also add some check that this expunging isn't done more than once a day. Something like:
if [ ! -f expungestamp ] || [
find Makefile -mtime +1d
!= "" ]; then touch expungestamp doveadm .. fiAlternatively if this is too slow you could also build a plugin to do this (mostly copy&paste code from doveadm-mail-expunge.c).
Am 24.11.2010 09:57, schrieb Antonio Perez-Aranda:
I need to clear two folder from Maildir at login.
Exatly, delete all mails older than 30 days on Trash and 1 day on spam folder.
I'm using dovecot 2.0 and I think about use a post-login script calling doveadm -u $user expunge but post-login scripts in dovecot 2.0 are very complex
i dont think you should do/can it with post-login script, this would produce heavy overload, as you connect much times i.e in an imap seesion but i may fail here...
Is there possible to get the environment vars like on dovecot 1.2 ?
I think this action must be done by expire plugin, but it isn't the work method if as I understand after read wiki2.dovecot.org about expire plugin, It run only with a cronjob.
i do it with cron and expire plugin
Best Regards
MfG Robert Schetterer
Germany/Munich/Bavaria
I can't use a cronjob because is a customer requeriment and the time to expunge over 200.000 accounts over nfs can take a log time.
2010/11/24 Robert Schetterer robert@schetterer.org:
Am 24.11.2010 09:57, schrieb Antonio Perez-Aranda:
I need to clear two folder from Maildir at login.
Exatly, delete all mails older than 30 days on Trash and 1 day on spam folder.
I'm using dovecot 2.0 and I think about use a post-login script calling doveadm -u $user expunge but post-login scripts in dovecot 2.0 are very complex
i dont think you should do/can it with post-login script, this would produce heavy overload, as you connect much times i.e in an imap seesion but i may fail here...
Is there possible to get the environment vars like on dovecot 1.2 ?
I think this action must be done by expire plugin, but it isn't the work method if as I understand after read wiki2.dovecot.org about expire plugin, It run only with a cronjob.
i do it with cron and expire plugin
Best Regards
MfG Robert Schetterer
Germany/Munich/Bavaria
Am 24.11.2010 11:31, schrieb Antonio Perez-Aranda:
I can't use a cronjob because is a customer requeriment and the time to expunge over 200.000 accounts over nfs can take a log time.
whatever, if really use post-login a find rm might be cheaper
i.e like, script optimized to your needs
http://wiki.dovecot.org/Plugins/Expire
v1.0 cronjob equivalent
For Dovecot v1.0, this can be accomplished by running a daily shell script:
# delete 30 day old mails find /var/virtualmail/ -regex '.*/\.\(Trash\|Junk\)\(/.*\)?\/\(cur\|new\)/.*' -type f -ctime +30 -delete # or -exec rm '{}' \; instead of -delete
but wait for timos comments
2010/11/24 Robert Schetterer robert@schetterer.org:
Am 24.11.2010 09:57, schrieb Antonio Perez-Aranda:
I need to clear two folder from Maildir at login.
Exatly, delete all mails older than 30 days on Trash and 1 day on spam folder.
I'm using dovecot 2.0 and I think about use a post-login script calling doveadm -u $user expunge but post-login scripts in dovecot 2.0 are very complex
i dont think you should do/can it with post-login script, this would produce heavy overload, as you connect much times i.e in an imap seesion but i may fail here...
Is there possible to get the environment vars like on dovecot 1.2 ?
I think this action must be done by expire plugin, but it isn't the work method if as I understand after read wiki2.dovecot.org about expire plugin, It run only with a cronjob.
i do it with cron and expire plugin
Best Regards
MfG Robert Schetterer
Germany/Munich/Bavaria
-- Best Regards
MfG Robert Schetterer
Germany/Munich/Bavaria
participants (3)
-
Antonio Perez-Aranda
-
Robert Schetterer
-
Timo Sirainen