]> git.rmz.io Git - dotfiles.git/blobdiff - isync/sync-mail
mbsync: update youtube hook
[dotfiles.git] / isync / sync-mail
index a3b8a7ab48742507cd7a40e489c0cbfbd51f33a3..ef2ef45903bb9fdb9e9b8f29810c6f4e377efb73 100755 (executable)
@@ -1,60 +1,19 @@
 #!/usr/bin/env bash
 
-dir="$(dirname "${BASH_SOURCE[0]}")"
-config=$dir/config
+mbsync_args="$*"
 
-### pre-sync {{{
+export dir="$(dirname "${BASH_SOURCE[0]}")"
+export config=$dir/config
 
-### }}}
-
-### sync {{{
-mbsync -c "$config" -a
-errno=$?
-
-if [[ $errno -ne 0 ]]; then
-    echo "mbsync failed, ignoring post-sync commands." >&2
-    exit $errno
-fi
-### }}}
-
-### post-sync {{{
-yt_src_mb=youtube-orig
-yt_dst_mb=youtube
-yt_parser=$dir/parse-mail.py
-maildir=$(sed -nr 's/^Path\s*(.*)$/\1/p' $config)
-
-
-if [[ -z $maildir ]]; then
-    echo "Could not extract 'Path' from 'MaildirStore' in '$config'" >&2
-    exit 1
-fi
-
-# expand tilde
-maildir=${maildir/#~/$HOME}
-
-shopt -s extglob
-shopt -s nullglob
-for mail in "$maildir"/$yt_src_mb/new/* ; do
-    mangled_mail=${mail/$yt_src_mb/$yt_dst_mb}
-    # remove UID for mbsync to regenerate it
-    mangled_mail="${mangled_mail/,U=+([0-9])}"
-
-    echo -n "Parsing new message '$(basename "$mail")'..."
-    $yt_parser <"$mail" >"$mangled_mail"
+for hook in $(find $dir/pre-sync.d -type f -executable); do
+    "$hook" $mbsync_args
+done
 
-    if [[ $? -eq 0 ]]; then
-        echo " Success."
-    else
-        echo " Failure! Copying message as is."
-        cp "$mail" "$mangled_mail"
-    fi
+mbsync -c "$config" $mbsync_args
+export mbsync_errno=$?
 
-    # sync {a,m}time
-    touch --reference "$mail" "$mangled_mail"
-    mv "$mail" "${mail/new/cur}S"
+for hook in $(find $dir/post-sync.d -type f -executable); do
+    "$hook" $mbsync_args
 done
-# resync new yt_dst_mb
-mbsync -c "$config" gmail-$yt_src_mb gmail-$yt_dst_mb
-
-### }}}
 
+exit $mbsync_errno