[Rt-commit] r7963 - in
rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface: .
ruz at bestpractical.com
ruz at bestpractical.com
Tue May 29 20:38:06 EDT 2007
Author: ruz
Date: Tue May 29 20:38:06 2007
New Revision: 7963
Modified:
rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email.pm
rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email/Auth/GnuPG.pm
Log:
* apply GPG plugin before decoding
** add new type of email plugins
** add _LoadPlugins function
Modified: rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email.pm Tue May 29 20:38:06 2007
@@ -949,6 +949,33 @@
=cut
+sub _LoadPlugins {
+ my @mail_plugins = @_;
+
+ my @res;
+ foreach (@mail_plugins) {
+ if ( ref($_) eq "CODE" ) {
+ push @res, $_;
+ } elsif ( !ref $_ ) {
+ my $Class = $_;
+ $Class = "RT::Interface::Email::" . $Class
+ unless $Class =~ /^RT::Interface::Email::/;
+ $Class->require or
+ do { $RT::Logger->error("Couldn't load $Class: $@"); next };
+
+ no strict 'refs';
+ unless ( defined *{ $Class . "::GetCurrentUser" }{CODE} ) {
+ $RT::Logger->crit( "No GetCurrentUser code found in $Class module");
+ next;
+ }
+ push @res, $Class;
+ } else {
+ $RT::Logger->crit( "$_ - is not class name or code reference");
+ }
+ }
+ return @res;
+}
+
sub Gateway {
my $argsref = shift;
my %args = (
@@ -976,9 +1003,9 @@
}
my $parser = RT::EmailParser->new();
- $parser->SmartParseMIMEEntityFromScalar( Message => $args{'message'} );
- my $Message = $parser->Entity();
+ $parser->SmartParseMIMEEntityFromScalar( Message => $args{'message'}, Decode => 0 );
+ my $Message = $parser->Entity();
unless ($Message) {
MailError(
To => RT->Config->Get('OwnerEmail'),
@@ -992,8 +1019,45 @@
);
}
- my $head = $Message->head;
+ my @mail_plugins = grep $_, RT->Config->Get('MailPlugins');
+ push @mail_plugins, "Auth::MailFrom" unless @mail_plugins;
+ @mail_plugins = _LoadPlugins( @mail_plugins );
+ my %skip_plugin;
+ foreach my $class( grep !ref, @mail_plugins ) {
+ # check if we should apply filter before decoding
+ my $check_cb = do {
+ no strict 'refs';
+ *{ $class . "::ApplyBeforeDecode" }{CODE};
+ };
+ next unless defined $check_cb;
+ next unless $check_cb->(
+ Message => $Message,
+ RawMessageRef => \$args{'message'},
+ );
+
+ $skip_plugin{ $class }++;
+
+ my $Code = do {
+ no strict 'refs';
+ *{ $class . "::GetCurrentUser" }{CODE};
+ };
+ my ($status, $msg) = $Code->(
+ Message => $Message,
+ RawMessageRef => \$args{'message'},
+ );
+ next if $status > 0;
+
+ if ( $status == -2 ) {
+ return (1, $msg, undef);
+ } elsif ( $status == -1 ) {
+ return (0, $msg, undef);
+ }
+ }
+ @mail_plugins = grep !$skip_plugin{"$_"}, @mail_plugins;
+ $parser->_PostProcessNewEntity;
+
+ my $head = $Message->head;
my $ErrorsTo = ParseErrorsToAddressFromHead( $head );
my $MessageId = $head->get('Message-ID')
@@ -1046,9 +1110,6 @@
# Initalize AuthStat so comparisons work correctly
my $AuthStat = -9999999;
- my @mail_plugins = grep $_, RT->Config->Get('MailPlugins');
- push @mail_plugins, "Auth::MailFrom" unless @mail_plugins;
-
my ( $CurrentUser, $error );
# if plugin returns AuthStat -2 we skip action
@@ -1057,24 +1118,14 @@
# Since this needs loading, no matter what
foreach (@mail_plugins) {
- my ($Code, $Class, $NewAuthStat);
+ my ($Code, $NewAuthStat);
if ( ref($_) eq "CODE" ) {
$Code = $_;
} else {
- $Class = $_;
- $Class = "RT::Interface::Email::" . $Class
- unless $Class =~ /^RT::Interface::Email::/;
- $Class->require or
- do { $RT::Logger->error("Couldn't load $Class: $@"); next };
-
no strict 'refs';
- unless ( defined( $Code = *{ $Class . "::GetCurrentUser" }{CODE} ) ) {
- $RT::Logger->crit( "No GetCurrentUser code found in $Class module");
- next;
- }
+ $Code = *{ $_ . "::GetCurrentUser" }{CODE};
}
-
foreach my $action (@actions) {
( $CurrentUser, $NewAuthStat ) = $Code->(
Message => $Message,
Modified: rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email/Auth/GnuPG.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email/Auth/GnuPG.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-RTIR-2.4/lib/RT/Interface/Email/Auth/GnuPG.pm Tue May 29 20:38:06 2007
@@ -54,7 +54,7 @@
To use the gnupg-secured mail gateway, you need to do the following:
-Set up a gnupgp key directory with a pubring containing only the keys
+Set up a GnuPG key directory with a pubring containing only the keys
you care about and specify the following in your SiteConfig.pm
Set(%GnuPGOptions, homedir => '/opt/rt3/var/data/GnuPG');
@@ -62,17 +62,13 @@
=cut
+sub ApplyBeforeDecode { return 1 }
+
use RT::Crypt::GnuPG;
sub GetCurrentUser {
my %args = (
Message => undef,
- RawMessageRef => undef,
- CurrentUser => undef,
- AuthLevel => undef,
- Ticket => undef,
- Queue => undef,
- Action => undef,
@_
);
@@ -83,10 +79,11 @@
my $msg = $args{'Message'}->dup;
my ($status, @res) = VerifyDecrypt( Entity => $args{'Message'} );
if ( $status && !@res ) {
- $args{'Message'}
- ->head->add( 'X-RT-Incoming-Encryption' => 'Not encrypted' );
+ $args{'Message'}->head->add(
+ 'X-RT-Incoming-Encryption' => 'Not encrypted'
+ );
- return @args{qw(CurrentUser AuthLevel)};
+ return 1;
}
# FIXME: Check if the message is encrypted to the address of
@@ -95,7 +92,8 @@
unless ( $status ) {
$RT::Logger->error("Had a problem during decrypting and verifying");
my $reject = HandleErrors( Message => $args{'Message'}, Result => \@res );
- return $args{'CurrentUser'}, -2 if $reject;
+ return (-2, 'rejected because of problems during decrypting and verifying')
+ if $reject;
}
# attach the original encrypted message
@@ -119,7 +117,8 @@
}
if ( $_->{Operation} eq 'Verify' && $_->{Status} eq 'DONE' ) {
$args{'Message'}->head->add(
- 'X-RT-Incoming-Signature' => $_->{UserString} );
+ 'X-RT-Incoming-Signature' => $_->{UserString}
+ );
}
}
@@ -128,7 +127,7 @@
: 'Not encrypted' );
}
- return @args{qw(CurrentUser AuthLevel)};
+ return 1;
}
sub HandleErrors {
More information about the Rt-commit
mailing list