From 2e10626576f7d4d156cf35fd544c690288644c8a Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 18 Feb 2014 17:20:18 -0600
Subject: [PATCH] tnef: Strip null bytes from attachment filenames

Also support the TransportName in the properties list and prefer it over the
attachment-level attribute, as it is Unicode encoded.
---
 include/tnef_decoder.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/tnef_decoder.php b/include/tnef_decoder.php
index 3b8b204a5..fdcdba818 100644
--- a/include/tnef_decoder.php
+++ b/include/tnef_decoder.php
@@ -215,6 +215,7 @@ class TnefAttribute {
     const AttachFilename = 0x3704;
     const AttachLongFilename = 0x3707;
     const AttachPathname = 0x3708;
+    const AttachTransportName = 0x370c;
     const AttachMimeTag = 0x370e;    # Mime content-type
     const AttachContentId = 0x3712;
     const AttachmentCharset = 0x371b;
@@ -486,7 +487,7 @@ class TnefStreamParser {
                     new TnefAttributeStreamReader($info['data']));
                 break;
             case self::attAttachTransportFilename:
-                $attach->_setFilename($info['data']);
+                $attach->_setFilename(rtrim($info['data'], "\x00"));
                 break;
             case self::attAttachData:
                 $attach->_setData($info['data']);
@@ -576,6 +577,8 @@ class TnefAttachment extends AbstractTnefObject {
             return basename($this->AttachLongFilename);
         elseif (isset($this->AttachFilename))
             return $this->AttachFilename;
+        elseif (isset($this->AttachTransportName))
+            return $this->AttachTransportName;
         else
             return $this->TransportFilename;
     }
-- 
GitLab