@@ -58,7 +58,7 @@ syncandnotify() {
case "$1" in
case "$1" in
imap) mbsync -q "$2" ;;
imap) mbsync -q "$2" ;;
pop) mpop -q "$2" ;;
pop) mpop -q "$2" ;;
esac
esac || return 1
new=$(find\
new=$(find\
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/new/ \
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/new/ \
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
@@ -74,7 +74,7 @@ syncandnotify() {
[ -z "$MAILSYNC_MUTE" ] &&
[ -z "$MAILSYNC_MUTE" ] &&
for file in $new; do
for file in $new; do
# Extract and decode subject and sender from mail.
# Extract and decode subject and sender from mail.
subject=$(awk '/^Subject: / && ++n == 1,/^.*: / && ++i == 2' "$file" | head -n-1 |
subject=$(awk '/^Subject: / && ++n == 1,/^.*: / && ++i == 2' "$file" | sed '$d' |
perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' |
perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' |
sed 's/^Subject: //' | tr -d '\n\t')
sed 's/^Subject: //' | tr -d '\n\t')
from="$(sed -n "/^From:/ s|From: *|| p" "$file" |
from="$(sed -n "/^From:/ s|From: *|| p" "$file" |
@@ -100,15 +100,34 @@ else
done || echo "error $arg"; done)"
done || echo "error $arg"; done)"
fi
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
for account in $tosync; do
count=$((count+1))
case $account in
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
esac
done
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
notmuch new --quiet