~dricottone/mail-filters

ref: b1a1f1c45b92fbfdba87ad9babc58a9caa2b177b mail-filters/src/googlegroups.awk -rwxr-xr-x 1.6 KiB
b1a1f1c4Dominic Ricottone Significant updates 2 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/awk -f

# googlegroups.awk
# ================
# A filter (as for mutt or aerc) intended to clean & decorate plaintext mail
# from @googlegroups.com, highlighting header information and hiding URLs.

BEGIN {
  in_header=0;
  do_not_print=0;

  dim="\033[2m";
  yellow="\033[33m";
  cyan="\033[36m";
  reset="\033[0m";
}
{
  # identify header section
  if (in_header==1 && $0 ~ /^={5,}/) in_header=0;
  else if ($0 ~ /^={5,}/) in_header=1;

  if (do_not_print==0) {
    if (in_header==1) {
      if ($0 ~ /^Topic:/) {
        $1=$1 dim cyan;
        $0=$0 reset;
      }
      else if ($0 ~ /^Url:/) {
        # skip printing this line
        do_not_print=1;
      }
    }
    else {
      if ($0 ~ /^(From|Date|Group):/) {
        $1=$1 dim cyan;
        $0=$0 reset;
      }
      else if ($0 ~ /^  - .* \[[1-9][0-9]? Updates?]/) {
        matched=match($0, /\[[1-9][0-9]? Updates?]/);
        if (matched!=0) {
          original=substr($0, RSTART, RLENGTH);
          replacement=reset yellow original reset;
          sub(/\[[1-9][0-9]? Updates?]/,replacement);

          # skip printing next line
          do_not_print=2;
          print dim cyan $0 reset;
        }
      }
      else if ($0 ~ /^-+ [1-9][0-9]? of [1-9][0-9]? -/) {
        $2=yellow $2;
        $4=$4 reset;
      }
      else if ($0 ~ /^Url: http/) {
        # skip printing this line
        do_not_print=1;
      }
      else if ($0 ~ /^Url:/) {
        # skip printing this AND next line
        do_not_print=2;
      }
    }
  }

  if (do_not_print==0) print $0;
  else do_not_print=do_not_print-1;
}