[pmg-devel] [PATCH pmg-api] fix disclaimer encoding for html entities
Dominik Csapak
d.csapak at proxmox.com
Fri Jan 17 10:52:47 CET 2020
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 <d.csapak at proxmox.com>
---
caught by user report in the forum:
https://forum.proxmox.com/threads/disclaimer-garbled-for-chinese.63489/
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.20.1
More information about the pmg-devel
mailing list