From bfc2b7c4ec7c8f18aa876c4e8a0648754c07a436 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 18 Feb 2014 17:04:35 -0600
Subject: [PATCH] tnef: Support yet another place for attachment data

---
 include/class.mailfetch.php | 7 +++++--
 include/class.mailparse.php | 2 +-
 include/tnef_decoder.php    | 8 ++++++++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index eaa1ebcdd..efbe8f2f0 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -617,7 +617,7 @@ class MailFetcher {
                 foreach ($this->tnef->attachments as $at) {
                     $attachments[] = array(
                         'cid' => @$at->AttachContentId ?: false,
-                        'data' => $at->Data,
+                        'data' => $at,
                         'type' => @$at->AttachMimeTag ?: false,
                         'name' => $at->getName(),
                     );
@@ -631,7 +631,10 @@ class MailFetcher {
                 if(!$ost->isFileTypeAllowed($file)) {
                     $file['error'] = 'Invalid file type (ext) for '.Format::htmlchars($file['name']);
                 }
-                elseif (!$file['data']) {
+                elseif (@$a['data'] instanceof TnefAttachment) {
+                    $file['data'] = $a['data']->getData();
+                }
+                else {
                     // only fetch the body if necessary
                     $self = $this;
                     $file['data'] = function() use ($self, $mid, $a) {
diff --git a/include/class.mailparse.php b/include/class.mailparse.php
index cf4a12691..27ea94701 100644
--- a/include/class.mailparse.php
+++ b/include/class.mailparse.php
@@ -390,7 +390,7 @@ class Mail_Parse {
             foreach ($this->tnef->attachments as $at) {
                 $files[] = array(
                     'cid' => @$at->AttachContentId ?: false,
-                    'data' => $at->Data,
+                    'data' => $at->getData(),
                     'type' => @$at->AttachMimeTag ?: false,
                     'name' => $at->getName(),
                 );
diff --git a/include/tnef_decoder.php b/include/tnef_decoder.php
index 18e95d697..3b8b204a5 100644
--- a/include/tnef_decoder.php
+++ b/include/tnef_decoder.php
@@ -209,6 +209,7 @@ class TnefAttribute {
     const AttributeReadOnly = 0x10f6;
     const CreationTime = 0x3007;
     const LastModificationTime = 0x3008;
+    const AttachDataBinary = 0x3701;
     const AttachEncoding = 0x3702;
     const AttachExtension = 0x3703;
     const AttachFilename = 0x3704;
@@ -555,6 +556,13 @@ class TnefAttachment extends AbstractTnefObject {
         $this->Data = $data;
     }
 
+    function getData() {
+        if (isset($this->Data))
+            return $this->Data;
+        elseif (isset($this->AttachDataBinary))
+            return $this->AttachDataBinary;
+    }
+
     function _setRenderingData($data) {
         // Pass
     }
-- 
GitLab