[Rt-commit] r7692 - in rt/branches/3.7-EXPERIMENTAL: .

ruz at bestpractical.com ruz at bestpractical.com
Wed Apr 25 09:49:52 EDT 2007


Author: ruz
Date: Wed Apr 25 09:49:47 2007
New Revision: 7692

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Crypt/GnuPG.pm

Log:
 r5135 at cubic-pc:  cubic | 2007-04-25 14:25:04 +0400
 * generalize Signer and Recipients options
 * update docs


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	Wed Apr 25 09:49:47 2007
@@ -102,10 +102,27 @@
     return shift->();
 }
 
-=head2 SignEncrypt Entity => MIME::Entity, [ Encrypt => 1, Sign => 1, Passphrase => undef ]
+=head2 SignEncrypt Entity => MIME::Entity, [ Encrypt => 1, Sign => 1, ... ]
 
-Signs and/or encrypts an email message with GnuPG utility. A passphrase is required
-only during signing, if value is undefined then L</GetPassphrase> called to get it.
+Signs and/or encrypts an email message with GnuPG utility.
+
+=over
+
+=item Signing
+
+During signing you can pass C<Signer> argument to set key we sign with this option
+overrides gnupg's C<default-key> option. If C<Signer> argument is not provided
+then address of a message sender is used.
+
+As well you can pass C<Passphrase>, but if value is undefined then L</GetPassphrase>
+called to get it.
+
+=item Encrypting
+
+During encryption you can pass a C<Recipients> array, otherwise C<To>, C<Cc> and
+C<Bcc> fields of the message are used to fetch the list.
+
+=back
 
 Returns a hash with the following keys:
 
@@ -132,7 +149,6 @@
             qw(To Cc Bcc)
         ];
     }
-
     
     my $format = lc RT->Config->Get('GnuPG')->{'OutgoingMessagesFormat'} || 'RFC';
     if ( $format eq 'inline' ) {
@@ -145,11 +161,17 @@
 sub SignEncryptRFC3156 {
     my %args = (
         Entity => undef,
-        Encrypt => 1,
+
         Sign => 1,
+        Signer => undef,
         Passphrase => undef,
+
+        Encrypt => 1,
+        Recipients => undef,
+
         @_
     );
+
     my $entity = $args{'Entity'};
 
     if ( $args{'Sign'} && !defined $args{'Passphrase'} ) {
@@ -159,13 +181,12 @@
     my $gnupg = new GnuPG::Interface;
     my %opt = RT->Config->Get('GnuPGOptions');
     $opt{'digest-algo'} ||= 'SHA1';
-    # address of the queue
-    my $sign_as = (Mail::Address->parse( $entity->head->get( 'From' ) ))[0]->address;
+    $opt{'default_key'} = $args{'Signer'}
+        if $args{'Sign'} && $args{'Signer'};
     $gnupg->options->hash_init(
         _PrepareGnuPGOptions( %opt ),
         armor => 1,
         meta_interactive => 0,
-        default_key => $sign_as,
     );
 
     my %res;
@@ -329,25 +350,17 @@
     my $gnupg = new GnuPG::Interface;
     my %opt = RT->Config->Get('GnuPGOptions');
     $opt{'digest-algo'} ||= 'SHA1';
+    $opt{'default_key'} = $args{'Signer'}
+        if $args{'Sign'} && $args{'Signer'};
     $gnupg->options->hash_init(
         _PrepareGnuPGOptions( %opt ),
         armor => 1,
         meta_interactive => 0,
-        ( $args{'Sign'} && $args{'Signer'}? (default_key => $args{'Signer'}): () ),
     );
 
-    my $entity = $args{'Entity'};
     if ( $args{'Encrypt'} ) {
-        unless ( $args{'Recipients'} ) {
-            my %seen;
-            $gnupg->options->push_recipients( $_ )
-                foreach grep $_ && !$seen{ $_ }++, map $_->address,
-                    map Mail::Address->parse( $entity->head->get( $_ ) ),
-                    qw(To Cc Bcc);
-        } else {
-            $gnupg->options->push_recipients( $_ )
-                foreach @{ $args{'Recipients'} };
-        }
+        $gnupg->options->push_recipients( $_ )
+            foreach @{ $args{'Recipients'} || [] };
     }
 
     my %res;
@@ -366,6 +379,7 @@
     $handles->options( 'stdout'  )->{'direct'} = 1;
     $gnupg->passphrase( $args{'Passphrase'} ) if $args{'Sign'};
 
+    my $entity = $args{'Entity'};
     eval {
         local $SIG{'CHLD'} = 'DEFAULT';
         my $method = $args{'Sign'} && $args{'Encrypt'}
@@ -420,25 +434,18 @@
     my $gnupg = new GnuPG::Interface;
     my %opt = RT->Config->Get('GnuPGOptions');
     $opt{'digest-algo'} ||= 'SHA1';
+    $opt{'default_key'} = $args{'Signer'}
+        if $args{'Sign'} && $args{'Signer'};
     $gnupg->options->hash_init(
         _PrepareGnuPGOptions( %opt ),
         armor => 1,
         meta_interactive => 0,
-        ( $args{'Sign'} && $args{'Signer'}? (default_key => $args{'Signer'}): () ),
     );
 
     my $entity = $args{'Entity'};
     if ( $args{'Encrypt'} ) {
-        unless ( $args{'Recipients'} ) {
-            my %seen;
-            $gnupg->options->push_recipients( $_ )
-                foreach grep $_ && !$seen{ $_ }++, map $_->address,
-                    map Mail::Address->parse( $entity->head->get( $_ ) ),
-                    qw(To Cc Bcc);
-        } else {
-            $gnupg->options->push_recipients( $_ )
-                foreach @{ $args{'Recipients'} };
-        }
+        $gnupg->options->push_recipients( $_ )
+            foreach @{ $args{'Recipients'} || [] };
     }
 
     my %res;


More information about the Rt-commit mailing list