aboutsummaryrefslogtreecommitdiffstats
path: root/modules/communication/neomutt/mail
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar@gmail.com>2026-09-18 03:43:48 +0530
committerArpit Chakladar <arpitchakladar@gmail.com>2026-09-18 03:47:06 +0530
commitd87a209b9efd2e32827aca20c66af7f94ce9e6c1 (patch)
tree53ba78ccd7d29840994eb1213a561a53cf6c5ecb /modules/communication/neomutt/mail
parent8ad26b8900fdef35a884df7673a90dea054e721a (diff)
downloadhome-manager-config-d87a209b9efd2e32827aca20c66af7f94ce9e6c1.tar.gz
home-manager-config-d87a209b9efd2e32827aca20c66af7f94ce9e6c1.zip
fix(communication/neomutt): fixed mbsync syncing with different modes
Now there are two channels created for every account quick and full variants, quick only gives new emails and full does the whole sync. neomutt-sync can now be told which channel to use to sync with.
Diffstat (limited to 'modules/communication/neomutt/mail')
-rw-r--r--modules/communication/neomutt/mail/mbsync.nix104
1 files changed, 102 insertions, 2 deletions
diff --git a/modules/communication/neomutt/mail/mbsync.nix b/modules/communication/neomutt/mail/mbsync.nix
index 28b7b2c..1d21377 100644
--- a/modules/communication/neomutt/mail/mbsync.nix
+++ b/modules/communication/neomutt/mail/mbsync.nix
@@ -1,7 +1,107 @@
-# Mailbox synchronization
-{ config, lib, ... }:
+{
+ config,
+ lib,
+ ...
+}@inputs:
+let
+ genValue =
+ v:
+ if lib.isList v then
+ lib.concatStringsSep " " (map genValue v)
+ else if lib.isBool v then
+ lib.hm.booleans.yesNo v
+ else if lib.isInt v then
+ toString v
+ else if lib.isString v then
+ if builtins.match ".* .*" v != null then ''"${lib.escape [ ''"'' ] v}"'' else v
+ else
+ throw "Unsupported mbsync value";
+
+ genSection = name: attrs: ''
+ ${name}
+ ${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "${n} ${genValue v}") attrs)}
+ '';
+
+ genAccount =
+ a:
+ let
+ mbsyncNames = (import ../lib.nix inputs).mbsyncNamesFromName a.name;
+
+ quick = {
+ Far = ":${mbsyncNames.servers.remote}:\"INBOX\"";
+ Near = ":${mbsyncNames.servers.local}:\"INBOX\"";
+ Create = "Near";
+ Expunge = "None";
+ Sync = [
+ "Pull"
+ "New"
+ ];
+ SyncState = "*";
+ };
+
+ full = {
+ Far = ":${mbsyncNames.servers.remote}:";
+ Near = ":${mbsyncNames.servers.local}:";
+ Patterns = a.mbsync.patterns;
+ Create = "Near";
+ Expunge = "Both";
+ Sync = "All";
+ SyncState = "*";
+ };
+ in
+ genSection "IMAPAccount ${mbsyncNames.base}" (
+ {
+ Host = a.imap.host;
+ User = a.userName;
+ PipelineDepth = 50;
+ TLSType =
+ if !a.imap.tls.enable then
+ "None"
+ else if a.imap.tls.useStartTls then
+ "STARTTLS"
+ else
+ "IMAPS";
+ }
+ // lib.optionalAttrs (a.passwordCommand != null) {
+ PassCmd = toString a.passwordCommand;
+ }
+ // lib.optionalAttrs (a.imap.tls.certificatesFile != null) {
+ CertificateFile = toString a.imap.tls.certificatesFile;
+ }
+ // lib.optionalAttrs (a.imap.port != null) {
+ Port = a.imap.port;
+ }
+ )
+
+ + "\n"
+ + genSection "IMAPStore ${mbsyncNames.servers.remote}" {
+ Account = mbsyncNames.base;
+ }
+
+ + "\n"
+ + genSection "MaildirStore ${mbsyncNames.servers.local}" {
+ Path = "${a.maildir.absPath}/";
+ Inbox = "${a.maildir.absPath}/${a.folders.inbox}";
+ SubFolders = "Verbatim";
+ }
+
+ + "\n"
+ + genSection "Channel ${mbsyncNames.channels.quick}" quick
+
+ + "\n"
+ + genSection "Channel ${mbsyncNames.channels.full}" full
+
+ + "\n";
+
+ accounts = lib.filter (a: a.enable && a.mbsync.enable) (
+ lib.attrValues config.accounts.email.accounts
+ );
+
+in
{
config = lib.mkIf config.communication.neomutt.enable {
programs.mbsync.enable = true;
+
+ xdg.configFile."mbsync/.mbsyncrc".text = lib.concatStringsSep "\n" (map genAccount accounts);
};
}