From 1fb5874f276e9ce7731e8f166b19a371ce33b894 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 27 Apr 2009 03:24:11 -0400
Subject: [PATCH] - fix attachment mimetype setting after upload - move style of delete button in attachment-list to mail.css file

---
 program/steps/mail/compose.inc |   69 ++++++++++++++++------------------
 1 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 1b83b1e..9328cc5 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -70,8 +70,10 @@
   $compose_mode = RCUBE_COMPOSE_REPLY;
 else if ($msg_uid = $_SESSION['compose']['param']['_forward_uid'])
   $compose_mode = RCUBE_COMPOSE_FORWARD;
-else if ($msg_uid = $_SESSION['compose']['param']['_draft_uid'])
+else if ($msg_uid = $_SESSION['compose']['param']['_draft_uid']) {
+  $RCMAIL->imap->set_mailbox($CONFIG['drafts_mbox']);
   $compose_mode = RCUBE_COMPOSE_DRAFT;
+}
 
 if (!empty($msg_uid))
 {
@@ -288,7 +290,7 @@
       $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
 
       // add signature to array
-      if (!empty($sql_arr['signature']))
+      if (!empty($sql_arr['signature']) && empty($_SESSION['compose']['param']['_nosig']))
       {
         $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
         $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false;
@@ -488,7 +490,7 @@
       }
 
     // add title line(s)
-    $prefix = wordwrap(sprintf("On %s, %s wrote:\n",
+    $prefix = rc_wordwrap(sprintf("On %s, %s wrote:\n",
       $MESSAGE->headers->date,
       $MESSAGE->get_header('from')), 76);
 
@@ -592,8 +594,6 @@
   global $OUTPUT;
   
   $cid_map = array();
-  $id = 0;
-  
   foreach ((array)$message->mime_parts as $pid => $part)
   {
     if (($part->ctype_primary != 'message' || !$bodyIsHtml) &&
@@ -601,16 +601,14 @@
          || (empty($part->disposition) && $part->filename)))
     {
       if ($attachment = rcmail_save_attachment($message, $pid)) {
-        $_SESSION['compose']['attachments'][$id] = $attachment;
-	if ($bodyIsHtml && $part->filename && $part->content_id) {
-	  $cid_map['cid:'.$part->content_id] = 
-	    $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$id;
+        $_SESSION['compose']['attachments'][$attachment['id']] = $attachment;
+        if ($bodyIsHtml && $part->filename && $part->content_id) {
+          $cid_map['cid:'.$part->content_id] = $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'];
         }
-	$id++;
       }
     }
   }
-	
+
   $_SESSION['compose']['forward_attachments'] = true;
 
   return $cid_map;
@@ -622,15 +620,11 @@
   global $OUTPUT;
 
   $cid_map = array();
-  $id = 0;
-  
   foreach ((array)$message->mime_parts as $pid => $part) {
     if ($part->content_id && $part->filename) {
       if ($attachment = rcmail_save_attachment($message, $pid)) {
-        $_SESSION['compose']['attachments'][$id] = $attachment;
-        $cid_map['cid:'.$part->content_id] = 
-	  $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$id;
-        $id++;
+        $_SESSION['compose']['attachments'][$attachment['id']] = $attachment;
+        $cid_map['cid:'.$part->content_id] = $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'];
       }
     }
   }
@@ -640,24 +634,22 @@
 
 function rcmail_save_attachment(&$message, $pid)
 {
-  global $RCMAIL;
-
-  $temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
-  $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
   $part = $message->mime_parts[$pid];
   
-  if ($fp = fopen($tmp_path, 'w'))
-  {
-    $message->get_part_content($pid, $fp);
-    fclose($fp);
-
-    return array(
-        'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
-        'name' => $part->filename,
-        'path' => $tmp_path,
-	'content_id' => $part->content_id
-    );
+  $attachment = array(
+    'name' => $part->filename,
+    'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
+    'content_id' => $part->content_id,
+    'data' => $message->get_part_content($pid),
+  );
+  
+  $attachment = rcmail::get_instance()->plugins->exec_hook('save_attachment', $attachment);
+  if ($attachment['status']) {
+    unset($attachment['data'], $attachment['status']);
+    return $attachment;
   }
+
+  return false;
 }
 
 
@@ -723,8 +715,8 @@
     if ($attrib['deleteicon'])
       $button = html::img(array(
         'src' => $CONFIG['skin_path'] . $attrib['deleteicon'],
-        'alt' => rcube_label('delete'),
-        'style' => "padding-right:2px;vertical-align:middle"));
+        'alt' => rcube_label('delete')
+	));
     else
       $button = Q(rcube_label('delete'));
 
@@ -737,7 +729,7 @@
         html::a(array(
             'href' => "#delete",
             'title' => rcube_label('delete'),
-            'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id)),
+            'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", JS_OBJECT_NAME, $id)),
           $button) . Q($a_prop['name']));
     }
   }
@@ -800,7 +792,12 @@
                        rcube_label('highest')),
                  array(5, 4, 0, 2, 1));
                  
-  $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE->headers->priority);
+  if (isset($_POST['_priority']))
+    $sel = $_POST['_priority'];
+  else if (intval($MESSAGE->headers->priority) != 3)
+    $sel = intval($MESSAGE->headers->priority);
+  else
+    $sel = 0;
 
   $out = $form_start ? "$form_start\n" : '';
   $out .= $selector->show($sel);

--
Gitblit v1.9.1