diff options
author | Luke Smith <luke@lukesmith.xyz> | 2021-09-23 13:19:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-23 13:19:31 -0400 |
commit | 4e92252dc2e8d67e759d0a67f069035b5355d855 (patch) | |
tree | e02beaf05132d4bdfda6380920bf914bce5eb625 /bin/mailsync | |
parent | 2a50561834c23565bd5587972dff5cc9de53dd57 (diff) | |
parent | e8458ace20a1e553df1c6249b9ef27234dd2aafd (diff) |
Merge branch 'master' into master
Diffstat (limited to 'bin/mailsync')
-rwxr-xr-x | bin/mailsync | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/bin/mailsync b/bin/mailsync index af7aa6c..bed86a9 100755 --- a/bin/mailsync +++ b/bin/mailsync @@ -14,7 +14,7 @@ # Run only if user logged in (prevent cron errors) pgrep -u "${USER:=$LOGNAME}" >/dev/null || { echo "$USER not logged in; sync will not run."; exit ;} # Run only if not already running in other instance -pidof -s mbsync >/dev/null && { echo "mbsync is already running." ; exit ;} +pidof mbsync >/dev/null && { echo "mbsync is already running."; exit ;} # First, we have to get the right variables for the mbsync file, the pass # archive, notmuch and the GPG home. This is done by searching common profile @@ -25,10 +25,7 @@ eval "$(grep -h -- \ "$HOME/.profile" "$HOME/.bash_profile" "$HOME/.zprofile" "$HOME/.config/zsh/.zprofile" "$HOME/.zshenv" \ "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.config/zsh/.zshrc" "$HOME/.pam_environment" 2>/dev/null)" -case "$(readlink -f /sbin/init)" in - *systemd*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; -esac -export GPG_TTY=$TTY +export GPG_TTY="$(tty)" [ -n "$MBSYNCRC" ] && alias mbsync="mbsync -c $MBSYNCRC" || MBSYNCRC="$HOME/.mbsyncrc" @@ -36,9 +33,11 @@ export GPG_TTY=$TTY case "$(uname)" in Darwin) notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;} - messageinfo() { osascript -e "display notification with title \"📧 $from\" subtitle \"$subject\"" ;} ;; *) + case "$(readlink -f /sbin/init)" in + *systemd*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; + esac # remember if a display server is running since `ps` doesn't always contain a display pgrepoutput="$(pgrep -a X\(org\|wayland\))" displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)" @@ -46,10 +45,6 @@ case "$(uname)" in export DISPLAY=$x notify-send --app-name="mutt-wizard" "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account." done ;} - messageinfo() { [ -n "$pgrepoutput" ] && for x in ${displays:-0:}; do - export DISPLAY=$x - notify-send --app-name="mutt-wizard" "📧$from:" "$subject" - done ;} ;; esac @@ -57,16 +52,17 @@ esac syncandnotify() { acc="$(echo "$account" | sed "s/.*\///")" if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi - new=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2> /dev/null) + new=$(find\ + "$HOME/.local/share/mail/$acc/INBOX/new/"\ + "$HOME/.local/share/mail/$acc/Inbox/new/"\ + "$HOME/.local/share/mail/$acc/inbox/new/"\ + "$HOME/.local/share/mail/$acc/INBOX/cur/"\ + "$HOME/.local/share/mail/$acc/Inbox/cur/"\ + "$HOME/.local/share/mail/$acc/inbox/cur/"\ + -type f -newer "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2> /dev/null) newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) case 1 in - $((newcount > 5)) ) notify "$acc" "$newcount" ;; - $((newcount > 0)) ) for file in $new; do - # Extract subject and sender from mail. - from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//') - subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n') - messageinfo & - done ;; + $((newcount > 0)) ) notify "$acc" "$newcount" ;; esac } |