From 12217da8b32a4e941d6b1c48601b223679224233 Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Thu, 28 May 2009 13:47:59 -0400 Subject: [PATCH] - simplified attachments handling on reply/forward/draft compose (possible regressions) - also fix #1485847 --- program/steps/mail/compose.inc | 110 ++++++++++++++++++++++++++++--------------------------- 1 files changed, 56 insertions(+), 54 deletions(-) diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 49c4c30..8d43de0 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -35,7 +35,11 @@ if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET)) { rcmail_compose_cleanup(); - $_SESSION['compose'] = array('id' => uniqid(rand()), 'param' => array_map('strip_tags', $_GET)); + $_SESSION['compose'] = array( + '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" if ($_SESSION['compose']['param']['_to']) { @@ -290,7 +294,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; @@ -363,7 +367,7 @@ } else if ($compose_mode) { - if ($isHtml && $MESSAGE->has_html_part()) + if (($isHtml || $compose_mode == RCUBE_COMPOSE_DRAFT) && $MESSAGE->has_html_part()) { $body = $MESSAGE->first_html_part(); $isHtml = true; @@ -433,6 +437,7 @@ "googie.lang_no_error_found = \"%s\";\n". "googie.setLanguages(%s);\n". "googie.setCurrentLanguage('%s');\n". + "googie.setSpellContainer('spellcheck-control');\n". "googie.decorateTextarea('%s');\n". "%s.set_env('spellcheck', googie);", $RCMAIL->comm_path, @@ -552,12 +557,12 @@ "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>", Q($MESSAGE->subject), Q($MESSAGE->headers->date), - htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true), - htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true)); + htmlspecialchars(Q($MESSAGE->get_header('from'), '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(), true)); + htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset())); $prefix .= "</tbody></table><br>"; } @@ -594,25 +599,20 @@ global $OUTPUT; $cid_map = array(); - $id = 0; - foreach ((array)$message->mime_parts as $pid => $part) { - if (($part->ctype_primary != 'message' || !$bodyIsHtml) && - ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] - || (empty($part->disposition) && $part->filename))) + if (($part->ctype_primary != 'message' || !$bodyIsHtml) && $part->filename && + ($part->disposition=='attachment' || ($part->disposition=='inline' && $bodyIsHtml) || (empty($part->disposition)))) { 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; @@ -624,15 +624,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']; } } } @@ -642,24 +638,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; } @@ -682,14 +676,14 @@ } // create a reply-subject else if ($compose_mode == RCUBE_COMPOSE_REPLY) { - if (eregi('^re:', $MESSAGE->subject)) + if (preg_match('/^re:/i', $MESSAGE->subject)) $subject = $MESSAGE->subject; else $subject = 'Re: '.$MESSAGE->subject; } // create a forward-subject else if ($compose_mode == RCUBE_COMPOSE_FORWARD) { - if (eregi('^fwd:', $MESSAGE->subject)) + if (preg_match('/^fwd:/i', $MESSAGE->subject)) $subject = $MESSAGE->subject; else $subject = 'Fwd: '.$MESSAGE->subject; @@ -725,8 +719,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')); @@ -739,7 +733,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'])); } } @@ -802,7 +796,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); @@ -839,23 +838,26 @@ { global $CONFIG, $MESSAGE, $compose_mode; - $choices = array( - 'html' => 'htmltoggle', - 'plain' => 'plaintoggle' - ); - // determine whether HTML or plain text should be checked $useHtml = $CONFIG['htmleditor'] ? true : false; if ($compose_mode) $useHtml = ($useHtml && $MESSAGE->has_html_part()); - $editorid = empty($attrib['editorid']) ? 'rcmComposeMessage' : $attrib['editorid']; + if (empty($attrib['editorid'])) + $attrib['editorid'] = 'rcmComposeMessage'; - $selector = ''; - $chosenvalue = $useHtml ? 'html' : 'plain'; - $radio = new html_radiobutton(array('name' => '_editorSelect', - 'onclick' => "return rcmail_toggle_editor(this.value=='html', '$editorid', '_is_html')")); + if (empty($attrib['name'])) + $attrib['name'] = 'editorSelect'; + + $attrib['onchange'] = "return rcmail_toggle_editor(this.value=='html', '".$attrib['editorid']."', '_is_html')"; + + $select = new html_select($attrib); + + $select->add(Q(rcube_label('htmltoggle')), 'html'); + $select->add(Q(rcube_label('plaintoggle')), 'plain'); + + return $select->show($useHtml ? 'html' : 'plain'); foreach ($choices as $value => $text) { -- Gitblit v1.9.1