~dricottone/mail-filters

ref: 4286bae71b4ca1c9203a3a3ebf1ff4701855e4b7 mail-filters/src/mailman.awk -rwxr-xr-x 1.2 KiB
4286bae7Dominic Ricottone Revamping Mailman filter with external digestion 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/awk -f

# mailman.awk
# ===========
# A filter (as for mutt or aerc) intended to clean & decorate plaintext mail
# from mailman servers, highlighting header information

BEGIN {
  in_todays_topics=0;
  do_not_print=0;

  dim="\033[2m";
  cyan="\033[36m";
  reset="\033[0m";
}
{
  # 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 ($0 ~ /(<html>|BEGIN PGP SIGNATURE)/) do_not_print=1;

  else {
    # 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;

    # highlight "Today's Topics"
    if (in_todays_topics==1) {
      matched=match($0, /\([^)]+\)/);
      if (matched!=0) {
        original=substr($0, RSTART, RLENGTH);
        replacement=reset original;
        sub(/\([^)]+\)/,replacement);
      }
      if ($0 ~ /^ +[1-9][0-9]?\./) {
        $1=$1 dim cyan;
        $0=$0 reset;
      }
      else if ($0 !~ /^Today's Topics:/) {
        $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;
  }
}