---

# cleanup maildirs:
# /vol/mail/maildirs/public-monitoring/
# /vol/mail/maildirs/develtester/

- name: cleanup maildies create job file
  tags: cleanup-maildirs
  become: true
  ansible.builtin.copy:
    dest: /opt/perfact/custom/cleanup-maildirs.sh
    content: |
      #!/bin/bash
      # cleanup old mails from shared used folders
      for maildir in \
        /vol/mail/maildirs/public-monitoring \
        /vol/mail/maildirs/develtesters \
      ; do
        if [ -d ${maildir}/new ]; then
           find ${maildir}/new -type f -ctime +31 -exec rm "{}" \;
        fi
        if [ -d ${maildir}/cur ]; then
           find ${maildir}/cur -type f -ctime +31 -exec rm "{}" \;
        fi
      done
    mode: '0755'

- name: cleanup maildies create cron
  tags: cleanup-maildirs
  become: true
  ansible.builtin.copy:
    dest: /etc/cron.d/perfact-cleanup-maildirs
    content: |
      # cleanup old mails from shared used folders
      14 4 * * * root  /opt/perfact/custom/cleanup-maildirs.sh
    mode: '0644'
