From 4286bae71b4ca1c9203a3a3ebf1ff4701855e4b7 Mon Sep 17 00:00:00 2001 From: Dominic Ricottone Date: Wed, 19 Aug 2020 19:16:12 -0400 Subject: [PATCH] Revamping Mailman filter with external digestion --- Makefile | 2 ++ README.md | 13 +++++++------ src/mailman.awk | 52 +++++++------------------------------------------ src/mailman.sh | 13 +++++++++++++ 4 files changed, 29 insertions(+), 51 deletions(-) create mode 100755 src/mailman.sh diff --git a/Makefile b/Makefile index a746f5e..78522d8 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ install: install -m755 src/googlegroups.awk $(INSTALL_DIR)/googlegroups.awk install -m755 src/html.sh $(INSTALL_DIR)/html.sh install -m755 src/mailman.awk $(INSTALL_DIR)/mailman.awk + install -m755 src/mailman.sh $(INSTALL_DIR)/mailman.sh install -m755 src/ubuntu.awk $(INSTALL_DIR)/ubuntu.awk uninstall: @@ -20,6 +21,7 @@ uninstall: rm $(INSTALL_DIR)/googlegroups.awk rm $(INSTALL_DIR)/html.sh rm $(INSTALL_DIR)/mailman.awk + rm $(INSTALL_DIR)/mailman.sh rm $(INSTALL_DIR)/ubuntu.awk rmdir $(INSTALL_DIR) diff --git a/README.md b/README.md index 3e9d5a3..70bf475 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,13 @@ to,~.@lists.ubuntu.com =path/to/ubuntu.awk to,~.@lists.debian.org =path/to/debian.awk from,~.@freebsd.org =path/to/freebsd.awk from,~.+@googlegroups.com=path/to/googlegroups.awk -from,~.+@archlinux.org =path/to/mailman.awk -from,~.+@python.org =path/to/mailman.awk -from,~.+@gnu.org =path/to/mailman.awk +from,~.+@archlinux.org =path/to/mailman.sh +from,~.+@python.org =path/to/mailman.sh +from,~.+@gnu.org =path/to/mailman.sh text/* =cat ``` +If possible, install [digestion](https://git.dominic-ricottone.com/digestion) as well. `mailman.sh` will automatically make use of it. ## Recommended mutt configuration @@ -69,11 +70,11 @@ elif grep --quiet -e '^From:.*@freebsd.org' "$TMP"; then elif grep --quiet -e '^From:.*@googlegroups.com' "$TMP"; then cat "$TMP" | path/to/googlegroups.awk elif grep --quiet -e '^From:.*@archlinux.org' "$TMP"; then - cat "$TMP" | path/to/mailman.awk + cat "$TMP" | path/to/mailman.sh elif grep --quiet -e '^From:.*@python.org' "$TMP"; then - cat "$TMP" | path/to/mailman.awk + cat "$TMP" | path/to/mailman.sh elif grep --quiet -e '^From:.*@gnu.org' "$TMP"; then - cat "$TMP" | path/to/mailman.awk + cat "$TMP" | path/to/mailman.sh else cat "$TMP" fi diff --git a/src/mailman.awk b/src/mailman.awk index bd8a26f..1cef16c 100755 --- a/src/mailman.awk +++ b/src/mailman.awk @@ -7,49 +7,23 @@ BEGIN { in_todays_topics=0; - in_header=0; do_not_print=0; - get_boundary=0; - boundary=""; - dim="\033[2m"; - yellow="\033[33m"; cyan="\033[36m"; reset="\033[0m"; } { - # get boundary - if (get_boundary==1) { - get_boundary=0; - matched=match($0,/boundary=".*"/); - if (matched!=0) boundary="--" substr($0,RSTART+10,RLENGTH-11); - # if failed to extract boundary, resume printing - else do_not_print=0; - } - # skip blocks of non-text (HTML, PGP Signatures, non-text MIME parts) if (do_not_print==1 && $0 ~ /(<\/html>|END PGP SIGNATURE)/) do_not_print=0; - else if (boundary!="" && $0 ~ boundary) do_not_print=0; - else if ($0 ~ /(|BEGIN PGP SIGNATURE)/) do_not_print=1; - else if ($0 ~ /^Content-Type:/) { - in_header=0; - if ($0 ~ /multipart\/alternative/) { do_not_print=1; get_boundary=1; } - else if (boundary!="" && $0 ~ /text\/html/) do_not_print=1; - # for other content types, resume printing - else do_not_print=0; - } else { - # identify "Today's Topics" section + # identify "Today's Topics" if (in_todays_topics==1 && $0 ~ /^-{5,}/) in_todays_topics=0; else if ($0 ~ /^Today's Topics:/) in_todays_topics=1; - # identify header section - if (in_header==1 && $0 ~ /^\s*$/) { in_header=0; do_not_print=0; } - else if ($0 ~ /^(Message|Date|From|To|Subject|Message-ID):/) in_header=1; - + # highlight "Today's Topics" if (in_todays_topics==1) { matched=match($0, /\([^)]+\)/); if (matched!=0) { @@ -65,23 +39,11 @@ BEGIN { $0=dim cyan $0 reset } } - else if (in_header==1) { - if ($0 ~ /^(Date|From|Subject):/) { - do_not_print=0; - $1=$1 dim cyan; - $0=$0 reset; - } - else if ($0 ~ /^Message:/) { - do_not_print=0; - $1=$1 yellow; - $0=$0 reset; - } - else if ($0 ~ /^(To|Message-ID):/) { - do_not_print=1; - } - else { - $0=dim cyan $0 reset; - } + + # highlight header lines + else if ($0 ~ /^(Subject|Date|From|To|Cc):/) { + $1=$1 dim cyan; + $0=$0 reset; } if (do_not_print==0) print $0; diff --git a/src/mailman.sh b/src/mailman.sh new file mode 100755 index 0000000..4fcd3d5 --- /dev/null +++ b/src/mailman.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# mailman.sh +# ========== +# A filter (as for mutt or aerc) which runs digestion and an awk filter. + +if command -v /usr/local/share/mail-filters/digestion 2>&1 >/dev/null; then + /usr/local/share/mail-filters/digestion -length $(tput cols) \ + | /usr/local/share/mail-filters/mailman.awk +else + /usr/local/share/mail-filters/mailman.awk +fi + -- 2.45.2