Provision the iCloud Thunderbird profile on GNOME desktops

Seed a Thunderbird profile on ikaros and nymph with the iCloud account
already declared: IMAP imap.mail.me.com:993 over SSL/TLS, SMTP
smtp.mail.me.com:587 over STARTTLS, identity and folder mapping, one
CalDAV calendar and one CardDAV address book.

Account defaults are rendered into a managed user.js because Thunderbird
rewrites prefs.js on exit, while user.js is re-applied at every start.
profiles.ini is seeded only when absent so a profile list Thunderbird
already owns is never replaced.

The address comes from vault_icloud_email and the display name from
vault_personal_full_name. The app-specific password is deliberately not
stored: Thunderbird requests it on first use and keeps it in its own
credential store.

Validated by rendering the templates and running Thunderbird 158 headless
against a sandbox profile: the account was accepted, Local Folders was
created by Thunderbird itself, the CalDAV calendar registered as default
and the CardDAV directory instantiated its abook-icloud.sqlite.
This commit is contained in:
2026-11-01 19:30:10 +01:00
parent 4e8665a7d4
commit 1e40a867e7
7 changed files with 176 additions and 0 deletions

View File

@@ -101,3 +101,23 @@ desktop_gnome_dotfiles:
src: .config/autostart/Nextcloud.desktop
dest: .config/autostart/Nextcloud.desktop
mode: "0644"
# Thunderbird is provisioned from a seeded profile plus a managed user.js:
# Thunderbird rewrites prefs.js on exit, so the declared account, calendar and
# address book defaults are re-applied at every start from user.js instead.
# The address comes from Vault; the app-specific password is never stored here
# and is requested by Thunderbird on first use.
thunderbird_icloud_enabled: true
thunderbird_profile_name: "{{ username }}"
thunderbird_profile_dir: "{{ username }}.default-release"
thunderbird_full_name: "{{ vault_personal_full_name | default(username) }}"
thunderbird_icloud_email: "{{ vault_icloud_email }}"
thunderbird_icloud_account_name: iCloud
thunderbird_icloud_imap_host: imap.mail.me.com
thunderbird_icloud_imap_port: 993
thunderbird_icloud_smtp_host: smtp.mail.me.com
thunderbird_icloud_smtp_port: 587
thunderbird_icloud_caldav_url: https://caldav.icloud.com/
thunderbird_icloud_carddav_url: https://contacts.icloud.com/
thunderbird_icloud_calendar_id: 4f2c1d6e-9b3a-4f7c-8e21-6d5a0c9b7e13
thunderbird_icloud_addressbook_uid: 9e0b7c4a-2d51-4a8f-b6c3-1f7d5e2a8b46

View File

@@ -279,3 +279,8 @@
loop_control:
label: "{{ item }}"
when: workstation_firewall_backend | default('firewalld') == 'firewalld'
- name: Configure Thunderbird for iCloud
tags: [dotfiles, dotfiles:desktop, gnome, thunderbird]
ansible.builtin.import_tasks: thunderbird.yml
when: thunderbird_icloud_enabled | default(false) | bool

View File

@@ -0,0 +1,52 @@
---
- name: Require the iCloud address for the managed Thunderbird profile
tags: [thunderbird]
ansible.builtin.assert:
that:
- vault_icloud_email is defined
- vault_icloud_email | length > 0
- vault_icloud_email != 'REPLACE_ME'
- vault_icloud_email is match('^[^@\s]+@[^@\s]+$')
fail_msg: >-
vault_icloud_email must hold the iCloud mail address before the
Thunderbird profile can be provisioned.
quiet: true
- name: Create the Thunderbird configuration directory
tags: [thunderbird]
ansible.builtin.file:
path: "{{ user_home }}/.thunderbird"
state: directory
owner: "{{ username }}"
group: "{{ user_group }}"
mode: "0700"
- name: Create the managed Thunderbird profile directory
tags: [thunderbird]
ansible.builtin.file:
path: "{{ user_home }}/.thunderbird/{{ thunderbird_profile_dir }}"
state: directory
owner: "{{ username }}"
group: "{{ user_group }}"
mode: "0700"
- name: Seed the Thunderbird profile registry when absent
tags: [thunderbird]
ansible.builtin.template:
src: thunderbird/profiles.ini.j2
dest: "{{ user_home }}/.thunderbird/profiles.ini"
owner: "{{ username }}"
group: "{{ user_group }}"
mode: "0600"
# Never rewrite a profile list Thunderbird has already taken over.
force: false
- name: Render the managed Thunderbird account defaults
tags: [thunderbird]
ansible.builtin.template:
src: thunderbird/user.js.j2
dest: "{{ user_home }}/.thunderbird/{{ thunderbird_profile_dir }}/user.js"
owner: "{{ username }}"
group: "{{ user_group }}"
mode: "0600"
no_log: true

View File

@@ -0,0 +1,9 @@
[Profile0]
Name={{ thunderbird_profile_name }}
IsRelative=1
Path={{ thunderbird_profile_dir }}
Default=1
[General]
StartWithLastProfile=1
Version=2

View File

@@ -0,0 +1,65 @@
// Managed by Ansible from profile_desktop_gnome (tag: thunderbird).
// Thunderbird rewrites prefs.js on exit, so the declared defaults live here
// and are re-applied at every start. Do not edit this file by hand.
//
// The account password is intentionally absent: iCloud mail requires an
// app-specific password, which Thunderbird prompts for and stores in its own
// credential store on first use.
// Mail account
user_pref("mail.accountmanager.accounts", "account1");
user_pref("mail.accountmanager.defaultaccount", "account1");
user_pref("mail.account.account1.server", "server1");
user_pref("mail.account.account1.identities", "id1");
user_pref("mail.server.server1.type", "imap");
user_pref("mail.server.server1.hostname", "{{ thunderbird_icloud_imap_host }}");
user_pref("mail.server.server1.port", {{ thunderbird_icloud_imap_port }});
user_pref("mail.server.server1.socketType", 3);
user_pref("mail.server.server1.authMethod", 3);
user_pref("mail.server.server1.userName", "{{ thunderbird_icloud_email }}");
user_pref("mail.server.server1.name", "{{ thunderbird_icloud_account_name }}");
user_pref("mail.server.server1.directory-rel", "[ProfD]ImapMail/{{ thunderbird_icloud_imap_host }}");
user_pref("mail.server.server1.directory", "{{ user_home }}/.thunderbird/{{ thunderbird_profile_dir }}/ImapMail/{{ thunderbird_icloud_imap_host }}");
user_pref("mail.server.server1.max_cached_connections", 5);
user_pref("mail.server.server1.check_new_mail", true);
user_pref("mail.server.server1.check_time", 10);
user_pref("mail.server.server1.login_at_startup", true);
user_pref("mail.server.server1.empty_trash", false);
user_pref("mail.identity.id1.fullName", "{{ thunderbird_full_name }}");
user_pref("mail.identity.id1.useremail", "{{ thunderbird_icloud_email }}");
user_pref("mail.identity.id1.valid", true);
user_pref("mail.identity.id1.smtpServer", "smtp1");
user_pref("mail.identity.id1.compose_html", true);
user_pref("mail.identity.id1.fcc_folder", "mailbox://{{ thunderbird_icloud_email }}@{{ thunderbird_icloud_imap_host }}/Sent%20Messages");
user_pref("mail.identity.id1.draft_folder", "mailbox://{{ thunderbird_icloud_email }}@{{ thunderbird_icloud_imap_host }}/Drafts");
user_pref("mail.smtpservers", "smtp1");
user_pref("mail.smtpserver.smtp1.hostname", "{{ thunderbird_icloud_smtp_host }}");
user_pref("mail.smtpserver.smtp1.port", {{ thunderbird_icloud_smtp_port }});
user_pref("mail.smtpserver.smtp1.try_ssl", 2);
user_pref("mail.smtpserver.smtp1.authMethod", 3);
user_pref("mail.smtpserver.smtp1.username", "{{ thunderbird_icloud_email }}");
user_pref("mail.smtpserver.smtp1.description", "{{ thunderbird_icloud_account_name }} SMTP");
// Calendar (CalDAV). Calendars are discovered from the registry branch.
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.type", "caldav");
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.name", "{{ thunderbird_icloud_account_name }}");
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.uri", "{{ thunderbird_icloud_caldav_url }}");
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.username", "{{ thunderbird_icloud_email }}");
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.refreshInterval", 30);
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.readOnly", false);
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.disabled", false);
user_pref("calendar.registry.{{ thunderbird_icloud_calendar_id }}.color", "#3a87ad");
user_pref("calendar.list.sortOrder", "{{ thunderbird_icloud_calendar_id }}");
// Address book (CardDAV). dirType 102 is nsIAbManager.CARDDAV_DIRECTORY_TYPE.
user_pref("ldap_2.servers.icloud.dirType", 102);
user_pref("ldap_2.servers.icloud.uid", "{{ thunderbird_icloud_addressbook_uid }}");
user_pref("ldap_2.servers.icloud.description", "{{ thunderbird_icloud_account_name }}");
user_pref("ldap_2.servers.icloud.filename", "abook-icloud.sqlite");
user_pref("ldap_2.servers.icloud.isOffline", false);
user_pref("ldap_2.servers.icloud.position", 3);
user_pref("ldap_2.servers.icloud.carddav.url", "{{ thunderbird_icloud_carddav_url }}");
user_pref("ldap_2.servers.icloud.carddav.username", "{{ thunderbird_icloud_email }}");