Skip to content

Commit

Permalink
aerc: support for directories remapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dezeroku committed May 2, 2024
1 parent aac0844 commit c0a368d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
16 changes: 13 additions & 3 deletions base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,24 @@ local_machine:
# from:
# name: "dezeroku"
# email: "dezeroku@example.com"
# aliases: []
# # aliases:
# # - '"My Alias" <alias@example.com>'
# # Sometimes remapping directories is required.
# # For most common cases, you can use the dir_map list,
# # but few special directories may still require explicit treatment.
# # For example to get rid of the [Gmail]/ prefix, while still putting messages
# # in the existing folders, you would set options as below
# # dir_map:
# # - "* = [Gmail]/*"
# # archive_dir: "[Gmail]/All Mail"
# # drafts_dir: "[Gmail]/Drafts"
# # sent_dir: "[Gmail]/Sent Mail"
#
# # If oauth is set to true, you'll need to run `mailctl 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
# oauth: false
# aliases:
# - '"My Alias" <alias@example.com>'
# imap_server: imap.example.com
# smtp_server: smtp.example.com
# username_cmd: secret-tool lookup mail/example_mailbox username
Expand Down
16 changes: 14 additions & 2 deletions roles/aerc/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
- aerc
- pandoc-cli

- name: Ensure directory exists
- name: Ensure directories exist
ansible.builtin.file:
path: ~/.config/aerc
path: "{{ item }}"
state: directory
mode: 0755
loop:
- ~/.config/aerc
- ~/.config/aerc/folder-map

- name: Copy config files
ansible.builtin.copy:
Expand All @@ -22,6 +25,15 @@
- aerc.conf
- binds.conf

- name: Create folder-map files
ansible.builtin.copy:
content: "{{ email_client[key].dir_map | join('\n') }}"
dest: ~/.config/aerc/folder-map/{{ key }}
mode: 0644
loop: "{{ (email_client | dict2items | selectattr('value.dir_map', 'defined') | list | items2dict).keys() }}"
loop_control:
loop_var: key

- name: Template accounts file
ansible.builtin.template:
src: accounts.conf
Expand Down
16 changes: 16 additions & 0 deletions roles/aerc/templates/accounts.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ from = "{{ item.from.name }}" <{{ item.from.email }}>
{% if 'aliases' in item %}
aliases = {{ item.aliases | join(", ") }}
{% endif %}

{% if 'dir_map' in item %}
folder-map = ~/.config/aerc/folder-map/{{ key }}
{% endif %}
{% if 'archive_dir' in item %}
archive = {{ item.archive_dir }}
{% endif %}
{% if 'drafts_dir' in item %}
postpone = {{ item.drafts_dir }}
{% endif %}
{% if 'sent_dir' in item %}
copy-to = {{ item.sent_dir }}
{% else %}
copy-to = Sent
{% endif %}

cache-headers = true
pgp-auto-sign = true

{% endfor %}

0 comments on commit c0a368d

Please sign in to comment.