From be56b6f2c5df6a4da8c91d4a3174f77d66c35533 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Wed, 7 Apr 2021 13:45:50 -0600 Subject: [PATCH] neomutt: Add encryptByDefault support (#1882) Adds support for encryptByDefault to the neomutt module using the crypt_opportunistic_encrypt option. --- modules/programs/neomutt.nix | 1 + tests/modules/programs/neomutt/default.nix | 1 + .../programs/neomutt/hm-example.com-expected | 1 + .../neomutt/hm-example.com-gpg-expected.conf | 32 ++++++++++++++++++ .../hm-example.com-msmtp-expected.conf | 1 + .../programs/neomutt/neomutt-with-gpg.nix | 33 +++++++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf create mode 100644 tests/modules/programs/neomutt/neomutt-with-gpg.nix diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index b8c793f8..5ee38e2a 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -189,6 +189,7 @@ let # GPG section set crypt_use_gpgme = yes set crypt_autosign = ${yesno (gpg.signByDefault or false)} + set crypt_opportunistic_encrypt = ${yesno (gpg.encryptByDefault or false)} set pgp_use_gpg_agent = yes set mbox_type = ${if maildir != null then "Maildir" else "mbox"} set sort = "${cfg.sort}" diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index 40ca4b02..b26923f7 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -6,4 +6,5 @@ neomutt-with-binds-with-warning = ./neomutt-with-binds-with-warning.nix; neomutt-with-binds-invalid-settings = ./neomutt-with-binds-invalid-settings.nix; + neomutt-with-gpg = ./neomutt-with-gpg.nix; } diff --git a/tests/modules/programs/neomutt/hm-example.com-expected b/tests/modules/programs/neomutt/hm-example.com-expected index 9181612c..6c96f61f 100644 --- a/tests/modules/programs/neomutt/hm-example.com-expected +++ b/tests/modules/programs/neomutt/hm-example.com-expected @@ -5,6 +5,7 @@ set certificate_file=/etc/ssl/certs/ca-certificates.crt # GPG section set crypt_use_gpgme = yes set crypt_autosign = no +set crypt_opportunistic_encrypt = no set pgp_use_gpg_agent = yes set mbox_type = Maildir set sort = "threads" diff --git a/tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf b/tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf new file mode 100644 index 00000000..f7763dbe --- /dev/null +++ b/tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf @@ -0,0 +1,32 @@ +# Generated by Home Manager. +set ssl_force_tls = yes +set certificate_file=/etc/ssl/certs/ca-certificates.crt + +# GPG section +set crypt_use_gpgme = yes +set crypt_autosign = yes +set crypt_opportunistic_encrypt = yes +set pgp_use_gpg_agent = yes +set mbox_type = Maildir +set sort = "threads" + +# MTA section +set smtp_pass="`password-command`" +set smtp_url='smtps://home.manager@smtp.example.com' + + + + + +# MRA section +set folder='/home/hm-user/Mail/hm@example.com' +set from='hm@example.com' +set postponed='+Drafts' +set realname='H. M. Test' +set record='+Sent' +set spoolfile='+Inbox' +set trash='+Trash' + + +# Extra configuration + diff --git a/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf b/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf index 925c7063..d2e2f3ee 100644 --- a/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf +++ b/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf @@ -5,6 +5,7 @@ set certificate_file=/etc/ssl/certs/ca-certificates.crt # GPG section set crypt_use_gpgme = yes set crypt_autosign = no +set crypt_opportunistic_encrypt = no set pgp_use_gpg_agent = yes set mbox_type = Maildir set sort = "threads" diff --git a/tests/modules/programs/neomutt/neomutt-with-gpg.nix b/tests/modules/programs/neomutt/neomutt-with-gpg.nix new file mode 100644 index 00000000..164e4b58 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-gpg.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: +with lib; { + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + gpg = { + encryptByDefault = true; + signByDefault = true; + }; + neomutt.enable = true; + imap.port = 993; + }; + }; + + programs.neomutt.enable = true; + + nixpkgs.overlays = + [ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ]; + + nmt.script = '' + assertFileExists home-files/.config/neomutt/neomuttrc + assertFileExists home-files/.config/neomutt/hm@example.com + assertFileContent home-files/.config/neomutt/neomuttrc ${ + ./neomutt-expected.conf + } + assertFileContent home-files/.config/neomutt/hm@example.com ${ + ./hm-example.com-gpg-expected.conf + } + ''; + }; +}