package RT::Interface::Email::Filter::PlussedQueue; # $AFresh1: PlussedQueue.pm,v 1.1 2011/02/28 23:36:27 andrew Exp $ ######################################################################## # Filter::PlussedQueue *** Change RT Queue based on plussed address ######################################################################## # Copyright (c) 2011 Andrew Fresh # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ######################################################################## use strict; use warnings; use Email::Address; use RT::EmailParser; sub GetCurrentUser { my %args = (@_); return ( $args{'CurrentUser'}, $args{'AuthLevel'} ) if !$args{'Queue'}; foreach ( Email::Address->parse( $args{'Message'}->head->get('To') ), Email::Address->parse( $args{'Message'}->head->get('Cc') ), ) { next unless $_; my $addr = $_->address; next unless $addr; next unless RT::EmailParser->IsRTAddress($addr); if ( $addr =~ /\+([^@]+)\@/ ) { my $queue = $1; my $oldqueue = $args{'Queue'}->id; $args{'Queue'}->Load($queue); if ( $args{'Queue'}->id ) { my $msgid = $args{'Message'}->head->get('Message-Id') || 'message'; $msgid =~ s/\s+//; $RT::Logger->debug( "Routing $msgid to queue " . $args{'Queue'}->Name ); last; } else { $args{'Queue'}->Load($oldqueue); } } } return ( $args{'CurrentUser'}, $args{'AuthLevel'} ); } =head1 NAME RT::Interface::Email::Filter::PlussedQueue - Change Queue based on plussed address =head1 SYNOPSIS @RT::MailPlugins = ("Filter::PlussedQueue", ...); =head1 DESCRIPTION Chooses queue based on plussed email addresses. If the queue specified by the plussed address doesn't exist, defaults to the queue it would have gone to anyway. Uses RT::EmailParser->isRTAddress to decide which addresses to check. For example rt+support@example.com would end up in a support queue if it exists. =cut eval "require RT::Interface::Email::Filter::PlussedQueue_Vendor"; die $@ if ( $@ && $@ !~ qr{^Can't locate RT/Interface/Email/Filter/PlussedQueue_Vendor.pm} ); eval "require RT::Interface::Email::Filter::PlussedQueue_Local"; die $@ if ( $@ && $@ !~ qr{^Can't locate RT/Interface/Email/Filter/PlussedQueue_Local.pm} ); 1;