mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 05:29:46 +01:00
thunderbird: add message filters option
Add option to declare account specific message filters.
This commit is contained in:
parent
9036fe9ef8
commit
64f4ea2a21
3 changed files with 78 additions and 5 deletions
|
@ -124,6 +124,28 @@ let
|
|||
'') prefs)}
|
||||
${extraPrefs}
|
||||
'';
|
||||
|
||||
filterIniHeader = ''
|
||||
version="9"
|
||||
logging="no"
|
||||
'';
|
||||
|
||||
mkFilterToIniStr = f: ''
|
||||
name="${f.name}"
|
||||
enabled="${if f.enabled then "yes" else "no"}"
|
||||
type="${f.type}"
|
||||
action="${f.action}"
|
||||
actionValue="${f.actionValue}"
|
||||
condition="${f.condition}"
|
||||
'';
|
||||
|
||||
mkFilterListToIni = filters:
|
||||
filterIniHeader + concatStrings (map (f: mkFilterToIniStr f) filters);
|
||||
|
||||
getAccountsForProfile = profileName: accounts:
|
||||
(filter (a:
|
||||
a.thunderbird.profiles == [ ]
|
||||
|| any (p: p == profileName) a.thunderbird.profiles) accounts);
|
||||
in {
|
||||
meta.maintainers = with hm.maintainers; [ d-dervishi jkarlson ];
|
||||
|
||||
|
@ -295,6 +317,28 @@ in {
|
|||
argument is an automatically generated identifier.
|
||||
'';
|
||||
};
|
||||
|
||||
msgFilters = mkOption {
|
||||
type = (types.listOf (types.attrs));
|
||||
default = [ ];
|
||||
defaultText = literalExpression "[ ]";
|
||||
example = literalExpression ''
|
||||
[
|
||||
{
|
||||
name = "Junk Status is: Junk";
|
||||
enabled = true;
|
||||
type = "48";
|
||||
action = "Move to folder";
|
||||
actionValue = "imap://joe%40example.com@mail.example.com/Junk";
|
||||
condition = "AND (junk status,is,2)";
|
||||
}
|
||||
]
|
||||
'';
|
||||
description = ''
|
||||
A list of thunderbird message filters which will be added to
|
||||
the account.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
@ -353,10 +397,7 @@ in {
|
|||
mkIf (profile.userContent != "") { text = profile.userContent; };
|
||||
|
||||
"${thunderbirdProfilesPath}/${name}/user.js" = let
|
||||
accounts = filter (a:
|
||||
a.thunderbird.profiles == [ ]
|
||||
|| any (p: p == name) a.thunderbird.profiles) enabledAccountsWithId;
|
||||
|
||||
accounts = getAccountsForProfile name enabledAccountsWithId;
|
||||
smtp = filter (a: a.smtp != null) accounts;
|
||||
in {
|
||||
text = mkUserJs (builtins.foldl' (a: b: a // b) { } ([
|
||||
|
@ -378,6 +419,14 @@ in {
|
|||
] ++ (map (a: toThunderbirdAccount a profile) accounts)))
|
||||
profile.extraConfig;
|
||||
};
|
||||
}));
|
||||
}) ++ (mapAttrsToList (name: profile:
|
||||
let
|
||||
accountsWithFilters = (filter (a: a.thunderbird.msgFilters != [ ])
|
||||
(getAccountsForProfile name enabledAccountsWithId));
|
||||
in (builtins.listToAttrs (map (a: {
|
||||
name =
|
||||
"${thunderbirdConfigPath}/${name}/ImapMail/${a.id}/msgFilterRules.dat";
|
||||
value = { text = mkFilterListToIni a.thunderbird.msgFilters; };
|
||||
}) accountsWithFilters))) cfg.profiles));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
version="9"
|
||||
logging="no"
|
||||
name="test filter"
|
||||
enabled="yes"
|
||||
type="32"
|
||||
action="ACTION_NAME"
|
||||
actionValue="//imap:"
|
||||
condition="AND "
|
|
@ -6,6 +6,14 @@
|
|||
thunderbird = {
|
||||
enable = true;
|
||||
profiles = [ "first" ];
|
||||
msgFilters = [{
|
||||
name = "test filter";
|
||||
enabled = true;
|
||||
type = "32";
|
||||
action = "ACTION_NAME";
|
||||
actionValue = "//imap:";
|
||||
condition = "AND ";
|
||||
}];
|
||||
};
|
||||
|
||||
aliases = [ "home-manager@example.com" ];
|
||||
|
@ -84,5 +92,13 @@
|
|||
assertFileExists home-files/.thunderbird/first/chrome/userContent.css
|
||||
assertFileContent home-files/.thunderbird/first/chrome/userContent.css \
|
||||
<(echo "* { color: red !important; }")
|
||||
|
||||
assertFileExists home-files/.thunderbird/first/ImapMail/${
|
||||
builtins.hashString "sha256" "hm@example.com"
|
||||
}/msgFilterRules.dat
|
||||
assertFileContent home-files/.thunderbird/first/ImapMail/${
|
||||
builtins.hashString "sha256" "hm@example.com"
|
||||
}/msgFilterRules.dat \
|
||||
${./thunderbird-expected-msgFilterRules.dat}
|
||||
'';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue