You've already forked ansible-role-directadmin
114 lines
3.5 KiB
YAML
114 lines
3.5 KiB
YAML
---
|
|
- name: Add imap_sieve to mail_plugins for dovecot
|
|
lineinfile:
|
|
path: /etc/dovecot/conf/imap_mail_plugins.conf
|
|
regex: "^mail_plugins = (?!.*imap_sieve)(.*)$"
|
|
line: "mail_plugins = \\1 imap_sieve"
|
|
backrefs: true
|
|
notify:
|
|
- "directadmin : Ensure Dovecot custom for custombuild is present"
|
|
- "directadmin : Persist mail plugins"
|
|
- "directadmin : Restart Dovecot"
|
|
|
|
- name: Configure plusaddressing for Dovecot
|
|
copy:
|
|
dest: /etc/dovecot/conf.d/subaddressing.conf
|
|
content: |
|
|
recipient_delimiter = +
|
|
lmtp_save_to_detail_mailbox = no
|
|
lda_mailbox_autocreate = yes
|
|
lda_mailbox_autosubscribe = yes
|
|
notify:
|
|
- "directadmin : Restart Dovecot"
|
|
|
|
- name: Configure imap_sieve for Dovecot
|
|
copy:
|
|
dest: /etc/dovecot/conf.d/99-imap-sieve.conf
|
|
content: |
|
|
plugin {
|
|
sieve_plugins = sieve_imapsieve sieve_extprograms
|
|
|
|
# From elsewhere to Spam folder
|
|
imapsieve_mailbox1_name = Spam
|
|
imapsieve_mailbox1_causes = COPY
|
|
imapsieve_mailbox1_before = file:/usr/local/bin/dovecot-sieve/report-spam.sieve
|
|
|
|
# From Spam folder to elsewhere
|
|
imapsieve_mailbox2_name = *
|
|
imapsieve_mailbox2_from = Spam
|
|
imapsieve_mailbox2_causes = COPY
|
|
imapsieve_mailbox2_before = file:/usr/local/bin/dovecot-sieve/report-ham.sieve
|
|
|
|
sieve_pipe_bin_dir = /usr/local/bin/dovecot-sieve
|
|
|
|
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
|
|
}
|
|
notify:
|
|
- "directadmin : Restart Dovecot"
|
|
|
|
- name: Ensure dovecot-sieve script directory is present
|
|
file:
|
|
path: /usr/local/bin/dovecot-sieve
|
|
state: directory
|
|
owner: mail
|
|
|
|
- name: Create report-spam script
|
|
copy:
|
|
dest: /usr/local/bin/dovecot-sieve/report-spam.sieve
|
|
content: |
|
|
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
|
|
|
|
if environment :matches "imap.user" "*" {
|
|
set "username" "${1}";
|
|
}
|
|
|
|
pipe :copy "sa-learn-spam.sh" [ "${username}" ];
|
|
notify:
|
|
- "directadmin : Compile and fix permissions report-spam script"
|
|
|
|
- name: Create report-ham script
|
|
copy:
|
|
dest: /usr/local/bin/dovecot-sieve/report-ham.sieve
|
|
content: |
|
|
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}" ];
|
|
notify:
|
|
- "directadmin : Compile and fix permissions report-ham script"
|
|
|
|
- name: Create spam learning script
|
|
copy:
|
|
dest: /usr/local/bin/dovecot-sieve/sa-learn-spam.sh
|
|
content: |
|
|
#!/bin/bash
|
|
# you can also use tcp/ip here, consult spamc(1)
|
|
inputmail=`/usr/bin/cat`
|
|
ddomain=`/usr/bin/echo "${1}"| /usr/bin/cut -d'@' -f2`
|
|
dusername=`/usr/bin/egrep "^${ddomain}:" /etc/virtual/domainowners| /usr/bin/cut -d' ' -f2`
|
|
exec /usr/bin/spamc -u ${dusername} -L spam <<< "${inputmail}"
|
|
mode: "0755"
|
|
|
|
- name: Create ham learning script
|
|
copy:
|
|
dest: /usr/local/bin/dovecot-sieve/sa-learn-ham.sh
|
|
content: |
|
|
#!/bin/bash
|
|
# you can also use tcp/ip here, consult spamc(1)
|
|
inputmail=`/usr/bin/cat`
|
|
ddomain=`/usr/bin/echo "${1}"| /usr/bin/cut -d'@' -f2`
|
|
dusername=`/usr/bin/egrep "^${ddomain}:" /etc/virtual/domainowners| /usr/bin/cut -d' ' -f2`
|
|
exec /usr/bin/spamc -u ${dusername} -L ham <<< "${inputmail}"
|
|
mode: "0755"
|