[pmg-devel] [PATCH pmg-api v4 10/12] utils: refactor rfc1522_to_html
Dominik Csapak
d.csapak at proxmox.com
Thu Nov 24 13:21:10 CET 2022
by reusing the utf8 decoding logic of decode_rfc1522
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/PMG/Utils.pm | 21 ++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 463de6d..e20fc91 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -1135,25 +1135,8 @@ sub decode_rfc1522 {
sub rfc1522_to_html {
my ($enc) = @_;
- my $res = '';
-
- return '' if !$enc;
-
- eval {
- foreach my $r (MIME::Words::decode_mimewords($enc)) {
- my ($d, $cs) = @$r;
- if ($d) {
- if ($cs) {
- $res .= encode('UTF-8', decode($cs, $d));
- } else {
- $res .= $d;
- }
- }
- }
- $res = encode_entities(decode('UTF-8', $res));
- };
-
- $res = $enc if $@;
+ my $res = eval { encode_entities(decode_rfc1522($enc)) };
+ return $enc if $@;
return $res;
}
--
2.30.2
More information about the pmg-devel
mailing list