Commit bfedfb57 authored by Claudemir Todo Bom's avatar Claudemir Todo Bom

* one imapsieve script to rule them all

parent 51ddb3d1
Pipeline #204 passed with stage
in 1 minute and 27 seconds
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables", "regex"];
require ["vnd.dovecot.pipe", "copy", "vnd.dovecot.imapsieve", "environment", "vnd.dovecot.environment" , "variables", "regex"];
if environment :matches "imap.mailbox" "*" {
if environment :matches "vnd.dovecot.mailbox-to" "*" {
set :lower "mailbox" "${1}";
}
......@@ -14,19 +14,43 @@ if string :regex "${mailbox}" "^(sent( .*)?|drafts|rascunhos|itens enviados)$" {
stop;
}
# detect spam folders
if environment :matches "imap.cause" "*" {
set "cause" "${1}";
}
if string :is "${cause}" "APPEND" {
# Do not learn from Unknown (APPEND/Outlook) to Archive folders (risk of too much messages)
if string :regex "${mailbox}" "^(archive|arquivo).*" {
stop;
}
set "fromtype" "unknown";
} elsif environment :matches "vnd.dovecot.mailbox-from" "*" {
set :lower "frombox" "${1}";
# Set type of origin folder
if string :regex "${frombox}" "^(junk( .*)?|spam|lixo eletr.*)$" {
set "fromtype" "spam";
} else {
set "fromtype" "ham";
}
} else {
# COPY without could not determine origin folder / should never execute
stop;
}
# Set type of destination folder
if string :regex "${mailbox}" "^(junk( .*)?|spam|lixo eletr.*)$" {
set "command" "spam";
} else {
set "command" "ham";
}
if environment :matches "imap.user" "*" {
set "username" "${1}";
# Do not learn when moving between same type folders
if string :is "${fromtype}" "${command}" {
stop;
}
if environment :matches "imap.cause" "*" {
set "cause" "${1}";
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
pipe :copy "sa-learn-pipe.sh" [ "${username}", "${command}" , "${cause}" , "${mailbox}" ];
pipe :copy "sa-learn-pipe.sh" [ "${username}", "${command}" , "${cause}" , "${frombox}(${fromtype})=>${mailbox}(${command})" ];
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables", "regex"];
if environment :matches "imap.mailbox" "*" {
set :lower "mailbox" "${1}";
}
# 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;
}
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
if environment :matches "imap.cause" "*" {
set "cause" "${1}";
}
pipe :copy "sa-learn-pipe.sh" [ "${username}", "ham" , "${cause}" , "${mailbox}" ];
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}";
}
if environment :matches "imap.cause" "*" {
set "cause" "${1}";
}
pipe :copy "sa-learn-pipe.sh" [ "${username}", "spam" , "${cause}" , "${mailbox}" ];
......@@ -6,6 +6,7 @@ mail_location = maildir:%h
mail_privileged_group = mail
mail_plugins = quota
mail_attribute_dict = file:%h/dovecot-attributes
imap_metadata = yes
imap_capability = +SPECIAL-USE
......@@ -22,44 +23,11 @@ plugin {
sieve_plugins = sieve_imapsieve sieve_extprograms
# Append action - used by Outlook when moving!
# Learn Spam/Ham
imapsieve_mailbox1_name = *
imapsieve_mailbox1_causes = APPEND
imapsieve_mailbox1_causes = COPY APPEND
imapsieve_mailbox1_before = file:/etc/wwmail/antispamsieve/learn.sieve
# From elsewhere to Junk folder
imapsieve_mailbox2_name = Junk*
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:/etc/wwmail/antispamsieve/learn_spam.sieve
# From Junk folder to elsewhere
imapsieve_mailbox3_name = *
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/
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
......
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