~dricottone/mail-filters

ref: 1d95aa9263475e71c60b26f2ea38bff998ed19d4 mail-filters/src/freebsd.awk -rwxr-xr-x 1.5 KiB
1d95aa92Dominic Ricottone Removing wrapper 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
#!/bin/awk -f

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

BEGIN {
  in_header=0;

  dim="\033[2m";
  yellow="\033[33m";
  cyan="\033[36m";
  reset="\033[0m";
}
{
  # hide blocks of non-plaintext
  if (do_not_print==1 && $0 ~ /END PGP SIGNATURE/) do_not_print=0;
  else if ($0 ~ /BEGIN PGP SIGNATURE/) do_not_print=1;

  else {
    # identify header section
    if (in_header==1 && $0 ~ /^\s*$/) in_header=0;
    else if ($0 ~ /^(={5,}|(Topic|Category|Module|Announced|Credits|Affects|Corrected|CVE Name):)/) in_header=1;

    if (in_header==1) {
      # highlight header details while preserving whitespace
      if ($0 ~ /^(Topic|Category|Module|Announced|Credits|Affects|Corrected):/) {
        whitespace=substr("                ",length($1)+2)
        $2=whitespace dim cyan $2;
        $0=$0 reset;
      }
      else if ($0 ~ /^CVE Name:/) {
        whitespace=substr("                ",length($1)+length($2)+3)
        $3=whitespace dim cyan $3;
        $0=$0 reset;
      }
      else if ($0 !~ /^=/) {
        $0=dim cyan $0 reset;
      }
    }
    else {
      # highlight section titles
      if ($0 ~ /^(I|II|III|IV|V|VI|VII)\.\s/) {
        $0=yellow $0 reset;
      }
      else if ($0 ~ /^(1|2|3|4|a|b|c|d)\)\s/) {
        $1=yellow $1 reset;
      }
      # color syntax sections
      else if ($1=="#") {
        $0=cyan $0 reset;
      }
    }

    if (do_not_print==0) print $0;
  }
}