/**
  * Issue command to set page title
  *
  * @param string $title New page title
  */
 public function set_pagetitle($title)
 {
     if ($this->config->get('devel_mode') && !empty($_SESSION['username'])) {
         $name = $_SESSION['username'];
     } else {
         $name = $this->config->get('product_name');
     }
     $this->command('set_pagetitle', empty($name) ? $title : $name . ' :: ' . $title);
 }
Example #2
0
 /**
  * Decrypt 3DES-encrypted string
  *
  * @param string $cipher encrypted text
  * @param string $key encryption key to retrieve from the configuration, defaults to 'des_key'
  * @param boolean $base64 whether or not input is base64-encoded
  *
  * @return string decrypted text
  */
 public function decrypt($cipher, $key = 'des_key', $base64 = true)
 {
     if (!$cipher) {
         return '';
     }
     $cipher = $base64 ? base64_decode($cipher) : $cipher;
     if (function_exists('mcrypt_module_open') && ($td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_CBC, ""))) {
         $iv_size = mcrypt_enc_get_iv_size($td);
         $iv = substr($cipher, 0, $iv_size);
         // session corruption? (#1485970)
         if (strlen($iv) < $iv_size) {
             return '';
         }
         $cipher = substr($cipher, $iv_size);
         mcrypt_generic_init($td, $this->config->get_crypto_key($key), $iv);
         $clear = mdecrypt_generic($td, $cipher);
         mcrypt_generic_deinit($td);
         mcrypt_module_close($td);
     } else {
         @(include_once 'des.inc');
         if (function_exists('des')) {
             $des_iv_size = 8;
             $iv = substr($cipher, 0, $des_iv_size);
             $cipher = substr($cipher, $des_iv_size);
             $clear = des($this->config->get_crypto_key($key), $cipher, 0, 1, $iv);
         } else {
             self::raise_error(array('code' => 500, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Could not perform decryption; make sure Mcrypt is installed or lib/des.inc is available"), true, true);
         }
     }
     /*-
      * Trim PHP's padding and the canary byte; see note in
      * rcube::encrypt() and http://php.net/mcrypt_generic#68082
      */
     $clear = substr(rtrim($clear, ""), 0, -1);
     return $clear;
 }
Example #3
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)
  *
  * @return boolean Send status.
  */
 public function deliver_message(&$message, $from, $mailto, &$error, &$body_file = null, $options = null)
 {
     $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();
     // send thru SMTP server using custom SMTP library
     if ($this->config->get('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']);
         $smtp_headers = $message->txtHeaders($send_headers, true);
         if ($message->getParam('delay_file_io')) {
             // use common temp dir
             $temp_dir = $this->config->get('temp_dir');
             $body_file = tempnam($temp_dir, 'rcmMsg');
             if (PEAR::isError($mime_result = $message->saveMessageBody($body_file))) {
                 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();
         }
         // send message
         if (!is_object($this->smtp)) {
             $this->smtp_init(true);
         }
         $sent = $this->smtp->send_mail($from, $a_recipients, $smtp_headers, $msg_body, $options);
         $response = $this->smtp->get_response();
         $error = $this->smtp->get_error();
         // log error
         if (!$sent) {
             self::raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__, 'message' => join("\n", $response)), true, false);
         }
     } 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]);
             }
         }
         $msg_body = $message->get();
         if (PEAR::isError($msg_body)) {
             self::raise_error(array('code' => 650, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Could not create message: " . $msg_body->getMessage()), TRUE, FALSE);
         } else {
             $delim = $this->config->header_delimiter();
             $to = $headers_enc['To'];
             $subject = $headers_enc['Subject'];
             $header_str = rtrim($header_str);
             if ($delim != "\r\n") {
                 $header_str = str_replace("\r\n", $delim, $header_str);
                 $msg_body = str_replace("\r\n", $delim, $msg_body);
                 $to = str_replace("\r\n", $delim, $to);
                 $subject = str_replace("\r\n", $delim, $subject);
             }
             if (filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN)) {
                 $sent = mail($to, $subject, $msg_body, $header_str);
             } else {
                 $sent = mail($to, $subject, $msg_body, $header_str, "-f{$from}");
             }
         }
     }
     if ($sent) {
         $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
             if (is_array($mailto)) {
                 $mailto = implode(',', $mailto);
             }
             if ($headers['Cc']) {
                 $mailto .= ',' . $headers['Cc'];
             }
             if ($headers['Bcc']) {
                 $mailto .= ',' . $headers['Bcc'];
             }
             $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) : ''));
         }
     } else {
         // 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));
     }
     if (is_resource($msg_body)) {
         fclose($msg_body);
     }
     $message->_headers = array();
     $message->headers($headers);
     return $sent;
 }
Example #4
0
 |                                                                       |
 | This file is part of the RoundCube Webmail client                     |
 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Delete rows from cache and messages tables                          |
 |                                                                       |
 +-----------------------------------------------------------------------+
 | Author: Dennis P. Nikolaenko <*****@*****.**>                   |
 +-----------------------------------------------------------------------+
 $Id: killcache.php 2238 2009-01-17 03:27:41Z till $
*/
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/');
require INSTALL_PATH . 'program/include/iniset.php';
$config = new rcube_config();
// don't allow public access if not in devel_mode
if (!$config->get('devel_mode') && $_SERVER['REMOTE_ADDR']) {
    header("HTTP/1.0 401 Access denied");
    die("Access denied!");
}
$options = array('use_transactions' => false, 'log_line_break' => "\n", 'idxname_format' => '%s', 'debug' => false, 'quote_identifier' => true, 'force_defaults' => false, 'portability' => true);
$dbh = MDB2::factory($config->get('db_dsnw'), $options);
if (PEAR::isError($dbh)) {
    exit($mdb2->getMessage());
}
//TODO: transaction here (if supported by DB) would be a good thing
$res =& $dbh->exec("DELETE FROM cache");
if (PEAR::isError($res)) {
    $dbh->disconnect();
    exit($res->getMessage());
Example #5
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;
 }
Example #6
0
 /**
  * Issue command to set page title
  *
  * @param string $title New page title
  */
 public function set_pagetitle($title)
 {
     $name = $this->config->get('product_name');
     $this->command('set_pagetitle', empty($name) ? $title : $name . ' :: ' . $title);
 }
Example #7
0
<?php

/** start RoundCube specific code */
define('INSTALL_PATH', preg_replace('/program[\\\\\\/]js[\\\\\\/].+$/', '', getcwd()));
require_once INSTALL_PATH . 'program/include/iniset.php';
$rcmail_config = new rcube_config();
$config['general.engine'] = $rcmail_config->get('spellcheck_engine') == 'pspell' ? 'PSpell' : 'GoogleSpell';
$config['GoogleSpell.rpc_uri'] = $rcmail_config->get('spellcheck_uri');
/** end RoundCube specific code */
// General settings
//$config['general.engine'] = 'GoogleSpell';
//$config['general.engine'] = 'PSpell';
//$config['general.engine'] = 'PSpellShell';
//$config['general.remote_rpc_url'] = 'http://some.other.site/some/url/rpc.php';
// PSpell settings
$config['PSpell.mode'] = PSPELL_FAST;
$config['PSpell.spelling'] = "";
$config['PSpell.jargon'] = "";
$config['PSpell.encoding'] = "";
// PSpellShell settings
$config['PSpellShell.mode'] = PSPELL_FAST;
$config['PSpellShell.aspell'] = '/usr/bin/aspell';
$config['PSpellShell.tmp'] = '/tmp';
// Windows PSpellShell settings
//$config['PSpellShell.aspell'] = '"c:\Program Files\Aspell\bin\aspell.exe"';
//$config['PSpellShell.tmp'] = 'c:/temp';
Example #8
0
 /**
  * Fixes some user preferences according to namespace handling change.
  * Old Roundcube versions were using folder names with removed namespace prefix.
  * Now we need to add the prefix on servers where personal namespace has prefix.
  *
  * @param rcube_user $user User object
  */
 private function fix_namespace_settings($user)
 {
     $prefix = $this->imap->get_namespace('prefix');
     $prefix_len = strlen($prefix);
     if (!$prefix_len) {
         return;
     }
     $prefs = $this->config->all();
     if (!empty($prefs['namespace_fixed'])) {
         return;
     }
     // Build namespace prefix regexp
     $ns = $this->imap->get_namespace();
     $regexp = array();
     foreach ($ns as $entry) {
         if (!empty($entry)) {
             foreach ($entry as $item) {
                 if (strlen($item[0])) {
                     $regexp[] = preg_quote($item[0], '/');
                 }
             }
         }
     }
     $regexp = '/^(' . implode('|', $regexp) . ')/';
     // Fix preferences
     $opts = array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox', 'archive_mbox');
     foreach ($opts as $opt) {
         if ($value = $prefs[$opt]) {
             if ($value != 'INBOX' && !preg_match($regexp, $value)) {
                 $prefs[$opt] = $prefix . $value;
             }
         }
     }
     if (!empty($prefs['default_imap_folders'])) {
         foreach ($prefs['default_imap_folders'] as $idx => $name) {
             if ($name != 'INBOX' && !preg_match($regexp, $name)) {
                 $prefs['default_imap_folders'][$idx] = $prefix . $name;
             }
         }
     }
     if (!empty($prefs['search_mods'])) {
         $folders = array();
         foreach ($prefs['search_mods'] as $idx => $value) {
             if ($idx != 'INBOX' && $idx != '*' && !preg_match($regexp, $idx)) {
                 $idx = $prefix . $idx;
             }
             $folders[$idx] = $value;
         }
         $prefs['search_mods'] = $folders;
     }
     if (!empty($prefs['message_threading'])) {
         $folders = array();
         foreach ($prefs['message_threading'] as $idx => $value) {
             if ($idx != 'INBOX' && !preg_match($regexp, $idx)) {
                 $idx = $prefix . $idx;
             }
             $folders[$prefix . $idx] = $value;
         }
         $prefs['message_threading'] = $folders;
     }
     if (!empty($prefs['collapsed_folders'])) {
         $folders = explode('&&', $prefs['collapsed_folders']);
         $count = count($folders);
         $folders_str = '';
         if ($count) {
             $folders[0] = substr($folders[0], 1);
             $folders[$count - 1] = substr($folders[$count - 1], 0, -1);
         }
         foreach ($folders as $value) {
             if ($value != 'INBOX' && !preg_match($regexp, $value)) {
                 $value = $prefix . $value;
             }
             $folders_str .= '&' . $value . '&';
         }
         $prefs['collapsed_folders'] = $folders_str;
     }
     $prefs['namespace_fixed'] = true;
     // save updated preferences and reset imap settings (default folders)
     $user->save_prefs($prefs);
     $this->set_imap_prop();
 }