From ae853367edd2720e2f899aa273ca8ac1a08f0079 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 30 Jul 2013 13:16:52 -0400
Subject: [PATCH] Fix downloading binary files with (wrong) text/* content-type (#1489267)

---
 program/lib/Roundcube/rcube_imap.php |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index b60aefc..c5346c8 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -2092,17 +2092,18 @@
     /**
      * Fetch message body of a specific message from the server
      *
-     * @param  int                $uid    Message UID
-     * @param  string             $part   Part number
-     * @param  rcube_message_part $o_part Part object created by get_structure()
-     * @param  mixed              $print  True to print part, ressource to write part contents in
-     * @param  resource           $fp     File pointer to save the message part
-     * @param  boolean            $skip_charset_conv Disables charset conversion
-     * @param  int                $max_bytes  Only read this number of bytes
+     * @param int                Message UID
+     * @param string             Part number
+     * @param rcube_message_part Part object created by get_structure()
+     * @param mixed              True to print part, resource to write part contents in
+     * @param resource           File pointer to save the message part
+     * @param boolean            Disables charset conversion
+     * @param int                Only read this number of bytes
+     * @param boolean            Enables formatting of text/* parts bodies
      *
      * @return string Message/part body if not printed
      */
-    public function get_message_part($uid, $part=1, $o_part=NULL, $print=NULL, $fp=NULL, $skip_charset_conv=false, $max_bytes=0)
+    public function get_message_part($uid, $part=1, $o_part=NULL, $print=NULL, $fp=NULL, $skip_charset_conv=false, $max_bytes=0, $formatted=true)
     {
         if (!$this->check_connection()) {
             return null;
@@ -2121,8 +2122,9 @@
         }
 
         if ($o_part && $o_part->size) {
+            $formatted = $formatted && $o_part->ctype_primary == 'text';
             $body = $this->conn->handlePartBody($this->folder, $uid, true,
-                $part ? $part : 'TEXT', $o_part->encoding, $print, $fp, $o_part->ctype_primary == 'text', $max_bytes);
+                $part ? $part : 'TEXT', $o_part->encoding, $print, $fp, $formatted, $max_bytes);
         }
 
         if ($fp || $print) {

--
Gitblit v1.9.1