Aleksander Machniak
2013-12-29 0f16a0353cdf37d7808c97449ce936b435c20261
CS fixes
2 files modified
198 ■■■■■ changed files
program/steps/mail/sendmail.inc 193 ●●●●● patch | view | raw | blame | history
program/steps/mail/sendmdn.inc 5 ●●●●● patch | view | raw | blame | history
program/steps/mail/sendmail.inc
@@ -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->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 (!$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 @@
// 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,14 +78,14 @@
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'];
@@ -89,7 +94,7 @@
    return $out;
  }
  return FALSE;
    return false;
}
/**
@@ -130,6 +135,7 @@
          if (!$mime_message->addHTMLImage($img_file, 'image/gif', '', true, $image_name)) {
            $RCMAIL->output->show_message("emoticonerror", 'error');
          }
          array_push($included_images, $image_name);
        }
@@ -210,9 +216,8 @@
  // 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) {
    $item = trim($item);
@@ -220,12 +225,14 @@
    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 @@
      $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_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 @@
    // 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 @@
  $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 @@
    $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 @@
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
@@ -434,6 +452,7 @@
if (!empty($_POST['_priority'])) {
  $priority = intval($_POST['_priority']);
  $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 @@
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 @@
  $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 @@
  }
  // 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 (!$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 @@
}
// 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 @@
// 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 @@
    $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 @@
      $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 @@
    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 @@
$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 @@
  }
  // 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,13 +801,16 @@
      $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 {
@@ -787,11 +818,12 @@
      $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 (!$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 ($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 @@
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 @@
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');
program/steps/mail/sendmdn.inc
@@ -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);