[Dovecot] Is it safe to manipulate Maildir files directly?
Dovecoters,
is it safe to manipulate files in Maildir/xxx directly or will Dovecot become unstable if I don't make these changes by talking to Dovecot and having it make the changes? (I'm running 2.1.7 under Wheezy, IMAP only)
My specific application: I am running spamassassin and would like users to be able to submit spam (and ham) directly by moving it into special folders. A cron job can then find it and take action: feed spam messages to the bayesian trainer and then delete them; feed ham messages to the trainer and then move them into ~/Maildir/cur/
Having the cron job find the messages and train spamassassin is no problem. The question is how to move the messages. Is it safe to simply rename the files from my cron job?
The dovecot wiki implies that dovecot will notice a change in mtime and deal with it safely. Am I reading this correctly? Changing a message flags (i.e. name) and/or directory will change mtime.
If I have to go through to Dovecot I am afraid I'd need the user's credentials, which is not appropriate.
Thanks! -d
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Mon, 4 Nov 2013, David Henkel-Wallace wrote:
is it safe to manipulate files in Maildir/xxx directly or will Dovecot
if "xxx" does not include the Dovecot-related index files etc., then yes.
become unstable if I don't make these changes by talking to Dovecot and having it make the changes? (I'm running 2.1.7 under Wheezy, IMAP only)
My specific application: I am running spamassassin and would like users to be able to submit spam (and ham) directly by moving it into special folders. A cron job can then find it and take action: feed spam messages to the bayesian trainer and then delete them; feed ham messages to the trainer and then move them into ~/Maildir/cur/
I did this before switching to antispam. I use antispam with spool2dir now, that central directory has a inotify watcher that trains the messages instantly.
Having the cron job find the messages and train spamassassin is no problem. The question is how to move the messages. Is it safe to simply rename the files from my cron job?
You mean "ham -> ~/Maildir/cur"? Yes, but there is a slight chance, that an user already copy'ed the message there. If the stem of the filename, the part before the colon ":", is already present in the Maildir/cur or ~~/new, Dovecot might gets confused. I think all present versions generate an error in the sense "duplicate found, fixed by renaming into something".
I did not moved the message files from "ham" into the INBOX. I named the folders: spam/yes and spam/no, all my users moved messages into spam/yes, but copied them into spam/no and moved them themselves into their correct mailbox. Maybe, you can avoid that step, too.
Steffen Kaiser -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux)
iQEVAwUBUnic0V3r2wJMiz2NAQKywgf/f2ZE+U1NzCVkAAgwASdsv79SxrqNkrf/ +G+2HyBgFfRqk3TchPjVp3GYxFZjLhVZT5GhvU3P1RGfbgv+WKiGfaHSF5FGXVfv u16xcdHkyBBikwyT1YQ8rsO6YAIgUmUEoUIkrQGqdN40NpBx6TgIZZjmhyVTlr4g Nda9A+7dEAfvwyaXJSUxVPIjZC0+CONJ6+o4Wm+taXLbBAnb7brHAly8+ovjjvAt S5wyrPefR9U7N3U2ENyeZI7okib+qKNDIZ5AaMOdcP2ZHvebjJMLPA524glzBWyu 1Hq7OHabfLcugThlHTXr3WxKBMACiA2J5uNOxH4A3hxQmB+x7S7NqQ== =VZIk -----END PGP SIGNATURE-----
On Mon, 4 Nov 2013 21:49:59 -0800 David Henkel-Wallace <gumby@henkel-wallace.org> wrote:
Having the cron job find the messages and train spamassassin is no problem. The question is how to move the messages. Is it safe to simply rename the files from my cron job?
[...]
If I have to go through to Dovecot I am afraid I'd need the user's credentials, which is not appropriate.
you can do all this with doveadm scripts. http://wiki2.dovecot.org/Tools/Doveadm Something like this should work:
doveadm search -A mailbox 'hamreport' 2>/dev/null | while read user guid uid; do doveadm fetch -u $user text mailbox-guid $guid uid $uid | sa-learn --ham ; doveadm move -u $user INBOX mailbox-guid $guid uid $uid ; done
this should fetch all mails in the 'hamreport' folder of every user, pass it to sa-learn and then move it to the user's INBOX you don't need the user credentials , but you have to make sure doveadm can find all users (iterate_query setting with SQL auth db)
hth Oli
-- message transmitted on 100% recycled electrons
participants (3)
-
David Henkel-Wallace
-
Oli Schacher
-
Steffen Kaiser