Create White list or black list email

Dear All

i need help, i want to filltering to create ticket with email. i want to manage allow few domain email to enable create ticket on RT.

Thank you

I’m doing that in the inbox account, adding a rule to delete all incoming messages except those from the authorized domains. It’s efficient, no work in RT side.

If you can only manage RT, you can add a batch scrip that send the ticket to an specific queue (I have one called “Trash”) and empty that queue periodically. See: CustomConditionSnippets - Request Tracker Wiki

I’m sure there are other ways to do this job.

We use a wrapper (bashscript) for rt-mailgate to do a bunch of preprocessing. Black/whitelist, additional loop-prevention, using old queue-names on changes, suppress incoming answers from other ticketsystems, extracting attached mails from forwards and so on.

It runs additional and is called via procmail. So it extends the solution @sollericos mentioned. Be careful what to do at which place to not confuse yourselft :sight: :smiley:

1 Like

We have implemented white/black list to create ticket by mail by adding a mail plugin, that is a module RT::Interface::Auth::NoNewTicketByEmail which redefines GetCurrentUser() method and parses $sender_address with RT::Interface::ParseSenderAddressFromHead to compare it with some configuration variables $BlacklistRegex and $WhitelistRegex to return $args{CurrentUser}to authorize the creation of the ticket (white list) or FAILURE() (black list) to refuse it. Moreover we have added a template NoNewTicketByEmail to some queues and use RT::Interface::MailError to return an error to the sender with this template if she is neither in white list nor in black list.

Here’s the full code of this mail plugin:

package RT::Interface::Email::Auth::NoNewTicketByEmail;

# this package is to prevent users to create tickets by sending a mail, for
# queues having a "NoNewTicketByEmail" template

use strict;
use warnings;
use utf8;

use Role::Basic 'with';
with 'RT::Interface::Email::Role';

sub GetCurrentUser {
    my %args = (
        Message       => undef,
        RawMessageRef => undef,
        CurrentUser   => undef,
        AuthLevel     => undef,
        Ticket        => undef,
        Queue         => undef,
        Action        => undef,
        @_
	);

    if ( $args{'Ticket'} && $args{'Ticket'}->id ) {
        # Reply to existing ticket is allowed
        return $args{CurrentUser};
    }

    my $Forbidden = RT::Template->new( RT->SystemUser );
    $Forbidden->LoadQueueTemplate( Queue => $args{'Queue'}->Id, Name => 'NoNewTicketByEmail' );

    if ( $Forbidden && $Forbidden->id ) {
        my $Parser = RT::EmailParser->new();
        my ($sender_address, $sender_name, $sender_errors) = RT::Interface::Email::ParseSenderAddressFromHead( $args{'Message'}->head );
        my $blacklist_re = RT->Config->Get('BlacklistRegex');
        my $whitelist_re = RT->Config->Get('WhitelistRegex');
        if ( $sender_address =~ m/$blacklist_re/i ) {
            RT->Logger->warning("Discarding new ticket from blacklisted $sender_address: ".$args{'Message'}->head->get( 'Subject' ));
            FAILURE("Discarding new ticket from blacklisted $sender_address: ".$args{'Message'}->head->get('Subject'));
        } elsif ( $sender_address =~ m/$whitelist_re/i ) {
            return $args{CurrentUser};
        }
        my $orig_message = $args{'Message'}->as_string;
        utf8::decode( $orig_message ) unless utf8::is_utf8( $orig_message );

        RT::Interface::Email::MailError(
           To => $sender_address,
           From => 'noreply@interdata.fr',
           Subject => 'Message rejected: '.$args{'Message'}->head->get( 'Subject' ),
           Explanation => $Forbidden->Content,
           Type => 'text/html',
           Attach => $orig_message,
           LogLevel => 'warning',
        );
        FAILURE('NoNewTicketByEmail Message rejected: '.$args{'Message'}->head->get('Subject'));
    }

    return $args{CurrentUser};
}

1;


Also, you have to include this plugin in @MailPlugins configuration variable:

Set(@MailPlugins => ‘Auth::NoNewTicketByEmail’,‘Auth::MailFrom’);

(the order is important).

Hope it helps

1 Like