summaryrefslogtreecommitdiff
path: root/bin/mailsync
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2023-02-18 17:11:54 -0500
committerLuke Smith <luke@lukesmith.xyz>2023-02-18 17:11:54 -0500
commitd3300a478d7a87800d9c2ccb78768b409ae660cf (patch)
tree6a75d885858d71c8fee77ae5c0e611864a742ce6 /bin/mailsync
parentfe23f7c6722ded6d6ee7823c63c4ebfc82e16d70 (diff)
simplification of decoding, show help on noopt
Diffstat (limited to 'bin/mailsync')
-rwxr-xr-xbin/mailsync16
1 files changed, 6 insertions, 10 deletions
diff --git a/bin/mailsync b/bin/mailsync
index ac1920b..cbd36ff 100755
--- a/bin/mailsync
+++ b/bin/mailsync
@@ -70,16 +70,12 @@ syncandnotify() {
echo "$newcount new mail for $2."
[ -z "$MAILSYNC_MUTE" ] &&
for file in $new; do
- # 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')
+ # Extract and decode subject and sender from mail.
+ subject="$(sed -n "/^Subject:/ s|Subject: *|| p" "$file" |
+ perl -CS -MEncode -ne 'print decode("MIME-Header", $_)')"
+ from="$(sed -n "/^From:/ s|From: *|| p" "$file" |
+ perl -CS -MEncode -ne 'print decode("MIME-Header", $_)')"
+ from="${from% *}" ; from="${from%\"}" ; from="${from#\"}"
notify "📧$from:" "$subject"
done
;;