ソースを参照

simplify mailsync, remove silly option passing

pull/908/head
Luke Smith 1年前
コミット
2a60bfb6d9
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 4C50B54A911F6252
3個のファイルの変更32行の追加54行の削除
  1. +27
    -40
      bin/mailsync
  2. +4
    -14
      mailsync.1
  3. +1
    -0
      share/mailcap

+ 27
- 40
bin/mailsync ファイルの表示

@@ -43,10 +43,10 @@ case "$(uname)" in
# remember if a display server is running since `ps` doesn't always contain a display
pgrepoutput="$(pgrep -ax X\(\|org\|wayland\))"
displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)"
[ -z $displays ] && [ -d /tmp/.X11-unix ] && displays=$(cd /tmp/.X11-unix && for x in X*; do echo ":${x#X}"; done)
[ -z "$displays" ] && [ -d /tmp/.X11-unix ] && displays=$(cd /tmp/.X11-unix && for x in X*; do echo ":${x#X}"; done)

notify() { [ -n "$pgrepoutput" ] && for x in ${displays:-0:}; do
export DISPLAY=$x
export DISPLAY="$x"
notify-send --app-name="mutt-wizard" "New mail!" "📬 $2 new mail(s) in \`$1\` account."
done ;}
;;
@@ -54,55 +54,42 @@ esac

# Check account for new mail. Notify if there is new content.
syncandnotify() {
acc="$(echo "$account" | sed "s/.*\///")"
if [ "$1" = "pop" ]; then
# Handle POP
mpop "$acc"
else
# Handle IMAP
if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi
fi
case "$1" in
imap) mbsync -q "$2" ;;
pop) mpop -q "$2" ;;
esac
new=$(find\
"$HOME/.local/share/mail/$acc/"[Ii][Nn][Bb][Oo][Xx]/new/ \
"$HOME/.local/share/mail/$acc/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/new/ \
"$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
-type f -newer "$lastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
[ -z "$MAILSYNC_MUTE" ] && case 1 in
$((newcount > 0)) ) notify "$acc" "$newcount" ;;
$((newcount > 0)) ) notify "$2" "$newcount" ;;
esac
}

# Sync accounts passed as argument or all.
if [ "$#" -gt "0" ]; then
for arg in "$@"; do
[ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1
done
accounts=$*
allaccounts="$(grep -hs "^\(Channel\|account\)" "$MBSYNCRC" "$MPOPRC")"

# Get accounts to sync. All if no argument. Prefix with `error` if non-existent.
IFS='
'
if [ -z "$1" ]; then
tosync="$allaccounts"
else
tosync="$(for arg in "$@"; do for availacc in $allaccounts; do
[ "$arg" = "${availacc##* }" ] && echo "$availacc" && break
done || echo "error $arg"; done)"
fi
[ -z "$imap_accounts" ] && [ -r "$MBSYNCRC" ] && imap_accounts="$(awk '/^Channel/ {print $2}' "$MBSYNCRC" 2>/dev/null)"
[ -z "$pop_accounts" ] && [ -r "$MPOPRC" ] && pop_accounts="$(awk '/^account/ {print $2}' "$MPOPRC" 2>/dev/null)"

# Parallelize multiple accounts
for account in $imap_accounts; do
if [ -n "$accounts" ]; then
for tmp_ac in $accounts; do
[ "$tmp_ac" = "$account" ] && syncandnotify "imap" &
done
continue
fi
syncandnotify "imap" &
done

for account in $pop_accounts; do
if [ -n "$accounts" ]; then
for tmp_ac in $accounts; do
[ "$tmp_ac" = "$account" ] && syncandnotify "pop" &
done
continue
fi
syncandnotify "pop" &
for account in $tosync; do
case $account in
Channel*) syncandnotify imap "${account##* }" & ;;
account*) syncandnotify pop "${account##* }" & ;;
error*) echo "ERROR: Account ${account##* } not found." ;;
esac
done


wait

notmuch new --quiet


+ 4
- 14
mailsync.1 ファイルの表示

@@ -16,16 +16,13 @@ syncs the mail of all accounts set up with
mw,
or if account names are given, syncs only those accounts.

.B
mailsync
can also pass on options to
.B
mbsync,
which it uses to sync mail.
.B
mailsync
is a wrapper for
.B mbsync,
.B mbsync
and
.B
mpop,
but also automatically reindexes new mail with
.B notmuch,
gives notifications if new mail is found and can also be set as a cronjob to sync and index mail quietly in the background.
@@ -38,13 +35,6 @@ sync all mail accounts and notify user if there is new mail
only sync the
.B account@example.org
account.
.TP
.B
-*
See the
.B
mbsync
manual for additional options that can be used.
.SH AUTHORS
Written by Luke Smith <luke@lukesmith.xyz> originally in 2018.
.SH LICENSE


+ 1
- 0
share/mailcap ファイルの表示

@@ -7,3 +7,4 @@ audio/*; mpv %s ;
application/pdf; /usr/local/lib/mutt-wizard/openfile %s ;
application/pgp-encrypted; gpg -d '%s'; copiousoutput;
application/pgp-keys; gpg --import '%s'; copiousoutput;
application/x-subrip; $EDITOR %s ;

読み込み中…
キャンセル
保存