aboutsummaryrefslogtreecommitdiffstats
path: root/bin/gpg2mutt
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2015-12-23 01:00:15 +0100
committerDavid Runge <dave@sleepmap.de>2015-12-23 01:00:15 +0100
commitcb1c7556fdf93de9ec2a0f060392db27daa30447 (patch)
tree4c8cfdde32b25227f6386a7532f5e4fb5e0a8ffd /bin/gpg2mutt
parent49bafdd81ecf8cc08c63a02b3d6ad050a8d4a974 (diff)
parentca41781b99ff2bc340bb71d2e3bf499ddca22e95 (diff)
downloaddotfiles-cb1c7556fdf93de9ec2a0f060392db27daa30447.tar.gz
dotfiles-cb1c7556fdf93de9ec2a0f060392db27daa30447.tar.bz2
dotfiles-cb1c7556fdf93de9ec2a0f060392db27daa30447.tar.xz
dotfiles-cb1c7556fdf93de9ec2a0f060392db27daa30447.zip
Merge branch 'master' of sleepmap.de:dotfiles
* 'master' of sleepmap.de:dotfiles: bin/gpg2mutt: Moving the lesser rememberable generate_pgp_auto to an easier to remember script name.
Diffstat (limited to 'bin/gpg2mutt')
-rwxr-xr-xbin/gpg2mutt69
1 files changed, 69 insertions, 0 deletions
diff --git a/bin/gpg2mutt b/bin/gpg2mutt
new file mode 100755
index 0000000..d9db27b
--- /dev/null
+++ b/bin/gpg2mutt
@@ -0,0 +1,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/.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
+
+' | egrep -v 'WhatYouDontWantInThisList@example\\\\\.org' | sort -u > ${output}
+# Note the triple escaped backslash!