From ce3105c58f921f33654c738fa7460d3d107813ce Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 24 Mar 2016 12:07:31 -0400
Subject: [PATCH] Reply/Reply-All/Forward/Change-format buttons for message/rfc822 preview

---
 program/lib/Roundcube/rcube_message.php |   64 ++++++++++++++++++++++++-------
 1 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php
index c5c436f..9e4e1d2 100644
--- a/program/lib/Roundcube/rcube_message.php
+++ b/program/lib/Roundcube/rcube_message.php
@@ -339,13 +339,17 @@
     {
         // check all message parts
         foreach ($this->mime_parts as $part) {
-            if (!$this->check_context($part)) {
-                continue;
-            }
-
             if ($part->mimetype == 'text/html' || ($enriched && $part->mimetype == 'text/enriched')) {
                 // Skip if part is an attachment, don't use is_attachment() here
                 if ($part->filename) {
+                    continue;
+                }
+
+                if (!$part->size) {
+                    continue;
+                }
+
+                if (!$this->check_context($part)) {
                     continue;
                 }
 
@@ -361,19 +365,22 @@
                         return true;
                     }
 
-                    $parent    = $this->mime_parts[join('.', $level)];
-                    $max_delta = $depth - (1 + ($last == 'multipart/alternative' ? 1 : 0));
-                    $last      = $parent->mimetype;
+                    $parent = $this->mime_parts[join('.', $level)];
 
-                    if (!preg_match('/^multipart\/(alternative|related|signed|encrypted|mixed)$/', $parent->mimetype)
-                        || ($parent->mimetype == 'multipart/mixed' && $parent_depth < $max_delta)) {
+                    if (!$this->check_context($parent)) {
+                        return true;
+                    }
+
+                    $max_delta = $depth - (1 + ($last == 'multipart/alternative' ? 1 : 0));
+                    $last      = $parent->real_mimetype ?: $parent->mimetype;
+
+                    if (!preg_match('/^multipart\/(alternative|related|signed|encrypted|mixed)$/', $last)
+                        || ($last == 'multipart/mixed' && $parent_depth < $max_delta)) {
                         continue 2;
                     }
                 }
 
-                if ($part->size) {
-                    return true;
-                }
+                return true;
             }
         }
 
@@ -400,6 +407,10 @@
                     continue;
                 }
 
+                if (!$part->size) {
+                    continue;
+                }
+
                 if (!$this->check_context($part)) {
                     continue;
                 }
@@ -413,14 +424,17 @@
                     }
 
                     $parent = $this->mime_parts[join('.', $level)];
+
+                    if (!$this->check_context($parent)) {
+                        return true;
+                    }
+
                     if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') {
                         continue 2;
                     }
                 }
 
-                if ($part->size) {
-                    return true;
-                }
+                return true;
             }
         }
 
@@ -479,6 +493,26 @@
     }
 
     /**
+     * Return message parts in current context
+     */
+    public function mime_parts()
+    {
+        if ($this->context === null) {
+            return $this->mime_parts;
+        }
+
+        $parts = array();
+
+        foreach ($this->mime_parts as $part_id => $part) {
+            if ($this->check_context($part)) {
+                $parts[$part_id] = $part;
+            }
+        }
+
+        return $parts;
+    }
+
+    /**
      * Checks if part of the message is an attachment (or part of it)
      *
      * @param rcube_message_part $part Message part

--
Gitblit v1.9.1