From c57c22a54d41fcfdd4ea44bac8b09fc9d07d842f Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 17 Aug 2015 15:43:08 -0500
Subject: [PATCH] mailparse: Fix incorrect parsing of some multipart messages

This patch drops the content after the last boundary in a multi-part message
which prevents it from being considered in some case where the available
content sections are not favorable.

Backport me to v1.9
---
 include/pear/Mail/mimeDecode.php | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/pear/Mail/mimeDecode.php b/include/pear/Mail/mimeDecode.php
index fd1fdba07..29095c960 100644
--- a/include/pear/Mail/mimeDecode.php
+++ b/include/pear/Mail/mimeDecode.php
@@ -529,6 +529,15 @@ class Mail_mimeDecode extends PEAR
         if ($input instanceof StringView) {
             $parts = $input->split('--' . $boundary);
             array_shift($parts);
+
+            if (count($parts) > 0
+                && $parts[count($parts)-1]->substr(0, 2)->__toString() == '--'
+            ) {
+                // Drop the last part if it starts with '--' as such would
+                // be past the end of a multipart section
+                array_pop($parts);
+            }
+
             return $parts;
         }
 
-- 
GitLab