Skip to content

Commit

Permalink
Fixed mixed up content types for article body and signature in generi…
Browse files Browse the repository at this point in the history
…c interface operations TicketCreate and TicketUpdate.
  • Loading branch information
jepf committed Sep 26, 2023
1 parent 714d9e6 commit 0a30c55
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 6.5.5 2023-??-??
- 2023-09-22 Fixed some errors in the customer interface being shown with the agent interface's header navigation. Thanks for reporting/hints to Tim Püttmanns, maxence.
- 2023-09-19 Fixed mixed up content types for article body and signature in generic interface operations TicketCreate and TicketUpdate.
- 2023-08-29 Updated maximum length of generic agent job database fields and their input fields in dialog AdminGenericAgent to prevent errors storing values too long for the database. [#474](https://github.com/znuny/Znuny/issues/474)
- 2023-08-23 Added parameter to enforce account selection for the Microsoft OAuth2 template.

Expand Down
33 changes: 23 additions & 10 deletions Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1608,13 +1608,15 @@ sub _TicketCreate {

my $PlainBody = $Article->{Body};

my $ArticleIsHTML = ( $Article->{ContentType} && $Article->{ContentType} =~ /text\/html/i )
|| ( $Article->{MimeType} && $Article->{MimeType} =~ /text\/html/i );

my $ArticleIsPlainText = ( $Article->{ContentType} && $Article->{ContentType} =~ /text\/plain/i )
|| ( $Article->{MimeType} && $Article->{MimeType} =~ /text\/plain/i );

# Convert article body to plain text, if HTML content was supplied. This is necessary since auto response code
# expects plain text content. Please see bug#13397 for more information.
if (
( $Article->{ContentType} && $Article->{ContentType} =~ /text\/html/i )
|| ( $Article->{MimeType} && $Article->{MimeType} =~ /text\/html/i )
)
{
if ($ArticleIsHTML) {
$PlainBody = $Kernel::OM->Get('Kernel::System::HTMLUtils')->ToAscii(
String => $Article->{Body},
);
Expand Down Expand Up @@ -1645,20 +1647,31 @@ sub _TicketCreate {
};
}

#
# Template generator implicitly takes Frontend::RichText into account.
# Temporarily enable/disable RichText setting according to content type of article,
# so that body and signature both are plain text or HTML.
#
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

my $OriginalRichTextSetting = $ConfigObject->Get('Frontend::RichText');

$ConfigObject->{'Frontend::RichText'} = 0 if $ArticleIsPlainText;
$ConfigObject->{'Frontend::RichText'} = 1 if $ArticleIsHTML;

my $Signature = $Kernel::OM->Get('Kernel::System::TemplateGenerator')->Signature(
TicketID => $TicketID,
UserID => $Param{UserID},
Data => $Article,
);

# Restore original RichText setting.
$ConfigObject->{'Frontend::RichText'} = $OriginalRichTextSetting;

if ($Signature) {
$Article->{Body} = $Article->{Body} . $Signature;

if (
( $Article->{ContentType} && $Article->{ContentType} =~ /text\/html/i )
|| ( $Article->{MimeType} && $Article->{MimeType} =~ /text\/html/i )
)
{
if ($ArticleIsHTML) {
$PlainBody = $Kernel::OM->Get('Kernel::System::HTMLUtils')->ToAscii(
String => $Article->{Body},
);
Expand Down
29 changes: 23 additions & 6 deletions Kernel/GenericInterface/Operation/Ticket/TicketUpdate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2156,13 +2156,15 @@ sub _TicketUpdate {

my $PlainBody = $Article->{Body};

my $ArticleIsHTML = ( $Article->{ContentType} && $Article->{ContentType} =~ /text\/html/i )
|| ( $Article->{MimeType} && $Article->{MimeType} =~ /text\/html/i );

my $ArticleIsPlainText = ( $Article->{ContentType} && $Article->{ContentType} =~ /text\/plain/i )
|| ( $Article->{MimeType} && $Article->{MimeType} =~ /text\/plain/i );

# Convert article body to plain text, if HTML content was supplied. This is necessary since auto response code
# expects plain text content. Please see bug#13397 for more information.
if (
( $Article->{ContentType} && $Article->{ContentType} =~ /text\/html/i )
|| ( $Article->{MimeType} && $Article->{MimeType} =~ /text\/html/i )
)
{
if ($ArticleIsHTML) {
$PlainBody = $Kernel::OM->Get('Kernel::System::HTMLUtils')->ToAscii(
String => $Article->{Body},
);
Expand Down Expand Up @@ -2193,16 +2195,31 @@ sub _TicketUpdate {
};
}

#
# Template generator implicitly takes Frontend::RichText into account.
# Temporarily enable/disable RichText setting according to content type of article,
# so that body and signature both are plain text or HTML.
#
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

my $OriginalRichTextSetting = $ConfigObject->Get('Frontend::RichText');

$ConfigObject->{'Frontend::RichText'} = 0 if $ArticleIsPlainText;
$ConfigObject->{'Frontend::RichText'} = 1 if $ArticleIsHTML;

my $Signature = $Kernel::OM->Get('Kernel::System::TemplateGenerator')->Signature(
TicketID => $TicketID,
UserID => $Param{UserID},
Data => $Article,
);

# Restore original RichText setting.
$ConfigObject->{'Frontend::RichText'} = $OriginalRichTextSetting;

if ($Signature) {
$Article->{Body} = $Article->{Body} . $Signature;

if ( $Article->{ContentType} =~ /text\/html/i || $Article->{MimeType} =~ /text\/html/i ) {
if ($ArticleIsHTML) {
$PlainBody = $Kernel::OM->Get('Kernel::System::HTMLUtils')->ToAscii(
String => $Article->{Body},
);
Expand Down

0 comments on commit 0a30c55

Please sign in to comment.