alecpl
2008-10-08 acff900c5a3a7c89faaf1141eff706ec221a4dd3
program/steps/mail/sendmail.inc
@@ -21,16 +21,37 @@
*/
if (!isset($_SESSION['compose']['id']))
  {
// remove all scripts and act as called in frame
$OUTPUT->reset();
$OUTPUT->framed = TRUE;
$savedraft = !empty($_POST['_draft']) ? TRUE : FALSE;
/****** checks ********/
if (!isset($_SESSION['compose']['id'])) {
  raise_error(array('code' => 500, 'file' => __FILE__, 'message' => "Invalid compose ID"), true, false);
  rcmail_overwrite_action('compose');
  return;
  }
  console("Sendmail error", $_SESSION['compose']);
  $OUTPUT->show_message("An internal error occured. Please try again.", 'error');
  $OUTPUT->send('iframe');
}
if (!$savedraft && empty($_POST['_to']) && empty($_POST['_cc']) && empty($_POST['_bcc']) && empty($_POST['_subject']) && $_POST['_message']) {
  $OUTPUT->show_message('sendingfailed', 'error');
  $OUTPUT->send('iframe');
}
if(!$savedraft && !empty($CONFIG['sendmail_delay'])) {
  $wait_sec = time() - intval($CONFIG['sendmail_delay']) - intval($_SESSION['last_message_time']);
  if($wait_sec < 0)
    {
    $OUTPUT->show_message('senttooquickly', 'error', array('sec' => $wait_sec * -1));
    $OUTPUT->send('iframe');
    }
}
/****** message sending functions ********/
// get identity record
function rcmail_get_identity($id)
@@ -42,9 +63,10 @@
    $out = $sql_arr;
    $out['mailto'] = $sql_arr['email'];
    $name = strpos($sql_arr['name'], ",") ? '"'.$sql_arr['name'].'"' : $sql_arr['name'];
    $out['string'] = sprintf('%s <%s>',
                             rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset()),
                             $sql_arr['email']);
    $out['string'] = rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset());
    if ($sql_arr['email'])
      $out['string'] .= ' <' . $sql_arr['email'] . '>';
    return $out;
    }
@@ -111,36 +133,22 @@
  $mime_message->setHTMLBody($body);
}
/****** compose message ********/
if (strlen($_POST['_draft_saveid']) > 3)
  $olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST);
$message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host']));
$savedraft = !empty($_POST['_draft']) ? TRUE : FALSE;
// remove all scripts and act as called in frame
$OUTPUT->reset();
$OUTPUT->framed = TRUE;
/****** check submission and compose message ********/
if (!$savedraft && empty($_POST['_to']) && empty($_POST['_cc']) && empty($_POST['_bcc']) && empty($_POST['_subject']) && $_POST['_message'])
  {
  $OUTPUT->show_message("sendingfailed", 'error');
  $OUTPUT->send('iframe');
  return;
  }
// set default charset
$input_charset = $OUTPUT->get_charset();
$message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset;
$mailto_regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/');
$mailto_replace = array(', ', ', ', '', ',');
$mailto_regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<\S+@\S+>)/U');
$mailto_replace = array(', ', ', ', '', ',', '\\1 \\2');
// replace new lines and strip ending ', '
// replace new lines and strip ending ', ', make address strings more valid also
$mailto = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset));
$mailcc = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset));
$mailbcc = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset));
@@ -153,8 +161,11 @@
  $mailto = 'undisclosed-recipients:;';
// get sender name and address
$identity_arr = rcmail_get_identity(get_input_value('_from', RCUBE_INPUT_POST));
$from = $identity_arr['mailto'];
$from = get_input_value('_from', RCUBE_INPUT_POST);
$identity_arr = rcmail_get_identity($from);
if ($identity_arr)
  $from = $identity_arr['mailto'];
if (empty($identity_arr['string']))
  $identity_arr['string'] = $from;
@@ -297,7 +308,10 @@
        $attachment['name'], true, 
        ($ctype == 'message/rfc822' ? $transfer_encoding : 'base64'),
        ($ctype == 'message/rfc822' ? 'inline' : 'attachment'),
        $message_charset);
        $message_charset, '', '',
   $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
   $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
   );
    }
  }
@@ -309,8 +323,11 @@
    $ctype = str_replace('image/pjpeg', 'image/jpeg', $ctype); // #1484914
    
    $MAIL_MIME->addAttachment($filepath, $ctype, $files['name'][$i], true,
   ($ctype == 'message/rfc822' ? $transfer_encoding : 'base64'),
   'attachment', $message_charset);
   $ctype == 'message/rfc822' ? $transfer_encoding : 'base64',
   'attachment', $message_charset, '', '',
   $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
   $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
   );
    }
@@ -338,6 +355,12 @@
// Begin SMTP Delivery Block 
if (!$savedraft)
{
  // check for 'From' address (identity may be incomplete)
  if ($identity_arr && !$identity_arr['mailto']) {
    $OUTPUT->show_message('nofromaddress', 'error');
    $OUTPUT->send('iframe');
  }
  $sent = rcmail_deliver_message($MAIL_MIME, $from, $mailto);
  
  // return to compose page if sending failed
@@ -345,8 +368,11 @@
    {
    $OUTPUT->show_message("sendingfailed", 'error'); 
    $OUTPUT->send('iframe');
    return;
    }
  // save message sent time
  if (!empty($CONFIG['sendmail_delay']))
    $_SESSION['last_message_time'] = time();
  
  // set replied/forwarded flag
  if ($_SESSION['compose']['reply_uid'])