#!/bin/bash . $HOME/.shenv if [ -e "$HOME/.nomovemymail" ]; then echo >&2 "no movemymail" exit 1 fi space=$(df -khP "$HOME/.fmail" | sed -e1d | awk '{ print $4 }') if ! [[ $space =~ G$ ]]; then echo >&2 "free disc space is low; no movemymail" exit 1 fi # if using notmuch on this machine, sync its database to maildir & git if [ -f "$HOME/.fmail/.notmuch/xapian/iamglass" ]; then mr -d "$HOME/lib/nmbug-spw" autoci # ensure all drafts are in the drafts folder floating_drafts=$(notmuch search --output=files -- tag:draft and not folder:drafts and not tag:deleted) if [ ! -z "$floating_drafts" ]; then # TODO for each entry in $floating_drafts, if it contains the # substring ".fmail/annex", remove it from $floating_drafts # (mdmv used to do this, but now I plan to upload it to # Debian, it doesn't) chronic mdmv $floating_drafts $HOME/.fmail/drafts fi # ensure all spam is in the spam folder to train FastMail's spam filter floating_spam=$(notmuch search --output=files -- tag:spam and not folder:spam) if [ ! -z "$floating_spam" ]; then # TODO for each entry in $floating_drafts, if it contains the # substring ".fmail/annex", remove it from $floating_drafts # (mdmv used to do this, but now I plan to upload it to # Debian, it doesn't) chronic mdmv $floating_spam $HOME/.fmail/spam fi # ensure all deleted messages are in the trash folder floating_deleted=$(notmuch search --output=files -- tag:deleted and not folder:trash) if [ ! -z "$floating_deleted" ]; then # TODO for each entry in $floating_drafts, if it contains the # substring ".fmail/annex", remove it from $floating_drafts # (mdmv used to do this, but now I plan to upload it to # Debian, it doesn't) chronic mdmv $floating_deleted $HOME/.fmail/trash fi fi if offline; then echo >&2 ERROR: We\'re offline\; cannot sync mail exit 1 else # this shouldn't be necessary because there is # /etc/network/if-up.d/postfix, but it's cheap so just call again # here postqueue -f if pgrep -u $USER mbsync 2>/dev/null; then (killall --user $USER mbsync 2>/dev/null && sleep 5) || true killall -9 --user $USER mbsync 2>/dev/null || true fi mbsync fastmail fi # to confirm queue was flushed before I close laptop lid mailq