* Don't autovifivy @fields array entries.
[interchange.git] / code / UI_Tag / get_gpg_keys.coretag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: get_gpg_keys.coretag,v 1.5 2007-03-30 23:40:54 pajamian Exp $
9
10 UserTag get-gpg-keys Order    dir
11 UserTag get-gpg-keys addAttr
12 UserTag get-gpg-keys Version  $Revision: 1.5 $
13 UserTag get-gpg-keys Routine  <<EOR
14 sub {
15         my ($dir, $opt) = @_;
16         my $gpgexe = $Global::Variable->{GPG_PATH} || 'gpg';
17
18         my $flags = "--list-keys";
19         if($dir) {
20                 $dir = filter_value('filesafe', $dir);
21                 $flags .= "--homedir $dir";
22         }
23 #::logDebug("gpg_get_keys flags=$flags");
24         
25         open(GPGIMP, "$gpgexe $flags |") 
26                 or die "Can't fork: $!";
27
28         my $fmt = $opt->{long} ?  "%s=%s (date %s, id %s)" : "%s=%s";
29
30         my @out;
31         while(<GPGIMP>) {
32                 next unless s/^pub\s+//;
33                 my ($id, $date, $text) = split /\s+/, $_, 3;
34                 $id =~ s:.*?/::;
35                 $text = ::errmsg( $fmt, $id, $text, $date, $id );
36                 $text =~ s/</&lt;/g;
37                 $text =~ s/>/&gt;/g;
38                 $text =~ s/,/&#44;/g;
39                 push @out, $text;
40         }
41         close GPGIMP;
42         my $joiner = $opt->{joiner} || ",\n";
43         unshift @out, "=none" if $opt->{none};
44         return join($joiner, @out);
45 }
46 EOR