alecpl
2010-09-30 13ffa2810eaef30a0f69fc3af6ecbb5bc9dd0bdc
program/steps/mail/sendmail.inc
@@ -4,8 +4,8 @@
 +-----------------------------------------------------------------------+
 | program/steps/mail/sendmail.inc                                       |
 |                                                                       |
 | This file is part of the RoundCube Webmail client                     |
 | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland                 |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2010, Roundcube Dev. - Switzerland                 |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
@@ -60,8 +60,7 @@
function rcmail_encrypt_header($what)
{
  global $CONFIG, $RCMAIL;
  if (!$CONFIG['http_received_header_encrypt'])
  {
  if (!$CONFIG['http_received_header_encrypt']) {
    return $what;
  }
  return $RCMAIL->encrypt($what);
@@ -69,29 +68,20 @@
// get identity record
function rcmail_get_identity($id)
  {
{
  global $USER, $OUTPUT;
  
  if ($sql_arr = $USER->get_identity($id))
    {
  if ($sql_arr = $USER->get_identity($id)) {
    $out = $sql_arr;
    $out['mailto'] = $sql_arr['email'];
    // Special chars as defined by RFC 822 need to in quoted string (or escaped).
    if (preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $sql_arr['name']))
      $name = '"' . addcslashes($sql_arr['name'], '"') . '"';
    else
      $name = $sql_arr['name'];
    $out['string'] = rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset());
    if ($sql_arr['email'])
      $out['string'] .= ' <' . $sql_arr['email'] . '>';
    $out['string'] = format_email_recipient($sql_arr['email'],
      rcube_charset_convert($sql_arr['name'], RCMAIL_CHARSET, $OUTPUT->get_charset()));
    return $out;
    }
  return FALSE;
  }
  return FALSE;
}
/**
 * go from this:
@@ -146,7 +136,7 @@
}
// parse email address input (and count addresses)
function rcmail_email_input_format($mailto, $count=false)
function rcmail_email_input_format($mailto, $count=false, $check=true)
{
  global $EMAIL_FORMAT_ERROR, $RECIPIENT_COUNT;
@@ -163,9 +153,11 @@
    $item = trim($item);
    // address in brackets without name (do nothing)
    if (preg_match('/^<\S+@\S+>$/', $item)) {
      $item = idn_to_ascii($item);
      $result[] = $item;
    // address without brackets and without name (add brackets)
    } else if (preg_match('/^\S+@\S+$/', $item)) {
      $item = idn_to_ascii($item);
      $result[] = '<'.$item.'>';
    // address with name (handle name)
    } else if (preg_match('/\S+@\S+>*$/', $item, $matches)) {
@@ -176,6 +168,7 @@
          && preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $name)) {
     $name = '"'.addcslashes($name, '"').'"';
      }
      $address = idn_to_ascii($address);
      if (!preg_match('/^<\S+@\S+>$/', $address))
        $address = '<'.$address.'>';
@@ -187,7 +180,7 @@
    // check address format
    $item = trim($item, '<>');
    if ($item && !check_email($item)) {
    if ($item && $check && !check_email($item)) {
      $EMAIL_FORMAT_ERROR = $item;
      return;
    }
@@ -205,7 +198,7 @@
if (strlen($_POST['_draft_saveid']) > 3)
  $olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST);
$message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.mt_rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host']));
$message_id = rcmail_gen_message_id();
// set default charset
$input_charset = $OUTPUT->get_charset();
@@ -287,7 +280,7 @@
  $headers['Received'] = $http_header;
}
$headers['Date'] = date('r');
$headers['Date'] = rcmail_user_date();
$headers['From'] = rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset);
$headers['To'] = $mailto;
@@ -297,7 +290,7 @@
if (!empty($mailbcc))
  $headers['Bcc'] = $mailbcc;
if (!empty($identity_arr['bcc'])) {
  $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc'];
  $RECIPIENT_COUNT ++;
@@ -319,11 +312,11 @@
if (!empty($_POST['_replyto']))
  $headers['Reply-To'] = rcmail_email_input_format(get_input_value('_replyto', RCUBE_INPUT_POST, TRUE, $message_charset));
else if (!empty($identity_arr['reply-to']))
  $headers['Reply-To'] = $identity_arr['reply-to'];
  $headers['Reply-To'] = rcmail_email_input_format($identity_arr['reply-to'], false, true);
if (!empty($_SESSION['compose']['reply_msgid']))
  $headers['In-Reply-To'] = $_SESSION['compose']['reply_msgid'];
// remember reply/forward UIDs in special headers
if (!empty($_SESSION['compose']['reply_uid']) && $savedraft)
  $headers['X-Draft-Info'] = array('type' => 'reply', 'uid' => $_SESSION['compose']['reply_uid']);
@@ -358,7 +351,7 @@
  $headers['User-Agent'] = $CONFIG['useragent'];
// exec hook for header checking and manipulation
$data = $RCMAIL->plugins->exec_hook('outgoing_message_headers', array('headers' => $headers));
$data = $RCMAIL->plugins->exec_hook('message_outgoing_headers', array('headers' => $headers));
// sending aborted by plugin
if ($data['abort'] && !$savedraft) {
@@ -428,7 +421,7 @@
// the HTML part and the plain-text part
if ($isHtml) {
  $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body',
  $plugin = $RCMAIL->plugins->exec_hook('message_outgoing_body',
    array('body' => $message_body, 'type' => 'html', 'message' => $MAIL_MIME));
  $MAIL_MIME->setHTMLBody($plugin['body']);
@@ -446,7 +439,7 @@
    $plainTextPart = preg_replace('/\r?\n/', "\r\n", $plainTextPart);
  }
  $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body',
  $plugin = $RCMAIL->plugins->exec_hook('message_outgoing_body',
    array('body' => $plainTextPart, 'type' => 'alternative', 'message' => $MAIL_MIME));
  $MAIL_MIME->setTXTBody($plugin['body']);
@@ -456,14 +449,14 @@
  $message_body = rcmail_fix_emoticon_paths($MAIL_MIME);
}
else {
  $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body',
  $plugin = $RCMAIL->plugins->exec_hook('message_outgoing_body',
    array('body' => $message_body, 'type' => 'plain', 'message' => $MAIL_MIME));
  $message_body = $plugin['body'];
  // compose format=flowed content if enabled and not a reply message
  if (empty($_SESSION['compose']['reply_msgid']) && ($flowed = $RCMAIL->config->get('send_format_flowed', true)))
    $message_body = rcube_message::format_flowed($message_body, $LINE_LENGTH);
  // compose format=flowed content if enabled
  if ($flowed = $RCMAIL->config->get('send_format_flowed', true))
    $message_body = rcube_message::format_flowed($message_body, min($LINE_LENGTH+2, 79));
  else
    $message_body = rc_wordwrap($message_body, $LINE_LENGTH, "\r\n");
@@ -481,7 +474,7 @@
{
  foreach ($_SESSION['compose']['attachments'] as $id => $attachment) {
    // This hook retrieves the attachment contents from the file storage backend
    $attachment = $RCMAIL->plugins->exec_hook('get_attachment', $attachment);
    $attachment = $RCMAIL->plugins->exec_hook('attachment_get', $attachment);
    $dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]*/';
    $message_body = $MAIL_MIME->getHTMLBody();
@@ -695,4 +688,4 @@
  $OUTPUT->send('iframe');
  }
?>