~dricottone/mail-filters

ref: b1a1f1c45b92fbfdba87ad9babc58a9caa2b177b mail-filters/src/fanfiction.awk -rwxr-xr-x 1.0 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
#!/bin/awk -f

# fanfiction.awk
# ==============
# A filter (as for mutt or aerc) intended to clean & decorate plaintext mail
# from FanFiction.net, dim cyaning descriptive information

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

  skip=0;

  comma_replacement=reset ", " dim cyan;
  brace_replacement=reset "] " dim cyan;
  close_brace_replacement=reset "] ";
}
{
  # stop processing at end of mail, marked by website URL
  if ($0 ~ /^FanFiction \[/) skip=1;
  if ($0 ~ /^URLs:/) skip=0;

  if ($0 ~ /^New (story|chapter) from/) {
    $4=cyan $4;
    $0=$0 reset;
  }
  else if ($0 ~ /^(Words|Genre|Rated):/) {
    $1=$1 dim cyan;
    $0=$0 reset;
  }
  else if ($0 ~ /^Character:/) {
    if ($2 ~ /^\[/) {
      $2="[" dim cyan substr($2,2);
    }
    else {
      $2=dim cyan $2;
    }
    gsub(/, /,comma_replacement);
    gsub(/\] /,brace_replacement);
    if ($NF ~ /]\s+$/) {
      sub(/]\s+$/,close_brace_replacement,$NF);
    }
    else {
      $0=$0 reset;
    }
  }

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