From 4840e2eb113ae2f9687b4237e49efd7b41b885fa Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Sat, 14 May 2022 16:53:03 +0200 Subject: [PATCH] Add mailcap --- roles/neomutt/files/mailcap | 9 +++++++++ roles/neomutt/files/openfile | 9 +++++++++ roles/neomutt/tasks/main.yml | 15 +++++++++++++++ roles/neomutt/templates/neomuttrc.j2 | 10 +++++----- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 roles/neomutt/files/mailcap create mode 100644 roles/neomutt/files/openfile diff --git a/roles/neomutt/files/mailcap b/roles/neomutt/files/mailcap new file mode 100644 index 0000000..8fa101d --- /dev/null +++ b/roles/neomutt/files/mailcap @@ -0,0 +1,9 @@ +text/plain; $EDITOR %s; +text/html; ~/.local/bin/openfile %s; nametemplate=%s.html +text/html; lynx -assume_charset=%{charset} -display_charset=utf-8 -dump -width=1024 %s; nametemplate=%s.html; copiousoutput; +image/*; ~/.local/bin/openfile %s; +video/*; setsid mpv --quiet %s &; copiousoutput +audio/*; mpv %s; +application/pdf; ~/.local/bin/openfile %s; +application/pgp-encrypted; gpg -d '%s'; copiousoutput; +application/pgp-keys; gpg --import '%s'; copiousoutput; diff --git a/roles/neomutt/files/openfile b/roles/neomutt/files/openfile new file mode 100644 index 0000000..97d5a91 --- /dev/null +++ b/roles/neomutt/files/openfile @@ -0,0 +1,9 @@ +#!/bin/sh + +# Helps open a file with xdg-open from mutt in a external program without weird side effects. +tempdir="$HOME/.cache/neomutt/files" +file="$tempdir/${1##*/}" +mkdir -p "$tempdir" +cp -f "$1" "$file" +setsid -f xdg-open "$file" >/dev/null 2>&1 +find "${tempdir:?}" -mtime +1 -type f -delete diff --git a/roles/neomutt/tasks/main.yml b/roles/neomutt/tasks/main.yml index 0205430..ec9667b 100644 --- a/roles/neomutt/tasks/main.yml +++ b/roles/neomutt/tasks/main.yml @@ -6,6 +6,8 @@ pacman: name: - neomutt + - lynx + - mpv when: ansible_facts['distribution'] == 'Archlinux' - name: Install packages (Debian) @@ -13,6 +15,8 @@ apt: name: - neomutt + - lynx + - mpv when: ansible_facts['distribution'] == 'Debian' - name: Get installed neomutt version @@ -54,3 +58,14 @@ file: path: ~/.cache/neomutt state: directory + +- name: Copy mailcap file + copy: + src: mailcap + dest: ~/.config/neomutt/mailcap + +- name: Copy openfile script + copy: + src: openfile + dest: ~/.local/bin/openfile + mode: 0755 diff --git a/roles/neomutt/templates/neomuttrc.j2 b/roles/neomutt/templates/neomuttrc.j2 index 8da9091..da781ab 100644 --- a/roles/neomutt/templates/neomuttrc.j2 +++ b/roles/neomutt/templates/neomuttrc.j2 @@ -1,5 +1,5 @@ -#set mailcap_path = $HOME/.config/mutt/mailcap:/usr/local/share/mutt-wizard/mailcap:$mailcap_path -#set mime_type_query_command = "file --mime-type -b %s" +set mailcap_path = $HOME/.config/neomutt/mailcap:$mailcap_path +set mime_type_query_command = "file --mime-type -b %s" set date_format="%y/%m/%d %I:%M%p" set index_format="%2C %Z %?X?A& ? %D %-15.15F %s (%-4.4c)" set sort = 'reverse-date' @@ -20,9 +20,9 @@ set include # include message in replies set mail_check = 120 # how often to check for new mail (in seconds) set imap_keepalive = 300 # intermittent polling to keep connection alive (in seconds) unset imap_passive # open imap connection when checking for mail -#auto_view text/html # automatically show html (mailcap uses lynx) -#auto_view application/pgp-encrypted -#alternative_order text/plain text/enriched text/html +auto_view text/html # automatically show html (mailcap uses lynx) +auto_view application/pgp-encrypted +alternative_order text/plain text/enriched text/html bind index,pager i noop bind index,pager g noop