Browse Source

disabled by default, enabled with -p or --preview

pull/202/head
luukvbaal 5 years ago
committed by GitHub
parent
commit
9a6b6e89c1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 13 deletions
  1. +23
    -13
      bin/mailsync

+ 23
- 13
bin/mailsync View File

@@ -27,25 +27,35 @@ syncandnotify() {
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
if [ "$newcount" -gt "0" ]; then
notify "$acc" "$newcount" &
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')
notify-send "📧$from:" "$subject" &
done
if [ "$preview" = true ]; then
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')
notify-send "📧$from:" "$subject" &
done
fi
fi
}

# Sync accounts passed as argument or all.
if [ "$#" -eq "0" ]; then
accounts="$(ls "$HOME/.local/share/mail")"
else
accounts=$*
fi

echo " 🔃" > /tmp/imapsyncicon_"$USER"
pkill -RTMIN+12 i3blocks >/dev/null 2>&1

# Parse arguments
accounts=""
while [ $# -gt 0 ]; do
case "$1" in
-p|--preview)
preview=true
shift ;;
*)
accounts="${accounts:+${accounts} }$1"
shift ;;
esac
done

# If no accounts are passed sync all accounts
[ -z "$accounts" ] && accounts="$(ls "$HOME/.local/share/mail")"
# Parallelize multiple accounts
for account in $accounts
do


Loading…
Cancel
Save