1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::PostMaster::Filter::FollowUpArticleVisibilityCheck;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Log',
'Kernel::System::CustomerUser',
'Kernel::System::Ticket',
'Kernel::System::Ticket::Article',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# get parser object
$Self->{ParserObject} = $Param{ParserObject} || die "Got no ParserObject!";
# Get communication log object.
$Self->{CommunicationLogObject} = $Param{CommunicationLogObject} || die "Got no CommunicationLogObject!";
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# This filter is not needed if there is no TicketID.
return 1 if !$Param{TicketID};
# check needed stuff
for (qw(JobConfig GetParam UserID)) {
if ( !$Param{$_} ) {
$Self->{CommunicationLogObject}->ObjectLog(
ObjectLogType => 'Message',
Priority => 'Error',
Key => 'Kernel::System::PostMaster::Filter::FollowUpArticleVisibilityCheck',
Value => "Need $_!",
);
return;
}
}
# Only run if we have a follow-up article with SenderType 'customer'.
# It could be that follow-ups have a different SenderType like 'system' for
# automatic notifications. In these cases there is no need to hide them.
# See also bug#10182 for details.
if (
!$Param{GetParam}->{'X-OTRS-FollowUp-SenderType'}
|| $Param{GetParam}->{'X-OTRS-FollowUp-SenderType'} ne 'customer'
)
{
return 1;
}
my %Ticket = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet(
TicketID => $Param{TicketID},
UserID => $Param{UserID},
);
# Check if it is a known customer, otherwise use email address from CustomerUserID field of the ticket.
my %CustomerData = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserDataGet(
User => $Ticket{CustomerUserID},
);
my $CustomerEmailAddress = $CustomerData{UserEmail} || $Ticket{CustomerUserID};
# Email sender address
my $SenderAddress = $Param{GetParam}->{'X-Sender'};
# Email Reply-To address for forwarded emails
my $ReplyToAddress;
if ( $Param{GetParam}->{ReplyTo} ) {
$ReplyToAddress = $Self->{ParserObject}->GetEmailAddress(
Email => $Param{GetParam}->{ReplyTo},
);
}
# check if current sender is customer (do nothing)
if ( $CustomerEmailAddress && $SenderAddress ) {
return 1 if lc $CustomerEmailAddress eq lc $SenderAddress;
}
my @References = $Self->{ParserObject}->GetReferences();
my $ArticleObject = $Kernel::OM->Get('Kernel::System::Ticket::Article');
# Get all internal email articles sent by agents.
my @MetaArticleIndex = $ArticleObject->ArticleList(
TicketID => $Param{TicketID},
CommunicationChannel => 'Email',
SenderType => 'agent',
IsVisibleForCustomer => 0,
);
return 1 if !@MetaArticleIndex;
my $ArticleBackendObject = $ArticleObject->BackendForChannel( ChannelName => 'Email' );
# check if current sender got an internal forward
my $IsInternalForward;
ARTICLE:
for my $MetaArticle ( reverse @MetaArticleIndex ) {
my $Article = {
$ArticleBackendObject->ArticleGet( %{$MetaArticle} )
};
# check recipients
next ARTICLE if !$Article->{To};
# check based on recipient addresses of the article
my @ToEmailAddresses = $Self->{ParserObject}->SplitAddressLine(
Line => $Article->{To},
);
my @CcEmailAddresses = $Self->{ParserObject}->SplitAddressLine(
Line => $Article->{Cc},
);
my @EmailAdresses = ( @ToEmailAddresses, @CcEmailAddresses );
EMAIL:
for my $Email (@EmailAdresses) {
my $Recipient = $Self->{ParserObject}->GetEmailAddress(
Email => $Email,
);
if ( lc $Recipient eq lc $SenderAddress ) {
$IsInternalForward = 1;
last ARTICLE;
}
if ( $ReplyToAddress && lc $Recipient eq lc $ReplyToAddress ) {
$IsInternalForward = 1;
last ARTICLE;
}
}
# check based on Message-ID of the article
for my $Reference (@References) {
if ( $Article->{MessageID} && $Article->{MessageID} eq $Reference ) {
$IsInternalForward = 1;
last ARTICLE;
}
}
}
return 1 if !$IsInternalForward;
$Param{GetParam}->{'X-OTRS-FollowUp-IsVisibleForCustomer'} = $Param{JobConfig}->{IsVisibleForCustomer} // 0;
$Param{GetParam}->{'X-OTRS-FollowUp-SenderType'} = $Param{JobConfig}->{SenderType} || 'customer';
return 1;
}
1;
|