summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Lucas <jlucas@disroot.org>2025-10-07 23:07:14 +0100
committerJoão Lucas <jlucas@disroot.org>2025-10-07 23:07:14 +0100
commit3dc1ee678bd2631e23c93b5777cdfafb28da8f34 (patch)
tree48266e49b14e3e996989c90960a19d803c510822
parentb7b7f21d692048f34287615312ebc9385cd3c378 (diff)
handle sync errors
- syncandnotify() aborts early if mbsync or mpop fails - mailsync aborts early (exit code 1, before notmuch) if all syncs fail
-rwxr-xr-xbin/mailsync29
1 files changed, 24 insertions, 5 deletions
diff --git a/bin/mailsync b/bin/mailsync
index 3a681f0..25e2e6e 100755
--- a/bin/mailsync
+++ b/bin/mailsync
@@ -58,7 +58,7 @@ syncandnotify() {
case "$1" in
imap) mbsync -q "$2" ;;
pop) mpop -q "$2" ;;
- esac
+ esac || return 1
new=$(find\
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/new/ \
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
@@ -100,15 +100,34 @@ else
done || echo "error $arg"; done)"
fi
+pids= # PIDs of backgrounded subshells
+count=0 # number of accounts in $tosync
+failed=0 # number of failed sync attempts
for account in $tosync; do
+ count=$((count+1))
case $account in
- Channel*) syncandnotify imap "${account##* }" & ;;
- account*) syncandnotify pop "${account##* }" & ;;
- error*) echo "ERROR: Account ${account##* } not found." ;;
+ Channel*)
+ syncandnotify imap "${account##* }" &
+ pids="$pids $!"
+ ;;
+ account*)
+ syncandnotify pop "${account##* }" &
+ pids="$pids $!"
+ ;;
+ error*)
+ echo "ERROR: Account ${account##* } not found."
+ failed=$((failed+1))
+ ;;
esac
done
-wait
+IFS=' '
+for pid in $pids; do
+ wait $pid || failed=$((failed+1))
+done
+
+# Abort if no account sync succeeded
+[ "$count" -gt "$failed" ] || exit 1
notmuch new --quiet