[Rt-commit] r8995 - rt/branches/3.7-EXPERIMENTAL/lib/RT/Crypt
ruz at bestpractical.com
ruz at bestpractical.com
Tue Sep 11 17:29:04 EDT 2007
Author: ruz
Date: Tue Sep 11 17:29:03 2007
New Revision: 8995
Modified:
rt/branches/3.7-EXPERIMENTAL/lib/RT/Crypt/GnuPG.pm
Log:
* add UseKeyForEncryption function, we can set, get and clear
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Crypt/GnuPG.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Crypt/GnuPG.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Crypt/GnuPG.pm Tue Sep 11 17:29:03 2007
@@ -469,8 +469,9 @@
}
if ( $args{'Encrypt'} ) {
my %seen;
- $gnupg->options->push_recipients( $_ )
- foreach grep !$seen{ $_ }++, map $_->address,
+ $gnupg->options->push_recipients( $_ ) foreach
+ map UseKeyForEncryption($_),
+ grep !$seen{ $_ }++, map $_->address,
map Mail::Address->parse( $entity->head->get( $_ ) ),
qw(To Cc Bcc);
@@ -591,8 +592,9 @@
}
if ( $args{'Encrypt'} ) {
- $gnupg->options->push_recipients( $_ )
- foreach @{ $args{'Recipients'} || [] };
+ $gnupg->options->push_recipients( $_ ) foreach
+ map UseKeyForEncryption($_),
+ @{ $args{'Recipients'} || [] };
}
my %res;
@@ -680,8 +682,9 @@
my $entity = $args{'Entity'};
if ( $args{'Encrypt'} ) {
- $gnupg->options->push_recipients( $_ )
- foreach @{ $args{'Recipients'} || [] };
+ $gnupg->options->push_recipients( $_ ) foreach
+ map UseKeyForEncryption($_),
+ @{ $args{'Recipients'} || [] };
}
my %res;
@@ -1553,6 +1556,22 @@
return %res;
}
+{ my %key;
+# no args -> clear
+# one arg -> return preferred key
+# many -> set
+sub UseKeyForEncryption {
+ unless ( @_ ) {
+ %key = ();
+ } elsif ( @_ > 1 ) {
+ %key = (%key, @_);
+ $key{ lc($_) } = delete $key{ $_ } foreach grep lc ne $_, keys %key;
+ } else {
+ return $key{ $_[0] } || $_[0];
+ }
+ return ();
+} }
+
=head2 GetKeysForEncryption
Takes identfier and returns keys suitable for encryption.
More information about the Rt-commit
mailing list