From f9d8aa6b2530f4e5ffea17f709d7d973297d78af Mon Sep 17 00:00:00 2001 From: Karl Hallsby Date: Fri, 26 Jun 2020 20:22:45 +0200 Subject: [PATCH] mbsync: write function to generate channel configuration blocks This function takes in a set of groups, which includes their consituent channels and writes the appropriate .mbsyncrc block for the channel. The block that is generated is shown below: Channel groupName1-channelName1 Master :-remote: Slave :-local: Channel groupName2-channelName2 Master :-remote: Slave :-local: Each group must have a unique name, no matter which account it is declared under. The same holds true for channels. Using channels with the patterns set up this way allows one to specify which maildir directories are to be synchronized FROM the master TO the slave. In addition, it allows for these maildirs to be remapped, between the master server and the local slave. This is critical, because Gmail has a strange way of storing its mail that makes using mbsync, mu, and mu4e more difficult. There are additional channel parameters that are already present in this codebase from the previous use of group-channel configuration, which will be reused. --- modules/programs/mbsync.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/programs/mbsync.nix b/modules/programs/mbsync.nix index 2ed0c6d01..14dc8ab6f 100644 --- a/modules/programs/mbsync.nix +++ b/modules/programs/mbsync.nix @@ -79,6 +79,31 @@ let SyncState = "*"; } // mbsync.extraConfig.channel) + "\n"; # Given the attr set of groups, return a string of channels to put into each group. + # Given the attr set of groups, return a string of channels that will direct + # mail to the proper directories, according to the pattern used in channel's + # master pattern definition. + genGroupChannelConfig = storeName: groups: + let + # Given the name of the group this channel is part of and the channel + # itself, generate the string for the desired configuration. + genChannelString = groupName: channel: + genSection "Channel ${groupName}-${channel.name}" ({ + Master = ":${storeName}-remote:${channel.masterPattern}"; + Slave = ":${storeName}-local:${channel.slavePattern}"; + }) + "\n"; + # Given the group name, and a attr set of channels within that group, + # Generate a list of strings for each channels' configuration. + genChannelStrings = groupName: channels: + mapAttrsToList (channelName: info: genChannelString groupName info) channels; + # Given a group, return a string that configures all the channels within + # the group. + genGroupsChannels = group: concatStrings + (genChannelStrings group.name group.channels); + in + # Generate all channel configurations for all groups for this account. + concatStringsSep "\n" + (mapAttrsToList (name: group: genGroupsChannels group) groups); + # Given the attr set of groups, return a string which maps channels to groups genAccountGroups = groups: let