1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9package Kernel::Output::HTML::TicketZoom::Agent::MIMEBase; 10 11use parent 'Kernel::Output::HTML::TicketZoom::Agent::Base'; 12 13use strict; 14use warnings; 15 16use Kernel::System::VariableCheck qw(IsPositiveInteger); 17 18our @ObjectDependencies = ( 19 'Kernel::Config', 20 'Kernel::Output::HTML::Article::MIMEBase', 21 'Kernel::Output::HTML::Layout', 22 'Kernel::System::CommunicationChannel', 23 'Kernel::System::Main', 24 'Kernel::System::Log', 25 'Kernel::System::Ticket::Article', 26 'Kernel::System::User', 27); 28 29=head2 ArticleRender() 30 31Returns article html. 32 33 my $HTML = $ArticleBaseObject->ArticleRender( 34 TicketID => 123, # (required) 35 ArticleID => 123, # (required) 36 ShowBrowserLinkMessage => 1, # (optional) Default: 0. 37 ArticleActions => [], # (optional) 38 UserID => 123, # (optional) 39 ); 40 41Result: 42 $HTML = "<div>...</div>"; 43 44=cut 45 46sub ArticleRender { 47 my ( $Self, %Param ) = @_; 48 49 # Check needed stuff. 50 for my $Needed (qw(TicketID ArticleID)) { 51 if ( !$Param{$Needed} ) { 52 $Kernel::OM->Get('Kernel::System::Log')->Log( 53 Priority => 'error', 54 Message => "Need $Needed!", 55 ); 56 return; 57 } 58 } 59 60 my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); 61 my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout'); 62 my $MainObject = $Kernel::OM->Get('Kernel::System::Main'); 63 my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForArticle(%Param); 64 65 my %Article = $ArticleBackendObject->ArticleGet( 66 %Param, 67 RealNames => 1, 68 ); 69 if ( !%Article ) { 70 $Kernel::OM->Get('Kernel::System::Log')->Log( 71 Priority => 'error', 72 Message => "Article not found (ArticleID=$Param{ArticleID})!" 73 ); 74 return; 75 } 76 77 # Get channel specific fields 78 my %ArticleFields = $LayoutObject->ArticleFields(%Param); 79 80 # Get dynamic fields and accounted time 81 my %ArticleMetaFields = $Self->ArticleMetaFields(%Param); 82 83 # Get data from modules like Google CVE search 84 my @ArticleModuleMeta = $Self->_ArticleModuleMeta(%Param); 85 86 # Show created by string, if creator is different from admin user. 87 if ( $Article{CreateBy} > 1 ) { 88 $Article{CreateByUser} = $Kernel::OM->Get('Kernel::System::User')->UserName( UserID => $Article{CreateBy} ); 89 } 90 91 my $RichTextEnabled = $ConfigObject->Get('Ticket::Frontend::ZoomRichTextForce') 92 || $LayoutObject->{BrowserRichText} 93 || 0; 94 95 # Show HTML if RichText is enabled and HTML attachment isn't missing. 96 my $ShowHTML = $RichTextEnabled; 97 my $HTMLBodyAttachID = $Kernel::OM->Get('Kernel::Output::HTML::Article::MIMEBase')->HTMLBodyAttachmentIDGet( 98 %Param, 99 ); 100 if ( $ShowHTML && !$HTMLBodyAttachID ) { 101 $ShowHTML = 0; 102 } 103 104 # Strip plain text attachments by default. 105 my $ExcludePlainText = 1; 106 107 # Do not strip plain text attachments if no plain text article body was found. 108 if ( $Article{Body} && $Article{Body} eq '- no text message => see attachment -' ) { 109 $ExcludePlainText = 0; 110 } 111 112 # Get attachment index (excluding body attachments). 113 my %AtmIndex = $ArticleBackendObject->ArticleAttachmentIndex( 114 ArticleID => $Param{ArticleID}, 115 ExcludePlainText => $ExcludePlainText, 116 ExcludeHTMLBody => $RichTextEnabled, 117 ExcludeInline => $RichTextEnabled, 118 ); 119 120 my @ArticleAttachments; 121 122 # Add block for attachments. 123 if (%AtmIndex) { 124 my $Config = $ConfigObject->Get('Ticket::Frontend::ArticleAttachmentModule'); 125 126 ATTACHMENT: 127 for my $FileID ( sort keys %AtmIndex ) { 128 129 my $Attachment; 130 131 # Run article attachment modules. 132 next ATTACHMENT if ref $Config ne 'HASH'; 133 my %Jobs = %{$Config}; 134 135 JOB: 136 for my $Job ( sort keys %Jobs ) { 137 my %File = %{ $AtmIndex{$FileID} }; 138 139 # load module 140 next JOB if !$MainObject->Require( $Jobs{$Job}->{Module} ); 141 my $Object = $Jobs{$Job}->{Module}->new( 142 %{$Self}, 143 TicketID => $Param{TicketID}, 144 ArticleID => $Param{ArticleID}, 145 UserID => $Param{UserID} || 1, 146 ); 147 148 # run module 149 my %Data = $Object->Run( 150 File => { 151 %File, 152 FileID => $FileID, 153 }, 154 TicketID => $Param{TicketID}, 155 Article => \%Article, 156 ); 157 158 if (%Data) { 159 %File = %Data; 160 } 161 162 $File{Links} = [ 163 { 164 Action => $File{Action}, 165 Class => $File{Class}, 166 Link => $File{Link}, 167 Target => $File{Target}, 168 }, 169 ]; 170 if ( $File{Action} && $File{Action} ne 'Download' ) { 171 delete $File{Action}; 172 delete $File{Class}; 173 delete $File{Link}; 174 delete $File{Target}; 175 } 176 177 if ($Attachment) { 178 push @{ $Attachment->{Links} }, $File{Links}->[0]; 179 } 180 else { 181 $Attachment = \%File; 182 } 183 } 184 push @ArticleAttachments, $Attachment; 185 } 186 } 187 188 my $ArticleContent; 189 190 if ($ShowHTML) { 191 if ( $Param{ShowBrowserLinkMessage} ) { 192 $LayoutObject->Block( 193 Name => 'BrowserLinkMessage', 194 ); 195 } 196 } 197 else { 198 $ArticleContent = $LayoutObject->ArticlePreview( 199 %Param, 200 ResultType => 'plain', 201 ); 202 203 # html quoting 204 $ArticleContent = $LayoutObject->Ascii2Html( 205 NewLine => $ConfigObject->Get('DefaultViewNewLine'), 206 Text => $ArticleContent, 207 VMax => $ConfigObject->Get('DefaultViewLines') || 5000, 208 HTMLResultMode => 1, 209 LinkFeature => 1, 210 ); 211 } 212 213 my %CommunicationChannel = $Kernel::OM->Get('Kernel::System::CommunicationChannel')->ChannelGet( 214 ChannelID => $Article{CommunicationChannelID}, 215 ); 216 217 if ( $CommunicationChannel{ChannelName} eq 'Email' ) { 218 my $TransmissionStatus = $ArticleBackendObject->ArticleTransmissionStatus( 219 ArticleID => $Article{ArticleID}, 220 ); 221 if ($TransmissionStatus) { 222 $LayoutObject->Block( 223 Name => 'TransmissionStatusMessage', 224 Data => $TransmissionStatus, 225 ); 226 } 227 } 228 229 my $Content = $LayoutObject->Output( 230 TemplateFile => 'AgentTicketZoom/ArticleRender/MIMEBase', 231 Data => { 232 %Article, 233 ArticleFields => \%ArticleFields, 234 ArticleMetaFields => \%ArticleMetaFields, 235 ArticleModuleMeta => \@ArticleModuleMeta, 236 Attachments => \@ArticleAttachments, 237 MenuItems => $Param{ArticleActions}, 238 Body => $ArticleContent, 239 HTML => $ShowHTML, 240 CommunicationChannel => $CommunicationChannel{DisplayName}, 241 ChannelIcon => $CommunicationChannel{DisplayIcon}, 242 SenderImage => $Self->_ArticleSenderImage( 243 Sender => $Article{From}, 244 UserID => $Param{UserID}, 245 ), 246 SenderInitials => $LayoutObject->UserInitialsGet( 247 Fullname => $Article{FromRealname}, 248 ), 249 }, 250 ); 251 252 return $Content; 253} 254 2551; 256