From 408ba13188ff9ce309fa2bdd2f81287d79773b00 Mon Sep 17 00:00:00 2001 From: Franz Pletz Date: Tue, 29 Aug 2023 23:56:29 +0200 Subject: [PATCH] neomutt: fix STARTTLS When smtps is used as a protocol, neomutt expects TLS but will if STARTTLS should be used. When using STARTTLS, smtp has to be used as protocol and `ssl_force_tls` is set. See . --- modules/programs/neomutt.nix | 7 +++- tests/modules/programs/neomutt/default.nix | 1 + .../neomutt/hm-example.com-starttls-expected | 38 +++++++++++++++++ .../neomutt/neomutt-with-starttls.nix | 41 +++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/modules/programs/neomutt/hm-example.com-starttls-expected create mode 100644 tests/modules/programs/neomutt/neomutt-with-starttls.nix diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index 65f3144f4..968036f27 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -118,7 +118,8 @@ let sendmail = "'${neomutt.sendMailCommand}'"; } else let - smtpProto = if smtp.tls.enable then "smtps" else "smtp"; + smtpProto = + if smtp.tls.enable && !smtp.tls.useStartTls then "smtps" else "smtp"; smtpPort = if smtp.port != null then ":${toString smtp.port}" else ""; smtpBaseUrl = "${smtpProto}://${escape userName}@${smtp.host}${smtpPort}"; @@ -217,7 +218,9 @@ let }"; in '' # Generated by Home Manager. - set ssl_force_tls = yes + set ssl_force_tls = ${ + lib.hm.booleans.yesNo (smtp.tls.enable || smtp.tls.useStartTls) + } set certificate_file=${toString config.accounts.email.certificatesFile} # GPG section diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index 8216017c1..88e90c1d4 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -11,4 +11,5 @@ neomutt-with-named-mailboxes = ./neomutt-with-named-mailboxes.nix; neomutt-with-signature = ./neomutt-with-signature.nix; neomutt-with-signature-command = ./neomutt-with-signature-command.nix; + neomutt-with-starttls = ./neomutt-with-starttls.nix; } diff --git a/tests/modules/programs/neomutt/hm-example.com-starttls-expected b/tests/modules/programs/neomutt/hm-example.com-starttls-expected new file mode 100644 index 000000000..1e5b15cac --- /dev/null +++ b/tests/modules/programs/neomutt/hm-example.com-starttls-expected @@ -0,0 +1,38 @@ +# 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 = no +set crypt_opportunistic_encrypt = no +set pgp_use_gpg_agent = yes +set mbox_type = Maildir +set sort = "threads" + +# MTA section +set smtp_pass="`password-command`" +set smtp_url='smtp://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 +color status cyan default + + +unset signature +# notmuch section +set nm_default_uri = "notmuch:///home/hm-user/Mail" +virtual-mailboxes "My INBOX" "notmuch://?query=tag%3Ainbox" diff --git a/tests/modules/programs/neomutt/neomutt-with-starttls.nix b/tests/modules/programs/neomutt/neomutt-with-starttls.nix new file mode 100644 index 000000000..09d37ff9e --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-starttls.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + neomutt = { + enable = true; + extraConfig = '' + color status cyan default + ''; + }; + imap.port = 143; + smtp.tls.useStartTls = true; + }; + }; + + programs.neomutt = { + enable = true; + vimKeys = false; + }; + + test.stubs.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-starttls-expected + } + ''; + }; +}