From 4e383e2ec8b4184c0fe74d02cf30fd3a4078128e Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 09 Sep 2012 11:35:19 -0400
Subject: [PATCH] Fix PLAIN authentication for some IMAP servers (#1488674)

---
 program/include/rcube_message.php |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/program/include/rcube_message.php b/program/include/rcube_message.php
index a140b86..6af1d01 100644
--- a/program/include/rcube_message.php
+++ b/program/include/rcube_message.php
@@ -50,13 +50,14 @@
      */
     private $mime;
     private $opt = array();
-    private $inline_parts = array();
     private $parse_alternative = false;
 
-    public $uid = null;
+    public $uid;
+    public $folder;
     public $headers;
     public $parts = array();
     public $mime_parts = array();
+    public $inline_parts = array();
     public $attachments = array();
     public $subject = '';
     public $sender = null;
@@ -68,16 +69,21 @@
      *
      * Provide a uid, and parse message structure.
      *
-     * @param string $uid The message UID.
+     * @param string $uid    The message UID.
+     * @param string $folder Folder name
      *
      * @see self::$app, self::$storage, self::$opt, self::$parts
      */
-    function __construct($uid)
+    function __construct($uid, $folder = null)
     {
         $this->uid  = $uid;
         $this->app  = rcube::get_instance();
         $this->storage = $this->app->get_storage();
+        $this->folder  = strlen($folder) ? $folder : $this->storage->get_folder();
         $this->storage->set_options(array('all_headers' => true));
+
+        // Set current folder
+        $this->storage->set_folder($this->folder);
 
         $this->headers = $this->storage->get_message($uid);
 
@@ -179,10 +185,12 @@
                 }
                 return $fp ? true : $part->body;
             }
+
             // get from IMAP
+            $this->storage->set_folder($this->folder);
+
             return $this->storage->get_message_part($this->uid, $mime_id, $part, NULL, $fp, $skip_charset_conv);
-        } else
-            return null;
+        }
     }
 
 
@@ -273,6 +281,32 @@
 
         $part = null;
         return null;
+    }
+
+
+    /**
+     * Checks if part of the message is an attachment (or part of it)
+     *
+     * @param rcube_message_part $part Message part
+     *
+     * @return bool True if the part is an attachment part
+     */
+    public function is_attachment($part)
+    {
+        foreach ($this->attachments as $att_part) {
+            if ($att_part->mime_id == $part->mime_id) {
+                return true;
+            }
+
+            // check if the part is a subpart of another attachment part (message/rfc822)
+            if ($att_part->mimetype == 'message/rfc822') {
+                if (in_array($part, (array)$att_part->parts)) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
     }
 
 
@@ -611,8 +645,10 @@
     function tnef_decode(&$part)
     {
         // @TODO: attachment may be huge, hadle it via file
-        if (!isset($part->body))
+        if (!isset($part->body)) {
+            $this->storage->set_folder($this->folder);
             $part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part);
+        }
 
         $parts = array();
         $tnef = new tnef_decoder;
@@ -647,8 +683,10 @@
     function uu_decode(&$part)
     {
         // @TODO: messages may be huge, hadle body via file
-        if (!isset($part->body))
+        if (!isset($part->body)) {
+            $this->storage->set_folder($this->folder);
             $part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part);
+        }
 
         $parts = array();
         // FIXME: line length is max.65?

--
Gitblit v1.9.1