thunderbird: default office365 to oauth2

Default Office365 Thunderbird IMAP/SMTP settings to OAuth2 while
keeping the existing outlook.office365.com flavor on IMAP and SMTP.
This commit is contained in:
Austin Horstman
2026-04-28 16:27:37 -05:00
parent ae6aeb9dbc
commit c2f07e2dca
3 changed files with 61 additions and 6 deletions
+12 -6
View File
@@ -649,12 +649,18 @@ in
{ config, ... }:
{
config.thunderbird = {
settings = lib.mkIf (config.flavor == "gmail.com") (id: {
"mail.smtpserver.smtp_${id}.authMethod" = mkOptionDefault 10; # 10 = OAuth2
"mail.server.server_${id}.authMethod" = mkOptionDefault 10; # 10 = OAuth2
"mail.server.server_${id}.socketType" = mkOptionDefault 3; # SSL/TLS
"mail.server.server_${id}.is_gmail" = mkOptionDefault true; # handle labels, trash, etc
});
settings = lib.mkIf (config.flavor == "gmail.com" || config.flavor == "outlook.office365.com") (
id:
lib.optionalAttrs (config.smtp != null && config.smtp.authentication == null) {
"mail.smtpserver.smtp_${id}.authMethod" = mkOptionDefault 10; # 10 = OAuth2
}
// lib.optionalAttrs (config.imap != null && config.imap.authentication == null) {
"mail.server.server_${id}.authMethod" = mkOptionDefault 10; # 10 = OAuth2
}
// lib.optionalAttrs (config.flavor == "gmail.com") {
"mail.server.server_${id}.is_gmail" = mkOptionDefault true; # handle labels, trash, etc
}
);
};
options.thunderbird = {
enable = lib.mkEnableOption "the Thunderbird mail client for this account";
@@ -2,6 +2,7 @@
thunderbird = ./thunderbird.nix;
thunderbird-auth-methods = ./thunderbird-auth-methods.nix;
thunderbird-auth-warning = ./thunderbird-auth-warning.nix;
thunderbird-office365 = ./thunderbird-office365.nix;
thunderbird-with-firefox = ./thunderbird-with-firefox.nix;
thunderbird-native-messaging-host = ./thunderbird-native-messaging-host.nix;
}
@@ -0,0 +1,48 @@
{
config,
pkgs,
...
}:
let
defaultAccountId = builtins.hashString "sha256" "default@example.com";
overriddenAccountId = builtins.hashString "sha256" "overridden@example.com";
inherit (pkgs.stdenv.hostPlatform) isDarwin;
profilesDir = if isDarwin then "Library/Thunderbird/Profiles" else ".thunderbird";
userJs = "home-files/${profilesDir}/default/user.js";
in
{
accounts.email.accounts."default@example.com" = {
address = "default@example.com";
flavor = "outlook.office365.com";
primary = true;
realName = "Default Office365";
thunderbird.enable = true;
};
accounts.email.accounts."overridden@example.com" = {
address = "overridden@example.com";
flavor = "outlook.office365.com";
realName = "Overridden Office365";
imap.authentication = "ntlm";
smtp.authentication = "clear";
thunderbird.enable = true;
};
programs.thunderbird = {
enable = true;
package = config.lib.test.mkStubPackage {
name = "thunderbird";
};
profiles.default.isDefault = true;
};
nmt.script = ''
assertFileContains ${userJs} 'user_pref("mail.server.server_${defaultAccountId}.authMethod", 10);'
assertFileContains ${userJs} 'user_pref("mail.smtpserver.smtp_${defaultAccountId}.authMethod", 10);'
assertFileContains ${userJs} 'user_pref("mail.server.server_${defaultAccountId}.socketType", 3);'
assertFileContains ${userJs} 'user_pref("mail.server.server_${overriddenAccountId}.authMethod", 6);'
assertFileContains ${userJs} 'user_pref("mail.smtpserver.smtp_${overriddenAccountId}.authMethod", 3);'
'';
}