Beispiel #1
0
 /**
  * Function to be executed in script shutdown
  * Registered with register_shutdown_function()
  */
 public function shutdown()
 {
     if (is_object($this->imap)) {
         $this->imap->close();
     }
     if (is_object($this->smtp)) {
         $this->smtp->disconnect();
     }
     foreach ($this->books as $book) {
         if (is_object($book)) {
             $book->close();
         }
     }
     // before closing the database connection, write session data
     if ($_SERVER['REMOTE_ADDR']) {
         session_write_close();
     }
     // write performance stats to logs/console
     if ($this->config->get('devel_mode')) {
         if (function_exists('memory_get_usage')) {
             $mem = show_bytes(memory_get_usage());
         }
         if (function_exists('memory_get_peak_usage')) {
             $mem .= '/' . show_bytes(memory_get_peak_usage());
         }
         $log = $this->task . ($this->action ? '/' . $this->action : '') . ($mem ? " [{$mem}]" : '');
         if (defined('RCMAIL_START')) {
             rcube_print_time(RCMAIL_START, $log);
         } else {
             console($log);
         }
     }
 }
Beispiel #2
0
 /**
  * Function to be executed in script shutdown
  * Registered with register_shutdown_function()
  */
 public function shutdown()
 {
     foreach ($this->shutdown_functions as $function) {
         call_user_func($function);
     }
     if (is_object($this->smtp)) {
         $this->smtp->disconnect();
     }
     foreach ($this->address_books as $book) {
         if (is_object($book) && is_a($book, 'rcube_addressbook')) {
             $book->close();
         }
     }
     foreach ($this->caches as $cache) {
         if (is_object($cache)) {
             $cache->close();
         }
     }
     if (is_object($this->storage)) {
         if ($this->expunge_cache) {
             $this->storage->expunge_cache();
         }
         $this->storage->close();
     }
     // before closing the database connection, write session data
     if ($_SERVER['REMOTE_ADDR'] && is_object($this->session)) {
         session_write_close();
     }
     // write performance stats to logs/console
     if ($this->config->get('devel_mode')) {
         if (function_exists('memory_get_usage')) {
             $mem = show_bytes(memory_get_usage());
         }
         if (function_exists('memory_get_peak_usage')) {
             $mem .= '/' . show_bytes(memory_get_peak_usage());
         }
         $log = $this->task . ($this->action ? '/' . $this->action : '') . ($mem ? " [{$mem}]" : '');
         if (defined('RCMAIL_START')) {
             rcube_print_time(RCMAIL_START, $log);
         } else {
             console($log);
         }
     }
 }
Beispiel #3
0
 /**
  * Function to be executed in script shutdown
  * Registered with register_shutdown_function()
  */
 public function shutdown()
 {
     foreach ($this->shutdown_functions as $function) {
         call_user_func($function);
     }
     if (is_object($this->smtp)) {
         $this->smtp->disconnect();
     }
     foreach ($this->caches as $cache) {
         if (is_object($cache)) {
             $cache->close();
         }
     }
     if (is_object($this->storage)) {
         if ($this->expunge_cache) {
             $this->storage->expunge_cache();
         }
         $this->storage->close();
     }
 }
Beispiel #4
0
 /**
  * When you're going to sleep the script execution for a longer time
  * it is good to close all external connections (sql, memcache, SMTP, IMAP).
  *
  * No action is required on wake up, all connections will be
  * re-established automatically.
  */
 public function sleep()
 {
     foreach ($this->caches as $cache) {
         if (is_object($cache)) {
             $cache->close();
         }
     }
     if ($this->storage) {
         $this->storage->close();
     }
     if ($this->db) {
         $this->db->closeConnection();
     }
     if ($this->memcache) {
         $this->memcache->close();
         // after close() need to re-init memcache
         $this->memcache_init();
     }
     if ($this->smtp) {
         $this->smtp->disconnect();
     }
 }
Beispiel #5
0
 /**
  * Function to be executed in script shutdown
  * Registered with register_shutdown_function()
  */
 public function shutdown()
 {
     foreach ($this->shutdown_functions as $function) {
         call_user_func($function);
     }
     // write session data as soon as possible and before
     // closing database connection, don't do this before
     // registered shutdown functions, they may need the session
     // Note: this will run registered gc handlers (ie. cache gc)
     if ($_SERVER['REMOTE_ADDR'] && is_object($this->session)) {
         $this->session->write_close();
     }
     if (is_object($this->smtp)) {
         $this->smtp->disconnect();
     }
     foreach ($this->caches as $cache) {
         if (is_object($cache)) {
             $cache->close();
         }
     }
     if (is_object($this->storage)) {
         $this->storage->close();
     }
 }
Beispiel #6
0
 /**
  * Send the given message using the configured method.
  *
  * @param object $message   Reference to Mail_MIME object
  * @param string $from      Sender address string
  * @param array  $mailto    Array of recipient address strings
  * @param array  $error     SMTP error array (reference)
  * @param string $body_file Location of file with saved message body (reference),
  *                          used when delay_file_io is enabled
  * @param array  $options   SMTP options (e.g. DSN request)
  * @param bool   $disconnect Close SMTP connection ASAP
  *
  * @return boolean Send status.
  */
 public function deliver_message(&$message, $from, $mailto, &$error, &$body_file = null, $options = null, $disconnect = false)
 {
     $plugin = $this->plugins->exec_hook('message_before_send', array('message' => $message, 'from' => $from, 'mailto' => $mailto, 'options' => $options));
     if ($plugin['abort']) {
         if (!empty($plugin['error'])) {
             $error = $plugin['error'];
         }
         if (!empty($plugin['body_file'])) {
             $body_file = $plugin['body_file'];
         }
         return isset($plugin['result']) ? $plugin['result'] : false;
     }
     $from = $plugin['from'];
     $mailto = $plugin['mailto'];
     $options = $plugin['options'];
     $message = $plugin['message'];
     $headers = $message->headers();
     // generate list of recipients
     $a_recipients = (array) $mailto;
     if (strlen($headers['Cc'])) {
         $a_recipients[] = $headers['Cc'];
     }
     if (strlen($headers['Bcc'])) {
         $a_recipients[] = $headers['Bcc'];
     }
     // remove Bcc header and get the whole head of the message as string
     $smtp_headers = $message->txtHeaders(array('Bcc' => null), true);
     if ($message->getParam('delay_file_io')) {
         // use common temp dir
         $temp_dir = $this->config->get('temp_dir');
         $body_file = tempnam($temp_dir, 'rcmMsg');
         $mime_result = $message->saveMessageBody($body_file);
         if (is_a($mime_result, 'PEAR_Error')) {
             self::raise_error(array('code' => 650, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Could not create message: " . $mime_result->getMessage()), true, false);
             return false;
         }
         $msg_body = fopen($body_file, 'r');
     } else {
         $msg_body = $message->get();
     }
     // initialize SMTP connection
     if (!is_object($this->smtp)) {
         $this->smtp_init(true);
     }
     // send message
     $sent = $this->smtp->send_mail($from, $a_recipients, $smtp_headers, $msg_body, $options);
     $response = $this->smtp->get_response();
     $error = $this->smtp->get_error();
     if (!$sent) {
         self::raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__, 'message' => join("\n", $response)), true, false);
         // allow plugins to catch sending errors with the same parameters as in 'message_before_send'
         $this->plugins->exec_hook('message_send_error', $plugin + array('error' => $error));
     } else {
         $this->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 ($this->config->get('smtp_log')) {
             // get all recipient addresses
             $mailto = implode(',', $a_recipients);
             $mailto = rcube_mime::decode_address_list($mailto, null, false, null, true);
             self::write_log('sendmail', sprintf("User %s [%s]; Message for %s; %s", $this->user->get_username(), rcube_utils::remote_addr(), implode(', ', $mailto), !empty($response) ? join('; ', $response) : ''));
         }
     }
     if (is_resource($msg_body)) {
         fclose($msg_body);
     }
     if ($disconnect) {
         $this->smtp->disconnect();
     }
     $message->headers($headers, true);
     return $sent;
 }