~dricottone/mail-filters

4286bae71b4ca1c9203a3a3ebf1ff4701855e4b7 — Dominic Ricottone 4 years ago 8bd6cd5
Revamping Mailman filter with external digestion
4 files changed, 29 insertions(+), 51 deletions(-)

M Makefile
M README.md
M src/mailman.awk
A src/mailman.sh
M Makefile => Makefile +2 -0
@@ 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)


M README.md => README.md +7 -6
@@ 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

M src/mailman.awk => src/mailman.awk +7 -45
@@ 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 ~ /(<html>|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;

A src/mailman.sh => src/mailman.sh +13 -0
@@ 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