3 # gpg2keys_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 3 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, see <http://www.gnu.org/licenses/>.
21 $Getopt::Std::STANDARD_HELP_VERSION=1;
22 $sendmail="@SENDMAIL@ -t";
26 sub VERSION_MESSAGE ()
28 print STDOUT "gpg2keys_mailto (GnuPG) @VERSION@\n";
35 --help Print this help
36 --version Print the version
37 -o FILE Write output to FILE
47 open(STDOUT,">$opt_o") || die "Can't open output file $opt_o\n";
52 open(STDIN,$ARGV[0]) || die "Can't open input file $ARGV[0]\n";
55 ($login,$name)=(getpwuid($<))[0,6];
57 $from="$name <$login>";
84 elsif($1=~/^no-verbose$/i)
91 $program="(unknown)" if(!defined($program));
93 if(!defined($address))
95 print STDERR "gpgkeys: no address provided\n";
101 ($address,$args)=split(/\?/,$address);
105 @pairs = split(/&/, $args);
106 foreach $pair (@pairs)
108 ($hdr, $val) = split(/=/, $pair);
110 $hdr =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
112 $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
113 # we only handle "from" right now
134 print "OPTION OUTOFBAND\n\n";
136 # Email keyservers get and search the same way
138 if($command=~/get/i || $command=~/search/i)
140 if($command=~/search/i)
147 open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
148 print MAIL "From: $from\n";
149 print MAIL "To: $address\n";
152 # mail keyservers don't like long-form keyids
154 if(substr($key,0,2) eq "0x")
161 $key=substr($key,-8);
164 print MAIL "Subject: GET 0x$key\n\n";
168 print MAIL "Subject: GET $key\n\n";
170 print MAIL "GnuPG $program email keyserver request\n";
173 # Tell GnuPG not to expect a key
174 print "KEY $key OUTOFBAND\n";
178 print STDERR "gpgkeys: key $key requested from $address\n";
183 if($command=~/send/i)
187 open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
188 print MAIL "From: $name <$login>\n";
189 print MAIL "To: $address\n";
190 print MAIL "Subject: ADD\n\n";
194 if(/^KEY (\S+) BEGIN$/)
215 print STDERR "gpgkeys: key $key sent to $address\n";