From 567e45ba565b1d03d8dc981dc0dfbc49eec4a355 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 13 Mar 2013 06:03:21 -0400
Subject: [PATCH] Fix HTML part detection for some specific message structures (#1488992)

---
 CHANGELOG                               |    1 +
 program/lib/Roundcube/rcube_message.php |   16 +++++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 499d5ba..6fef2d0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix HTML part detection for some specific message structures (#1488992)
 - Don't show fake address - phishing prevention (#1488981)
 - Fix forward as attachment bug with editormode != 1 (#1488991)
 - Fix LIMIT/OFFSET queries handling on MS SQL Server (#1488984)
diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php
index 60161a4..3f14266 100644
--- a/program/lib/Roundcube/rcube_message.php
+++ b/program/lib/Roundcube/rcube_message.php
@@ -210,18 +210,20 @@
                 if (!$recursive) {
                     $level = explode('.', $part->mime_id);
 
-                    // Skip if level too deep or part has a file name
-                    if (count($level) > 2 || $part->filename) {
+                    // Skip if part is an attachment
+                    if ($this->is_attachment($part)) {
                         continue;
                     }
 
-                    // HTML part can be on the lower level, if not...
-                    if (count($level) > 1) {
-                        array_pop($level);
+                    // Check if the part belongs to higher-level's alternative/related
+                    while (array_pop($level) !== null) {
+                        if (!count($level)) {
+                            return true;
+                        }
+
                         $parent = $this->mime_parts[join('.', $level)];
-                        // ... parent isn't multipart/alternative or related
                         if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') {
-                            continue;
+                            continue 2;
                         }
                     }
                 }

--
Gitblit v1.9.1