diff --git a/README.md b/README.md index b6d64b8..9029b1e 100644 --- a/README.md +++ b/README.md @@ -61,16 +61,53 @@ AUR packages are installed via the [ansible-aur][7] module. Note that while [aura][8], an [AUR helper][9], is installed by default, it will *not* be used during any of the provisioning. -## System Mail +## Mail + +### Receiving Mail + +Receiving mail is supported by syncing from IMAP servers via both [isync][10] +and [OfflineIMAP][11]. By default isync is enabled, but this can be changed to +OfflineIMAP by setting the value of the `mail.sync_tool` variable to +`offlineimap`. + +### Sending Mail + +[msmtp][12] is used to send mail. Included as part of msmtp's documentation are +a set of [msmtpq scripts][13] for queuing mail. These scripts are copied to the +user's path for use. When calling `msmtpq` instead of `msmtp`, mail is sent +normally if internet connectivity is available. If the user is offline, the +mail is saved in a queue, to be sent out when internet connectivity is again +available. This helps support a seamless workflow, both offline and online. + +### System Mail If the `email.user` variable is defined, the system will be configured to forward mail for the user and root to this address. Removing this variable will cause no mail aliases to be put in place. +The cron implementation is configured to send mail using `msmtpq`. + +### Syncing and Scheduling Mail + +A shell script called `mailsync` is included to sync mail, by first sending any +mail in the msmtp queue and then syncing with the chosen IMAP servers via +either isync or OfflineIMAP. Before syncing, the script checks for internet +connectivity using NetworkMananger. `mailsync` may be called directly by the +user, ie by configuring a hotkey in Mutt. + +A [systemd timer][14] is also included to periodically call `mailsync`. By +default, the timer starts 5 minutes after boot (to allow time for network +connectivity to be established, configurable through the `mail.sync_boot_delay` +variable) and syncs every 15 minutes (configurable through the `mail.sync_time` +variable). + +If the `mail.sync_time` variable is not defined, neither the synchronization +service nor timer will be installed. + ## Known Issues -* [tpfanco][10], normally installed as part of the `thinkpad` role is currently - [unavailable in the AUR][11]. No ThinkPad fan control software is currently +* [tpfanco][15], normally installed as part of the `thinkpad` role is currently + [unavailable in the AUR][16]. No ThinkPad fan control software is currently installed. @@ -83,5 +120,10 @@ cause no mail aliases to be put in place. [7]: https://github.com/pigmonkey/ansible-aur [8]: https://github.com/aurapm/aura [9]: https://wiki.archlinux.org/index.php/AUR_helpers -[10]: https://code.google.com/p/tpfanco/ -[11]: https://aur.archlinux.org/packages/?O=0&K=tpfanco +[10]: http://isync.sourceforge.net/ +[11]: http://offlineimap.org/ +[12]: http://msmtp.sourceforge.net/ +[13]: http://sourceforge.net/p/msmtp/code/ci/master/tree/scripts/msmtpq/README.msmtpq +[14]: https://wiki.archlinux.org/index.php/Systemd/Timers +[15]: https://code.google.com/p/tpfanco/ +[16]: https://aur.archlinux.org/packages/?O=0&K=tpfanco diff --git a/group_vars/all b/group_vars/all index f75c5be..ad8506a 100644 --- a/group_vars/all +++ b/group_vars/all @@ -24,9 +24,10 @@ ssh: user_key: /root/id_rsa enable_sshd: False -isync: - boot_delay: 5min - sync: 15min +mail: + sync_tool: isync + sync_time: 15min + sync_boot_delay: 5min editors: - gvim diff --git a/roles/mail/files/mbsync.service b/roles/mail/files/mailsync.service similarity index 100% rename from roles/mail/files/mbsync.service rename to roles/mail/files/mailsync.service diff --git a/roles/mail/tasks/isync.yml b/roles/mail/tasks/isync.yml index 0d94697..80e1aaa 100644 --- a/roles/mail/tasks/isync.yml +++ b/roles/mail/tasks/isync.yml @@ -3,21 +3,3 @@ pacman: name=isync state=present tags: - isync - -- name: Push mbsync service file - copy: src=mbsync.service dest=/etc/systemd/system/mbsync@.service - when: isync is defined - tags: - - isync - -- name: Push mbsync timer file - template: src=mbsync.timer.j2 dest=/etc/systemd/system/mbsync@.timer - when: isync is defined - tags: - - isync - -- name: Enable and start mbsync timer - service: name="mbsync@{{ user.name }}.timer" enabled=yes state=started - when: isync is defined - tags: - - isync diff --git a/roles/mail/tasks/mailsync.yml b/roles/mail/tasks/mailsync.yml new file mode 100644 index 0000000..8c38bcb --- /dev/null +++ b/roles/mail/tasks/mailsync.yml @@ -0,0 +1,23 @@ +--- +- name: Push mail sync script + template: src=mailsync.sh.j2 dest=/usr/local/bin/mailsync mode=755 + tags: + - mailsync + +- name: Push mailsync service file + copy: src=mailsync.service dest=/etc/systemd/system/mailsync@.service + when: mail.sync_time is defined + tags: + - mailsync + +- name: Push mailsync timer file + template: src=mailsync.timer.j2 dest=/etc/systemd/system/mailsync@.timer + when: mail.sync_time is defined + tags: + - mailsync + +- name: Enable and start mailsync timer + service: name="mailsync@{{ user.name }}.timer" enabled=yes state=started + when: mail.sync_time is defined + tags: + - mailsync diff --git a/roles/mail/tasks/main.yml b/roles/mail/tasks/main.yml index 8dcd70d..a7b2aa7 100644 --- a/roles/mail/tasks/main.yml +++ b/roles/mail/tasks/main.yml @@ -12,10 +12,8 @@ - name: Install notmuch pacman: name=notmuch state=present -- name: Push mail sync script - copy: src=mailsync.sh dest=/usr/local/bin/mailsync mode=755 - - include: msmtp.yml - include: isync.yml - include: offlineimap.yml +- include: mailsync.yml - include: contacts.yml diff --git a/roles/mail/files/mailsync.sh b/roles/mail/templates/mailsync.sh.j2 similarity index 67% rename from roles/mail/files/mailsync.sh rename to roles/mail/templates/mailsync.sh.j2 index 7049f3d..f377ea3 100755 --- a/roles/mail/files/mailsync.sh +++ b/roles/mail/templates/mailsync.sh.j2 @@ -1,4 +1,5 @@ #!/bin/sh +# {{ ansible_managed }} # Original source: http://bit.ly/1Ztk5wg # Send and receive mail when full internet connectivity is available. @@ -7,7 +8,11 @@ STATE=`nmcli networking connectivity` if [ $STATE = 'full' ] then /usr/local/bin/msmtp-queue -r +{% if mail.sync_tool == "isync" %} /usr/bin/mbsync -a +{% elif mail.sync_tool == "offlineimap" %} + /usr/bin/offlineimap -o +{% endif %} exit $? fi echo "No internet connection." diff --git a/roles/mail/templates/mbsync.timer.j2 b/roles/mail/templates/mailsync.timer.j2 similarity index 53% rename from roles/mail/templates/mbsync.timer.j2 rename to roles/mail/templates/mailsync.timer.j2 index 6d65eec..d6aa1a1 100644 --- a/roles/mail/templates/mbsync.timer.j2 +++ b/roles/mail/templates/mailsync.timer.j2 @@ -3,9 +3,9 @@ Description=Mailbox synchronization timer [Timer] -OnBootSec={{ isync.boot_delay }} -OnUnitActiveSec= {{ isync.sync }} -Unit=mbsync@%i.service +OnBootSec={{ mail.sync_boot_delay }} +OnUnitActiveSec= {{ mail.sync_time }} +Unit=mailsync@%i.service [Install] WantedBy=timers.target