]> git.proxmox.com Git - pmg-api.git/commitdiff
fix disclaimer encoding for html entities
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 17 Jan 2020 09:52:47 +0000 (10:52 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 23 Jan 2020 12:11:59 +0000 (13:11 +0100)
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@proxmox.com>
Tested-By: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-By: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/RuleDB/Disclaimer.pm

index 9f0546ec3816512c956e7b2860805f5facfbc340..3d2120bb06afadf72192c9941db63d3fb36919ff 100644 (file)
@@ -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;