Commit 51ddb3d1 authored by Claudemir Todo Bom's avatar Claudemir Todo Bom

* better spam learning

parent cc8ae824
Pipeline #203 passed with stage
in 1 minute and 24 seconds
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables", "regex"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
set :lower "mailbox" "${1}";
}
if string :is "${mailbox}" [ "Trash" , "trash" , "Deleted Items" , "deleted messages" ] {
# do not process Trash folders
if string :regex "${mailbox}" "^(trash|deleted( .*)?|itens exclu.*)$" {
stop;
}
if string :is "${mailbox}" [ "Sent" , "Archive" , "Drafts" ] {
# do not process Draft and Sent folders
if string :regex "${mailbox}" "^(sent( .*)?|drafts|rascunhos|itens enviados)$" {
stop;
}
if string :is "${mailbox}" [ "Junk" , "junk" , "spam" , "Spam" , "SPAM" , "Junk E-mail" ] {
# detect spam folders
if string :regex "${mailbox}" "^(junk( .*)?|spam|lixo eletr.*)$" {
set "command" "spam";
} else {
set "command" "ham";
......@@ -26,4 +29,4 @@ if environment :matches "imap.cause" "*" {
set "cause" "${1}";
}
pipe :copy "sa-learn-pipe.sh" [ "${username}", "${command}" , "${cause}" ];
pipe :copy "sa-learn-pipe.sh" [ "${username}", "${command}" , "${cause}" , "${mailbox}" ];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables", "regex"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
set :lower "mailbox" "${1}";
}
if string "${mailbox}" "Trash" {
# do not process Trash folders
if string :regex "${mailbox}" "^(trash|deleted( .*)?|itens exclu.*)$" {
stop;
}
# do not process Junk folders
if string :regex "${mailbox}" "^(junk( .*)?|spam|lixo eletr.*)$" {
stop;
}
......@@ -16,4 +22,4 @@ if environment :matches "imap.cause" "*" {
set "cause" "${1}";
}
pipe :copy "sa-learn-pipe.sh" [ "${username}", "ham" , "${cause}" ];
pipe :copy "sa-learn-pipe.sh" [ "${username}", "ham" , "${cause}" , "${mailbox}" ];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables", "regex"];
if environment :matches "imap.mailbox" "*" {
set :lower "mailbox" "${1}";
}
# Work only on Junk folders - exit if not
if not string :regex "${mailbox}" "^(junk( .*)?|spam|lixo eletr.*)$" {
stop;
}
if environment :matches "imap.user" "*" {
set "username" "${1}";
......@@ -8,4 +17,4 @@ if environment :matches "imap.cause" "*" {
set "cause" "${1}";
}
pipe :copy "sa-learn-pipe.sh" [ "${username}", "spam" , "${cause}" ];
pipe :copy "sa-learn-pipe.sh" [ "${username}", "spam" , "${cause}" , "${mailbox}" ];
......@@ -7,9 +7,6 @@ MYPID=$$
TEMPFILE=/var/spool/maildir/salearn-queue/salearn-msg-$$.$RANDOM.msg
cat - > ${TEMPFILE}
## DEBUG
## echo /usr/bin/sa-learn $* /tmp/sendmail-msg-$$.txt
### check if queue is being read
( [ -f /var/run/sa-learn-queue/sa-learn-queue.pid ] \
&& SAQ_PID=$(cat /var/run/sa-learn-queue/sa-learn-queue.pid) \
......@@ -18,10 +15,9 @@ cat - > ${TEMPFILE}
SAUSER="$1"
SACOMMAND="--$2"
SACAUSE="$3"
[ -e /var/spool/maildir/salearn.pipe ] || ( /usr/bin/mkfifo /var/spool/maildir/salearn.pipe && /bin/chmod ugo+r /var/spool/maildir/salearn.pipe )
[ "${SACOMMAND}" ] && [ "${SAUSER}" ] && [ "${TEMPFILE}" ] && echo "${SACOMMAND} ${SAUSER} ${TEMPFILE}" > /var/spool/maildir/salearn.pipe
/usr/bin/logger -p mail.notice -t sa-learn-pipe\[${MYPID}\] "added to queue: Cause ${SACAUSE} / command: ${SACOMMAND} ${SAUSER} ${TEMPFILE}"
/usr/bin/logger -p mail.notice -t sa-learn-pipe\[${MYPID}\] "added to queue: ${TEMPFILE} $*"
......@@ -22,21 +22,43 @@ plugin {
sieve_plugins = sieve_imapsieve sieve_extprograms
# From elsewhere to Junk folder
imapsieve_mailbox1_name = Junk
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_before = file:/etc/wwmail/antispamsieve/learn_spam.sieve
# Append action - used by Outlook when moving!
imapsieve_mailbox1_name = *
imapsieve_mailbox1_causes = APPEND
imapsieve_mailbox1_before = file:/etc/wwmail/antispamsieve/learn.sieve
# From Junk folder to elsewhere
imapsieve_mailbox2_name = *
imapsieve_mailbox2_from = Junk
# From elsewhere to Junk folder
imapsieve_mailbox2_name = Junk*
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:/etc/wwmail/antispamsieve/learn_ham.sieve
imapsieve_mailbox2_before = file:/etc/wwmail/antispamsieve/learn_spam.sieve
# Append action - used by Outlook when moving!
# From Junk folder to elsewhere
imapsieve_mailbox3_name = *
imapsieve_mailbox3_causes = APPEND
imapsieve_mailbox3_before = file:/etc/wwmail/antispamsieve/learn.sieve
imapsieve_mailbox3_from = Junk*
imapsieve_mailbox3_causes = COPY
imapsieve_mailbox3_before = file:/etc/wwmail/antispamsieve/learn_ham.sieve
# Variations of Junk folder names
imapsieve_mailbox4_name = Spam*
imapsieve_mailbox4_causes = COPY
imapsieve_mailbox4_before = file:/etc/wwmail/antispamsieve/learn_spam.sieve
# From Junk folder to elsewhere
imapsieve_mailbox5_name = *
imapsieve_mailbox5_from = Spam*
imapsieve_mailbox5_causes = COPY
imapsieve_mailbox5_before = file:/etc/wwmail/antispamsieve/learn_ham.sieve
imapsieve_mailbox6_name = Lixo*
imapsieve_mailbox6_causes = COPY
imapsieve_mailbox6_before = file:/etc/wwmail/antispamsieve/learn_spam.sieve
# From Junk folder to elsewhere
imapsieve_mailbox7_name = *
imapsieve_mailbox7_from = Lixo*
imapsieve_mailbox7_causes = COPY
imapsieve_mailbox7_before = file:/etc/wwmail/antispamsieve/learn_ham.sieve
sieve_pipe_bin_dir = /etc/wwmail/antispamsieve/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment