~dricottone/mail-filters

ref: e23b0ade6b52994745a1b26e7c6cba0db64294df mail-filters/src/freebsd.awk -rwxr-xr-x 2.3 KiB
e23b0adeDominic Ricottone In addition to CVE numbers, debian mail can include Debian Bug numbers 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/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;
      }

      # highlight release names
      for (i=10; i<=12; i++) {
        for (j=1; j<=4; j++) {
          release=i "." j "-STABLE";
          replacement=yellow release cyan;
          gsub(release,replacement);

          for (k=1; k<=9; k++) {
            release=i "." j "-RELEASE-p" k;
            replacement=yellow release cyan;
            gsub(release,replacement);
          }
        }
      }
    }
    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;
      }

      # highlight release names
      for (i=10; i<=12; i++) {
        for (j=1; j<=4; j++) {
          release=i "." j "-STABLE";
          replacement=yellow release reset;
          gsub(release,replacement);

          for (k=1; k<=9; k++) {
            release=i "." j "-RELEASE-p" k;
            replacement=yellow release reset;
            gsub(release,replacement);
          }
        }
      }
    }

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