summaryrefslogtreecommitdiff
path: root/collect-tos-for-alpine-addressbook
blob: 937642cf7fb9fa01802f92f93642084cf4d2c56f (plain)
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
#!/bin/bash

sed '
  :a
    N
    s/\n\s\+/ /
    ta
  P
  D
' tmp/header \
| sed -n '
  s@^\(bcc\|Bcc\|BCC\|cc\|Cc\|CC\|To\|Reply-To\): @@
  T
  :b
    s@^\(\([^"]*"[^"]*"\)*[^"]*\),\s\+@\1\n@g
    tb
  p
' \
| sed '
  s#^\(.*\S\)\s*<\(\S\+@\S\+\)>$#\2 \1#
  t
  /^\S\+@\S\+$/!d
' \
| sort -uf \
| while read -r email comment; do
  printf '%s %s %s\n' \
    "${#comment}" \
    "$(echo "$comment" | base64 -w0)" \
    "${email}"
done \
| sort -k3,3 -k1nr,1 \
| uniq -f2 \
| while read -r _ comment email; do
  printf '\t%s\t%s\n' \
    "$(
      printf '%s\n' "${comment}" \
      | base64 -d \
      | sed 's@^\(["'"'"']\)\(.*\)\1@\2@'
    )" \
    "${email}"
done