~dricottone/mail-filters

mail-filters/src/debian.awk -rwxr-xr-x 1.4 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

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

BEGIN {
  in_header=0;
  do_not_print=0;

  dim="\033[2m";
  yellow="\033[33m";
  cyan="\033[36m";
  reset="\033[0m";

  _releases = "oldstable stable testing unstable squeeze wheezy jessie stretch buster";
  split(_releases,releases," ");
}
{
  # 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+-{5,}/ || $0 ~ /^\s*$/) in_header=0;
    else if ($0 ~ /^(-\s+-{5,}|(Package|CVE ID)\s*:)/) in_header=1;

    if (in_header==1) {
      if ($0 ~ /^Package\s*:/) {
        whitespace=substr("                ",length($1)+3)
        $3=whitespace dim cyan $3;
        $0=$0 reset;
      }
      else if ($0 ~ /^(CVE ID|Debian Bug)\s*:/) {
        whitespace=substr("                ",length($1)+length($2)+4)
        $4=whitespace dim cyan $4;
        $0=$0 reset;
      }
      else if ($0 !~ /^-/) {
        $0=dim cyan $0 reset;
      }
    }
    else {
      if ($0 ~ /^Mailing list:/) {
        $3=dim cyan $3;
        $0=$0 reset;
      }
      for (i in releases) {
        replacement=yellow releases[i] reset;
        gsub(releases[i],replacement);
      }
    }

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