pull/160/head
Aleksander Machniak 11 years ago
parent 14ace838c1
commit 0f16a0353c

@ -5,7 +5,7 @@
| program/steps/mail/sendmail.inc |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2011, The Roundcube Dev Team |
| Copyright (C) 2005-2013, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@ -25,6 +25,8 @@ $OUTPUT->reset();
$OUTPUT->framed = TRUE;
$savedraft = !empty($_POST['_draft']) ? true : false;
$sendmail_delay = (int) $RCMAIL->config->get('sendmail_delay');
$drafts_mbox = $RCMAIL->config->get('drafts_mbox');
$COMPOSE_ID = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
$COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
@ -42,13 +44,14 @@ if (!isset($COMPOSE['id'])) {
if (!$savedraft) {
if (empty($_POST['_to']) && empty($_POST['_cc']) && empty($_POST['_bcc'])
&& empty($_POST['_subject']) && $_POST['_message']) {
&& empty($_POST['_subject']) && $_POST['_message']
) {
$OUTPUT->show_message('sendingfailed', 'error');
$OUTPUT->send('iframe');
}
if(!empty($CONFIG['sendmail_delay'])) {
$wait_sec = time() - intval($CONFIG['sendmail_delay']) - intval($CONFIG['last_message_time']);
if ($sendmail_delay) {
$wait_sec = time() - $sendmail_delay - intval($RCMAIL->config->get('last_message_time'));
if ($wait_sec < 0) {
$OUTPUT->show_message('senttooquickly', 'error', array('sec' => $wait_sec * -1));
$OUTPUT->send('iframe');
@ -62,10 +65,12 @@ if (!$savedraft) {
// encrypt parts of the header
function rcmail_encrypt_header($what)
{
global $CONFIG, $RCMAIL;
if (!$CONFIG['http_received_header_encrypt']) {
global $RCMAIL;
if (!$RCMAIL->config->get('http_received_header_encrypt')) {
return $what;
}
return $RCMAIL->encrypt($what);
}
@ -73,15 +78,15 @@ function rcmail_encrypt_header($what)
function rcmail_get_identity($id)
{
global $RCMAIL, $message_charset;
global $RCMAIL;
if ($sql_arr = $RCMAIL->user->get_identity($id)) {
$out = $sql_arr;
if ($message_charset != RCUBE_CHARSET) {
foreach ($out as $k => $v)
foreach ($out as $k => $v) {
$out[$k] = rcube_charset::convert($v, RCUBE_CHARSET, $message_charset);
}
}
$out['mailto'] = $sql_arr['email'];
$out['string'] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
@ -89,7 +94,7 @@ function rcmail_get_identity($id)
return $out;
}
return FALSE;
return false;
}
/**
@ -130,6 +135,7 @@ function rcmail_fix_emoticon_paths($mime_message)
if (!$mime_message->addHTMLImage($img_file, 'image/gif', '', true, $image_name)) {
$RCMAIL->output->show_message("emoticonerror", 'error');
}
array_push($included_images, $image_name);
}
@ -210,22 +216,23 @@ function rcmail_email_input_format($mailto, $count=false, $check=true)
// replace new lines and strip ending ', ', make address input more valid
$mailto = trim(preg_replace($regexp, $replace, $mailto));
$result = array();
$items = rcube_utils::explode_quoted_string($delim, $mailto);
$result = array();
foreach($items as $item) {
foreach ($items as $item) {
$item = trim($item);
// address in brackets without name (do nothing)
if (preg_match('/^<'.$email_regexp.'>$/', $item)) {
$item = rcube_utils::idn_to_ascii(trim($item, '<>'));
$result[] = $item;
}
// address without brackets and without name (add brackets)
} else if (preg_match('/^'.$email_regexp.'$/', $item)) {
else if (preg_match('/^'.$email_regexp.'$/', $item)) {
$item = rcube_utils::idn_to_ascii($item);
$result[] = $item;
}
// address with name (handle name)
} else if (preg_match('/<*'.$email_regexp.'>*$/', $item, $matches)) {
else if (preg_match('/<*'.$email_regexp.'>*$/', $item, $matches)) {
$address = $matches[0];
$name = trim(str_replace($address, '', $item));
if ($name[0] == '"' && $name[count($name)-1] == '"') {
@ -235,7 +242,8 @@ function rcmail_email_input_format($mailto, $count=false, $check=true)
$address = rcube_utils::idn_to_ascii(trim($address, '<>'));
$result[] = format_email_recipient($address, $name);
$item = $address;
} else if (trim($item)) {
}
else if (trim($item)) {
continue;
}
@ -257,14 +265,13 @@ function rcmail_email_input_format($mailto, $count=false, $check=true)
function rcmail_generic_message_footer($isHtml)
{
global $CONFIG;
global $RCMAIL;
if ($isHtml && !empty($CONFIG['generic_message_footer_html'])) {
$file = $CONFIG['generic_message_footer_html'];
if ($isHtml && ($file = $RCMAIL->config->get('generic_message_footer_html'))) {
$html_footer = true;
}
else {
$file = $CONFIG['generic_message_footer'];
$file = $RCMAIL->config->get('generic_message_footer');
$html_footer = false;
}
@ -272,8 +279,9 @@ function rcmail_generic_message_footer($isHtml)
// sanity check
if (!preg_match('/\.(php|ini|conf)$/', $file) && strpos($file, '/etc/') === false) {
$footer = file_get_contents($file);
if ($isHtml && !$html_footer)
if ($isHtml && !$html_footer) {
$footer = '<pre>' . $footer . '</pre>';
}
return $footer;
}
}
@ -308,8 +316,9 @@ if (empty($mailto) && !empty($mailcc)) {
$mailto = $mailcc;
$mailcc = null;
}
else if (empty($mailto))
else if (empty($mailto)) {
$mailto = 'undisclosed-recipients:;';
}
// Get sender name and address...
$from = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST, true, $message_charset);
@ -333,46 +342,55 @@ else if ($from_string = rcmail_email_input_format($from)) {
$from = null;
}
if (!$from_string && $from)
if (!$from_string && $from) {
$from_string = $from;
}
// compose headers array
$headers = array();
// if configured, the Received headers goes to top, for good measure
if ($CONFIG['http_received_header'])
{
if ($RCMAIL->config->get('http_received_header')) {
$nldlm = "\r\n\t";
$encrypt = $RCMAIL->config->get('http_received_header_encrypt');
// FROM/VIA
$http_header = 'from ';
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
$hostname = gethostbyaddr($hosts[0]);
if ($CONFIG['http_received_header_encrypt']) {
if ($encrypt) {
$http_header .= rcmail_encrypt_header($hostname);
if ($host != $hostname)
$http_header .= ' ('. rcmail_encrypt_header($host) . ')';
} else {
}
else {
$http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']');
if ($host != $hostname)
$http_header .= ' (['. $host .'])';
}
$http_header .= $nldlm . ' via ';
}
$host = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($host);
if ($CONFIG['http_received_header_encrypt']) {
if ($encrypt) {
$http_header .= rcmail_encrypt_header($hostname);
if ($host != $hostname)
$http_header .= ' ('. rcmail_encrypt_header($host) . ')';
} else {
}
else {
$http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']');
if ($host != $hostname)
$http_header .= ' (['. $host .'])';
}
// BY
$http_header .= $nldlm . 'by ' . $_SERVER['HTTP_HOST'];
// WITH
$http_header .= $nldlm . 'with HTTP (' . $_SERVER['SERVER_PROTOCOL'] .
' '.$_SERVER['REQUEST_METHOD'] . '); ' . date('r');
@ -406,14 +424,14 @@ $headers['Subject'] = trim(rcube_utils::get_input_value('_subject', rcube_utils:
if (!empty($identity_arr['organization'])) {
$headers['Organization'] = $identity_arr['organization'];
}
if (!empty($_POST['_replyto'])) {
$headers['Reply-To'] = rcmail_email_input_format(rcube_utils::get_input_value('_replyto', rcube_utils::INPUT_POST, TRUE, $message_charset));
if ($hdr = rcube_utils::get_input_value('_replyto', rcube_utils::INPUT_POST, TRUE, $message_charset)) {
$headers['Reply-To'] = rcmail_email_input_format($hdr);
}
if (!empty($headers['Reply-To'])) {
$headers['Mail-Reply-To'] = $headers['Reply-To'];
}
if (!empty($_POST['_followupto'])) {
$headers['Mail-Followup-To'] = rcmail_email_input_format(rcube_utils::get_input_value('_followupto', rcube_utils::INPUT_POST, TRUE, $message_charset));
if ($hdr = rcube_utils::get_input_value('_followupto', rcube_utils::INPUT_POST, TRUE, $message_charset)) {
$headers['Mail-Followup-To'] = rcmail_email_input_format();
}
// remember reply/forward UIDs in special headers
@ -433,7 +451,8 @@ if (!empty($COMPOSE['references'])) {
if (!empty($_POST['_priority'])) {
$priority = intval($_POST['_priority']);
$a_priorities = array(1=>'highest', 2=>'high', 4=>'low', 5=>'lowest');
$a_priorities = array(1 => 'highest', 2 => 'high', 4 => 'low', 5 => 'lowest');
if ($str_priority = $a_priorities[$priority]) {
$headers['X-Priority'] = sprintf("%d (%s)", $priority, ucfirst($str_priority));
}
@ -451,8 +470,8 @@ $headers['X-Sender'] = $from;
if (is_array($headers['X-Draft-Info'])) {
$headers['X-Draft-Info'] = rcmail_draftinfo_encode($headers['X-Draft-Info'] + array('folder' => $COMPOSE['mailbox']));
}
if (!empty($CONFIG['useragent'])) {
$headers['User-Agent'] = $CONFIG['useragent'];
if ($hdr = $RCMAIL->config->get('useragent')) {
$headers['User-Agent'] = $hdr;
}
// exec hook for header checking and manipulation
@ -464,9 +483,9 @@ if ($data['abort'] && !$savedraft) {
$OUTPUT->show_message($data['message'] ? $data['message'] : 'sendingfailed');
$OUTPUT->send('iframe');
}
else
else {
$headers = $data['headers'];
}
$isHtml = (bool) rcube_utils::get_input_value('_is_html', rcube_utils::INPUT_POST);
@ -501,7 +520,7 @@ if (!$savedraft) {
}
// Check spelling before send
if ($CONFIG['spellcheck_before_send'] && $CONFIG['enable_spellcheck']
if ($RCMAIL->config->get('spellcheck_before_send') && $RCMAIL->config->get('enable_spellcheck')
&& empty($COMPOSE['spell_checked']) && !empty($message_body)
) {
$message_body = str_replace("\r\n", "\n", $message_body);
@ -512,6 +531,7 @@ if (!$savedraft) {
if (!$spell_result) {
$result = $isHtml ? $spellchecker->get_words() : $spellchecker->get_xml();
$OUTPUT->show_message('mispellingsfound', 'error');
$OUTPUT->command('spellcheck_resume', $isHtml, $result);
$OUTPUT->send('iframe');
@ -530,8 +550,7 @@ if ($isHtml) {
}
// sort attachments to make sure the order is the same as in the UI (#1488423)
$files = rcube_utils::get_input_value('_attachments', rcube_utils::INPUT_POST);
if ($files) {
if ($files = rcube_utils::get_input_value('_attachments', rcube_utils::INPUT_POST)) {
$files = explode(',', $files);
$files = array_flip($files);
foreach ($files as $idx => $val) {
@ -553,22 +572,22 @@ $MAIL_MIME = new Mail_mime("\r\n");
// Check if we have enough memory to handle the message in it
// It's faster than using files, so we'll do this if we only can
if (is_array($COMPOSE['attachments']) && $CONFIG['smtp_server']
&& ($mem_limit = parse_bytes(ini_get('memory_limit'))))
{
$memory = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB
foreach ($COMPOSE['attachments'] as $id => $attachment)
if (is_array($COMPOSE['attachments']) && $RCMAIL->config->get('smtp_server')
&& ($mem_limit = parse_bytes(ini_get('memory_limit')))
) {
$memory = 0;
foreach ($COMPOSE['attachments'] as $id => $attachment) {
$memory += $attachment['size'];
}
// Yeah, Net_SMTP needs up to 12x more memory, 1.33 is for base64
if ($memory * 1.33 * 12 > $mem_limit)
if (!rcube_utils::mem_check($memory * 1.33 * 12)) {
$MAIL_MIME->setParam('delay_file_io', true);
}
}
// For HTML-formatted messages, construct the MIME message with both
// the HTML part and the plain-text part
if ($isHtml) {
$plugin = $RCMAIL->plugins->exec_hook('message_outgoing_body',
array('body' => $message_body, 'type' => 'html', 'message' => $MAIL_MIME));
@ -622,7 +641,8 @@ if (is_array($COMPOSE['attachments'])) {
$attachment = $RCMAIL->plugins->exec_hook('attachment_get', $attachment);
if ($isHtml) {
$dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]*/';
$dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile'
. preg_quote($attachment['id']) . '[\s\'"]*/';
$message_body = $MAIL_MIME->getHTMLBody();
$is_inline = preg_match($dispurl, $message_body);
}
@ -637,7 +657,8 @@ if (is_array($COMPOSE['attachments'])) {
$cid = preg_replace('/[^0-9a-zA-Z]/', '', uniqid(time(), true));
if (preg_match('#(@[0-9a-zA-Z\-\.]+)#', $from, $matches)) {
$cid .= $matches[1];
} else {
}
else {
$cid .= '@localhost';
}
@ -653,16 +674,17 @@ if (is_array($COMPOSE['attachments'])) {
else {
$ctype = str_replace('image/pjpeg', 'image/jpeg', $attachment['mimetype']); // #1484914
$file = $attachment['data'] ? $attachment['data'] : $attachment['path'];
$folding = (int) $RCMAIL->config->get('mime_param_folding');
$MAIL_MIME->addAttachment($file,
$ctype,
$attachment['name'],
($attachment['data'] ? false : true),
($ctype == 'message/rfc822' ? '8bit' : 'base64'),
$attachment['data'] ? false : true,
$ctype == 'message/rfc822' ? '8bit' : 'base64',
'attachment',
'', '', '',
$CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
$CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL,
$folding ? 'quoted-printable' : NULL,
$folding == 2 ? 'quoted-printable' : NULL,
'', RCUBE_CHARSET
);
}
@ -707,8 +729,7 @@ if (function_exists('mb_encode_mimeheader')) {
$MAIL_MIME->headers($headers);
// Begin SMTP Delivery Block
if (!$savedraft)
{
if (!$savedraft) {
// check 'From' address (identity may be incomplete)
if (empty($from)) {
$OUTPUT->show_message('nofromaddress', 'error');
@ -738,33 +759,40 @@ if (!$savedraft)
}
// save message sent time
if (!empty($CONFIG['sendmail_delay']))
if ($sendmail_delay) {
$RCMAIL->user->save_prefs(array('last_message_time' => time()));
}
// set replied/forwarded flag
if ($COMPOSE['reply_uid'])
$RCMAIL->storage->set_flag($COMPOSE['reply_uid'], 'ANSWERED', $COMPOSE['mailbox']);
else if ($COMPOSE['forward_uid'])
$RCMAIL->storage->set_flag($COMPOSE['forward_uid'], 'FORWARDED', $COMPOSE['mailbox']);
} // End of SMTP Delivery Block
}
// Determine which folder to save message
if ($savedraft)
$store_target = $CONFIG['drafts_mbox'];
else if (!$RCMAIL->config->get('no_save_sent_messages'))
$store_target = isset($_POST['_store_target']) ? rcube_utils::get_input_value('_store_target', rcube_utils::INPUT_POST) : $CONFIG['sent_mbox'];
if ($savedraft) {
$store_target = $drafts_mbox;
}
else if (!$RCMAIL->config->get('no_save_sent_messages')) {
$store_target = rcube_utils::get_input_value('_store_target', rcube_utils::INPUT_POST);
if (!strlen($store_target)) {
$sore_target = $RCMAIL->config->get('sent_mbox');
}
}
if ($store_target) {
// check if folder is subscribed
if ($RCMAIL->storage->folder_exists($store_target, true))
if ($RCMAIL->storage->folder_exists($store_target, true)) {
$store_folder = true;
}
// folder may be existing but not subscribed (#1485241)
else if (!$RCMAIL->storage->folder_exists($store_target))
else if (!$RCMAIL->storage->folder_exists($store_target)) {
$store_folder = $RCMAIL->storage->create_folder($store_target, true);
else if ($RCMAIL->storage->subscribe($store_target))
}
else if ($RCMAIL->storage->subscribe($store_target)) {
$store_folder = true;
}
// append message to sent box
if ($store_folder) {
@ -773,25 +801,29 @@ if ($store_target) {
$headers = $MAIL_MIME->txtHeaders();
// file already created
if ($mailbody_file)
if ($mailbody_file) {
$msg = $mailbody_file;
}
else {
$temp_dir = $RCMAIL->config->get('temp_dir');
$mailbody_file = tempnam($temp_dir, 'rcmMsg');
if (!PEAR::isError($msg = $MAIL_MIME->saveMessageBody($mailbody_file)))
if (!PEAR::isError($msg = $MAIL_MIME->saveMessageBody($mailbody_file))) {
$msg = $mailbody_file;
}
}
}
else {
$msg = $MAIL_MIME->getMessage();
$headers = '';
}
if (PEAR::isError($msg))
if (PEAR::isError($msg)) {
rcube::raise_error(array('code' => 650, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Could not create message: ".$msg->getMessage()),
TRUE, FALSE);
true, false);
}
else {
$saved = $RCMAIL->storage->save_message($store_target, $msg, $headers,
$mailbody_file ? true : false, array('SEEN'));
@ -807,7 +839,7 @@ if ($store_target) {
if (!$saved) {
rcube::raise_error(array('code' => 800, 'type' => 'imap',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Could not save message in $store_target"), TRUE, FALSE);
'message' => "Could not save message in $store_target"), true, false);
if ($savedraft) {
$OUTPUT->show_message('errorsaving', 'error');
@ -817,15 +849,16 @@ if ($store_target) {
}
}
if ($saved && ($old_id = rcube_utils::get_input_value('_draft_saveid', rcube_utils::INPUT_POST))) {
// delete previous saved draft
$deleted = $RCMAIL->storage->delete_message($old_id, $CONFIG['drafts_mbox']);
if ($saved && ($old_id = rcube_utils::get_input_value('_draft_saveid', rcube_utils::INPUT_POST))) {
$deleted = $RCMAIL->storage->delete_message($old_id, $drafts_mbox);
// raise error if deletion of old draft failed
if (!$deleted)
if (!$deleted) {
rcube::raise_error(array('code' => 800, 'type' => 'imap',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Could not delete message from ".$CONFIG['drafts_mbox']), TRUE, FALSE);
'message' => "Could not delete message from $drafts_mbox"), true, false);
}
}
}
// remove temp file
@ -837,7 +870,7 @@ else if ($mailbody_file) {
if ($savedraft) {
// remember new draft-uid ($saved could be an UID or true/false here)
if ($saved && is_bool($saved)) {
$index = $RCMAIL->storage->search_once($CONFIG['drafts_mbox'], 'HEADER Message-ID ' . $message_id);
$index = $RCMAIL->storage->search_once($drafts_mbox, 'HEADER Message-ID ' . $message_id);
$saved = @max($index->get());
}
@ -860,21 +893,21 @@ if ($savedraft) {
else {
$folders = array();
if ($COMPOSE['mode'] == 'reply' || $COMPOSE['mode'] == 'forward')
if ($COMPOSE['mode'] == 'reply' || $COMPOSE['mode'] == 'forward') {
$folders[] = $COMPOSE['mailbox'];
}
rcmail_compose_cleanup($COMPOSE_ID);
$OUTPUT->command('remove_compose_data', $COMPOSE_ID);
if ($store_folder && !$saved)
if ($store_folder && !$saved) {
$OUTPUT->command('sent_successfully', 'error', $RCMAIL->gettext('errorsavingsent'), $folders);
else {
if ($store_folder) {
}
else if ($store_folder) {
$folders[] = $store_target;
}
$OUTPUT->command('sent_successfully', 'confirmation', $RCMAIL->gettext('messagesent'), $folders);
}
}
$OUTPUT->send('iframe');

@ -5,7 +5,7 @@
| program/steps/mail/sendmdn.inc |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2008-2009, The Roundcube Dev Team |
| Copyright (C) 2008-2013, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@ -20,8 +20,9 @@
*/
// only process ajax requests
if (!$OUTPUT->ajax_call)
if (!$OUTPUT->ajax_call) {
return;
}
if (!empty($_POST['_uid'])) {
$sent = rcmail_send_mdn(rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST), $smtp_error);

Loading…
Cancel
Save