From 48ac83c07f7f62475400dcec179c0695bd7aba3e Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Thu, 16 Feb 2023 14:11:49 -0500 Subject: [PATCH] bring back ugly but functional cmds to get subject fix #910 --- bin/mailsync | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/mailsync b/bin/mailsync index 537e0f1..1f2aa32 100755 --- a/bin/mailsync +++ b/bin/mailsync @@ -70,9 +70,16 @@ syncandnotify() { echo "$newcount new mail for $2." [ -z "$MAILSYNC_MUTE" ] && for file in $new; do - # Extract subject and sender from mail. - from="$(sed -n "/^From:/ s/\(.*: \| *<.*\)//g p" "$file")" - subject="$(sed -n "/^Subject:/ s|.*: || p" "$file")" + # Extract subject and sender from mail. TODO: beautify and clean up. + 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 "📧$from:" "$subject" done ;;