[Rt-commit] rt branch, 4.4/multiple-reply-to, created. rt-4.2.3-73-g2019687
? sunnavy
sunnavy at bestpractical.com
Mon Oct 6 12:40:03 EDT 2014
The branch, 4.4/multiple-reply-to has been created
at 201968703385a2f6c34a1fe9b2b73c0417fb37bd (commit)
- Log -----------------------------------------------------------------
commit bb657e933520dab5f5b621377a55731c64614120
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Feb 2 22:59:45 2012 +0400
simple test for multiple reply-to addresses
diff --git a/t/mail/multiple-reply-to.t b/t/mail/multiple-reply-to.t
new file mode 100644
index 0000000..2afa96c
--- /dev/null
+++ b/t/mail/multiple-reply-to.t
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+
+use RT::Test tests => 7;
+
+diag "grant everybody with CreateTicket right";
+{
+ ok( RT::Test->set_rights(
+ { Principal => 'Everyone', Right => [qw(CreateTicket)], },
+ { Principal => 'Requestor', Right => [qw(ReplyToTicket)], },
+ ), "Granted rights");
+}
+
+{
+ my $text = <<EOF;
+From: user\@example.com
+Subject: test
+
+Blah!
+Foob!
+EOF
+ my ($status, $id) = RT::Test->send_via_mailgate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok ($id, "ticket created");
+
+ $text = <<EOF;
+From: user\@example.com
+Subject: [@{[RT->Config->Get('rtname')]} #$id] test
+
+Blah!
+Foob!
+EOF
+ ($status, my $tid) = RT::Test->send_via_mailgate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ is ($tid, $id, "ticket updated");
+
+ $text = <<EOF;
+From: somebody\@example.com
+Reply-To: boo\@example.com, user\@example.com
+Subject: [@{[RT->Config->Get('rtname')]} #$id] test
+
+Blah!
+Foob!
+EOF
+ ($status, $tid) = RT::Test->send_via_mailgate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ is ($tid, $id, "ticket updated");
+}
+
+
+1;
commit 201968703385a2f6c34a1fe9b2b73c0417fb37bd
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 7 00:01:11 2014 +0800
take into account multiple sender's addresses
use first address that exists, if none exists then do what we did before
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 9fc60cc..232a3b9 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -435,19 +435,35 @@ investigate the parse failure.
=cut
sub ParseSenderAddressFromHead {
+ my ( $list, @errors ) = ParseSenderAddressesFromHead(@_);
+ if ( $list ) {
+ return ( $list->[0]->address, $list->[0]->phrase, @errors );
+ }
+ else {
+ return ( undef, undef, @errors );
+ }
+}
+
+=head2 ParseSenderAddressesFromHead HEAD
+
+Takes a MIME::Header object. Returns ([list of addreses], errors)
+
+=cut
+
+sub ParseSenderAddressesFromHead {
my $head = shift;
my @errors; # Accumulate any errors
foreach my $header ( 'Reply-To', 'From', 'Sender' ) {
my $addr_line = $head->get($header) || next;
- my ($addr) = RT::EmailParser->ParseEmailAddress( $addr_line );
- return ($addr->address, $addr->phrase, @errors) if $addr;
+ my (@addr) = RT::EmailParser->ParseEmailAddress( $addr_line );
+ return (\@addr, @errors) if @addr;
chomp $addr_line;
push @errors, "$header: $addr_line";
}
- return (undef, undef, @errors);
+ return (undef, @errors);
}
=head3 ParseErrorsToAddressFromHead HEAD
diff --git a/lib/RT/Interface/Email/Auth/MailFrom.pm b/lib/RT/Interface/Email/Auth/MailFrom.pm
index 081a570..ede4952 100644
--- a/lib/RT/Interface/Email/Auth/MailFrom.pm
+++ b/lib/RT/Interface/Email/Auth/MailFrom.pm
@@ -78,32 +78,34 @@ sub GetCurrentUser {
);
# We don't need to do any external lookups
- my ( $Address, $Name, @errors ) = RT::Interface::Email::ParseSenderAddressFromHead( $args{'Message'}->head );
- $RT::Logger->warning("Failed to parse ".join(', ', @errors))
- if @errors;
-
- unless ( $Address ) {
+ my ($addresses, @errors) = RT::Interface::Email::ParseSenderAddressesFromHead( $args{'Message'}->head );
+ $RT::Logger->warning("Failed to parse ".join(', ', @errors)) if @errors;
+ unless ( $addresses ) {
$RT::Logger->error("Couldn't parse or find sender's address");
FAILURE("Couldn't parse or find sender's address");
}
- my $CurrentUser = RT::CurrentUser->new;
- $CurrentUser->LoadByEmail( $Address );
- $CurrentUser->LoadByName( $Address ) unless $CurrentUser->Id;
- if ( $CurrentUser->Id ) {
- $RT::Logger->debug("Mail from user #". $CurrentUser->Id ." ($Address)" );
- return $CurrentUser;
- }
+ foreach my $addr ( @$addresses ) {
+ $RT::Logger->debug("Testing $addr as sender");
+ my $CurrentUser = RT::CurrentUser->new;
+ $CurrentUser->LoadByEmail( $addr->address );
+ $CurrentUser->LoadByName( $addr->address ) unless $CurrentUser->Id;
+ if ( $CurrentUser->Id ) {
+ $RT::Logger->debug("$addr belongs to user #". $CurrentUser->Id );
+ return $CurrentUser;
+ }
+ }
+ my $first_addr = $addresses->[0];
my $user = RT::User->new( RT->SystemUser );
$user->LoadOrCreateByEmail(
- RealName => $Name,
- EmailAddress => $Address,
+ RealName => $first_addr->phrase,
+ EmailAddress => $first_addr->address,
Comments => 'Autocreated on ticket submission',
);
- $CurrentUser = RT::CurrentUser->new;
+ my $CurrentUser = RT::CurrentUser->new;
$CurrentUser->Load( $user->id );
return $CurrentUser;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list