| | |
| | | | program/steps/mail/compose.inc | |
| | | | | |
| | | | This file is part of the RoundCube Webmail client | |
| | | | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland | |
| | | | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland | |
| | | | Licensed under the GNU GPL | |
| | | | | |
| | | | PURPOSE: | |
| | |
| | | $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)) |
| | | { |
| | |
| | | && !in_array($addr_part['mailto'], $sa_recipients) |
| | | && (!$MESSAGE->compose_from |
| | | || !in_array_nocase($addr_part['mailto'], $MESSAGE->compose_from) |
| | | || count($to_addresses)==1)) // allow reply to yourself |
| | | || (count($to_addresses)==1 && $header=='to'))) // allow reply to yourself |
| | | { |
| | | $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string']; |
| | | $sa_recipients[] = $addr_part['mailto']; |
| | |
| | | $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; |
| | |
| | | // load draft message body |
| | | else if ($compose_mode == RCUBE_COMPOSE_DRAFT) |
| | | $body = rcmail_create_draft_body($body, $isHtml); |
| | | |
| | | if ($isHtml) { |
| | | // replace cid with href in inline images links |
| | | foreach ((array)$_SESSION['compose']['attachments'] as $pid => $attachment) { |
| | | if ($attachment['content_id']) { |
| | | $body = str_replace('cid:'. $attachment['content_id'], |
| | | $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$pid, $body); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else if (!empty($_SESSION['compose']['param']['_body'])) |
| | | { |
| | |
| | | } |
| | | |
| | | // 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); |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | // save inline images to files |
| | | $cid_map = rcmail_write_inline_attachments($MESSAGE); |
| | | // set is_safe flag (we need this for html body washing) |
| | | rcmail_check_safe($MESSAGE); |
| | | // clean up html tags |
| | | $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map); |
| | | |
| | | // build reply (quote content) |
| | | $prefix = sprintf("On %s, %s wrote:<br />\n", |
| | | $MESSAGE->headers->date, |
| | | htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset())); |
| | | $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">'; |
| | | $suffix = "</blockquote><p></p>"; |
| | | |
| | | rcmail_write_inline_attachments($MESSAGE); |
| | | } |
| | | |
| | | return $prefix.$body.$suffix; |
| | |
| | | function rcmail_create_forward_body($body, $bodyIsHtml) |
| | | { |
| | | global $IMAP, $MESSAGE, $OUTPUT; |
| | | |
| | | // add attachments |
| | | if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts)) |
| | | $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
| | | |
| | | if (!$bodyIsHtml) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | // set is_safe flag (we need this for html body washing) |
| | | rcmail_check_safe($MESSAGE); |
| | | // clean up html tags |
| | | $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map); |
| | | |
| | | $prefix = sprintf( |
| | | "<br><br>-------- Original Message --------" . |
| | | "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" . |
| | |
| | | |
| | | $prefix .= "</tbody></table><br>"; |
| | | } |
| | | |
| | | // add attachments |
| | | if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts)) |
| | | rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
| | | |
| | | return $prefix.$body; |
| | | } |
| | |
| | | |
| | | function rcmail_create_draft_body($body, $bodyIsHtml) |
| | | { |
| | | global $MESSAGE; |
| | | global $MESSAGE, $OUTPUT; |
| | | |
| | | /** |
| | | * add attachments |
| | |
| | | if (!isset($_SESSION['compose']['forward_attachments']) |
| | | && is_array($MESSAGE->mime_parts) |
| | | && count($MESSAGE->mime_parts) > 0) |
| | | rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
| | | { |
| | | $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml); |
| | | |
| | | // replace cid with href in inline images links |
| | | if ($cid_map) |
| | | $body = str_replace(array_keys($cid_map), array_values($cid_map), $body); |
| | | } |
| | | |
| | | return $body; |
| | | } |
| | | |
| | | |
| | | function rcmail_write_compose_attachments(&$message, $bodyIsHtml) |
| | | { |
| | | global $OUTPUT; |
| | | |
| | | $cid_map = array(); |
| | | 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 ($attachment = rcmail_save_attachment($message, $pid)) |
| | | $_SESSION['compose']['attachments'][] = $attachment; |
| | | if ($attachment = rcmail_save_attachment($message, $pid)) { |
| | | $_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']; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | $_SESSION['compose']['forward_attachments'] = true; |
| | | |
| | | return $cid_map; |
| | | } |
| | | |
| | | |
| | | function rcmail_write_inline_attachments(&$message) |
| | | { |
| | | foreach ((array)$message->mime_parts as $pid => $part) |
| | | { |
| | | if ($part->content_id && $part->filename) |
| | | { |
| | | if ($attachment = rcmail_save_attachment($message, $pid)) |
| | | $_SESSION['compose']['attachments'][] = $attachment; |
| | | global $OUTPUT; |
| | | |
| | | $cid_map = array(); |
| | | foreach ((array)$message->mime_parts as $pid => $part) { |
| | | if ($part->content_id && $part->filename) { |
| | | if ($attachment = rcmail_save_attachment($message, $pid)) { |
| | | $_SESSION['compose']['attachments'][$attachment['id']] = $attachment; |
| | | $cid_map['cid:'.$part->content_id] = $OUTPUT->app->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id']; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return $cid_map; |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | |
| | |
| | | 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')); |
| | | |
| | |
| | | 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'])); |
| | | } |
| | | } |
| | |
| | | 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); |