From c1987240bcaaef22a2f61b52bb399d951b8f3fc3 Mon Sep 17 00:00:00 2001 From: Ben Grande Date: Fri, 26 Jan 2024 22:43:46 +0100 Subject: [PATCH] refactor: muttrc configuration source order Script to source muttrc configuration is preferred as it can choose what files must exist and not throw extraneous error messages on optional files. Adding the example configuration files to slim out the readme from the qusal project, also helps with copying the file from inside the qube itself instead of having to copy inter-qube. --- .reuse/dep5 | 4 +++ .../mutt/{colors.muttrc => 00_colors.muttrc} | 0 .../{mailbox.muttrc => 00_mailbox.muttrc} | 7 ++++ .../mutt/{server.muttrc => 00_server.muttrc} | 4 --- .../{bindings.muttrc => 05_bindings.muttrc} | 0 .../mutt/{pgp.muttrc => 05_pgp.muttrc} | 5 ++- files/mutt/.config/mutt/muttrc | 11 ++---- .../mutt/sample/muttrc-aliases.local.example | 4 +++ .../sample/muttrc-credentials.local.example | 12 +++++++ .../.config/mutt/sample/muttrc.local.example | 8 +++++ .../mutt/sample/offline.muttrc.example | 19 ++++++++++ .../.config/mutt/sample/signature.example | 4 +++ files/mutt/.local/bin/mutt-sorcerer | 35 +++++++++++++++++++ 13 files changed, 97 insertions(+), 16 deletions(-) rename files/mutt/.config/mutt/{colors.muttrc => 00_colors.muttrc} (100%) rename files/mutt/.config/mutt/{mailbox.muttrc => 00_mailbox.muttrc} (89%) rename files/mutt/.config/mutt/{server.muttrc => 00_server.muttrc} (83%) rename files/mutt/.config/mutt/{bindings.muttrc => 05_bindings.muttrc} (100%) rename files/mutt/.config/mutt/{pgp.muttrc => 05_pgp.muttrc} (85%) create mode 100644 files/mutt/.config/mutt/sample/muttrc-aliases.local.example create mode 100644 files/mutt/.config/mutt/sample/muttrc-credentials.local.example create mode 100644 files/mutt/.config/mutt/sample/muttrc.local.example create mode 100644 files/mutt/.config/mutt/sample/offline.muttrc.example create mode 100644 files/mutt/.config/mutt/sample/signature.example create mode 100755 files/mutt/.local/bin/mutt-sorcerer diff --git a/.reuse/dep5 b/.reuse/dep5 index 605c310..1b788ae 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -7,6 +7,10 @@ Files: files/git/.config/git/message Copyright: 2023 Benjamin Grande M. S. License: MIT +Files: files/mutt/.config/mutt/sample/*.example +Copyright: 2024 Benjamin Grande M. S. +License: GPL-3.0-or-later + Files: files/sh/.config/less/lesskey-old Copyright: 2023 Benjamin Grande M. S. License: GPL-3.0-or-later diff --git a/files/mutt/.config/mutt/colors.muttrc b/files/mutt/.config/mutt/00_colors.muttrc similarity index 100% rename from files/mutt/.config/mutt/colors.muttrc rename to files/mutt/.config/mutt/00_colors.muttrc diff --git a/files/mutt/.config/mutt/mailbox.muttrc b/files/mutt/.config/mutt/00_mailbox.muttrc similarity index 89% rename from files/mutt/.config/mutt/mailbox.muttrc rename to files/mutt/.config/mutt/00_mailbox.muttrc index 13d3b04..a131a7f 100644 --- a/files/mutt/.config/mutt/mailbox.muttrc +++ b/files/mutt/.config/mutt/00_mailbox.muttrc @@ -23,6 +23,9 @@ set charset = "utf-8" set pager_index_lines = 5 set my_editor = "vim -c 'setf mail' " set editor = "$my_editor " +set mailcap_path = "~/.mailcap" +unauto_view * +auto_view text/plain text/html ## Composing ## Option 'use_envelope_from' does not work reliably, force Message-ID @@ -46,6 +49,10 @@ set forward_format = "Fwd: %s" set forward_quote ## Cache +set spoolfile = "+INBOX" +## GMail duplicates sent mails if the 'record' option is set. +#set record = "+Sent" +unset record set mbox = "~/.cache/mutt/archived" set record = "~/.cache/mutt/sent" set postponed = "~/.cache/mutt/postponed" diff --git a/files/mutt/.config/mutt/server.muttrc b/files/mutt/.config/mutt/00_server.muttrc similarity index 83% rename from files/mutt/.config/mutt/server.muttrc rename to files/mutt/.config/mutt/00_server.muttrc index 047edcf..3f90054 100644 --- a/files/mutt/.config/mutt/server.muttrc +++ b/files/mutt/.config/mutt/00_server.muttrc @@ -4,7 +4,6 @@ ## IMAP set folder = "imaps://imap.$my_server" -set spoolfile = "+INBOX" set imap_user = "$my_user" set imap_pass = "$my_pass" set imap_check_subscribed @@ -20,9 +19,6 @@ set pop_last = yes ## SMTP set smtp_url = "smtps://$my_user@smtp.$my_server" -## GMail duplicates sent mails if the 'record' option is set. -#set record = "+Sent" -unset record set smtp_pass = "$my_pass" set realname = "$my_name" set ssl_starttls = yes diff --git a/files/mutt/.config/mutt/bindings.muttrc b/files/mutt/.config/mutt/05_bindings.muttrc similarity index 100% rename from files/mutt/.config/mutt/bindings.muttrc rename to files/mutt/.config/mutt/05_bindings.muttrc diff --git a/files/mutt/.config/mutt/pgp.muttrc b/files/mutt/.config/mutt/05_pgp.muttrc similarity index 85% rename from files/mutt/.config/mutt/pgp.muttrc rename to files/mutt/.config/mutt/05_pgp.muttrc index e678d80..71e4b8f 100644 --- a/files/mutt/.config/mutt/pgp.muttrc +++ b/files/mutt/.config/mutt/05_pgp.muttrc @@ -8,10 +8,9 @@ ## Hooks send-hook "~A" "set pgp_autoinline=no" -send-hook "~t ^security@qubes-os\\.org$" "set pgp_autoinline=yes crypt_autoencrypt=yes" -send-hook "~t @invisiblethingslab\\.com" "set pgp_autoinline=yes crypt_autoencrypt=yes" +send-hook "~t ^security@qubes-os\\.org$" "set pgp_autoinline=no crypt_autoencrypt=yes" +send-hook "~t @invisiblethingslab\\.com" "set pgp_autoinline=no crypt_autoencrypt=yes" send-hook "~t @googlegroups\\.com" "set pgp_autoinline=yes crypt_autoencrypt=no" -send-hook "~t $from" "set pgp_autoinline=yes" ## General Encryption and Signature set crypt_autopgp = yes # Use PGP for encryption diff --git a/files/mutt/.config/mutt/muttrc b/files/mutt/.config/mutt/muttrc index f31fd9f..2f26971 100644 --- a/files/mutt/.config/mutt/muttrc +++ b/files/mutt/.config/mutt/muttrc @@ -2,14 +2,7 @@ ## ## SPDX-License-Identifier: AGPL-3.0-or-later -## Source configuration +## Source all configurations cd ~/.config/mutt -source ~/.muttrc-credentials.local -source server.muttrc -source mailbox.muttrc -source pgp.muttrc -source bindings.muttrc -source colors.muttrc -source ~/.muttrc-aliases.local -source ~/.muttrc.local +source mutt-sorcerer| ## vim: ft=muttrc diff --git a/files/mutt/.config/mutt/sample/muttrc-aliases.local.example b/files/mutt/.config/mutt/sample/muttrc-aliases.local.example new file mode 100644 index 0000000..a778671 --- /dev/null +++ b/files/mutt/.config/mutt/sample/muttrc-aliases.local.example @@ -0,0 +1,4 @@ +## Copy to ~/.muttrc-aliases.local and modify. +## Optional configuration. + +alias qubes-devel diff --git a/files/mutt/.config/mutt/sample/muttrc-credentials.local.example b/files/mutt/.config/mutt/sample/muttrc-credentials.local.example new file mode 100644 index 0000000..58bc110 --- /dev/null +++ b/files/mutt/.config/mutt/sample/muttrc-credentials.local.example @@ -0,0 +1,12 @@ +## Copy to ~/.muttrc-credentials.local and modify. +## Mandatory configuration. +## First file to be sourced: defines variables to be referenced by other files. + +set pgp_default_key = "0x1234567890ABCDEF" +set pgp_sign_as = "0x1234567890ABCDEF" +set my_name = "Bilbo Baggins" +set my_user = "bilbo" +set my_server = "shire.org" + +## Password is unnecessary if Mutt is permanently offline. +set my_pass = "mypassword" diff --git a/files/mutt/.config/mutt/sample/muttrc.local.example b/files/mutt/.config/mutt/sample/muttrc.local.example new file mode 100644 index 0000000..9ddc432 --- /dev/null +++ b/files/mutt/.config/mutt/sample/muttrc.local.example @@ -0,0 +1,8 @@ +## Copy to ~/.muttrc.local and modify. +## Optional configuration. +## Last file to be source: overrides previous definitions. + +lists .*@googlegroups\\.com +subscribe qubes-(announce|devel)@googlegroups\\.com +fcc-save-hook qubes-announce@googlegroups\\.com =list/qubes-announce/ +fcc-save-hook qubes-devel@googlegroups\\.com =list/qubes-devel/ diff --git a/files/mutt/.config/mutt/sample/offline.muttrc.example b/files/mutt/.config/mutt/sample/offline.muttrc.example new file mode 100644 index 0000000..b1d2a7f --- /dev/null +++ b/files/mutt/.config/mutt/sample/offline.muttrc.example @@ -0,0 +1,19 @@ +## Copy to ~/.config/mutt/offline.muttrc and modify. + +## SPDX-FileCopyrightText: 2023 Benjamin Grande M. S. +## +## SPDX-License-Identifier: AGPL-3.0-or-later + +set read_only = yes + +unset spoolfile +unset folder +unset smtp_url +set imap_passive = yes + +set sendmail = "env EMAIL_CONN_TEST=x /usr/libexec/msmtp/msmtpq/msmtpq" +set sendmail_wait = 0 +set folder = "~/mail" +set spoolfile = "+INBOX" + +## vim: ft=muttrc diff --git a/files/mutt/.config/mutt/sample/signature.example b/files/mutt/.config/mutt/sample/signature.example new file mode 100644 index 0000000..f003a4b --- /dev/null +++ b/files/mutt/.config/mutt/sample/signature.example @@ -0,0 +1,4 @@ +## Copy to ~/.signature and modify, including deleting all commends. +## Optional configuration. +Regards, +John Doe diff --git a/files/mutt/.local/bin/mutt-sorcerer b/files/mutt/.local/bin/mutt-sorcerer new file mode 100755 index 0000000..e7edf27 --- /dev/null +++ b/files/mutt/.local/bin/mutt-sorcerer @@ -0,0 +1,35 @@ +#!/bin/sh +## +## SPDX-FileCopyrightText: 2023 Benjamin Grande M. S. +## +## SPDX-License-Identifier: AGPL-3.0-or-later +## +## Mutt Sorcerer - source Mutt configuration like a wizard +## Useful if some configurations files in non-default locations might exist. + +set -eu + +credentials_file="${HOME}/.muttrc-credentials.local" +aliases_file="${HOME}/.muttrc-aliases.local" +local_file="${HOME}/.muttrc.local" + +## source_redable(): do not require that the file exists in the first place. +source_existent(){ + for file in "${@}"; do + if test -f "${file}"; then + echo source "\"${file}\"" + fi + done + unset file +} + +## Source files that must exist, let mutt fail otherwise. +echo source "\"${credentials_file}\"" + +## PWD is inherited from the muttrc that called this script. +for file in *.muttrc; do + echo source "\"${file}\"" +done +unset file + +source_existent "${aliases_file}" "${local_file}"