- rcmail::get_instance()->plugins->exec_hook('cleanup_attachments',array());
-
- rcube_sess_unset('compose');
- }
-
-
-/**
- * Send the given message compose object using the configured method
- */
-function rcmail_deliver_message(&$message, $from, $mailto, &$smtp_error)
-{
- global $CONFIG, $RCMAIL;
-
- $msg_body = $message->get();
- $headers = $message->headers();
-
- // send thru SMTP server using custom SMTP library
- if ($CONFIG['smtp_server']) {
- // generate list of recipients
- $a_recipients = array($mailto);
-
- if (strlen($headers['Cc']))
- $a_recipients[] = $headers['Cc'];
- if (strlen($headers['Bcc']))
- $a_recipients[] = $headers['Bcc'];
-
- // clean Bcc from header for recipients
- $send_headers = $headers;
- unset($send_headers['Bcc']);
- // here too, it because txtHeaders() below use $message->_headers not only $send_headers
- unset($message->_headers['Bcc']);
-
- // send message
- if (!is_object($RCMAIL->smtp))
- $RCMAIL->smtp_init(true);
-
- $sent = $RCMAIL->smtp->send_mail($from, $a_recipients, ($foo = $message->txtHeaders($send_headers, true)), $msg_body);
- $smtp_response = $RCMAIL->smtp->get_response();
- $smtp_error = $RCMAIL->smtp->get_error();
-
- // log error
- if (!$sent)
- raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__,
- 'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE);
- }
- // send mail using PHP's mail() function
- else {
- // unset some headers because they will be added by the mail() function
- $headers_enc = $message->headers($headers);
- $headers_php = $message->_headers;
- unset($headers_php['To'], $headers_php['Subject']);
-
- // reset stored headers and overwrite
- $message->_headers = array();
- $header_str = $message->txtHeaders($headers_php);
-
- // #1485779
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
- if (preg_match_all('/<([^@]+@[^>]+)>/', $headers_enc['To'], $m)) {
- $headers_enc['To'] = implode(', ', $m[1]);
- }
- }
-
- if (ini_get('safe_mode'))
- $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str);
- else
- $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from");
- }
-
- if ($sent) {
- $RCMAIL->plugins->exec_hook('message_sent', array('headers' => $headers, 'body' => $msg_body));
-
- // remove MDN headers after sending
- unset($headers['Return-Receipt-To'], $headers['Disposition-Notification-To']);
-
- if ($CONFIG['smtp_log']) {
- write_log('sendmail', sprintf("User %s [%s]; Message for %s; %s",
- $RCMAIL->user->get_username(),
- $_SERVER['REMOTE_ADDR'],
- $mailto,
- !empty($smtp_response) ? join('; ', $smtp_response) : ''));
- }
- }
-
- $message->_headers = array();
- $message->headers($headers);
-
- return $sent;