From 7d8e168cb1700455ae0746087d2e81c0696fbfaa Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 10 Jul 2009 10:52:11 -0400
Subject: [PATCH] Fix compose step: correctly choose html mode and attachments when in draft or edit mode

---
 program/steps/mail/compose.inc       |   24 ++++++++++++------------
 skins/default/templates/compose.html |    4 ++--
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 3c82c8e..99e925c 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -37,9 +37,9 @@
 {
   rcmail_compose_cleanup();
   $_SESSION['compose'] = array(
-	'id' => uniqid(rand()),
-	'param' => array_map('strip_tags', $_GET),
-	'mailbox' => $IMAP->get_mailbox_name()
+    'id' => uniqid(rand()),
+    'param' => array_map('strip_tags', $_GET),
+    'mailbox' => $IMAP->get_mailbox_name(),
   );
   
   // process values like "mailto:foo@bar.com?subject=new+message&cc=another"
@@ -86,7 +86,7 @@
 {
   // similar as in program/steps/mail/show.inc
   // re-set 'prefer_html' to have possibility to use html part for compose
-  $CONFIG['prefer_html'] = $CONFIG['htmleditor'];
+  $CONFIG['prefer_html'] = $CONFIG['htmleditor'] || $compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT;
   $MESSAGE = new rcube_message($msg_uid);
   
   if (!empty($MESSAGE->headers->charset))
@@ -357,7 +357,7 @@
 
   $attrib['name'] = '_message';
 
-  if ($CONFIG['htmleditor'])
+  if ($CONFIG['htmleditor'] || (($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) && $MESSAGE->first_html_part()))
     $isHtml = true;
   else
     $isHtml = false;
@@ -562,11 +562,11 @@
       Q($MESSAGE->subject),
       Q($MESSAGE->headers->date),
       htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset()),
-	htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset()));
+      htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset()));
 
     if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from)
       $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Reply-To: </th><td>%s</td></tr>",
-	htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset()));
+        htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset()));
 
     $prefix .= "</tbody></table><br>";
   }
@@ -583,7 +583,7 @@
    * add attachments
    * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text!
    */
-  if (!isset($_SESSION['compose']['forward_attachments'])
+  if (empty($_SESSION['compose']['forward_attachments'])
       && is_array($MESSAGE->mime_parts)
       && count($MESSAGE->mime_parts) > 0)
   {
@@ -605,12 +605,12 @@
   $cid_map = array();
   foreach ((array)$message->mime_parts as $pid => $part)
   {
-    if (($part->ctype_primary != 'message' || !$bodyIsHtml) && $part->filename &&
-        ($part->disposition=='attachment' || ($part->disposition=='inline' && $bodyIsHtml) || (empty($part->disposition))))
+    if (($part->ctype_primary != 'message' || !$bodyIsHtml) && $part->ctype_primary != 'multipart' && 
+        ($part->disposition == 'attachment' || ($part->disposition == 'inline' && $bodyIsHtml) || $part->filename))
     {
       if ($attachment = rcmail_save_attachment($message, $pid)) {
         $_SESSION['compose']['attachments'][$attachment['id']] = $attachment;
-        if ($bodyIsHtml && $part->filename && $part->content_id) {
+        if ($bodyIsHtml && $part->content_id) {
           $cid_map['cid:'.$part->content_id] = $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'];
         }
       }
@@ -645,7 +645,7 @@
   $part = $message->mime_parts[$pid];
   
   $attachment = array(
-    'name' => $part->filename,
+    'name' => $part->filename ? $part->filename : 'Part_'.$pid.'.'.$part->ctype_secondary,
     'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
     'content_id' => $part->content_id,
     'data' => $message->get_part_content($pid),
diff --git a/skins/default/templates/compose.html b/skins/default/templates/compose.html
index 0e122ed..e032c58 100644
--- a/skins/default/templates/compose.html
+++ b/skins/default/templates/compose.html
@@ -68,7 +68,7 @@
 	    </tr><tr>
 		<td class="title"><roundcube:label name="editortype" /></td>
 		<td>
-		    <div id="editor-select"><roundcube:object name="editorSelector" editorid="compose-body" tabindex="7" /></div>
+		    <div id="editor-select"><roundcube:object name="editorSelector" editorid="compose-body" /></div>
 		    <div id="spellcheck-control"></div>
 		</td>
 	    </tr>
@@ -76,7 +76,7 @@
 	</table>
     </div>
     <div id="compose-div">
-	<roundcube:object name="composeBody" id="compose-body" form="form" cols="70" rows="20" tabindex="8" />
+	<roundcube:object name="composeBody" id="compose-body" form="form" cols="70" rows="20" tabindex="7" />
 	<table border="0" cellspacing="0" summary="" style="width:100%; margin-top: 5px;"><tbody>
 	    <tr>
 		<td style="white-space: nowrap">

--
Gitblit v1.9.1