notmuch & neomutt: Control virtualboxes being set in NeoMutt for Notmuch integration ()

Virtual mailboxes (described by Notmuch queries) can now configured for each account in NeoMutt.
Plus, it is possible to disable Notmuch section for a specific account.
This commit is contained in:
Ryan Lahfa 2023-04-24 16:41:29 +02:00 committed by GitHub
parent 6f9781b1b0
commit 0263da497e
Failed to generate hash of commit
6 changed files with 69 additions and 7 deletions

View file

@ -21,6 +21,23 @@ let
}; };
in { in {
options.notmuch.neomutt = {
enable = mkEnableOption "Notmuch support in NeoMutt" // { default = true; };
virtualMailboxes = mkOption {
type = types.listOf (types.submodule ./notmuch-virtual-mailbox.nix);
example = [{
name = "My INBOX";
query = "tag:inbox";
}];
default = [{
name = "My INBOX";
query = "tag:inbox";
}];
description = "List of virtual mailboxes using Notmuch queries";
};
};
options.neomutt = { options.neomutt = {
enable = mkEnableOption "NeoMutt"; enable = mkEnableOption "NeoMutt";

View file

@ -3,7 +3,6 @@
with lib; with lib;
let let
cfg = config.programs.neomutt; cfg = config.programs.neomutt;
neomuttAccounts = neomuttAccounts =
@ -89,6 +88,14 @@ let
}; };
}; };
mkNotmuchVirtualboxes = virtualMailboxes:
"${concatStringsSep "\n" (map ({ name, query, limit, type }:
''
virtual-mailboxes "${name}" "notmuch://?query=${lib.escapeURL query}${
optionalString (limit != null) "&limit=${toString limit}"
}${optionalString (type != null) "&type=${type}"}"'')
virtualMailboxes)}";
setOption = n: v: if v == null then "unset ${n}" else "set ${n}=${v}"; setOption = n: v: if v == null then "unset ${n}" else "set ${n}=${v}";
escape = replaceStrings [ "%" ] [ "%25" ]; escape = replaceStrings [ "%" ] [ "%25" ];
@ -188,10 +195,13 @@ let
''; '';
notmuchSection = account: notmuchSection = account:
with account; '' let virtualMailboxes = account.notmuch.neomutt.virtualMailboxes;
in with account; ''
# notmuch section # notmuch section
set nm_default_uri = "notmuch://${config.accounts.email.maildirBasePath}" set nm_default_uri = "notmuch://${config.accounts.email.maildirBasePath}"
virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" ${optionalString
(notmuch.neomutt.enable && builtins.length virtualMailboxes > 0)
(mkNotmuchVirtualboxes virtualMailboxes)}
''; '';
accountStr = account: accountStr = account:
@ -234,7 +244,9 @@ let
${account.neomutt.extraConfig} ${account.neomutt.extraConfig}
${signature} ${signature}
'' + optionalString account.notmuch.enable (notmuchSection account); ''
+ optionalString (account.notmuch.enable && account.notmuch.neomutt.enable)
(notmuchSection account);
in { in {
options = { options = {

View file

@ -0,0 +1,33 @@
{ config, lib, ... }:
with lib; {
options = {
name = mkOption {
type = types.str;
example = "My INBOX";
default = "My INBOX";
description = "Name to display";
};
query = mkOption {
type = types.str;
example = "tag:inbox";
default = "tag:inbox";
description = "Notmuch query";
};
limit = mkOption {
type = types.nullOr types.int;
example = 10;
default = null;
description = "Restricts number of messages/threads in the result.";
};
type = mkOption {
type = types.nullOr (types.enum ([ "threads" "messages" ]));
example = "threads";
default = null;
description =
"Reads all matching messages or whole-threads. The default is 'messages' or nm_query_type.";
};
};
}

View file

@ -35,4 +35,4 @@ color status cyan default
unset signature unset signature
# notmuch section # notmuch section
set nm_default_uri = "notmuch:///home/hm-user/Mail" set nm_default_uri = "notmuch:///home/hm-user/Mail"
virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" virtual-mailboxes "My INBOX" "notmuch://?query=tag%3Ainbox"

View file

@ -35,4 +35,4 @@ color status cyan default
set signature = "/nix/store/00000000000000000000000000000000-signature|" set signature = "/nix/store/00000000000000000000000000000000-signature|"
# notmuch section # notmuch section
set nm_default_uri = "notmuch:///home/hm-user/Mail" set nm_default_uri = "notmuch:///home/hm-user/Mail"
virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" virtual-mailboxes "My INBOX" "notmuch://?query=tag%3Ainbox"

View file

@ -35,4 +35,4 @@ color status cyan default
set signature = /nix/store/00000000000000000000000000000000-signature.txt set signature = /nix/store/00000000000000000000000000000000-signature.txt
# notmuch section # notmuch section
set nm_default_uri = "notmuch:///home/hm-user/Mail" set nm_default_uri = "notmuch:///home/hm-user/Mail"
virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" virtual-mailboxes "My INBOX" "notmuch://?query=tag%3Ainbox"