~dricottone/mail-filters

ref: 465cfce3214923455f31b4490ef4f1f199e3d6ae mail-filters/src/ubuntu.awk -rwxr-xr-x 1.2 KiB
465cfce3Dominic Ricottone Re-adding 'dim' ANSI code 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
#!/bin/awk -f

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

BEGIN {
  in_header=0;
  in_references=0;
  do_not_print_blank=0;

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

  colon_replacement=": " reset
}
{
  # identify header/references section
  if (in_header==1 && $0 ~ /^={5,}/) in_header=0;
  else if ($0 ~ /^={5,}/) in_header=1;
  else if (in_references==1 && $0 ~ /^\s+$/) in_references=0;
  else if ($0 ~ /^References:/) in_references=1;

  if (in_header==1) {
    if ($0 !~ /={5,}/) {
      $0=dim cyan $0 reset;
    }
  }
  else {
    # skip next line if blank
    if ($0 ~ /^(A security issue affects|Summary|Details|Software Description|Update instructions):/) do_not_print_blank=2;

    # highlight header details (except references)
    if ($0 ~ /^- [A-Za-z]/) {
      $2=dim cyan $2;
      $0=$0 reset;
      sub(/: /,colon_replacement);
    }
    else if (in_references==0 && $0 ~ /^  [A-Za-z]/) {
      $1=dim cyan $1 reset;
      $0="  " $0;
    }
  }

  if (do_not_print_blank==0) print $0;
  else {
    if ($0 !~ /^\s*$/) print $0;
    do_not_print_blank=do_not_print_blank-1;
  }
}