]> git.proxmox.com Git - pmg-api.git/commitdiff
PMG::Utils::decode_rfc1522 - new helper
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 8 Aug 2017 07:46:19 +0000 (09:46 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 8 Aug 2017 07:46:19 +0000 (09:46 +0200)
PMG/Utils.pm

index 1aedd9b8d8ac48844fb48c62867a59a5ffa416a7..4b5b80db53d80a60f69c45769832ba77ba0fe2bc 100644 (file)
@@ -856,6 +856,31 @@ sub create_rrd_data {
     return $res;
 }
 
+sub decode_rfc1522 {
+    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 .= decode($cs, $d);
+               } else {
+                   $res .= $d;
+               }
+           }
+       }
+    };
+
+    $res = $enc if $@;
+
+    return $res;
+}
+
 sub rfc1522_to_html {
     my ($enc) = @_;