From 77becc9d521490a71560fa87ee33e4f600839cfd Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Wed, 30 Sep 2026 03:09:58 +0530 Subject: feat(communication/neomutt): reworked the email syncing Now we have the ability to map each folder on the remote server with a folder with an arbitrary name in the local server. Each folder gets its own channel with quick and full variations where the quick only download the new emails from the remote to the local and full makes a sync both ways. --- modules/communication/neomutt/account/.neomuttrc | 4 +-- modules/communication/neomutt/account/default.nix | 36 ++++++++++++++++++++-- .../neomutt/account/flavors/gmail/.neomuttrc | 2 +- .../neomutt/account/flavors/gmail/default.nix | 28 ++++++++--------- modules/communication/neomutt/account/options.nix | 8 +++++ .../communication/neomutt/account/sync-channel.nix | 11 +++---- 6 files changed, 63 insertions(+), 26 deletions(-) (limited to 'modules/communication/neomutt/account') diff --git a/modules/communication/neomutt/account/.neomuttrc b/modules/communication/neomutt/account/.neomuttrc index 2f8c9f2..37dc9aa 100644 --- a/modules/communication/neomutt/account/.neomuttrc +++ b/modules/communication/neomutt/account/.neomuttrc @@ -1,2 +1,2 @@ -macro index,pager gs "set my_wait_key=$wait_key wait_key=noneomutt-sync @@QUICK_CHANNEL@@set wait_key=$my_wait_key" -macro index,pager gS "set my_wait_key=$wait_key wait_key=noneomutt-sync @@FULL_CHANNEL@@set wait_key=$my_wait_key" +macro index,pager gs "set my_wait_key=$wait_key wait_key=noneomutt-sync @@QUICK_GROUP@@set wait_key=$my_wait_key" +macro index,pager gS "set my_wait_key=$wait_key wait_key=noneomutt-sync @@FULL_GROUP@@set wait_key=$my_wait_key" diff --git a/modules/communication/neomutt/account/default.nix b/modules/communication/neomutt/account/default.nix index 07a4b89..1d8046a 100644 --- a/modules/communication/neomutt/account/default.nix +++ b/modules/communication/neomutt/account/default.nix @@ -2,6 +2,7 @@ { config, lib, ... }: let cfg = config.communication.neomutt; + mbsyncGroupNames = (import ../lib.nix { inherit lib; }).mbsyncGroupNames; in { imports = [ @@ -47,10 +48,10 @@ in inherit (accountInformation.folders) inbox trash; } // lib.optionalAttrs (accountInformation.folders.drafts != null) { - drafts = accountInformation.folders.drafts; + inherit (accountInformation.folders) drafts; } // lib.optionalAttrs (accountInformation.folders.sent != null) { - sent = accountInformation.folders.sent; + inherit (accountInformation.folders) sent; }; neomutt = { @@ -62,14 +63,43 @@ in mbsync = { enable = true; create = accountInformation.mbsync.create; + expunge = "both"; patterns = accountInformation.mbsync.patterns; flatten = accountInformation.mbsync.flatten; extraConfig = { - account = accountInformation.mbsync.extraConfig.account; + account = { + PipelineDepth = 50; + } + // accountInformation.mbsync.extraConfig.account; channel = accountInformation.mbsync.extraConfig.channel; local = accountInformation.mbsync.extraConfig.local; remote = accountInformation.mbsync.extraConfig.remote; }; + + groups = + let + group = mbsyncGroupNames accountName; + + mkChannels = + sync: + lib.mapAttrs (local: remote: { + farPattern = remote; + nearPattern = local; + extraConfig = { + Create = "Near"; + Expunge = "Both"; + Sync = sync; + SyncState = "*"; + }; + }) accountInformation.mbsync.folders.map; + in + { + "${group.full}".channels = mkChannels "All"; + "${group.quick}".channels = mkChannels [ + "Pull" + "New" + ]; + }; }; notmuch = { diff --git a/modules/communication/neomutt/account/flavors/gmail/.neomuttrc b/modules/communication/neomutt/account/flavors/gmail/.neomuttrc index c87bba0..2106b65 100644 --- a/modules/communication/neomutt/account/flavors/gmail/.neomuttrc +++ b/modules/communication/neomutt/account/flavors/gmail/.neomuttrc @@ -1,2 +1,2 @@ -mailboxes =Inbox ="[Gmail]/Drafts" ="[Gmail]/Sent Mail" ="[Gmail]/Spam" ="[Gmail]/Trash" +mailboxes =inbox =drafts =sent =spam =trash unset record diff --git a/modules/communication/neomutt/account/flavors/gmail/default.nix b/modules/communication/neomutt/account/flavors/gmail/default.nix index b0b7733..ea696b2 100644 --- a/modules/communication/neomutt/account/flavors/gmail/default.nix +++ b/modules/communication/neomutt/account/flavors/gmail/default.nix @@ -8,25 +8,25 @@ { config = lib.mkIf (config.flavor == "gmail.com") { folders = { - inbox = lib.mkDefault "Inbox"; - drafts = lib.mkDefault "[Gmail]/Drafts"; - sent = lib.mkDefault "[Gmail]/Sent Mail"; - trash = lib.mkDefault "[Gmail]/Trash"; + inbox = lib.mkDefault "inbox"; + drafts = lib.mkDefault "drafts"; + sent = lib.mkDefault "sent"; + trash = lib.mkDefault "trash"; }; mbsync = { create = lib.mkDefault "maildir"; - patterns = lib.mkDefault [ - "INBOX" - "[Gmail]/Drafts" - "[Gmail]/Sent Mail" - "[Gmail]/Spam" - ]; + patterns = lib.mkDefault [ "INBOX" ]; + folders.map = lib.mkDefault { + inbox = "INBOX"; + drafts = "[Gmail]/Drafts"; + sent = "[Gmail]/Sent Mail"; + spam = "[Gmail]/Spam"; + trash = "[Gmail]/Trash"; + }; extraConfig.channel = { Sync = lib.mkDefault "All"; CopyArrivalDate = lib.mkDefault "yes"; - Expunge = lib.mkDefault "Both"; - SyncState = lib.mkDefault "*"; }; }; @@ -34,8 +34,8 @@ notmuch.neomutt.virtual-mailboxes = lib.mkDefault [ { - name = "All Mail"; - query = "folder:${name}/Inbox or folder:\"${name}/[Gmail]/Sent Mail\""; + name = "all"; + query = "folder:${name}/inbox or folder:\"${name}/sent\""; } ]; }; diff --git a/modules/communication/neomutt/account/options.nix b/modules/communication/neomutt/account/options.nix index 676f8b0..3090db2 100644 --- a/modules/communication/neomutt/account/options.nix +++ b/modules/communication/neomutt/account/options.nix @@ -121,6 +121,14 @@ description = "Flatten hierarchy delimiter."; }; + folders = { + map = lib.mkOption { + type = lib.types.attrsOf lib.types.str; + default = { }; + description = "Local folder name -> remote folder name, for folders that should be renamed locally."; + }; + }; + extraConfig = { account = lib.mkOption { type = lib.types.attrsOf ( diff --git a/modules/communication/neomutt/account/sync-channel.nix b/modules/communication/neomutt/account/sync-channel.nix index 2252594..cb966c8 100644 --- a/modules/communication/neomutt/account/sync-channel.nix +++ b/modules/communication/neomutt/account/sync-channel.nix @@ -5,20 +5,19 @@ ... }: let - - mbsyncNamesFromName = (import ../lib.nix { inherit lib; }).mbsyncNamesFromName; + mbsyncGroupNames = (import ../lib.nix { inherit lib; }).mbsyncGroupNames; in { config = lib.mkIf config.enable { neomutt.extraConfig = let - mbsyncNames = mbsyncNamesFromName name; + group = mbsyncGroupNames name; in builtins.replaceStrings - [ "@@QUICK_CHANNEL@@" "@@FULL_CHANNEL@@" ] + [ "@@QUICK_GROUP@@" "@@FULL_GROUP@@" ] [ - mbsyncNames.channels.quick - mbsyncNames.channels.full + group.quick + group.full ] (builtins.readFile ./.neomuttrc); }; -- cgit v1.2.3