diff --git a/modules/programs/thunderbird.nix b/modules/programs/thunderbird.nix index c15a946e..11438351 100644 --- a/modules/programs/thunderbird.nix +++ b/modules/programs/thunderbird.nix @@ -116,6 +116,18 @@ let (builtins.map (address: toThunderbirdIdentity account address) addresses) // account.thunderbird.settings id; + toThunderbirdFeed = feed: profile: + let id = feed.id; + in { + "mail.account.account_${id}.server" = "server_${id}"; + "mail.server.server_${id}.name" = feed.name; + "mail.server.server_${id}.type" = "rss"; + "mail.server.server_${id}.directory" = + "${thunderbirdProfilesPath}/${profile.name}/Mail/Feeds-${id}"; + "mail.server.server_${id}.directory-rel" = "[ProfD]Mail/Feeds-${id}"; + "mail.server.server_${id}.hostname" = "Feeds-${id}"; + }; + mkUserJs = prefs: extraPrefs: '' // Generated by Home Manager. @@ -160,6 +172,25 @@ in { ''; }; + feedAccounts = mkOption { + type = types.attrsOf (submodule ({ config, name, ... }: { + options = { + name = mkOption { + type = types.str; + default = name; + readOnly = true; + description = "This feed account's name."; + }; + }; + })); + default = { }; + description = '' + Attribute set of feed accounts. Feeds themselves have to be + managed through Thunderbird's settings. This option allows + feeds to coexist with declaratively managed email accounts. + ''; + }; + settings = mkOption { type = with types; attrsOf (oneOf [ bool int str ]); default = { }; @@ -353,11 +384,17 @@ in { mkIf (profile.userContent != "") { text = profile.userContent; }; "${thunderbirdProfilesPath}/${name}/user.js" = let - accounts = filter (a: + emailAccounts = filter (a: a.thunderbird.profiles == [ ] || any (p: p == name) a.thunderbird.profiles) enabledAccountsWithId; - smtp = filter (a: a.smtp != null) accounts; + smtp = filter (a: a.smtp != null) emailAccounts; + + feedAccounts = + map (f: f // { id = builtins.hashString "sha256" f.name; }) + (attrValues profile.feedAccounts); + + accounts = emailAccounts ++ feedAccounts; in { text = mkUserJs (builtins.foldl' (a: b: a // b) { } ([ cfg.settings @@ -375,7 +412,8 @@ in { { "mail.openpgp.allow_external_gnupg" = profile.withExternalGnupg; } profile.settings - ] ++ (map (a: toThunderbirdAccount a profile) accounts))) + ] ++ (map (a: toThunderbirdAccount a profile) emailAccounts) + ++ (map (f: toThunderbirdFeed f profile) feedAccounts))) profile.extraConfig; }; })); diff --git a/tests/modules/programs/thunderbird/thunderbird-expected-first.js b/tests/modules/programs/thunderbird/thunderbird-expected-first.js index a0876893..e77b2285 100644 --- a/tests/modules/programs/thunderbird/thunderbird-expected-first.js +++ b/tests/modules/programs/thunderbird/thunderbird-expected-first.js @@ -3,9 +3,10 @@ user_pref("general.useragent.override", ""); user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.identities", "id_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); user_pref("mail.account.account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.server", "server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc"); +user_pref("mail.account.account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.server", "server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.identities", "id_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562"); user_pref("mail.account.account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.server", "server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); -user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); +user_pref("mail.accountmanager.accounts", "account_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc,account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f,account_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); user_pref("mail.accountmanager.defaultaccount", "account_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); user_pref("mail.identity.id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562.attachPgpKey", false); user_pref("mail.identity.id_8bbcff78f53202c0bfaa490a2068e3e5d6e36872144c659952ecc0ada47d7562.autoEncryptDrafts", true); @@ -51,6 +52,11 @@ user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da50 user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.socketType", 3); user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.type", "imap"); user_pref("mail.server.server_bcd3ace52bed41febb6cdc2fb1303aebaa573e0d993872da503950901bb6c6fc.userName", "home.manager.jr"); +user_pref("mail.server.server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.directory", ".thunderbird/first/Mail/Feeds-c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); +user_pref("mail.server.server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.directory-rel", "[ProfD]Mail/Feeds-c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); +user_pref("mail.server.server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.hostname", "Feeds-c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab"); +user_pref("mail.server.server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.name", "rss"); +user_pref("mail.server.server_c6cc42837ed0a8041f93ff12c579a4af0dbe702461c97eef069f9f5f8dc4bfab.type", "rss"); user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.directory", ".thunderbird/first/ImapMail/cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.directory-rel", "[ProfD]ImapMail/cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f"); user_pref("mail.server.server_cda3f13b64c1db7d4b58ce07a31304a362d7dcaf14476bfabcca913ae41ada9f.hostname", "imap.example.com"); diff --git a/tests/modules/programs/thunderbird/thunderbird.nix b/tests/modules/programs/thunderbird/thunderbird.nix index f65f80bd..8d65309a 100644 --- a/tests/modules/programs/thunderbird/thunderbird.nix +++ b/tests/modules/programs/thunderbird/thunderbird.nix @@ -51,6 +51,8 @@ extraConfig = '' user_pref("mail.html_compose", false); ''; + + feedAccounts.rss = { }; }; second.settings = { "second.setting" = "some-test-setting"; };