* gpg-mailkeys: use right content-type for attached key,
[pgp-tools.git] / gpg-mailkeys / gpg-mailkeys
1 #! /bin/sh
2 #
3 # gpg-mailkeys: mail out just signed keys to their owners
4 #
5 # $Id$
6
7 set -e
8
9 VERSION='$Rev$'
10
11 if [ -z "$*" ]; then
12 echo "Send people their newly signed GPG key by mail."
13 echo "Usage: $0 keyid ..."
14 exit 1
15 fi
16
17 if [ -e ~/.gpg-mailkeysrc ] ; then
18 . ~/.gpg-mailkeysrc
19 fi
20 if [ -n "$EMAIL" ]; then
21 FROM="$EMAIL"
22 fi
23 if [ -z "$SUBJECT" ]; then
24 SUBJECT="Your signed GPG key"
25 fi
26 if [ -z "$NAME" ]; then
27 NAME=`getent passwd $USER | cut -d: -f5 | cut -d, -f1`
28 fi
29 if [ -z "$TEXT" ]; then
30 TEXT="Hi,
31
32 Here is your signed GPG key.
33
34 Enjoy,
35 $NAME"
36 fi
37
38 FAILKEYS=
39
40 while [ -n "$1" ]; do
41 echo -n "[$1] "
42 TEMPFILE=`mktemp -t gpg2mail.XXXXXX`
43 ADDR=`gpg --with-colons --fixed-list-mode --list-key $1 | sed -e 's/^uid:[^re][^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:<]*<[^:>]*>\):.*/@@uid@@ \1/' -e '/^@@uid@@ /!d' -e 's/([^)]*)//g' -e 's/ */ /g' -e 's/^@@uid@@ //' | head -1`
44 if [ -z "$ADDR" ]; then
45 echo "(no usable user ids)"
46 FAILKEYS="$FAILKEYS:$1"
47 shift 1
48 continue
49 fi
50 BOUNDARY="ksp-$$-boundary-$RANDOM"
51
52 echo -n "$ADDR:"
53 if [ $FROM ]; then
54 echo >$TEMPFILE "From: $NAME <$FROM>"
55 fi
56 cat << EOM >> $TEMPFILE
57 To: $ADDR
58 Subject: $SUBJECT
59 User-Agent: gpg-mailkeys/$VERSION
60 MIME-Version: 1.0
61 Content-Type: multipart/mixed; micalg=pgp-sha1;
62 boundary="$BOUNDARY"
63 Content-Disposition: inline
64
65
66
67 --$BOUNDARY
68 Content-Type: text/plain; charset=us-ascii
69 Content-Disposition: inline
70 Content-Transfer-Encoding: quoted-printable
71
72
73 $TEXT
74
75 EOM
76
77 if [ -f ~/.signature ];
78 then echo "--=20" >> $TEMPFILE
79 cat ~/.signature >> $TEMPFILE
80 fi
81
82 cat << EOM >> $TEMPFILE
83
84 --$BOUNDARY
85 Content-Type: application/pgp-keys
86 Content-Disposition: attachment; filename="$1.asc"
87
88 `gpg --armor --export $1`
89
90 --$BOUNDARY--
91 EOM
92 echo -n " sending"
93 /usr/sbin/sendmail -ti <$TEMPFILE
94 rm $TEMPFILE
95 echo " done."
96 shift 1
97 done
98
99 if [ -n "$FAILKEYS" ]; then
100 echo
101 echo "Note: The following keys could not be sent:"
102 echo "$FAILKEYS" | tr ':' '\n' | sed -e '/^ *$/d' -e 's/^/ /'
103 fi