Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for email between queues on same server #320

Open
wants to merge 4 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/RT/Action/SendEmail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ sub SetRTSpecialHeaders {
}
}

$self->SetHeader( 'X-RT-Loop-Prevention', RT->Config->Get('rtname') );
my $looppreventionheader = $self->TransactionObj->Message->First->GetHeader( 'X-RT-Loop-Prevention' );
$self->SetHeader( 'X-RT-Loop-Prevention', $self->TicketObj->QueueObj->Name . '.' . RT->Config->Get('rtname') . ',' . $looppreventionheader );
$self->SetHeader( 'X-RT-Ticket',
RT->Config->Get('rtname') . " #" . $self->TicketObj->id() );
$self->SetHeader( 'X-Managed-by',
Expand Down
16 changes: 11 additions & 5 deletions lib/RT/Interface/Email.pm
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ sub Gateway {
if IsMachineGeneratedMail(
Message => $Message,
Subject => $Subject,
Queue => $SystemQueueObj->Name,
);

# Make all errors from here on out bounce back to $ErrorsTo
Expand All @@ -215,7 +216,7 @@ sub Gateway {
$bare_MailError->(To => $ErrorsTo, MIMEObj => $Message, @_)
};

$args{'ticket'} ||= ExtractTicketId( $Message );
$args{'ticket'} ||= ExtractTicketId( $Message, $SystemQueueObj->SubjectTag );

my $SystemTicket = RT::Ticket->new( RT->SystemUser );
$SystemTicket->Load( $args{'ticket'} ) if ( $args{'ticket'} ) ;
Expand Down Expand Up @@ -487,12 +488,13 @@ sub IsMachineGeneratedMail {
my %args = (
Message => undef,
Subject => undef,
Queue => undef,
@_
);
my $head = $args{'Message'}->head;

my $IsAutoGenerated = CheckForAutoGenerated($head);
my $IsALoop = CheckForLoops($head);
my $IsALoop = CheckForLoops($head, $args{'Queue'});

my $owner_mail = RT->Config->Get('OwnerEmail');

Expand Down Expand Up @@ -542,11 +544,13 @@ this RT instance, by checking the C<X-RT-Loop-Prevention> header.

sub CheckForLoops {
my $head = shift;
my $queue = shift;

# If this instance of RT sent it our, we don't want to take it in
my $RTLoop = Encode::decode( "UTF-8", $head->get("X-RT-Loop-Prevention") || "" );
chomp ($RTLoop); # remove that newline
if ( $RTLoop eq RT->Config->Get('rtname') ) {
if ( $RTLoop =~ ( $queue . '.' . RT->Config->Get('rtname') . ',') ) {
$RT::Logger->warning("Dropping mail because X-RT-Loop-Protection contains " . $queue . '.' . RT->Config->Get('rtname'));
return 1;
}

Expand Down Expand Up @@ -607,10 +611,11 @@ will be used during ticket creation.

sub ExtractTicketId {
my $entity = shift;
my $tag = shift;

my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') || '' );
chomp $subject;
return ParseTicketId( $subject, $entity );
return ParseTicketId( $subject, $entity, $tag );
}

=head3 ParseTicketId
Expand All @@ -627,9 +632,10 @@ Returns the id if a match is found. Otherwise returns undef.
sub ParseTicketId {
my $Subject = shift;
my $Entity = shift;
my $tag = shift;

my $rtname = RT->Config->Get('rtname');
my $test_name = RT->Config->Get('EmailSubjectTagRegex') || qr/\Q$rtname\E/i;
my $test_name = qr/\Q$tag\E/;

# We use @captures and pull out the last capture value to guard against
# someone using (...) instead of (?:...) in $EmailSubjectTagRegex.
Expand Down