neomutt: Allow named mailboxes (#2212)
At the moment, only the inbox of each mail account is added to neomutt. This inbox is always called "Inbox", so if you configure multiple accounts, it is hard to know which one is which. This change allows the user to specify a display name per account that uses `named-mailboxes` under the hood. Additionally this change now allows to add other folders than the inbox, for example the Trash, Spam or Drafts folders to be added on a per-account basis. Using extraOptions is not possible here, as those are lazily loaded on mailbox open and thus would appear at the bottom and not sorted by account. This commit also changes the default sidebar format string to use %D instead of %B because %B will ignore named mailboxes and show the folder name instead.
This commit is contained in:
parent
1a6df903e3
commit
bf6b85136b
|
@ -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 = "==== <mailbox-name> ===";
|
||||
description = "Use a different name as mailbox name";
|
||||
};
|
||||
|
||||
extraMailboxes = mkOption {
|
||||
type = with types; listOf (either str (submodule extraMailboxOptions));
|
||||
default = [ ];
|
||||
description = "List of extra mailboxes";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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} "
|
||||
'';
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 "
|
||||
|
||||
|
|
|
@ -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 "
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ macro index,pager c "<change-folder>?<change-dir><home>^K=<enter><tab>"
|
|||
# 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 "
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue