Index: program/include/rcube_message.php
===================================================================
--- program/include/rcube_message.php	(revision c1439f925dbfbd20566337a0251a6b4e85e9a2f9)
+++ program/include/rcube_message.php	(revision 6b6f2e83de0e5b48ba48583206bd456508554540)
@@ -199,4 +199,8 @@
       if ($mimetype == 'text/plain') {
         $out = $this->imap->get_message_part($this->uid, $mime_id, $part);
+        
+        // re-format format=flowed content
+        if ($part->ctype_secondary == "plain" && $part->ctype_parameters['format'] == "flowed")
+          $out = self::unfold_flowed($out);
         break;
       }
@@ -478,4 +482,36 @@
 
 
+  /**
+   * Interpret a format=flowed message body according to RFC 2646
+   *
+   * @param string  Raw body formatted as flowed text
+   * @return string Interpreted text with unwrapped lines and stuffed space removed
+   */
+  public static function unfold_flowed($text)
+  {
+    return preg_replace(
+      array('/-- (\r?\n)/',   '/^ /m',  '/(.) \r?\n/',  '/--%SIGEND%(\r?\n)/'),
+      array('--%SIGEND%\\1',  '',       '\\1 ',         '-- \\1'),
+      $text);
+  }
+  
+  /**
+   * Wrap the given text to comply with RFC 2646
+   */
+  public static function format_flowed($text, $length = 72)
+  {
+    $out = '';
+    
+    foreach (preg_split('/\r?\n/', trim($text)) as $line) {
+      // don't wrap quoted lines (to avoid wrapping problems)
+      if ($line[0] != '>')
+        $line = rc_wordwrap(rtrim($line), $length - 1, " \r\n");
+
+      $out .= $line . "\r\n";
+    }
+    
+    return $out;
+  }
+
 }
 
