Skip to content

Commit

Permalink
mailctl: replace with oama
Browse files Browse the repository at this point in the history
  • Loading branch information
dezeroku committed May 17, 2024
1 parent f88a5a9 commit 4fccd2d
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 55 deletions.
4 changes: 2 additions & 2 deletions base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ local_machine:
# # drafts_dir: "[Gmail]/Drafts"
# # sent_dir: "[Gmail]/Sent Mail"
#
# # If oauth is set to true, you'll need to run `mailctl authorize <service> <email>`
# # If oauth is set to true, you'll need to run `oama authorize <service> <email>`
# # one-time before using the account
# # You'll also have to create an OAuth app or use publicly available credentials
# # See configurable variables for the `mailctl` role for more details
# # See configurable variables for the `oama` role for more details
# oauth: false
# # Set this to true if you are using a GSuite based pim tooling
# # It requires non-standard authentication flow
Expand Down
2 changes: 1 addition & 1 deletion playbooks/mail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- {role: imapnotify, tags: ['imapnotify']}
- {role: isync, tags: ['isync']}
- {role: msmtp, tags: ['msmtp']}
- {role: mailctl, tags: ['mailctl'], when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
- {role: oama, tags: ['oama'], when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
tags:
- mail
- never
Expand Down
2 changes: 1 addition & 1 deletion roles/imapnotify/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
dependencies:
- role: isync
- {role: mailctl, when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
- {role: oama, when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
2 changes: 1 addition & 1 deletion roles/isync/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
dependencies:
- {role: mailctl, when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
- {role: oama, when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
15 changes: 0 additions & 15 deletions roles/mailctl/templates/config.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions roles/mailctl/templates/services.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion roles/msmtp/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
dependencies:
- {role: mailctl, when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
- {role: oama, when: 'email_client | dict2items | selectattr("value.oauth", "defined") | selectattr("value.oauth", "equalto", true) | list | items2dict'}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Create a private app for these
# Or (not recommended) use the publicly available details from Thunderbird
# https://hg.mozilla.org/comm-central/file/tip/mailnews/base/src/OAuth2Providers.sys.mjs
mailctl_google_client_id: ""
mailctl_google_client_secret: ""
oama_google_client_id: ""
oama_google_client_secret: ""
28 changes: 20 additions & 8 deletions roles/mailctl/tasks/main.yml → roles/oama/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
---
# mailctl-bin SEGFAULTs for me locally,
# installing the static binary from Github works
- name: Install mailctl
- name: Remove mailctl-bin
become: true
become_user: root
community.general.pacman:
name:
- mailctl-bin
state: absent

- name: Remove mailctl legacy config files
become: true
become_user: root
ansible.builtin.file:
path: ~/.config/mailctl
state: absent

- name: Install oama
become: true
become_user: aur_builder
kewlfft.aur.aur:
state: present
name:
- mailctl-bin
- oama-bin

# This probably belongs more in the isync config
# But we won't really need it anywhere outside the mailctl context
# But we won't really need it anywhere outside the oama context
- name: Install XOAUTH2 SASL helper
become: true
become_user: aur_builder
Expand All @@ -21,15 +34,14 @@

- name: Ensure config directory exists
ansible.builtin.file:
path: ~/.config/mailctl
path: ~/.config/oama
state: directory
mode: 0755

- name: Template config files
ansible.builtin.template:
src: "{{ item }}"
dest: ~/.config/mailctl/{{ item }}
dest: ~/.config/oama/{{ item }}
mode: 0600
loop:
- config.yaml
- services.yaml
13 changes: 13 additions & 0 deletions roles/oama/templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
encryption:
tag: GRING

redirect_port: 8080

services:
google:
client_id: {{oama_google_client_id}}
client_secret: {{oama_google_client_secret}}
# Only the first scope is strictly required for email
# But for the sake of mail-pim let's add all the scopes we might want
auth_scope: https://mail.google.com/ https://www.googleapis.com/auth/carddav https://www.googleapis.com/auth/calendar
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ TOKEN_FILE="$TOKEN_DIR/$MAIL_ADDRESS"
touch "$TOKEN_FILE"
chmod 0600 "$TOKEN_FILE"

mailctl access "$MAIL_ADDRESS" > /dev/null
oama access "$MAIL_ADDRESS" > /dev/null

# Using mailctl access directly will not work
# Using oama access directly will not work
# as we need to access the whole JSON here
# Thus we get it from gnome-keyring in the expanded format
secret-tool lookup mailctl "$MAIL_ADDRESS" > "$TOKEN_FILE"
secret-tool lookup oama "$MAIL_ADDRESS" > "$TOKEN_FILE"

echo "$TOKEN_FILE"
2 changes: 1 addition & 1 deletion roles/vdirsyncer/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
dependencies:
- {role: mailctl, when: 'email_client | dict2items | selectattr("value.google", "defined") | selectattr("value.google", "equalto", true) | list | items2dict'}
- {role: oama, when: 'email_client | dict2items | selectattr("value.google", "defined") | selectattr("value.google", "equalto", true) | list | items2dict'}
4 changes: 2 additions & 2 deletions roles/vdirsyncer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

- name: Copy the oauth wrapper script
ansible.builtin.copy:
src: oauth-mailctl.sh
dest: ~/.config/vdirsyncer/oauth-mailctl.sh
src: oauth-oama.sh
dest: ~/.config/vdirsyncer/oauth-oama.sh
mode: 0755

- name: Enable the systemd timer
Expand Down
8 changes: 4 additions & 4 deletions roles/vdirsyncer/templates/config
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ password.fetch = ["command", {{ item.password_cmd.split() | map('join') | map("t
{% else %}
type = "google_contacts"

token_file.fetch = ["command", "~/.config/vdirsyncer/oauth-mailctl.sh", "{{ item.from.email }}"]
# We provide neither, as the script wrapper takes care of that via mailctl
token_file.fetch = ["command", "~/.config/vdirsyncer/oauth-oama.sh", "{{ item.from.email }}"]
# We provide neither, as the script wrapper takes care of that via oama
client_id = ""
client_secret = ""
{% endif %}
Expand Down Expand Up @@ -70,8 +70,8 @@ password.fetch = ["command", {{ item.password_cmd.split() | map('join') | map("t
{% else %}
type = "google_calendar"

token_file.fetch = ["command", "~/.config/vdirsyncer/oauth-mailctl.sh", "{{ item.from.email }}"]
# We provide neither, as the script wrapper takes care of that via mailctl
token_file.fetch = ["command", "~/.config/vdirsyncer/oauth-oama.sh", "{{ item.from.email }}"]
# We provide neither, as the script wrapper takes care of that via oama
client_id = ""
client_secret = ""
{% endif %}
Expand Down

0 comments on commit 4fccd2d

Please sign in to comment.