diff --git a/modules/programs/neomutt-accounts.nix b/modules/programs/neomutt-accounts.nix index 009cf1fa7..b66e7209d 100644 --- a/modules/programs/neomutt-accounts.nix +++ b/modules/programs/neomutt-accounts.nix @@ -2,7 +2,25 @@ with lib; -{ +let + extraMailboxOptions = { + options = { + mailbox = mkOption { + type = types.str; + example = "Sent"; + description = "Name of mailbox folder to be included"; + }; + + name = mkOption { + type = types.nullOr types.str; + example = "Junk"; + default = null; + description = "Name to display"; + }; + }; + }; + +in { options.neomutt = { enable = mkEnableOption "NeoMutt"; @@ -32,5 +50,18 @@ with lib; Extra lines to add to the folder hook for this account. ''; }; + + mailboxName = mkOption { + type = types.nullOr types.str; + default = null; + example = "==== ==="; + description = "Use a different name as mailbox name"; + }; + + extraMailboxes = mkOption { + type = with types; listOf (either str (submodule extraMailboxOptions)); + default = [ ]; + description = "List of extra mailboxes"; + }; }; } diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index 26b5914dc..1f31f3ab7 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -30,7 +30,7 @@ let format = mkOption { type = types.str; - default = "%B%?F? [%F]?%* %?N?%N/?%S"; + default = "%D%?F? [%F]?%* %?N?%N/?%S"; description = '' Sidebar format. Check neomutt documentation for details. ''; @@ -133,10 +133,25 @@ let ''; registerAccount = account: - with account; '' + let + mailboxes = if account.neomutt.mailboxName == null then + "mailboxes" + else + ''named-mailboxes "${account.neomutt.mailboxName}"''; + extraMailboxes = concatMapStringsSep "\n" (extra: + if isString extra then + ''mailboxes "${account.maildir.absPath}/${extra}"'' + else if extra.name == null then + ''mailboxes "${account.maildir.absPath}/${extra.mailbox}"'' + else + '' + named-mailboxes "${extra.name}" "${account.maildir.absPath}/${extra.mailbox}"'') + account.neomutt.extraMailboxes; + in with account; '' # register account ${name} - mailboxes "${account.maildir.absPath}/${folders.inbox}" - folder-hook ${account.maildir.absPath}/ " \ + ${mailboxes} "${maildir.absPath}/${folders.inbox}" + ${extraMailboxes} + folder-hook ${maildir.absPath}/ " \ source ${accountFilename account} " ''; diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index d24813545..62319dd36 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -8,4 +8,5 @@ ./neomutt-with-binds-invalid-settings.nix; neomutt-with-gpg = ./neomutt-with-gpg.nix; neomutt-no-folder-change = ./neomutt-no-folder-change.nix; + neomutt-with-named-mailboxes = ./neomutt-with-named-mailboxes.nix; } diff --git a/tests/modules/programs/neomutt/neomutt-expected.conf b/tests/modules/programs/neomutt/neomutt-expected.conf index 6d51da816..7c0e5d28a 100644 --- a/tests/modules/programs/neomutt/neomutt-expected.conf +++ b/tests/modules/programs/neomutt/neomutt-expected.conf @@ -19,6 +19,7 @@ set delete = yes # Register accounts # register account hm@example.com mailboxes "/home/hm-user/Mail/hm@example.com/Inbox" + folder-hook /home/hm-user/Mail/hm@example.com/ " \ source /home/hm-user/.config/neomutt/hm@example.com " diff --git a/tests/modules/programs/neomutt/neomutt-not-primary-expected.conf b/tests/modules/programs/neomutt/neomutt-not-primary-expected.conf index ed64124d9..4a583a02d 100644 --- a/tests/modules/programs/neomutt/neomutt-not-primary-expected.conf +++ b/tests/modules/programs/neomutt/neomutt-not-primary-expected.conf @@ -19,6 +19,7 @@ set delete = yes # Register accounts # register account hm-account mailboxes "/home/hm-user/Mail/hm-account/Inbox" + folder-hook /home/hm-user/Mail/hm-account/ " \ source /home/hm-user/.config/neomutt/hm-account " diff --git a/tests/modules/programs/neomutt/neomutt-with-binds-expected.conf b/tests/modules/programs/neomutt/neomutt-with-binds-expected.conf index 7f89c3178..8b4bb7bce 100644 --- a/tests/modules/programs/neomutt/neomutt-with-binds-expected.conf +++ b/tests/modules/programs/neomutt/neomutt-with-binds-expected.conf @@ -21,6 +21,7 @@ macro index,pager c "?^K=" # Register accounts # register account hm@example.com mailboxes "/home/hm-user/Mail/hm@example.com/Inbox" + folder-hook /home/hm-user/Mail/hm@example.com/ " \ source /home/hm-user/.config/neomutt/hm@example.com " diff --git a/tests/modules/programs/neomutt/neomutt-with-named-mailboxes-expected.conf b/tests/modules/programs/neomutt/neomutt-with-named-mailboxes-expected.conf new file mode 100644 index 000000000..e58660fc7 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-named-mailboxes-expected.conf @@ -0,0 +1,35 @@ +# Generated by Home Manager. +set header_cache = "/home/hm-user/.cache/neomutt/headers/" +set message_cachedir = "/home/hm-user/.cache/neomutt/messages/" +set editor = "$EDITOR" +set implicit_autoview = yes + +alternative_order text/enriched text/plain text + +set delete = yes + +# Binds + + +# Macros + + + + +# Register accounts +# register account hm@example.com +named-mailboxes "someCustomName" "/home/hm-user/Mail/hm@example.com/Inbox" +mailboxes "/home/hm-user/Mail/hm@example.com/Sent" +named-mailboxes "Spam" "/home/hm-user/Mail/hm@example.com/Junk Email" +mailboxes "/home/hm-user/Mail/hm@example.com/Trash" +folder-hook /home/hm-user/Mail/hm@example.com/ " \ + source /home/hm-user/.config/neomutt/hm@example.com " + + +# Source primary account +source /home/hm-user/.config/neomutt/hm@example.com + +# Extra configuration + + + diff --git a/tests/modules/programs/neomutt/neomutt-with-named-mailboxes.nix b/tests/modules/programs/neomutt/neomutt-with-named-mailboxes.nix new file mode 100644 index 000000000..9478a9110 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-named-mailboxes.nix @@ -0,0 +1,50 @@ +{ 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 + ''; + mailboxName = "someCustomName"; + extraMailboxes = [ + "Sent" + { + mailbox = "Junk Email"; + name = "Spam"; + } + { mailbox = "Trash"; } + ]; + }; + imap.port = 993; + }; + }; + + programs.neomutt = { + enable = true; + vimKeys = false; + }; + + 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-with-named-mailboxes-expected.conf + } + assertFileContent home-files/.config/neomutt/hm@example.com ${ + ./hm-example.com-expected + } + ''; + }; +}