3 # gpgkeys_mailto - talk to a email keyserver
4 # Copyright (C) 2001, 2002 Free Software Foundation, Inc.
6 # This file is part of GnuPG.
8 # GnuPG is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # GnuPG is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 $Getopt::Std::STANDARD_HELP_VERSION=1;
24 $sendmail="@SENDMAIL@ -t";
28 sub VERSION_MESSAGE ()
30 print STDOUT "gpgkeys_mailto (GnuPG) @VERSION@\n";
37 --help Print this help
38 --version Print the version
39 -o FILE Write output to FILE
49 open(STDOUT,">$opt_o") || die "Can't open output file $opt_o\n";
54 open(STDIN,$ARGV[0]) || die "Can't open input file $ARGV[0]\n";
57 ($login,$name)=(getpwuid($<))[0,6];
59 $from="$name <$login>";
86 elsif($1=~/^no-verbose$/i)
93 $program="(unknown)" if(!defined($program));
95 if(!defined($address))
97 print STDERR "gpgkeys: no address provided\n";
103 ($address,$args)=split(/\?/,$address);
107 @pairs = split(/&/, $args);
108 foreach $pair (@pairs)
110 ($hdr, $val) = split(/=/, $pair);
112 $hdr =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
114 $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
115 # we only handle "from" right now
136 print "OPTION OUTOFBAND\n\n";
138 # Email keyservers get and search the same way
140 if($command=~/get/i || $command=~/search/i)
142 if($command=~/search/i)
149 open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
150 print MAIL "From: $from\n";
151 print MAIL "To: $address\n";
154 # mail keyservers don't like long-form keyids
156 if(substr($key,0,2) eq "0x")
163 $key=substr($key,-8);
166 print MAIL "Subject: GET 0x$key\n\n";
170 print MAIL "Subject: GET $key\n\n";
172 print MAIL "GnuPG $program email keyserver request\n";
175 # Tell GnuPG not to expect a key
176 print "KEY $key OUTOFBAND\n";
180 print STDERR "gpgkeys: key $key requested from $address\n";
185 if($command=~/send/i)
189 open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
190 print MAIL "From: $name <$login>\n";
191 print MAIL "To: $address\n";
192 print MAIL "Subject: ADD\n\n";
196 if(/^KEY (\S+) BEGIN$/)
217 print STDERR "gpgkeys: key $key sent to $address\n";