MuttGuide/UseGPG: generate_pgp_auto

File generate_pgp_auto, 1.8 KB (added by MichaelRay, 3 years ago)

generate_pgp_auto script from http://erack.de/download/generate_pgp_auto

Line 
1#!/bin/sh
2# ~/.mutt/generate_pgp_auto
3# Generate mutt pgp_auto* send-hooks from gpg pubring.
4# Redirect output to file and source that in muttrc.
5# Add the global hook _before_ sourcing the list:
6# send-hook . 'reset pgp_autoencrypt'
7# -=*# created by erAck #*=- CopyLeft Eike Rathke 2008-01-08T01:36+0100
8
9# At least in an UTF-8 environment sed gets confused by 8-bit characters in
10# real names and doesn't match the address anymore, an empty LANG variable
11# works around.
12LANG=
13
14# 2nd gpg colon field:
15# d := disabled (deprecated - use the 'D' in field 12 instead)
16# e := expired
17# r := revoked
18
19# Note that the following lines are part of the sed script passed by the shell
20# and may not contain the ' character! Hence the double backslash in mail
21# addresses to escape the regex . dot meta character for Mutt.
22gpg --list-keys --with-colons --fixed-list-mode --no-secmem-warning | sed -ne '
23
24:START
25
26# ignore d|e|r keys
27/^pub:[der]:/ b IGNORE
28
29# ignore disabled keys, D in last field (12)
30/^pub:.*D[^:]*:$/ b IGNORE
31
32# take keys with encryption capability (E in last field), ignore without and
33# other records like ^tru:
34/^pub:.*E[^:]*:$/ ! b IGNORE
35
36# extract uids and convert address to mutt hook and print
37:EXTRACT
38# ignore non-uid or no address
39/^uid:[^der]:[^<]*<\([^:>]\+@[^:>]\+\)>/ ! b NUSKIP
40# extract address
41# somehow the colon part after \)> is needed to not produce a trailing : in output
42# sed buffer problem?
43s/^uid:[^der]:[^<]*<\([^:>]\+@[^:>]\+\)>[^:]*:/\1/
44# escape dot meta characters, with escaped backslash for mutt
45s/\./\\\\./g
46# print hook
47s/\(.*\)/send-hook "!~l ~t \1" "set pgp_autoencrypt pgp_autosign"/p
48:NUSKIP
49n
50/^pub:/ b START
51b EXTRACT
52
53# ignore entire key with uid/sub/... until next pub is encountered
54:IGNORE
55n
56/^pub:/ b START
57b IGNORE
58
59' | egrep -v 'WhatYouDontWantInThisList@example\\\\\.org' | sort -u
60# Note the triple escaped backslash!