~nka/ansible-role-dovecot

ref: 03f0b864b29b8ce5c0faef3f3a8223e8fd31a641 ansible-role-dovecot/tasks/main.yml -rw-r--r-- 2.9 KiB
03f0b864Nicolas KAROLAK add auto expunge of trash and junk 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---

- name: install packages
  apt:
    force_apt_get: true
    install_recommends: false
    name: "{{ imap_packages }}"

- name: create vmail group
  register: imap_group
  group:
    name: vmail
    system: yes

- name: create vmail user
  register: imap_user
  user:
    name: vmail
    group: vmail
    comment: Virtual Mail Handler
    home: /var/mail/vhosts
    shell: /usr/sbin/nologin
    system: yes

- name: create vmail directories
  loop:
    - /var/mail/vhosts
    - /var/mail/vhosts/sieve
    - /var/mail/vhosts/sieve/global
    - /var/mail/attachments
  file:
    path: "{{ item }}"
    owner: vmail
    group: vmail
    mode: 0770
    state: directory

- name: configure imap server
  notify: restart imap server
  loop:
    - conf.d/10-auth.conf
    - conf.d/10-mail.conf
    - conf.d/10-master.conf
    - conf.d/10-ssl.conf
    - conf.d/15-mailboxes.conf
    - conf.d/20-imap.conf
    - conf.d/20-lmtp.conf
    - conf.d/20-managesieve.conf
    - conf.d/90-quota.conf
    - conf.d/90-sieve.conf
    - dovecot-dict-sql.conf.ext
    - dovecot-sql.conf.ext
    - dovecot.conf
  template:
    src: "{{ item }}.j2"
    dest: /etc/dovecot/{{ item }}

- name: quota warning script
  template:
    src: quota-warning.sh.j2
    dest: /etc/dovecot/quota-warning.sh
    mode: 0755

- name: global check spam sieve script
  notify: compile check spam script
  copy:
    dest: /var/mail/vhosts/sieve/global/check-spam.sieve
    owner: vmail
    group: vmail
    content: |
      require ["fileinto","mailbox"];

      if anyof(
          header :contains ["X-Spam-Flag"] "YES",
          header :contains ["X-Spam"] "Yes",
          header :contains ["Subject"] "*** SPAM ***"
          )
      {
          fileinto :create "Junk";
          stop;
      }

- name: global learn spam sieve script
  notify: compile learn spam script
  copy:
    dest: /var/mail/vhosts/sieve/global/report-spam.sieve
    owner: vmail
    group: vmail
    content: |
      require ["vnd.dovecot.pipe", "copy", "imapsieve"];
      pipe :copy "rspamc" ["learn_spam"];

- name: global learn ham sieve script
  notify: compile learn ham script
  copy:
    dest: /var/mail/vhosts/sieve/global/report-ham.sieve
    owner: vmail
    group: vmail
    content: |
      require ["vnd.dovecot.pipe", "copy", "imapsieve"];
      pipe :copy "rspamc" ["learn_ham"];

- name: update certificates links
  notify: restart imap server
  loop:
    - link: /etc/dovecot/private/dovecot.key
      source: "{{ imap_tls_key }}"
    - link: /etc/dovecot/private/dovecot.pem
      source: "{{ imap_tls_cert }}"
  file:
    src: "{{ item.source }}"
    dest: "{{ item.link }}"
    force: true
    state: link

- name: expunge trash cronjob
  cron:
    job: '/usr/bin/doveadm expunge -A mailbox Trash savedbefore 14d'
    name: 'expunge trash'
    special_time: 'daily'

- name: expunge junk cronjob
  cron:
    job: '/usr/bin/doveadm expunge -A mailbox Junk savedbefore 14d'
    name: 'expunge junk'
    special_time: 'daily'