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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 $sendmail="@SENDMAIL@ -t";
31 open(STDOUT,">$opt_o") || die "Can't open output file $opt_o\n";
36 open(STDIN,$ARGV[0]) || die "Can't open input file $ARGV[0]\n";
39 ($login,$name)=(getpwuid($<))[0,6];
41 $from="$name <$login>";
68 elsif($1=~/^no-verbose$/i)
75 $program="(unknown)" if(!defined($program));
77 if(!defined($address))
79 print STDERR "gpgkeys: no address provided\n";
85 ($address,$args)=split(/\?/,$address);
89 @pairs = split(/&/, $args);
90 foreach $pair (@pairs)
92 ($hdr, $val) = split(/=/, $pair);
94 $hdr =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
96 $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
97 # we only handle "from" right now
118 print "OPTION OUTOFBAND\n\n";
120 # Email keyservers get and search the same way
122 if($command=~/get/i || $command=~/search/i)
124 if($command=~/search/i)
131 open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
132 print MAIL "From: $from\n";
133 print MAIL "To: $address\n";
136 # mail keyservers don't like long-form keyids
138 if(substr($key,0,2) eq "0x")
145 $key=substr($key,-8);
148 print MAIL "Subject: GET 0x$key\n\n";
152 print MAIL "Subject: GET $key\n\n";
154 print MAIL "GnuPG $program email keyserver request\n";
157 # Tell GnuPG not to expect a key
158 print "KEY $key OUTOFBAND\n";
162 print STDERR "gpgkeys: key $key requested from $address\n";
167 if($command=~/send/i)
171 open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
172 print MAIL "From: $name <$login>\n";
173 print MAIL "To: $address\n";
174 print MAIL "Subject: ADD\n\n";
178 if(/^KEY (\S+) BEGIN$/)
199 print STDERR "gpgkeys: key $key sent to $address\n";