blob: 976b558543af4957207ecba4b3c593ca1c341edd (
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
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
|
#!/bin/bash
# ~/.mutt/generate_pgp_auto
# Generate mutt pgp_auto* send-hooks from gpg pubring.
# Redirect output to file and source that in muttrc.
# Add the global hook _before_ sourcing the list:
# send-hook . 'reset pgp_autoencrypt'
# -=*# created by erAck #*=- CopyLeft Eike Rathke 2008-01-08T01:36+0100
# At least in an UTF-8 environment sed gets confused by 8-bit characters in
# real names and doesn't match the address anymore, an empty LANG variable
# works around.
LANG=
# Output file
output="$HOME/.config/mutt/gpg-auto.rc"
# if the file exists, delete it
if [ -f "${output}" ]; then
rm "${output}"
fi
# 2nd gpg colon field:
# d := disabled (deprecated - use the 'D' in field 12 instead)
# e := expired
# r := revoked
# Note that the following lines are part of the sed script passed by the shell
# and may not contain the ' character! Hence the double backslash in mail
# addresses to escape the regex . dot meta character for Mutt.
#gpg --list-keys --with-colons --fixed-list-mode --no-secmem-warning
gpg --list-keys --with-colons --fixed-list-mode --no-secmem-warning | sed -ne '
:START
# ignore d|e|r keys
/^pub:[der]:/ b IGNORE
# ignore disabled keys, D in last field (12)
/^pub:.*D[^:]*:$/ b IGNORE
# take keys with encryption capability (E in last field), ignore without and
# other records like ^tru:
#/^pub:.*E[^:]*:$/ ! b IGNORE
# extract uids and convert address to mutt hook and print
:EXTRACT
# ignore non-uid or no address
/^uid:[^der]:[^<]*<\([^:>]\+@[^:>]\+\)>/ ! b NUSKIP
# extract address
# somehow the colon part after \)> is needed to not produce a trailing : in output
# sed buffer problem?
s/^uid:[^der]:[^<]*<\([^:>]\+@[^:>]\+\)>[^:]*:/\1/
# escape dot meta characters, with escaped backslash for mutt
s/\./\\\\./g
# print hook
s/\(.*\)/send-hook "!~l ~t \1" "set crypt_autoencrypt"/p
:NUSKIP
n
/^pub:/ b START
b EXTRACT
# ignore entire key with uid/sub/... until next pub is encountered
:IGNORE
n
/^pub:/ b START
b IGNORE
' | grep -Ev 'WhatYouDontWantInThisList@example\\\\\.org' | sort -u > "${output}"
# Note the triple escaped backslash!
|