perl decoding

This commit is contained in:
luukvbaal 2019-05-31 00:02:48 +02:00 committed by GitHub
parent 70257daa83
commit de2be5439d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,13 +28,9 @@ syncandnotify() {
if [ "$newcount" -gt "0" ]; then if [ "$newcount" -gt "0" ]; then
notify "$acc" "$newcount" & notify "$acc" "$newcount" &
for file in $new; do for file in $new; do
# Extract subject and sender from mail (room for improvement). # Extract subject and sender from mail.
subject=$(grep "^Subject: " "$file" | sed 's/Subject: //' | head -n4) from=$(grep "^From: " "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; $NF=""; print $0 }' | tr -d "\"\'\<\>" | sed 's/^ \(.*\) $/\1/')
from=$(grep "^From: " "$file" | awk '{ $1=""; $NF=""; print $0 }' | tr -d "\"\'\<\>" | sed 's/^ \(.*\) $/\1/') subject=$(grep "^Subject: " "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/Subject: //')
substring="=?"
# Some html emails contain weird Subject and/or Sender formatting, in which case the html tag content is used (room for improvement).
[ "${subject#*$substring}" != "$subject" ] && subject=$(tr '\n' ' ' < "$file" | sed 's/.*<title>\(.*\)<\/title>.*/\1/')
[ "${from#*$substring}" != "$from" ] && from=$(grep ^"From: " "$file" | sed 's/.*<\(.*\)>.*/\1/')
notify-send "📧$from:" "$subject" & notify-send "📧$from:" "$subject" &
done done
fi fi