summaryrefslogtreecommitdiff
path: root/bin/movemymail
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2019-04-07 10:07:32 -0700
committerSean Whitton <spwhitton@spwhitton.name>2019-04-07 10:07:54 -0700
commit0c9f44f0962bd0a94479360035591097b9807b98 (patch)
treee7bb16feda5972e1b935b4a28d912e6e9426f7fe /bin/movemymail
parent95df33be09ad2565804a67368ef18e3b4ebc95b0 (diff)
downloaddotfiles-0c9f44f0962bd0a94479360035591097b9807b98.tar.gz
movemail->movemymail to avoid clash with mailutils' movemail
Diffstat (limited to 'bin/movemymail')
-rwxr-xr-xbin/movemymail60
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/movemymail b/bin/movemymail
new file mode 100755
index 00000000..05d0ce96
--- /dev/null
+++ b/bin/movemymail
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+. $HOME/.shenv
+
+if [ -e "$HOME/.nomovemymail" ]; then
+ echo >&2 "no movemymail"
+ exit 1
+fi
+
+# if using notmuch on this machine, sync its database to maildir
+if [ -f "$HOME/.fmail/.notmuch/xapian/iamglass" ]; then
+ # 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