From 9d9d826054c9b8cf33615cf0b6e01cf6ae6fb4ac Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 2 Sep 2018 14:58:54 +0900 Subject: [PATCH] mbsync: Adds extraConfig.{local|remote} ... to be able to limit the number of mails to be retrieved. local refers to the "store" configuration, remote to the "channel". --- modules/programs/mbsync-accounts.nix | 25 +++++++++++++++++++++++ modules/programs/mbsync.nix | 30 +++++++++++++++++----------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/modules/programs/mbsync-accounts.nix b/modules/programs/mbsync-accounts.nix index a983b7ff..c3c223eb 100644 --- a/modules/programs/mbsync-accounts.nix +++ b/modules/programs/mbsync-accounts.nix @@ -2,6 +2,9 @@ with lib; +let + extraConfigType = with lib.types; attrsOf (either (either str int) bool); +in { options.mbsync = { enable = mkEnableOption "synchronization using mbsync"; @@ -53,5 +56,27 @@ with lib; Pattern of mailboxes to synchronize. ''; }; + + extraConfig.local = mkOption { + type = extraConfigType; + default = {}; + description = '' + Per store extra config. + ''; + }; + + extraConfig.remote = mkOption { + type = extraConfigType; + default = {}; + example = literalExample '' + { + MaxMessages = 10000; + MaxSize = 1m; + }; + ''; + description = '' + Per channel extra config. + ''; + }; }; } diff --git a/modules/programs/mbsync.nix b/modules/programs/mbsync.nix index 4abfc7b3..06e07e03 100644 --- a/modules/programs/mbsync.nix +++ b/modules/programs/mbsync.nix @@ -33,10 +33,13 @@ let genSection = header: entries: let escapeValue = escape [ "\"" ]; + hasSpace = v: builtins.match ".* .*" v != null; genValue = v: if isList v then concatMapStringsSep " " genValue v - else "\"${escapeValue v}\""; + else if isInt v then toString v + else if (hasSpace v) then "\"${escapeValue v}\"" + else v; in '' ${header} @@ -70,19 +73,22 @@ let Inbox = "${maildir.absPath}/${folders.inbox}"; SubFolders = "Verbatim"; } - // - optionalAttrs (mbsync.flatten != null) { Flatten = mbsync.flatten; } + // optionalAttrs (mbsync.flatten != null) { Flatten = mbsync.flatten; } + // mbsync.extraConfig.local ) + "\n" - + genSection "Channel ${name}" { - Master = ":${name}-remote:"; - Slave = ":${name}-local:"; - Patterns = mbsync.patterns; - Create = masterSlaveMapping.${mbsync.create}; - Remove = masterSlaveMapping.${mbsync.remove}; - Expunge = masterSlaveMapping.${mbsync.expunge}; - SyncState = "*"; - } + + genSection "Channel ${name}" ( + { + Master = ":${name}-remote:"; + Slave = ":${name}-local:"; + Patterns = mbsync.patterns; + Create = masterSlaveMapping.${mbsync.create}; + Remove = masterSlaveMapping.${mbsync.remove}; + Expunge = masterSlaveMapping.${mbsync.expunge}; + SyncState = "*"; + } + // mbsync.extraConfig.remote + ) + "\n"; genGroupConfig = name: channels: