Philon bytesplit@gmail.com wrote:
I also looked into Sven’s advice (Danke!) about doveadm fetch. I just came across this script here: https://git.mnt-tech.fr/admintools.git/raw/master/blacklist.sh. It does much more than just fetch, but for me it was a good reference for retrival of mails using doveadm.
My code for my personal "salearn" script looks like this:
,----
| #!/bin/bash
|
| tempdir=mktemp -d
|
| doveadm search mailbox SPAM | while read guid uid;
| do
| tempfile=mktemp --tmpdir=$tempdir
| echo -n "$uid "
| doveadm fetch text mailbox-guid $guid uid $uid | tail -n +2 | head -n -1 > $tempfile
| done
| echo
|
| sa-learn --spam --no-sync --progress $tempdir
| sa-learn --sync
|
| rm -r $tempdir
`----
Some notes:
The dance with "| tail -n +2 | head -n -1" is to remove the leading "text:" line and the ^L (page feed) at the end doveadm inserts. (I really would like to have an option to fetch the raw source of the mail without doveadm adding, removing or reformatting anything.)
I don't use "-u '*'" here since this script runs as my user only directly on the server where the mails are stored. If you want to learn mails from multiple users you will of course need to iterate over all of them, just as the example script from mnt-tech.fr does.
Grüße, Sven.
-- Sigmentation fault. Core dumped.