[BACK]Return to ByQueueRegex.pm CVS log [TXT][DIR] Up to [local] / RT / Interface / Email / Filter

Annotation of RT/Interface/Email/Filter/ByQueueRegex.pm, Revision 1.1

1.1     ! andrew      1: package RT::Interface::Email::Filter::ByQueueRegex;
        !             2:
        !             3: # $AFresh1$
        !             4: ########################################################################
        !             5: # Filter::ByQueueRegex *** Change RT Queue based on plussed address
        !             6: ########################################################################
        !             7: # Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>
        !             8: #
        !             9: # Permission to use, copy, modify, and distribute this software for any
        !            10: # purpose with or without fee is hereby granted, provided that the above
        !            11: # copyright notice and this permission notice appear in all copies.
        !            12: #
        !            13: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            14: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            15: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            16: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            17: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            18: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            19: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            20: ########################################################################
        !            21: use strict;
        !            22: use warnings;
        !            23:
        !            24: use Email::Address;
        !            25: use RT::EmailParser;
        !            26:
        !            27: use Data::Dumper;
        !            28:
        !            29: sub GetCurrentUser {
        !            30:     my %args = (@_);
        !            31:
        !            32:     unless ( $args{'CurrentUser'} ) {
        !            33:         $RT::Logger->error(
        !            34:             "Filter::TakeAction executed when "
        !            35:             ."CurrentUser (actor) is not authorized. "
        !            36:             ."Most probably you want to add Auth::MailFrom plugin before "
        !            37:             ."Filter::TakeAction in the \@MailPlugins config."
        !            38:         );
        !            39:         return ( $args{'CurrentUser'}, $args{'AuthLevel'} );
        !            40:     }
        !            41:
        !            42:     # If a ticket is being modified, or for some reason doesn't
        !            43:     # have a queue, we don't need to bother.
        !            44:     if ( $args{'Ticket'}->id || !$args{'Queue'} ) {
        !            45:         return ( $args{'CurrentUser'}, $args{'AuthLevel'} );
        !            46:     }
        !            47:
        !            48:     my @addresses;
        !            49:     foreach my $address (
        !            50:        map { $_->address }
        !            51:         map { Email::Address->parse( $_ ) }
        !            52:         map { $args{'Message'}->head->get( $_ )  }
        !            53:        qw/ from to cc /
        !            54:     ) {
        !            55:        $RT::Logger->debug("Found address [$address]");
        !            56:        push @addresses, $address;
        !            57:     }
        !            58:
        !            59:     my $qs = RT::Queues->new($RT::SystemUser); #$args{'CurrentUser'});
        !            60:     $qs->UnLimit;
        !            61:     $qs->FindAllRows;
        !            62:
        !            63:     my %queues;
        !            64:     while (my $q = $qs->Next) {
        !            65:         my $value = $q->FirstCustomFieldValue('EmailRegex');
        !            66:         next unless $value;
        !            67:         $RT::Logger->debug("Queue [" . $q->id . "] " . $q->Name . " -> EmailRegex " . $value);
        !            68:         $queues{ $value } = $q;
        !            69:     }
        !            70:
        !            71:     ADDRESS: foreach my $address (@addresses) {
        !            72:         while (my ($re, $q) = each %queues) {
        !            73:             RT::Logger->debug("Checking address $address =~ /$re/");
        !            74:             my $match = 0;
        !            75:             eval { $match = $address =~ /$re/ };
        !            76:             if ($@) {
        !            77:                 $RT::Logger->warning(
        !            78:                     "Error in EmailRegex for " . $q->Name . " /$re/: $@");
        !            79:             }
        !            80:             elsif ($match) {
        !            81:                 $args{'Queue'}->Load($q->id);
        !            82:
        !            83:                 my $msgid = $args{'Message'}->head->get('Message-Id')
        !            84:                     || 'message';
        !            85:                 $msgid =~ s/\s+//;
        !            86:
        !            87:                 $RT::Logger->info(
        !            88:                     "Routing $msgid to queue " . $args{'Queue'}->Name );
        !            89:
        !            90:                 last ADDRESS;
        !            91:             }
        !            92:         }
        !            93:     }
        !            94:
        !            95:     return ( $args{'CurrentUser'}, $args{'AuthLevel'} );
        !            96: }
        !            97:
        !            98: =head1 NAME
        !            99:
        !           100: RT::Interface::Email::Filter::ByQueueRegex - Change Queue based on Regex
        !           101:
        !           102: =head1 SYNOPSIS
        !           103:
        !           104:     @RT::MailPlugins = ("Filter::ByQueueRegex", ...);
        !           105:
        !           106: =head1 DESCRIPTION
        !           107:
        !           108: Chooses queue based on plussed email addresses.  If the queue
        !           109: specified by the plussed address doesn't exist, defaults to the
        !           110: queue it would have gone to anyway.
        !           111:
        !           112: Uses RT::EmailParser->isRTAddress to decide which addresses to
        !           113: check.
        !           114:
        !           115: For example rt+support@example.com would end up in a support queue
        !           116: if it exists.
        !           117:
        !           118: =cut
        !           119:
        !           120: eval "require RT::Interface::Email::Filter::ByQueueRegex_Vendor";
        !           121: die $@
        !           122:     if ( $@
        !           123:     && $@
        !           124:     !~ qr{^Can't locate RT/Interface/Email/Filter/ByQueueRegex_Vendor.pm} );
        !           125: eval "require RT::Interface::Email::Filter::ByQueueRegex_Local";
        !           126: die $@
        !           127:     if ( $@
        !           128:     && $@
        !           129:     !~ qr{^Can't locate RT/Interface/Email/Filter/ByQueueRegex_Local.pm} );
        !           130:
        !           131: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>