Re: Lost emails!

"Sternberger, Sven" <[email protected]> Mon, 5 Dec 2016 09:58:02 +0100 (CET)
Newsgroups gmane.comp.bug-tracking.request-tracker.user
Message-ID <[email protected]>
forgot the attachment

----- Ursprüngliche Mail -----
> Von: "Sternberger, Sven" <[email protected]>
> An: "rt-users" <[email protected]>
> Gesendet: Montag, 5. Dezember 2016 09:40:25
> Betreff: Re: [rt-users] Lost emails!

> Hello!
> 
> it would be very helpful if somebody could look at my overlay if it is
> syntactical correct overlay file.
> 
> I found maybe my problem. I've just copied the original file
> to SendEmail_Local.pm and make my changes. But when I looked at the end of
> the copied file I found  "RT::Base->_ImportOverlays();"
> which is maybe not a good idea to have it in SendEmail_Local.pm file?
> 
> Now I have only the header and the method I've changed in SendEmail_Local.pm.
> 
> best regards!
> 
> Sven
> 
> ----- Ursprüngliche Mail -----
>> Von: "Sternberger, Sven" <[email protected]>
>> An: "rt-users" <[email protected]>
>> Gesendet: Donnerstag, 1. Dezember 2016 14:42:11
>> Betreff: Re: [rt-users] Lost emails!
> 
>> Hello!
>> 
>> I now changed some things. I switched to perl 5.24 (perlbrew) and I updated to
>> 4.2.13
>> but the problem is still the same
>> 
>> Dec  1 12:27:40 rt-xxxx RT: [5776] Ticket 699881 created in queue 'it-xxxx' by
>> [email protected]
>> Dec  1 12:27:40 rt-xxxx RT: [5776] Redundant argument in sprintf at
>> /opt/rt4/sbin/../lib/RT/Action/Notify.pm line 130.
>> Dec  1 12:27:40 rt-xxxx RT: [5776] Use of uninitialized value in method with
>> known name at /opt/rt4/sbin/../lib/RT/Action/SendEmail_Local.pm line 1043.
>> Dec  1 12:27:40 rt-xxxx RT: [5776] Use of uninitialized value in method with
>> known name at /opt/rt4/sbin/../lib/RT/Action/SendEmail_Local.pm line 1043.
>> Dec  1 12:27:40 rt-xxxx RT: [5776] Scrip Prepare 238 died. - Can't locate object
>> method "" via package "RT::Action::Notify" at
>> /opt/rt4/sbin/../lib/RT/Action/SendEmail_Local.pm line 1043.#012#012Stack:#012
>> [/opt/rt4/sbin/../lib/RT/Action/SendEmail_Local.pm:1043]#012
>> [/opt/rt4/sbin/../lib/RT/Action/SendEmail_Local.pm:580]#012
>> [/opt/rt4/sbin/../lib/RT/Action/SendEmail_Local.pm:152]#012
>> [/opt/rt4/sbin/../lib/RT/Action/Notify.pm:69]#012
>> [/opt/rt4/sbin/../lib/RT/ScripAction.pm:223]#012
>> [/opt/rt4/sbin/../lib/RT/Scrip.pm:637]#012
>> [/opt/rt4/sbin/../lib/RT/Scrips.pm:342]#012
>> [/opt/rt4/sbin/../lib/RT/Scrips.pm:275]#012
>> [/opt/rt4/sbin/../lib/RT/Ticket.pm:2607]#012
>> [/opt/rt4/sbin/../lib/RT/Ticket.pm:2578]#012
>> [/opt/rt4/sbin/../lib/RT/Ticket.pm:2648]
>> 
>> I don't have an idea how to track down the problem. My next try would be to
>> replace SendEmail.pm with my SendEmail_Local.pm maybe the
>> customization mechanism is broken?
>> 
>> Best regards,
>> 
>> Sven
>> 
>> PS the actual diff /opt/rt4/lib/RT/Action/SendEmail.pm
>> /opt/rt4/lib/RT/Action/SendEmail_Local.pm
>> 
>> 832,838c832,839
>> <     $self->RecipientFilter(
>> <         Callback => sub {
>> <             return unless RT::EmailParser->IsRTAddress( $_[0] );
>> <             return "$_[0] appears to point to this RT instance. Skipping";
>> <         },
>> <         All => 1,
>> <     );
>> ---
>>>     # removed for q2q
>>>     #$self->RecipientFilter(
>>>     #    Callback => sub {
>>>     #        return unless RT::EmailParser->IsRTAddress( $_[0] );
>>>     #        return "$_[0] appears to point to this RT instance. Skipping";
>>>     #    },
>>>     #    All => 1,
>>>     #);
>> ---------
>> RT 4.4 and RTIR training sessions, and a new workshop day!
>> https://bestpractical.com/training
>> * Los Angeles - January 9-11 2017
> ---------
> RT 4.4 and RTIR training sessions, and a new workshop day!
> https://bestpractical.com/training
> * Los Angeles - January 9-11 2017

---------
RT 4.4 and RTIR training sessions, and a new workshop day! https://bestpractical.com/training
* Los Angeles - January 9-11 2017
SendEmail_Local.pm (application/x-perl, 4.4 KB)
package RT::Action::SendEmail;

use strict;

use warnings;
no warnings qw(redefine);

use base qw(RT::Action);

use RT::EmailParser;
use RT::Interface::Email;
use Email::Address;
our @EMAIL_RECIPIENT_HEADERS = qw(To Cc Bcc);


sub RemoveInappropriateRecipients {
    my $self = shift;

    my %blacklist = ();

    # If there are no recipients, don't try to send the message.
    # If the transaction has content and has the header RT-Squelch-Replies-To

    my $msgid = Encode::decode( "UTF-8", $self->TemplateObj->MIMEObj->head->get('Message-Id') );
    chomp $msgid;

    if ( my $attachment = $self->TransactionObj->Attachments->First ) {

        if ( $attachment->GetHeader('RT-DetectedAutoGenerated') ) {

            # What do we want to do with this? It's probably (?) a bounce
            # caused by one of the watcher addresses being broken.
            # Default ("true") is to redistribute, for historical reasons.

            my $redistribute = RT->Config->Get('RedistributeAutoGeneratedMessages');

            if ( !$redistribute ) {

                # Don't send to any watchers.
                @{ $self->{$_} } = () for (@EMAIL_RECIPIENT_HEADERS);
                $RT::Logger->info( $msgid
                        . " The incoming message was autogenerated. "
                        . "Not redistributing this message based on site configuration."
                );
            } elsif ( $redistribute eq 'privileged' ) {

                # Only send to "privileged" watchers.
                foreach my $type (@EMAIL_RECIPIENT_HEADERS) {
                    foreach my $addr ( @{ $self->{$type} } ) {
                        my $user = RT::User->new(RT->SystemUser);
                        $user->LoadByEmail($addr);
                        $blacklist{ $addr } ||= 'not privileged'
                            unless $user->id && $user->Privileged;
                    }
                }
                $RT::Logger->info( $msgid
                        . " The incoming message was autogenerated. "
                        . "Not redistributing this message to unprivileged users based on site configuration."
                );
            }
        }

        if ( my $squelch = $attachment->GetHeader('RT-Squelch-Replies-To') ) {
            $blacklist{ $_->address } ||= 'squelch:attachment'
                foreach Email::Address->parse( $squelch );
        }
    }

    # Let's grab the SquelchMailTo attributes and push those entries
    # into the blacklisted
    $blacklist{ $_->Content } ||= 'squelch:transaction'
        foreach $self->TransactionObj->SquelchMailTo;
    $blacklist{ $_->Content } ||= 'squelch:ticket'
        foreach $self->TicketObj->SquelchMailTo;

    # canonicalize emails
    foreach my $address ( keys %blacklist ) {
        my $reason = delete $blacklist{ $address };
        $blacklist{ lc $_ } = $reason
            foreach map RT::User->CanonicalizeEmailAddress( $_->address ),
            Email::Address->parse( $address );
    }

    # removed for q2q
    #$self->RecipientFilter(
    #    Callback => sub {
    #        return unless RT::EmailParser->IsRTAddress( $_[0] );
    #        return "$_[0] appears to point to this RT instance. Skipping";
    #    },
    #    All => 1,
    #);

    $self->RecipientFilter(
        Callback => sub {
            return unless $blacklist{ lc $_[0] };
            return "$_[0] is blacklisted $squelch_reasons{ $blacklist{ lc $_[0] } }. Skipping";
        },
    );


    # Cycle through the people we're sending to and pull out anyone that meets any of the callbacks
    for my $type (@EMAIL_RECIPIENT_HEADERS) {
        my @addrs;

      ADDRESS:
        for my $addr ( @{ $self->{$type} } ) {
            for my $filter ( map {$_->{Callback}} @{$self->{RecipientFilter}} ) {
                my $skip = $filter->($addr);
                next unless $skip;
                $RT::Logger->info( "$msgid $skip" );
                next ADDRESS;
            }
            push @addrs, $addr;
        }

      NOSQUELCH_ADDRESS:
        for my $addr ( @{ $self->{NoSquelch}{$type} } ) {
            for my $filter ( map {$_->{Callback}} grep {$_->{All}} @{$self->{RecipientFilter}} ) {
                my $skip = $filter->($addr);
                next unless $skip;
                $RT::Logger->info( "$msgid $skip" );
                next NOSQUELCH_ADDRESS;
            }
            push @addrs, $addr;
        }

        @{ $self->{$type} } = @addrs;
    }
}


1;