[pmg-devel] [PATCH pmg-api] fix disclaimer encoding for html entities
Stoiko Ivanov
s.ivanov at proxmox.com
Thu Jan 23 11:49:05 CET 2020
applied the patch tried sending a few mails, with an active
rule attaching a disclaimer.
Was surprised when it sometimes did not attach the disclaimer,
until I saw that the multi-byte characters I sent were not compatible
with the encoding of the disclaimer - so "accidentally" did some negative
tests as well :)
Works fine and as advertised - Thanks!
Tested-By: Stoiko Ivanov <s.ivanov at proxmox.com>
Reviewed-By: Stoiko Ivanov <s.ivanov at proxmox.com>
On Fri, 17 Jan 2020 10:52:47 +0100
Dominik Csapak <d.csapak at proxmox.com> wrote:
> 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;
More information about the pmg-devel
mailing list