{ config, ... }: let repo = config.repo; account = repo.account; in { flake.modules.homeManager.email = { config, lib, ... }: let mkOffice365Account = { address, primary, ... }: { enable = true; inherit address primary; realName = account.realName; userName = address; thunderbird = { enable = true; settings = id: { "mail.smtpserver.smtp_${id}.authMethod" = 10; "mail.server.server_${id}.authMethod" = 10; }; }; flavor = "outlook.office365.com"; }; mkMxrouteAccount = { address, primary, ... }: { enable = true; inherit address primary; realName = account.realName; userName = address; thunderbird.enable = true; imap = { authentication = "plain"; host = "taylor.mxrouting.net"; port = 993; tls.enable = true; }; smtp = { authentication = "plain"; host = "taylor.mxrouting.net"; port = 465; tls.enable = true; }; }; mkEmailAccount = email: if email.type == "office365" then mkOffice365Account email else if email.type == "mxrouting" then mkMxrouteAccount email else throw "Unsupported email type `${email.type}` for ${config.home.username}"; in { programs.thunderbird = { enable = true; profiles.${config.home.username} = { isDefault = true; withExternalGnupg = true; settings = { "mail.ui.display.message_pane_vertical" = true; "mail.ui.display.thread_pane_view_type" = "cards"; "mail.uidensity" = 1; "privacy.donottrackheader.enabled" = true; "mail.server.server2.hidden" = true; "mailnews.start_page.enabled" = false; "mail.provider.enabled" = false; "layout.css.devPixelsPerPx" = 0.85; }; }; }; accounts.email.accounts = lib.mapAttrs (_: mkEmailAccount) account.emails; }; flake.modules.homeManager.calendar-tasks = { config, ... }: let calendarsPath = "${config.xdg.dataHome}/calendars"; in { programs.pimsync.enable = true; services.pimsync.enable = true; programs.khal = { enable = false; locale = { timeformat = "%H:%M"; dateformat = "$m-$d"; }; }; programs.todoman = { enable = true; glob = "*/*"; extraConfig = '' date_format = "%Y-%m-%d" time_format = "%H:%M" default_list = "personal" default_due = 0 default_command = "list --sort priority,due" humanize = True ''; }; accounts.calendar = { basePath = calendarsPath; accounts.radicale = { primary = true; primaryCollection = "personal"; local = { type = "filesystem"; fileExt = ".ics"; }; remote = { url = repo.services.radicale.url; type = "caldav"; userName = config.home.username; passwordCommand = [ "rbw" "get" "Radicale" ]; }; pimsync = { enable = true; extraPairDirectives = [ { name = "collections"; params = [ "from b" ]; } ]; }; khal = { enable = true; type = "discover"; color = "light blue"; }; }; }; }; }