[rt-users] prevent AdminCC to get emails twice with NotifyActor=1

Dorothea Muecke-Herzberg dorotheamuecke at googlemail.com
Fri Oct 24 07:45:42 EDT 2008


Thank you for your responses. I also understood that NotifyActor is to
prevent people
getting copies of their own updates. So, after some digging, I went
and changed Notify.pm
to handle duplicate emails and it seems to be working fine (sorry,
it's longwinded, but my perl is
rudimentary). It checks whether creator is already in the AdminCc, Cc
or Requestors email
addresses and also whether there are duplicates between AdminCc&Cc,
AdminCc&Requestor
and Cc&Requestor:

 my @adminscc = $self->TicketObj->QueueObj->AdminCc->MemberEmailAddresses;
 my @ceecees = $self->TicketObj->Cc->MemberEmailAddresses;
 my @requestees = $self->TicketObj->Requestors->MemberEmailAddresses;

 ## based on creator
    my $in_admincc = 0;
    foreach my $admin_address ( @adminscc ) {
         $in_admincc = 1 if ( lc($creator) eq lc($admin_address) );
    }
    my $in_cc = 0;
    foreach my $cc_address ( @ceecees ) {
         $in_cc = 1 if ( lc($creator) eq lc($cc_address) );
    }
    ## based on requestor and AdminCC (most common case)
    foreach my $to_address ( @requestees ) {
        foreach my $admin_address ( @adminscc ) {
            if ( lc($to_address) eq lc($admin_address) ) {
                $RT::Logger->info( "BeforeDuplicate address in
Requestors and AdminCC $to_address");
                @{ $self->{'To'} }  = @To = grep ( lc $_ ne lc
$to_address, @To );
                @{ $self->{'Cc'} }  = @Cc;
                @{ $self->{'Bcc'} } = @Bcc;
                $RT::Logger->info( "After Duplicate address in
Requestors and AdminCC - $to_address removed from list:
'@{$self->{'To'}}'");
            }
        }
    }
    ## based on requestor and CC
    foreach my $to_address ( @requestees ) {
        foreach my $cc_address ( @ceecees ) {
            if ( lc($to_address) eq lc($cc_address) ) {
                @{ $self->{'To'} }  = @To = grep ( lc $_ ne lc
$to_address, @To );
                @{ $self->{'Cc'} }  = @Cc;
                @{ $self->{'Bcc'} } = @Bcc;
                $RT::Logger->info( "Duplicate address in Requestors
and CC - $to_address removed from list: '@{$self->{'To'}}'");
            }
        }
    }
    ## based on Cc and AdminCc
    foreach my $cc_address ( @ceecees ) {
        foreach my $admin_address ( @adminscc ) {
            if ( lc($cc_address) eq lc($admin_address) ) {
                @{ $self->{'To'} }  = @To;
                @{ $self->{'Cc'} }  = @Cc = grep ( lc $_ ne lc
$cc_address, @Cc );
                @{ $self->{'Bcc'} } = @Bcc;
                $RT::Logger->info( "Duplicate address in CC and
AdminCC - $cc_address removed from list: '@{ $self->{'Cc'} }'");
            }
        }
    }
    ## Now handle duplicates based on creator:
    if ( $RT::NotifyActor ) {
       # if creator not in AdminCC or CC, send as is; do not strip
creator from To, Cc or AdminCC
       if ( !$in_admincc && !$in_cc ) {
           @{ $self->{'To'} }  = @To;
           @{ $self->{'Cc'} }  = @Cc;
           @{ $self->{'Bcc'} } = @Bcc;
       }
       # if creator is in Cc, but not in AdminCC, strip creator from
To and AdminCc
       if ( !$in_admincc && $in_cc ) {
           @{ $self->{'To'} }  = grep ( lc $_ ne lc $creator, @To );
           @{ $self->{'Cc'} }  = @Cc;
           @{ $self->{'Bcc'} } = grep ( lc $_ ne lc $creator, @Bcc );
       }
       # if creator is in AdminCc, but not in CC, strip creator from
To and AdminCc
       if ( $in_admincc && !$in_cc ) {
           @{ $self->{'To'} }  = grep ( lc $_ ne lc $creator, @To );
           @{ $self->{'Cc'} }  = grep ( lc $_ ne lc $creator, @Cc );
           @{ $self->{'Bcc'} } = @Bcc;
       }
       # if creator is in Cc and AdminCC, strip creator from To and Cc
(only send to AdminCc)
       if ( $in_admincc && $in_cc ) {
           @{ $self->{'To'} }  = grep ( lc $_ ne lc $creator, @To );
           @{ $self->{'Cc'} }  = grep ( lc $_ ne lc $creator, @Cc );
           @{ $self->{'Bcc'} } = @Bcc;
       }
       # in case we have forgotten something, default is not to strip anything
       else {
           @{ $self->{'To'} }  = @To;
           @{ $self->{'Cc'} }  = @Cc;
           @{ $self->{'Bcc'} } = @Bcc;
       }
    }
    else {
        @{ $self->{'To'} }  = grep ( lc $_ ne lc $creator, @To );
        @{ $self->{'Cc'} }  = grep ( lc $_ ne lc $creator, @Cc );
        @{ $self->{'Bcc'} } = grep ( lc $_ ne lc $creator, @Bcc );
    }

    @{ $self->{'PseudoTo'} } = @PseudoTo;

}



Dorothea



More information about the rt-users mailing list