---
- name: Install neomutt
  pacman:
    name: neomutt
    state: present

- name: Make neomutt available as mutt
  file:
    src: /usr/bin/neomutt
    dest: /usr/local/bin/mutt
    state: link

- name: Verify mutt firejail local profile exists
  copy:
    content: ""
    dest: /etc/firejail/mutt.local
    force: false
  tags:
    - firejail

- name: Whitelist mutt related files
  blockinfile:
    dest: /etc/firejail/mutt.local
    block: |
        noblacklist ~/.config/vdirsyncer
        noblacklist ~/.vdirsyncer
        noblacklist ~/.calendars
        noblacklist ~/.contacts
        noblacklist ~/.mbsyncrc
        noblacklist ~/.offlineimap
        noblacklist ~/.offlineimaprc
  tags:
    - firejail

- name: Install urlscan
  pacman:
    name: urlscan

- name: Install notmuch
  pacman:
    name: notmuch
    state: present

- name: Install mutt-ics
  kewlfft.aur.aur:
    name: mutt-ics
  become: yes
  become_user: "{{ aur.user }}"
  tags:
    - aur

- name: Push mutt-mailto script
  copy:
    src: mutt-mailto.sh
    dest: /usr/local/bin/mutt-mailto
    mode: 0755

- name: Create local desktop application dir
  file:
    path: /usr/local/share/applications
    state: directory

- name: Push mutt desktop file
  copy:
    src: mutt.desktop
    dest: /usr/local/share/applications/mutt.desktop

- name: Verify mimeapps.list exists
  copy:
    content: ""
    dest: /etc/xdg/mimeapps.list
    force: false

- name: Set mutt as default application for mailto links
  lineinfile:
    dest: /etc/xdg/mimeapps.list
    regexp: "^x-scheme-handler/mailto="
    line: "x-scheme-handler/mailto=mutt.desktop"

- include_tasks: msmtp.yml
- include_tasks: isync.yml
#- include_tasks: offlineimap.yml
- include_tasks: mailsync.yml
- include_tasks: oauth2.yml
