- Replace some references to rcmail with rcube
| | |
| | | |
| | | /* |
| | | +-----------------------------------------------------------------------+ |
| | | | program/include/rcmail.php | |
| | | | program/include/rcube.php | |
| | | | | |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2008-2012, The Roundcube Dev Team | |
| | |
| | | const INIT_WITH_PLUGINS = 2; |
| | | |
| | | /** |
| | | * Singleton instace of rcmail |
| | | * Singleton instace of rcube |
| | | * |
| | | * @var rcmail |
| | | */ |
| | |
| | | /** |
| | | * This implements the 'singleton' design pattern |
| | | * |
| | | * @return rcmail The one and only instance |
| | | * @return rcube The one and only instance |
| | | */ |
| | | static function get_instance() |
| | | { |
| | |
| | | |
| | | /*- |
| | | * Trim PHP's padding and the canary byte; see note in |
| | | * rcmail::encrypt() and http://php.net/mcrypt_generic#68082 |
| | | * rcube::encrypt() and http://php.net/mcrypt_generic#68082 |
| | | */ |
| | | $clear = substr(rtrim($clear, "\0"), 0, -1); |
| | | |
| | |
| | | { |
| | | $args = func_get_args(); |
| | | |
| | | if (class_exists('rcmail', false)) { |
| | | if (class_exists('rcube', false)) { |
| | | $rcube = self::get_instance(); |
| | | if (is_object($rcube->plugins)) { |
| | | $plugin = $rcube->plugins->exec_hook('console', array('args' => $args)); |
| | | if ($plugin['abort']) { |
| | | return; |
| | | } |
| | | $args = $plugin['args']; |
| | | $plugin = $rcube->plugins->exec_hook('console', array('args' => $args)); |
| | | if ($plugin['abort']) { |
| | | return; |
| | | } |
| | | $args = $plugin['args']; |
| | | } |
| | | |
| | | $msg = array(); |
| | |
| | | */ |
| | | function __construct($type, $userid, $prefix='', $ttl=0, $packed=true) |
| | | { |
| | | $rcmail = rcube::get_instance(); |
| | | $type = strtolower($type); |
| | | $rcube = rcube::get_instance(); |
| | | $type = strtolower($type); |
| | | |
| | | if ($type == 'memcache') { |
| | | $this->type = 'memcache'; |
| | | $this->db = $rcmail->get_memcache(); |
| | | $this->db = $rcube->get_memcache(); |
| | | } |
| | | else if ($type == 'apc') { |
| | | $this->type = 'apc'; |
| | |
| | | } |
| | | else { |
| | | $this->type = 'db'; |
| | | $this->db = $rcmail->get_dbh(); |
| | | $this->db = $rcube->get_dbh(); |
| | | } |
| | | |
| | | $this->userid = (int) $userid; |
| | |
| | | $result = $def; |
| | | } |
| | | |
| | | $rcmail = rcube::get_instance(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | if ($name == 'timezone' && isset($this->prop['_timezone_value'])) |
| | | $result = $this->prop['_timezone_value']; |
| | | |
| | | if (is_object($rcmail->plugins)) { |
| | | $plugin = $rcmail->plugins->exec_hook('config_get', array( |
| | | 'name' => $name, 'default' => $def, 'result' => $result)); |
| | | $plugin = $rcube->plugins->exec_hook('config_get', array( |
| | | 'name' => $name, 'default' => $def, 'result' => $result)); |
| | | |
| | | return $plugin['result']; |
| | | } |
| | | |
| | | return $result; |
| | | return $plugin['result']; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public function resize($size, $filename = null) |
| | | { |
| | | $result = false; |
| | | $rcmail = rcmail::get_instance(); |
| | | $convert = $rcmail->config->get('im_convert_path', false); |
| | | $props = $this->props(); |
| | | $result = false; |
| | | $rcube = rcube::get_instance(); |
| | | $convert = $rcmail->config->get('im_convert_path', false); |
| | | $props = $this->props(); |
| | | |
| | | if (!$filename) { |
| | | $filename = $this->image_file; |
| | |
| | | $p['-opts'] = array('-resize' => $size.'>'); |
| | | |
| | | if (in_array($type, explode(',', $p['types']))) { // Valid type? |
| | | $result = rcmail::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p) === ''; |
| | | $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p) === ''; |
| | | } |
| | | |
| | | if ($result) { |
| | |
| | | */ |
| | | private function identify() |
| | | { |
| | | $rcmail = rcmail::get_instance(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | if ($cmd = $rcmail->config->get('im_identify_path')) { |
| | | if ($cmd = $rcube->config->get('im_identify_path')) { |
| | | $args = array('in' => $this->image_file, 'format' => "%m %[fx:w] %[fx:h]"); |
| | | $id = rcmail::exec($cmd. ' 2>/dev/null -format {format} {in}', $args); |
| | | $id = rcube::exec($cmd. ' 2>/dev/null -format {format} {in}', $args); |
| | | |
| | | if ($id) { |
| | | return explode(' ', strtolower($id)); |
| | |
| | | } |
| | | |
| | | // Give plugins a chance to provide a list of folders |
| | | $data = rcmail::get_instance()->plugins->exec_hook('storage_folders', |
| | | $data = rcube::get_instance()->plugins->exec_hook('storage_folders', |
| | | array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LIST')); |
| | | |
| | | if (isset($data['folders'])) { |
| | |
| | | /** |
| | | * Enable or disable indexes caching |
| | | * |
| | | * @param string $type Cache type (@see rcmail::get_cache) |
| | | * @param string $type Cache type (@see rcube::get_cache) |
| | | */ |
| | | public function set_caching($type) |
| | | { |
| | |
| | | protected function get_cache_engine() |
| | | { |
| | | if ($this->caching && !$this->cache) { |
| | | $rcmail = rcube::get_instance(); |
| | | $ttl = $rcmail->config->get('message_cache_lifetime', '10d') - mktime(); |
| | | $this->cache = $rcmail->get_cache('IMAP', $this->caching, $ttl); |
| | | $rcube = rcube::get_instance(); |
| | | $ttl = $rcube->config->get('message_cache_lifetime', '10d') - mktime(); |
| | | $this->cache = $rcube->get_cache('IMAP', $this->caching, $ttl); |
| | | } |
| | | |
| | | return $this->cache; |
| | |
| | | public function expunge_cache() |
| | | { |
| | | if ($this->mcache) { |
| | | $ttl = rcmail::get_instance()->config->get('message_cache_lifetime', '10d'); |
| | | $ttl = rcube::get_instance()->config->get('message_cache_lifetime', '10d'); |
| | | $this->mcache->expunge($ttl); |
| | | } |
| | | |
| | |
| | | protected function get_mcache_engine() |
| | | { |
| | | if ($this->messages_caching && !$this->mcache) { |
| | | $rcmail = rcube::get_instance(); |
| | | if ($dbh = $rcmail->get_dbh()) { |
| | | $rcube = rcube::get_instance(); |
| | | if ($dbh = $rcube->get_dbh()) { |
| | | $this->mcache = new rcube_imap_cache( |
| | | $dbh, $this, $rcmail->get_user_id(), $this->options['skip_deleted']); |
| | | $dbh, $this, $rcube->get_user_id(), $this->options['skip_deleted']); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public function debug_handler(&$imap, $message) |
| | | { |
| | | rcmail::write_log('imap', $message); |
| | | rcube::write_log('imap', $message); |
| | | } |
| | | |
| | | |
| | |
| | | $this->mail_domain = $mail_domain; |
| | | |
| | | // initialize cache |
| | | $rcmail = rcmail::get_instance(); |
| | | $this->cache = $rcmail->get_cache('LDAP.' . asciiwords($this->prop['name']), 'db', 600); |
| | | $rcube = rcube::get_instance(); |
| | | $this->cache = $rcube->get_cache('LDAP.' . asciiwords($this->prop['name']), 'db', 600); |
| | | |
| | | $this->_connect(); |
| | | } |
| | |
| | | */ |
| | | private function _connect() |
| | | { |
| | | $RCMAIL = rcmail::get_instance(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | if (!function_exists('ldap_connect')) |
| | | rcube::raise_error(array('code' => 100, 'type' => 'ldap', |
| | |
| | | |
| | | foreach ($this->prop['hosts'] as $host) |
| | | { |
| | | $host = idn_to_ascii(rcube_utils::parse_host($host)); |
| | | $host = rcube_utils::idn_to_ascii(rcube_utils::parse_host($host)); |
| | | $hostname = $host.($this->prop['port'] ? ':'.$this->prop['port'] : ''); |
| | | |
| | | $this->_debug("C: Connect [$hostname] [{$this->prop['name']}]"); |
| | |
| | | if ($this->prop['user_specific']) { |
| | | // No password set, use the session password |
| | | if (empty($bind_pass)) { |
| | | $bind_pass = $RCMAIL->decrypt($_SESSION['password']); |
| | | $bind_pass = $rcube->decrypt($_SESSION['password']); |
| | | } |
| | | |
| | | // Get the pieces needed for variable replacement. |
| | | if ($fu = $RCMAIL->get_user_name()) |
| | | if ($fu = $rcube->get_user_name()) |
| | | list($u, $d) = explode('@', $fu); |
| | | else |
| | | $d = $this->mail_domain; |
| | |
| | | private function _debug($str) |
| | | { |
| | | if ($this->debug) { |
| | | rcmail::write_log('ldap', $str); |
| | | rcube::write_log('ldap', $str); |
| | | } |
| | | } |
| | | |
| | |
| | | if ($scope != 'prepare') { |
| | | $debug_output = sprintf('%s(%d): %s;', |
| | | $scope, $db->db_index, rtrim($message, ';')); |
| | | rcmail::write_log('sql', $debug_output); |
| | | rcube::write_log('sql', $debug_output); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public function table_name($table) |
| | | { |
| | | $rcmail = rcube::get_instance(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | // return table name if configured |
| | | $config_key = 'db_table_'.$table; |
| | | |
| | | if ($name = $rcmail->config->get($config_key)) { |
| | | if ($name = $rcube->config->get($config_key)) { |
| | | return $name; |
| | | } |
| | | |
| | |
| | | */ |
| | | public function sequence_name($sequence) |
| | | { |
| | | $rcmail = rcube::get_instance(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | // return sequence name if configured |
| | | $config_key = 'db_sequence_'.$sequence; |
| | | |
| | | if ($name = $rcmail->config->get($config_key)) { |
| | | if ($name = $rcube->config->get($config_key)) { |
| | | return $name; |
| | | } |
| | | |
| | |
| | | class rcube_message |
| | | { |
| | | /** |
| | | * Instace of rcmail. |
| | | * Instace of framework class. |
| | | * |
| | | * @var rcmail |
| | | * @var rcube |
| | | */ |
| | | private $app; |
| | | |
| | |
| | | self::$default_charset = $default_charset; |
| | | } |
| | | else { |
| | | self::$default_charset = rcmail::get_instance()->config->get('default_charset', RCMAIL_CHARSET); |
| | | self::$default_charset = rcube::get_instance()->config->get('default_charset', RCMAIL_CHARSET); |
| | | } |
| | | } |
| | | |
| | |
| | | array($this, 'file_callback'), $output); |
| | | |
| | | // trigger hook with final HTML content to be sent |
| | | $hook = rcmail::get_instance()->plugins->exec_hook("send_page", array('content' => $output)); |
| | | $hook = $this->app->plugins->exec_hook("send_page", array('content' => $output)); |
| | | if (!$hook['abort']) { |
| | | if ($this->charset != RCMAIL_CHARSET) { |
| | | echo rcube_charset::convert($hook['content'], RCMAIL_CHARSET, $this->charset); |
| | |
| | | */ |
| | | public function redirect($p = array(), $delay = 1) |
| | | { |
| | | $location = rcmail::get_instance()->url($p); |
| | | $location = $this->app->url($p); |
| | | $this->remote_response(sprintf("window.setTimeout(function(){ %s.redirect('%s',true); }, %d);", |
| | | rcmail::JS_OBJECT_NAME, $location, $delay)); |
| | | exit; |
| | |
| | | public function load_config($fname = 'config.inc.php') |
| | | { |
| | | $fpath = $this->home.'/'.$fname; |
| | | $rcmail = rcube::get_instance(); |
| | | if (is_file($fpath) && !$rcmail->config->load_from_file($fpath)) { |
| | | $rcube = rcube::get_instance(); |
| | | if (is_file($fpath) && !$rcube->config->load_from_file($fpath)) { |
| | | rcube::raise_error(array( |
| | | 'code' => 527, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | |
| | | foreach ($texts as $key => $value) |
| | | $add[$domain.'.'.$key] = $value; |
| | | |
| | | $rcmail = rcube::get_instance(); |
| | | $rcmail = rcmail::get_instance(); |
| | | $rcmail->load_language($lang, $add); |
| | | |
| | | // add labels to client |
| | |
| | | |
| | | // use memcache backend |
| | | if ($config->get('session_storage', 'db') == 'memcache') { |
| | | $this->memcache = rcmail::get_instance()->get_memcache(); |
| | | $this->memcache = rcube::get_instance()->get_memcache(); |
| | | |
| | | // set custom functions for PHP session management if memcache is available |
| | | if ($this->memcache) { |
| | |
| | | function log($line) |
| | | { |
| | | if ($this->logging) |
| | | rcmail::write_log('session', $line); |
| | | rcube::write_log('session', $line); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | public function connect($host=null, $port=null, $user=null, $pass=null) |
| | | { |
| | | $RCMAIL = rcube::get_instance(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | // disconnect/destroy $this->conn |
| | | $this->disconnect(); |
| | |
| | | $this->error = $this->response = null; |
| | | |
| | | // let plugins alter smtp connection config |
| | | $CONFIG = $RCMAIL->plugins->exec_hook('smtp_connect', array( |
| | | 'smtp_server' => $host ? $host : $RCMAIL->config->get('smtp_server'), |
| | | 'smtp_port' => $port ? $port : $RCMAIL->config->get('smtp_port', 25), |
| | | 'smtp_user' => $user ? $user : $RCMAIL->config->get('smtp_user'), |
| | | 'smtp_pass' => $pass ? $pass : $RCMAIL->config->get('smtp_pass'), |
| | | 'smtp_auth_cid' => $RCMAIL->config->get('smtp_auth_cid'), |
| | | 'smtp_auth_pw' => $RCMAIL->config->get('smtp_auth_pw'), |
| | | 'smtp_auth_type' => $RCMAIL->config->get('smtp_auth_type'), |
| | | 'smtp_helo_host' => $RCMAIL->config->get('smtp_helo_host'), |
| | | 'smtp_timeout' => $RCMAIL->config->get('smtp_timeout'), |
| | | $CONFIG = $rcube->plugins->exec_hook('smtp_connect', array( |
| | | 'smtp_server' => $host ? $host : $rcube->config->get('smtp_server'), |
| | | 'smtp_port' => $port ? $port : $rcube->config->get('smtp_port', 25), |
| | | 'smtp_user' => $user ? $user : $rcube->config->get('smtp_user'), |
| | | 'smtp_pass' => $pass ? $pass : $rcube->config->get('smtp_pass'), |
| | | 'smtp_auth_cid' => $rcube->config->get('smtp_auth_cid'), |
| | | 'smtp_auth_pw' => $rcube->config->get('smtp_auth_pw'), |
| | | 'smtp_auth_type' => $rcube->config->get('smtp_auth_type'), |
| | | 'smtp_helo_host' => $rcube->config->get('smtp_helo_host'), |
| | | 'smtp_timeout' => $rcube->config->get('smtp_timeout'), |
| | | 'smtp_auth_callbacks' => array(), |
| | | )); |
| | | |
| | |
| | | |
| | | $this->conn = new Net_SMTP($smtp_host, $smtp_port, $helo_host); |
| | | |
| | | if ($RCMAIL->config->get('smtp_debug')) |
| | | if ($rcube->config->get('smtp_debug')) |
| | | $this->conn->setDebug(true, array($this, 'debug_handler')); |
| | | |
| | | // register authentication methods |
| | |
| | | } |
| | | |
| | | $smtp_user = str_replace('%u', $_SESSION['username'], $CONFIG['smtp_user']); |
| | | $smtp_pass = str_replace('%p', $RCMAIL->decrypt($_SESSION['password']), $CONFIG['smtp_pass']); |
| | | $smtp_pass = str_replace('%p', $rcube->decrypt($_SESSION['password']), $CONFIG['smtp_pass']); |
| | | $smtp_auth_type = empty($CONFIG['smtp_auth_type']) ? NULL : $CONFIG['smtp_auth_type']; |
| | | |
| | | if (!empty($CONFIG['smtp_auth_cid'])) { |
| | |
| | | */ |
| | | public function debug_handler(&$smtp, $message) |
| | | { |
| | | rcmail::write_log('smtp', preg_replace('/\r\n$/', '', $message)); |
| | | rcube::write_log('smtp', preg_replace('/\r\n$/', '', $message)); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | function __construct($lang = 'en') |
| | | { |
| | | $this->rc = rcmail::get_instance(); |
| | | $this->rc = rcube::get_instance(); |
| | | $this->engine = $this->rc->config->get('spellcheck_engine', 'googie'); |
| | | $this->lang = $lang ? $lang : 'en'; |
| | | |
| | |
| | | private $db; |
| | | |
| | | /** |
| | | * rcmail object. |
| | | * Framework object. |
| | | * |
| | | * @var rcmail |
| | | * @var rcube |
| | | */ |
| | | private $rc; |
| | | |
| | |
| | | */ |
| | | function __construct($id = null, $sql_arr = null) |
| | | { |
| | | $this->rc = rcmail::get_instance(); |
| | | $this->rc = rcube::get_instance(); |
| | | $this->db = $this->rc->get_dbh(); |
| | | |
| | | if ($id && !$sql_arr) { |
| | |
| | | */ |
| | | static function query($user, $host) |
| | | { |
| | | $dbh = rcmail::get_instance()->get_dbh(); |
| | | $dbh = rcube::get_instance()->get_dbh(); |
| | | |
| | | // query for matching user name |
| | | $query = "SELECT * FROM ".$dbh->table_name('users')." WHERE mail_host = ? AND %s = ?"; |
| | |
| | | { |
| | | $user_name = ''; |
| | | $user_email = ''; |
| | | $rcmail = rcmail::get_instance(); |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | // try to resolve user in virtuser table and file |
| | | if ($email_list = self::user2email($user, false, true)) { |
| | | $user_email = is_array($email_list[0]) ? $email_list[0]['email'] : $email_list[0]; |
| | | } |
| | | |
| | | $data = $rcmail->plugins->exec_hook('user_create', |
| | | $data = $rcube->plugins->exec_hook('user_create', |
| | | array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email, 'host'=>$host)); |
| | | |
| | | // plugin aborted this operation |
| | |
| | | $user_name = $data['user_name']; |
| | | $user_email = $data['user_email']; |
| | | |
| | | $dbh = $rcmail->get_dbh(); |
| | | $dbh = $rcube->get_dbh(); |
| | | |
| | | $dbh->query( |
| | | "INSERT INTO ".$dbh->table_name('users'). |
| | |
| | | if ($user_id = $dbh->insert_id('users')) { |
| | | // create rcube_user instance to make plugin hooks work |
| | | $user_instance = new rcube_user($user_id); |
| | | $rcmail->user = $user_instance; |
| | | $rcube->user = $user_instance; |
| | | |
| | | $mail_domain = $rcmail->config->mail_domain($host); |
| | | $mail_domain = $rcube->config->mail_domain($host); |
| | | |
| | | if ($user_email == '') { |
| | | $user_email = strpos($user, '@') ? $user : sprintf('%s@%s', $user, $mail_domain); |
| | |
| | | if (empty($email_list)) |
| | | $email_list[] = strip_newlines($user_email); |
| | | // identities_level check |
| | | else if (count($email_list) > 1 && $rcmail->config->get('identities_level', 0) > 1) |
| | | else if (count($email_list) > 1 && $rcube->config->get('identities_level', 0) > 1) |
| | | $email_list = array($email_list[0]); |
| | | |
| | | // create new identities records |
| | |
| | | $record['user_id'] = $user_id; |
| | | $record['standard'] = $standard; |
| | | |
| | | $plugin = $rcmail->plugins->exec_hook('identity_create', |
| | | $plugin = $rcube->plugins->exec_hook('identity_create', |
| | | array('login' => true, 'record' => $record)); |
| | | |
| | | if (!$plugin['abort'] && $plugin['record']['email']) { |
| | | $rcmail->user->insert_identity($plugin['record']); |
| | | $rcube->user->insert_identity($plugin['record']); |
| | | } |
| | | $standard = 0; |
| | | } |
| | |
| | | */ |
| | | static function email2user($email) |
| | | { |
| | | $rcmail = rcmail::get_instance(); |
| | | $plugin = $rcmail->plugins->exec_hook('email2user', |
| | | $rcube = rcube::get_instance(); |
| | | $plugin = $rcube->plugins->exec_hook('email2user', |
| | | array('email' => $email, 'user' => NULL)); |
| | | |
| | | return $plugin['user']; |
| | |
| | | */ |
| | | static function user2email($user, $first=true, $extended=false) |
| | | { |
| | | $rcmail = rcmail::get_instance(); |
| | | $plugin = $rcmail->plugins->exec_hook('user2email', |
| | | $rcube = rcube::get_instance(); |
| | | $plugin = $rcube->plugins->exec_hook('user2email', |
| | | array('email' => NULL, 'user' => $user, |
| | | 'first' => $first, 'extended' => $extended)); |
| | | |