From c5b670914fe5e2e675a804837cc65770af80b993 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 17 Jan 2020 10:52:47 +0100 Subject: [PATCH] fix disclaimer encoding for html entities we also want to encode the disclaimer for text/html parts and not only for text/plain. while doing this, combine those two cases, as they differ only by the variable to be encoded this also fixes a missing charset, which we would ignore, but should actually be treated as US-ASCII[0] so that an ascii disclaimer still gets appended the only (non-rfc-compliant) use case this breaks is if: * the part has no charet defined (unusual) * the clients of both the sender and receiver treat a missing charset as 'iso-8859-1' (non-rfc-compliant) * the disclaimer contains characters from 'iso-8859-1' and was added to the pmg before encoding this to utf-8 (unlikely) so i think we can ignore that case 0: https://tools.ietf.org/html/rfc1521 Signed-off-by: Dominik Csapak Tested-By: Stoiko Ivanov Reviewed-By: Stoiko Ivanov --- src/PMG/RuleDB/Disclaimer.pm | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm index 9f0546e..3d2120b 100644 --- a/src/PMG/RuleDB/Disclaimer.pm +++ b/src/PMG/RuleDB/Disclaimer.pm @@ -158,16 +158,14 @@ sub sign { last; } } - } elsif ($entity->head->mime_type =~ m{text/}) { - if ($entity->head->mime_type =~ m{text/html}) { - $self->add_data ($entity, $html); - $found = 1; - } elsif ($entity->head->mime_type =~ m{text/plain}) { - my $cs = $entity->head->mime_attr("content-type.charset"); + } elsif ($entity->head->mime_type =~ m{text/}) { + if ($entity->head->mime_type =~ m{text/(html|plain)}) { + my $type = $1; + my $cs = $entity->head->mime_attr("content-type.charset") // 'ascii'; eval { - my $enc_text = encode($cs, $text, Encode::FB_CROAK); - $self->add_data($entity, $enc_text); - }; + my $encoded = encode($cs, $type eq 'html' ? $html : $text, Encode::FB_CROAK); + $self->add_data($entity, $encoded); + }; # simply ignore if we can't represent the disclainer # with that encoding $found = 1; -- 2.39.2