X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=gpg-mailkeys%2Fgpg-mailkeys;h=7ba5139dfe6decf69a12ba012a8179561bd5cb5e;hb=17fd91ece11d3f5a25cf01dd1624f71440eb08f5;hp=d9ca25968dff3d540d237b40f0d23704ce1ddec2;hpb=89e4e056bd8cb0af9b515fec994cb6706bfe7e1c;p=pgp-tools.git diff --git a/gpg-mailkeys/gpg-mailkeys b/gpg-mailkeys/gpg-mailkeys index d9ca259..7ba5139 100755 --- a/gpg-mailkeys/gpg-mailkeys +++ b/gpg-mailkeys/gpg-mailkeys @@ -8,9 +8,36 @@ set -e VERSION='$Rev$' +# Define the charset used in the text message of the mail +LOCAL_CHARSET="" + +## +# Get the local charset. +# +# The local charset is deduced from the charset used by both ~/.gpg-mailkeysrc +# and ~/.signature. If none of these files exist, the local charset is assumed +# to be us-ascii. + +get_local_charset () +{ + local charset="us-ascii" + local file_list="$HOME/.signature $HOME/.gpg-mailkeysrc" + + for filename in $file_list; do + + if [ -e $filename ]; then + charset=`file --mime-encoding $filename | cut -d ' ' -f 2` + break + fi + + done; + + LOCAL_CHARSET=$charset +} + if [ -z "$*" ]; then - echo "Send people their newly signed GPG key by mail." - echo "Usage: $0 keyid ..." + printf "Send people their newly signed GPG key by mail.\n" + printf "Usage: $0 keyid ...\n" exit 1 fi @@ -35,23 +62,26 @@ Enjoy, $NAME" fi +get_local_charset + FAILKEYS= while [ -n "$1" ]; do - echo -n "[$1] " + printf "[$1] " TEMPFILE=`mktemp -t gpg2mail.XXXXXX` 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` if [ -z "$ADDR" ]; then - echo "(no usable user ids)" + printf "(no usable user ids)\n" FAILKEYS="$FAILKEYS:$1" shift 1 continue fi - BOUNDARY="ksp-$$-boundary-$RANDOM" + NANOTIME=`date +%s-%N` + BOUNDARY="ksp-$$-boundary-$NANOTIME" - echo -n "$ADDR:" + printf "$ADDR:" if [ $FROM ]; then - echo >$TEMPFILE "From: $NAME <$FROM>" + printf >$TEMPFILE "From: $NAME <$FROM>\n" fi cat << EOM >> $TEMPFILE To: $ADDR @@ -65,18 +95,18 @@ Content-Disposition: inline --$BOUNDARY -Content-Type: text/plain; charset=us-ascii +Content-Type: text/plain; charset=$LOCAL_CHARSET Content-Disposition: inline Content-Transfer-Encoding: quoted-printable -$TEXT +`echo "$TEXT" | qprint -e` EOM if [ -f ~/.signature ]; - then echo "--=20" >> $TEMPFILE - cat ~/.signature >> $TEMPFILE + then printf -- "--=20\n" >> $TEMPFILE + qprint -e ~/.signature >> $TEMPFILE fi cat << EOM >> $TEMPFILE @@ -89,15 +119,14 @@ Content-Disposition: attachment; filename="$1.asc" --$BOUNDARY-- EOM - echo -n " sending" + printf " sending" /usr/sbin/sendmail -ti <$TEMPFILE rm $TEMPFILE - echo " done." + printf " done.\n" shift 1 done if [ -n "$FAILKEYS" ]; then - echo - echo "Note: The following keys could not be sent:" - echo "$FAILKEYS" | tr ':' '\n' | sed -e '/^ *$/d' -e 's/^/ /' + printf "\nNote: The following keys could not be sent:\n" + printf "$FAILKEYS\n" | tr ':' '\n' | sed -e '/^ *$/d' -e 's/^/ /' fi