Merge pull request #61 from fsr/imap-sieve
Mail: enable spam training through imap-sieve
This commit is contained in:
commit
d8e3bb4689
|
@ -31,7 +31,7 @@
|
|||
./modules/sops.nix
|
||||
./modules/kpp.nix
|
||||
./modules/ldap
|
||||
./modules/mail.nix
|
||||
./modules/mail
|
||||
./modules/mailman.nix
|
||||
./modules/nginx.nix
|
||||
./modules/hydra.nix
|
||||
|
|
|
@ -38,6 +38,34 @@ in
|
|||
4190 # sieve
|
||||
];
|
||||
users.users.postfix.extraGroups = [ "opendkim" ];
|
||||
environment.etc = {
|
||||
"dovecot/sieve-pipe/sa-learn-spam.sh" = {
|
||||
text = ''
|
||||
#!/bin/sh
|
||||
${pkgs.rspamd}/bin/rspamc learn_spam
|
||||
'';
|
||||
mode = "0555";
|
||||
};
|
||||
"dovecot/sieve-pipe/sa-learn-ham.sh" = {
|
||||
text = ''
|
||||
#!/bin/sh
|
||||
${pkgs.rspamd}/bin/rspamc learn_ham
|
||||
'';
|
||||
mode = "0555";
|
||||
};
|
||||
"dovecot/sieve/report-spam.sieve" = {
|
||||
source = ./report-spam.sieve;
|
||||
user = "dovecot2";
|
||||
group = "dovecot2";
|
||||
mode = "0544";
|
||||
};
|
||||
"dovecot/sieve/report-ham.sieve" = {
|
||||
source = ./report-ham.sieve;
|
||||
user = "dovecot2";
|
||||
group = "dovecot2";
|
||||
mode = "0544";
|
||||
};
|
||||
};
|
||||
|
||||
services = {
|
||||
postfix = {
|
||||
|
@ -143,7 +171,7 @@ in
|
|||
mailPlugins = {
|
||||
perProtocol = {
|
||||
imap = {
|
||||
enable = [ ];
|
||||
enable = [ "imap_sieve" ];
|
||||
};
|
||||
lmtp = {
|
||||
enable = [ "sieve" ];
|
||||
|
@ -152,19 +180,20 @@ in
|
|||
};
|
||||
mailboxes = {
|
||||
Spam = {
|
||||
auto = "create";
|
||||
auto = "subscribe";
|
||||
specialUse = "Junk";
|
||||
autoexpunge = "60d";
|
||||
};
|
||||
Sent = {
|
||||
auto = "create";
|
||||
auto = "subscribe";
|
||||
specialUse = "Sent";
|
||||
};
|
||||
Drafts = {
|
||||
auto = "create";
|
||||
auto = "subscribe";
|
||||
specialUse = "Drafts";
|
||||
};
|
||||
Trash = {
|
||||
auto = "create";
|
||||
auto = "subscribe";
|
||||
specialUse = "Trash";
|
||||
};
|
||||
};
|
||||
|
@ -202,6 +231,24 @@ in
|
|||
}
|
||||
client_limit = 1
|
||||
}
|
||||
|
||||
|
||||
plugin {
|
||||
sieve_plugins = sieve_imapsieve sieve_extprograms
|
||||
sieve_global_extensions = +vnd.dovecot.pipe
|
||||
sieve_pipe_bin_dir = /etc/dovecot/sieve-pipe
|
||||
|
||||
# Spam: From elsewhere to Spam folder or flag changed in Spam folder
|
||||
imapsieve_mailbox1_name = Spam
|
||||
imapsieve_mailbox1_causes = COPY APPEND FLAG
|
||||
imapsieve_mailbox1_before = file:/etc/dovecot/sieve/report-spam.sieve
|
||||
|
||||
# Ham: From Spam folder to elsewhere
|
||||
imapsieve_mailbox2_name = *
|
||||
imapsieve_mailbox2_from = Spam
|
||||
imapsieve_mailbox2_causes = COPY
|
||||
imapsieve_mailbox2_before = file:/etc/dovecot/sieve/report-ham.sieve
|
||||
}
|
||||
'';
|
||||
};
|
||||
opendkim = {
|
15
modules/mail/report-ham.sieve
Executable file
15
modules/mail/report-ham.sieve
Executable file
|
@ -0,0 +1,15 @@
|
|||
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
|
||||
|
||||
if environment :matches "imap.mailbox" "*" {
|
||||
set "mailbox" "${1}";
|
||||
}
|
||||
|
||||
if string "${mailbox}" "Trash" {
|
||||
stop;
|
||||
}
|
||||
|
||||
if environment :matches "imap.user" "*" {
|
||||
set "username" "${1}";
|
||||
}
|
||||
|
||||
pipe :copy "sa-learn-ham.sh" [ "${username}" ];
|
7
modules/mail/report-spam.sieve
Executable file
7
modules/mail/report-spam.sieve
Executable file
|
@ -0,0 +1,7 @@
|
|||
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
|
||||
|
||||
if environment :matches "imap.user" "*" {
|
||||
set "username" "${1}";
|
||||
}
|
||||
|
||||
pipe :copy "sa-learn-spam.sh" [ "${username}" ];
|
Loading…
Reference in a new issue