summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube
diff options
context:
space:
mode:
Diffstat (limited to 'program/lib/Roundcube')
-rw-r--r--program/lib/Roundcube/bootstrap.php6
-rw-r--r--program/lib/Roundcube/rcube.php15
-rw-r--r--program/lib/Roundcube/rcube_addressbook.php28
-rw-r--r--program/lib/Roundcube/rcube_cache.php6
-rw-r--r--program/lib/Roundcube/rcube_cache_shared.php6
-rw-r--r--program/lib/Roundcube/rcube_config.php1
-rw-r--r--program/lib/Roundcube/rcube_contacts.php114
-rw-r--r--program/lib/Roundcube/rcube_db.php2
-rw-r--r--program/lib/Roundcube/rcube_db_mysql.php25
-rw-r--r--program/lib/Roundcube/rcube_db_pgsql.php4
-rw-r--r--program/lib/Roundcube/rcube_ldap.php67
-rw-r--r--program/lib/Roundcube/rcube_ldap_generic.php43
-rw-r--r--program/lib/Roundcube/rcube_mime.php2
-rw-r--r--program/lib/Roundcube/rcube_plugin_api.php91
-rw-r--r--program/lib/Roundcube/rcube_smtp.php15
-rw-r--r--program/lib/Roundcube/rcube_utils.php24
-rw-r--r--program/lib/Roundcube/rcube_vcard.php4
-rw-r--r--program/lib/Roundcube/rcube_washtml.php15
18 files changed, 307 insertions, 161 deletions
diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php
index 24c1f86d4..0c950dc14 100644
--- a/program/lib/Roundcube/bootstrap.php
+++ b/program/lib/Roundcube/bootstrap.php
@@ -78,9 +78,11 @@ if (!defined('RCUBE_LOCALIZATION_DIR')) {
}
// set internal encoding for mbstring extension
-if (extension_loaded('mbstring')) {
+if (function_exists('mb_internal_encoding')) {
mb_internal_encoding(RCUBE_CHARSET);
- @mb_regex_encoding(RCUBE_CHARSET);
+}
+if (function_exists('mb_regex_encoding')) {
+ mb_regex_encoding(RCUBE_CHARSET);
}
// make sure the Roundcube lib directory is in the include_path
diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php
index a7c6b9317..3d081539f 100644
--- a/program/lib/Roundcube/rcube.php
+++ b/program/lib/Roundcube/rcube.php
@@ -1672,15 +1672,18 @@ class rcube
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))) {
+ $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);
+ true, false);
return false;
}
+
$msg_body = fopen($body_file, 'r');
}
else {
@@ -1723,11 +1726,11 @@ class rcube
$msg_body = $message->get();
- if (PEAR::isError($msg_body)) {
+ if (is_a($msg_body, 'PEAR_Error')) {
self::raise_error(array('code' => 650, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Could not create message: ".$msg_body->getMessage()),
- TRUE, FALSE);
+ true, false);
}
else {
$delim = $this->config->header_delimiter();
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php
index 69027b0e8..31189e0fc 100644
--- a/program/lib/Roundcube/rcube_addressbook.php
+++ b/program/lib/Roundcube/rcube_addressbook.php
@@ -544,13 +544,20 @@ abstract class rcube_addressbook
$fn = trim($fn, ', ');
- // fallback to display name
- if (empty($fn) && $contact['name'])
- $fn = $contact['name'];
-
- // fallback to email address
- if (empty($fn) && ($email = self::get_col_values('email', $contact, true)) && !empty($email)) {
- return $email[0];
+ // fallbacks...
+ if ($fn === '') {
+ // ... display name
+ if (!empty($contact['name'])) {
+ $fn = $contact['name'];
+ }
+ // ... organization
+ else if (!empty($contact['organization'])) {
+ $fn = $contact['organization'];
+ }
+ // ... email address
+ else if (($email = self::get_col_values('email', $contact, true)) && !empty($email)) {
+ $fn = $email[0];
+ }
}
return $fn;
@@ -587,6 +594,13 @@ abstract class rcube_addressbook
switch ($key) {
case 'name':
$value = $name ?: self::compose_list_name($contact);
+
+ // If name(s) are undefined compose_list_name() may return an email address
+ // here we prevent from returning the same name and email
+ if ($name === $email && strpos($result, '{email}') !== false) {
+ $value = '';
+ }
+
break;
case 'email':
diff --git a/program/lib/Roundcube/rcube_cache.php b/program/lib/Roundcube/rcube_cache.php
index 52a2db997..303abdac4 100644
--- a/program/lib/Roundcube/rcube_cache.php
+++ b/program/lib/Roundcube/rcube_cache.php
@@ -605,8 +605,10 @@ class rcube_cache
$this->max_packet = 2097152; // default/max is 2 MB
if ($this->type == 'db') {
- $value = $this->db->get_variable('max_allowed_packet', $this->max_packet);
- $this->max_packet = max($value, $this->max_packet) - 2000;
+ if ($value = $this->db->get_variable('max_allowed_packet', $this->max_packet)) {
+ $this->max_packet = $value;
+ }
+ $this->max_packet -= 2000;
}
else if ($this->type == 'memcache') {
$stats = $this->db->getStats();
diff --git a/program/lib/Roundcube/rcube_cache_shared.php b/program/lib/Roundcube/rcube_cache_shared.php
index 339a9aa20..3f0f20e41 100644
--- a/program/lib/Roundcube/rcube_cache_shared.php
+++ b/program/lib/Roundcube/rcube_cache_shared.php
@@ -595,8 +595,10 @@ class rcube_cache_shared
$this->max_packet = 2097152; // default/max is 2 MB
if ($this->type == 'db') {
- $value = $this->db->get_variable('max_allowed_packet', 1048500);
- $this->max_packet = min($value, $this->max_packet) - 2000;
+ if ($value = $this->db->get_variable('max_allowed_packet', $this->max_packet)) {
+ $this->max_packet = $value;
+ }
+ $this->max_packet -= 2000;
}
else if ($this->type == 'memcache') {
$stats = $this->db->getStats();
diff --git a/program/lib/Roundcube/rcube_config.php b/program/lib/Roundcube/rcube_config.php
index 89e45449d..e80474af2 100644
--- a/program/lib/Roundcube/rcube_config.php
+++ b/program/lib/Roundcube/rcube_config.php
@@ -683,7 +683,6 @@ class rcube_config
'180' => "Europe/Moscow",
'210' => "Asia/Tehran",
'240' => "Asia/Dubai",
- '300' => "Asia/Karachi",
'270' => "Asia/Kabul",
'300' => "Asia/Karachi",
'330' => "Asia/Kolkata",
diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php
index 6ac9fd5de..6438c431a 100644
--- a/program/lib/Roundcube/rcube_contacts.php
+++ b/program/lib/Roundcube/rcube_contacts.php
@@ -302,8 +302,6 @@ class rcube_contacts extends rcube_addressbook
*/
function search($fields, $value, $mode=0, $select=true, $nocount=false, $required=array())
{
- if (!is_array($fields))
- $fields = array($fields);
if (!is_array($required) && !empty($required))
$required = array($required);
@@ -312,36 +310,19 @@ class rcube_contacts extends rcube_addressbook
$WS = ' ';
$AS = self::SEPARATOR;
- foreach ($fields as $idx => $col) {
- // direct ID search
- if ($col == 'ID' || $col == $this->primary_key) {
- $ids = !is_array($value) ? explode(self::SEPARATOR, $value) : $value;
- $ids = $this->db->array2list($ids, 'integer');
- $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
- continue;
- }
- // fulltext search in all fields
- else if ($col == '*') {
- $words = array();
- foreach (explode($WS, rcube_utils::normalize_string($value)) as $word) {
- switch ($mode) {
- case 1: // strict
- $words[] = '(' . $this->db->ilike('words', $word . '%')
- . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . $WS . '%')
- . ' OR ' . $this->db->ilike('words', '%' . $WS . $word) . ')';
- break;
- case 2: // prefix
- $words[] = '(' . $this->db->ilike('words', $word . '%')
- . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . '%') . ')';
- break;
- default: // partial
- $words[] = $this->db->ilike('words', '%' . $word . '%');
- }
- }
- $where[] = '(' . join(' AND ', $words) . ')';
- }
- else {
- $val = is_array($value) ? $value[$idx] : $value;
+ // direct ID search
+ if ($fields == 'ID' || $fields == $this->primary_key) {
+ $ids = !is_array($value) ? explode(self::SEPARATOR, $value) : $value;
+ $ids = $this->db->array2list($ids, 'integer');
+ $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
+ }
+ else if (is_array($value)) {
+ foreach ((array)$fields as $idx => $col) {
+ $val = $value[$idx];
+
+ if (!strlen($val))
+ continue;
+
// table column
if (in_array($col, $this->table_cols)) {
switch ($mode) {
@@ -362,28 +343,26 @@ class rcube_contacts extends rcube_addressbook
// vCard field
else {
if (in_array($col, $this->fulltext_cols)) {
- foreach (rcube_utils::normalize_string($val, true) as $word) {
- switch ($mode) {
- case 1: // strict
- $words[] = '(' . $this->db->ilike('words', $word . $WS . '%')
- . ' OR ' . $this->db->ilike('words', '%' . $AS . $word . $WS .'%')
- . ' OR ' . $this->db->ilike('words', '%' . $AS . $word) . ')';
- break;
- case 2: // prefix
- $words[] = '(' . $this->db->ilike('words', $word . '%')
- . ' OR ' . $this->db->ilike('words', $AS . $word . '%') . ')';
- break;
- default: // partial
- $words[] = $this->db->ilike('words', '%' . $word . '%');
- }
- }
- $where[] = '(' . join(' AND ', $words) . ')';
+ $where[] = $this->fulltext_sql_where($val, $mode, 'words');
}
- if (is_array($value))
- $post_search[$col] = mb_strtolower($val);
+ $post_search[$col] = mb_strtolower($val);
}
}
}
+ // fulltext search in all fields
+ else if ($fields == '*') {
+ $where[] = $this->fulltext_sql_where($value, $mode, 'words');
+ }
+ else {
+ // require each word in to be present in one of the fields
+ foreach (rcube_utils::tokenize_string($value, 1) as $word) {
+ $groups = array();
+ foreach ((array)$fields as $idx => $col) {
+ $groups[] = $this->fulltext_sql_where($word, $mode, $col);
+ }
+ $where[] = '(' . join(' OR ', $groups) . ')';
+ }
+ }
foreach (array_intersect($required, $this->table_cols) as $col) {
$and_where[] = $this->db->quote_identifier($col).' <> '.$this->db->quote('');
@@ -391,7 +370,7 @@ class rcube_contacts extends rcube_addressbook
if (!empty($where)) {
// use AND operator for advanced searches
- $where = join(is_array($value) ? ' AND ' : ' OR ', $where);
+ $where = join(" AND ", $where);
}
if (!empty($and_where))
@@ -460,6 +439,34 @@ class rcube_contacts extends rcube_addressbook
return $this->result;
}
+ /**
+ * Helper method to compose SQL where statements for fulltext searching
+ */
+ private function fulltext_sql_where($value, $mode, $col = 'words', $bool = 'AND')
+ {
+ $WS = ' ';
+ $AS = $col == 'words' ? $WS : self::SEPARATOR;
+ $words = $col == 'words' ? rcube_utils::normalize_string($value, true) : array($value);
+
+ $where = array();
+ foreach ($words as $word) {
+ switch ($mode) {
+ case 1: // strict
+ $where[] = '(' . $this->db->ilike($col, $word . '%')
+ . ' OR ' . $this->db->ilike($col, '%' . $WS . $word . $WS . '%')
+ . ' OR ' . $this->db->ilike($col, '%' . $WS . $word) . ')';
+ break;
+ case 2: // prefix
+ $where[] = '(' . $this->db->ilike($col, $word . '%')
+ . ' OR ' . $this->db->ilike($col, '%' . $AS . $word . '%') . ')';
+ break;
+ default: // partial
+ $where[] = $this->db->ilike($col, '%' . $word . '%');
+ }
+ }
+
+ return '(' . join(" $bool ", $where) . ')';
+ }
/**
* Count number of available contacts in database
@@ -714,6 +721,11 @@ class rcube_contacts extends rcube_addressbook
// copy values into vcard object
$vcard = new rcube_vcard($record['vcard'] ? $record['vcard'] : $save_data['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap);
$vcard->reset();
+
+ // don't store groups in vCard (#1490277)
+ $vcard->set('groups', null);
+ unset($save_data['groups']);
+
foreach ($save_data as $key => $values) {
list($field, $section) = explode(':', $key);
$fulltext = in_array($field, $this->fulltext_cols);
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index ab7058f2f..2cacb3013 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -357,7 +357,7 @@ class rcube_db
public function get_variable($varname, $default = null)
{
// to be implemented by driver class
- return $default;
+ return rcube::get_instance()->config->get('db_' . $varname, $default);
}
/**
diff --git a/program/lib/Roundcube/rcube_db_mysql.php b/program/lib/Roundcube/rcube_db_mysql.php
index 0e85b0f9c..dd28c25c8 100644
--- a/program/lib/Roundcube/rcube_db_mysql.php
+++ b/program/lib/Roundcube/rcube_db_mysql.php
@@ -161,15 +161,30 @@ class rcube_db_mysql extends rcube_db
{
if (!isset($this->variables)) {
$this->variables = array();
+ }
- $result = $this->query('SHOW VARIABLES');
+ if (array_key_exists($varname, $this->variables)) {
+ return $this->variables[$varname];
+ }
- while ($row = $this->fetch_array($result)) {
- $this->variables[$row[0]] = $row[1];
- }
+ // configured value has higher prio
+ $conf_value = rcube::get_instance()->config->get('db_' . $varname);
+ if ($conf_value !== null) {
+ return $this->variables[$varname] = $conf_value;
+ }
+
+ $result = $this->query('SHOW VARIABLES LIKE ?', $varname);
+
+ while ($row = $this->fetch_array($result)) {
+ $this->variables[$row[0]] = $row[1];
+ }
+
+ // not found, use default
+ if (!isset($this->variables[$varname])) {
+ $this->variables[$varname] = $default;
}
- return isset($this->variables[$varname]) ? $this->variables[$varname] : $default;
+ return $this->variables[$varname];
}
/**
diff --git a/program/lib/Roundcube/rcube_db_pgsql.php b/program/lib/Roundcube/rcube_db_pgsql.php
index d33cdd859..ff41df224 100644
--- a/program/lib/Roundcube/rcube_db_pgsql.php
+++ b/program/lib/Roundcube/rcube_db_pgsql.php
@@ -139,9 +139,11 @@ class rcube_db_pgsql extends rcube_db
// There's a known case when max_allowed_packet is queried
// PostgreSQL doesn't have such limit, return immediately
if ($varname == 'max_allowed_packet') {
- return $default;
+ return rcube::get_instance()->config->get('db_' . $varname, $default);
}
+ $this->variables[$varname] = rcube::get_instance()->config->get('db_' . $varname);
+
if (!isset($this->variables)) {
$this->variables = array();
diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php
index 13d55bde6..f492111cc 100644
--- a/program/lib/Roundcube/rcube_ldap.php
+++ b/program/lib/Roundcube/rcube_ldap.php
@@ -698,8 +698,9 @@ class rcube_ldap extends rcube_addressbook
for ($i=0; $i < $entry['memberurl']['count']; $i++) {
// extract components from url
- if (!preg_match('!ldap:///([^\?]+)\?\?(\w+)\?(.*)$!', $entry['memberurl'][$i], $m))
+ if (!preg_match('!ldap://[^/]*/([^\?]+)\?\?(\w+)\?(.*)$!', $entry['memberurl'][$i], $m)) {
continue;
+ }
// add search filter if any
$filter = $this->filter ? '(&(' . $m[3] . ')(' . $this->filter . '))' : $m[3];
@@ -791,33 +792,24 @@ class rcube_ldap extends rcube_addressbook
return $this->result;
}
- // use AND operator for advanced searches
- $filter = is_array($value) ? '(&' : '(|';
- // set wildcards
- $wp = $ws = '';
- if (!empty($this->prop['fuzzy_search']) && $mode != 1) {
- $ws = '*';
- if (!$mode) {
- $wp = '*';
- }
- }
+ // advanced per-attribute search
+ if (is_array($value)) {
+ // use AND operator for advanced searches
+ $filter = '(&';
- if ($fields == '*') {
- // search_fields are required for fulltext search
- if (empty($this->prop['search_fields'])) {
- $this->set_error(self::ERROR_SEARCH, 'nofulltextsearch');
- $this->result = new rcube_result_set();
- return $this->result;
- }
- if (is_array($this->prop['search_fields'])) {
- foreach ($this->prop['search_fields'] as $field) {
- $filter .= "($field=$wp" . rcube_ldap_generic::quote_string($value) . "$ws)";
+ // set wildcards
+ $wp = $ws = '';
+ if (!empty($this->prop['fuzzy_search']) && $mode != 1) {
+ $ws = '*';
+ if (!$mode) {
+ $wp = '*';
}
}
- }
- else {
+
foreach ((array)$fields as $idx => $field) {
- $val = is_array($value) ? $value[$idx] : $value;
+ $val = $value[$idx];
+ if (!strlen($val))
+ continue;
if ($attrs = $this->_map_field($field)) {
if (count($attrs) > 1)
$filter .= '(|';
@@ -827,8 +819,33 @@ class rcube_ldap extends rcube_addressbook
$filter .= ')';
}
}
+
+ $filter .= ')';
+ }
+ else {
+ if ($fields == '*') {
+ // search_fields are required for fulltext search
+ if (empty($this->prop['search_fields'])) {
+ $this->set_error(self::ERROR_SEARCH, 'nofulltextsearch');
+ $this->result = new rcube_result_set();
+ return $this->result;
+ }
+ $attributes = (array)$this->prop['search_fields'];
+ }
+ else {
+ // map address book fields into ldap attributes
+ $me = $this;
+ $attributes = array();
+ array_walk($fields, function($field) use ($me, &$attributes) {
+ if ($me->coltypes[$field] && ($attrs = (array)$me->coltypes[$field]['attributes'])) {
+ $attributes = array_merge($attributes, $attrs);
+ }
+ });
+ }
+
+ // compose a full-text-like search filter
+ $filter = rcube_ldap_generic::fulltext_search_filter($value, $attributes, $mode);
}
- $filter .= ')';
// add required (non empty) fields filter
$req_filter = '';
diff --git a/program/lib/Roundcube/rcube_ldap_generic.php b/program/lib/Roundcube/rcube_ldap_generic.php
index a76ad6d06..abe16760d 100644
--- a/program/lib/Roundcube/rcube_ldap_generic.php
+++ b/program/lib/Roundcube/rcube_ldap_generic.php
@@ -6,7 +6,7 @@
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2006-2014, The Roundcube Dev Team |
- | Copyright (C) 2012-2014, Kolab Systems AG |
+ | Copyright (C) 2012-2015, Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -316,6 +316,47 @@ class rcube_ldap_generic extends Net_LDAP3
return $rec;
}
+
+ /**
+ * Compose an LDAP filter string matching all words from the search string
+ * in the given list of attributes.
+ *
+ * @param string $value Search value
+ * @param mixed $attrs List of LDAP attributes to search
+ * @param int $mode Matching mode:
+ * 0 - partial (*abc*),
+ * 1 - strict (=),
+ * 2 - prefix (abc*)
+ * @return string LDAP filter
+ */
+ public static function fulltext_search_filter($value, $attributes, $mode = 1)
+ {
+ if (empty($attributes)) {
+ $attributes = array('cn');
+ }
+
+ $groups = array();
+ $value = str_replace('*', '', $value);
+ $words = $mode == 0 ? rcube_utils::tokenize_string($value, 1) : array($value);
+
+ // set wildcards
+ $wp = $ws = '';
+ if ($mode != 1) {
+ $ws = '*';
+ $wp = !$mode ? '*' : '';
+ }
+
+ // search each word in all listed attributes
+ foreach ($words as $word) {
+ $parts = array();
+ foreach ($attributes as $attr) {
+ $parts[] = "($attr=$wp" . self::quote_string($word) . "$ws)";
+ }
+ $groups[] = '(|' . join('', $parts) . ')';
+ }
+
+ return count($groups) > 1 ? '(&' . join('', $groups) . ')' : join('', $groups);
+ }
}
// for backward compat.
diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php
index 3f2fcc330..e9cab6107 100644
--- a/program/lib/Roundcube/rcube_mime.php
+++ b/program/lib/Roundcube/rcube_mime.php
@@ -520,7 +520,7 @@ class rcube_mime
// remove space-stuffing
$line = preg_replace('/^ /', '', $line);
- if (isset($text[$last]) && $line
+ if (isset($text[$last]) && $line && !$q_level
&& $text[$last] != '-- '
&& $text[$last][strlen($text[$last])-1] == ' '
) {
diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php
index 8fd3253e0..9bc60f639 100644
--- a/program/lib/Roundcube/rcube_plugin_api.php
+++ b/program/lib/Roundcube/rcube_plugin_api.php
@@ -43,6 +43,7 @@ class rcube_plugin_api
public $active_plugins = array();
protected $plugins = array();
+ protected $plugins_initialized = array();
protected $tasks = array();
protected $actions = array();
protected $actionmap = array();
@@ -94,8 +95,9 @@ class rcube_plugin_api
foreach ($this->plugins as $plugin) {
// ... task, request type and framed mode
- if (!$this->filter($plugin)) {
+ if (!$this->plugins_initialized[$plugin_name] && !$this->filter($plugin)) {
$plugin->init();
+ $this->plugins_initialized[$plugin->ID] = $plugin;
}
}
@@ -146,7 +148,7 @@ class rcube_plugin_api
/**
* Load the specified plugin
*
- * @param string Plugin name
+ * @param string Plugin name
* @param boolean Force loading of the plugin even if it doesn't match the filter
* @param boolean Require loading of the plugin, error if it doesn't exist
*
@@ -161,63 +163,62 @@ class rcube_plugin_api
$plugins_dir = unslashify($dir->path);
}
- // plugin already loaded
- if ($this->plugins[$plugin_name]) {
- return true;
- }
+ // plugin already loaded?
+ if (!$this->plugins[$plugin_name]) {
+ $fn = "$plugins_dir/$plugin_name/$plugin_name.php";
+
+ if (!is_readable($fn)) {
+ if ($require) {
+ rcube::raise_error(array('code' => 520, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Failed to load plugin file $fn"), true, false);
+ }
- $fn = "$plugins_dir/$plugin_name/$plugin_name.php";
+ return false;
+ }
- if (is_readable($fn)) {
if (!class_exists($plugin_name, false)) {
include $fn;
}
// instantiate class if exists
- if (class_exists($plugin_name, false)) {
- $plugin = new $plugin_name($this);
- $this->active_plugins[] = $plugin_name;
-
- // check inheritance...
- if (is_subclass_of($plugin, 'rcube_plugin')) {
- // ... task, request type and framed mode
-
- // call onload method on plugin if it exists.
- // this is useful if you want to be called early in the boot process
- if (method_exists($plugin, 'onload')) {
- $plugin->onload();
- }
+ if (!class_exists($plugin_name, false)) {
+ rcube::raise_error(array('code' => 520, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "No plugin class $plugin_name found in $fn"),
+ true, false);
- // init a plugin only if $force is set or if we're called after initialization
- if (($force || $this->initialized)
- && !$this->filter($plugin))
- {
- $plugin->init();
- }
+ return false;
+ }
- $this->plugins[$plugin_name] = $plugin;
+ $plugin = new $plugin_name($this);
+ $this->active_plugins[] = $plugin_name;
- if (!empty($plugin->allowed_prefs)) {
- $this->allowed_prefs = array_merge($this->allowed_prefs, $plugin->allowed_prefs);
- }
+ // check inheritance...
+ if (is_subclass_of($plugin, 'rcube_plugin')) {
+ // call onload method on plugin if it exists.
+ // this is useful if you want to be called early in the boot process
+ if (method_exists($plugin, 'onload')) {
+ $plugin->onload();
+ }
- return true;
+ if (!empty($plugin->allowed_prefs)) {
+ $this->allowed_prefs = array_merge($this->allowed_prefs, $plugin->allowed_prefs);
}
- }
- else {
- rcube::raise_error(array('code' => 520, 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "No plugin class $plugin_name found in $fn"),
- true, false);
+
+ $this->plugins[$plugin_name] = $plugin;
}
}
- else if ($require) {
- rcube::raise_error(array('code' => 520, 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Failed to load plugin file $fn"), true, false);
+
+ if ($plugin = $this->plugins[$plugin_name]) {
+ // init a plugin only if $force is set or if we're called after initialization
+ if (($force || $this->initialized) && !$this->plugins_initialized[$plugin_name] && !$this->filter($plugin)) {
+ $plugin->init();
+ $this->plugins_initialized[$plugin_name] = $plugin;
+ }
}
- return false;
+ return true;
}
/**
@@ -228,9 +229,9 @@ class rcube_plugin_api
*/
private function filter($plugin)
{
- return (($plugin->noajax && !(is_object($this->output) && $this->output->type == 'html') )
+ return ($plugin->noajax && !(is_object($this->output) && $this->output->type == 'html'))
|| ($plugin->task && !preg_match('/^('.$plugin->task.')$/i', $this->task))
- || ($plugin->noframe && !empty($_REQUEST['_framed']))) ? true : false;
+ || ($plugin->noframe && !empty($_REQUEST['_framed']));
}
/**
diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php
index c3a51467b..0322a0d46 100644
--- a/program/lib/Roundcube/rcube_smtp.php
+++ b/program/lib/Roundcube/rcube_smtp.php
@@ -126,7 +126,7 @@ class rcube_smtp
// try to connect to server and exit on failure
$result = $this->conn->connect($CONFIG['smtp_timeout']);
- if (PEAR::isError($result)) {
+ if (is_a($result, 'PEAR_Error')) {
$this->response[] = "Connection failed: ".$result->getMessage();
$this->error = array('label' => 'smtpconnerror', 'vars' => array('code' => $this->conn->_code));
$this->conn = null;
@@ -159,7 +159,7 @@ class rcube_smtp
$result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls, $smtp_authz);
- if (PEAR::isError($result)) {
+ if (is_a($result, 'PEAR_Error')) {
$this->error = array('label' => 'smtpautherror', 'vars' => array('code' => $this->conn->_code));
$this->response[] .= 'Authentication failure: ' . $result->getMessage() . ' (Code: ' . $result->getCode() . ')';
$this->reset();
@@ -240,7 +240,8 @@ class rcube_smtp
}
// set From: address
- if (PEAR::isError($this->conn->mailFrom($from, $from_params))) {
+ $result = $this->conn->mailFrom($from, $from_params);
+ if (is_a($result, 'PEAR_Error')) {
$err = $this->conn->getResponse();
$this->error = array('label' => 'smtpfromerror', 'vars' => array(
'from' => $from, 'code' => $err[0], 'msg' => $err[1]));
@@ -252,7 +253,7 @@ class rcube_smtp
// prepare list of recipients
$recipients = $this->_parse_rfc822($recipients);
- if (PEAR::isError($recipients)) {
+ if (is_a($recipients, 'PEAR_Error')) {
$this->error = array('label' => 'smtprecipientserror');
$this->reset();
return false;
@@ -260,7 +261,8 @@ class rcube_smtp
// set mail recipients
foreach ($recipients as $recipient) {
- if (PEAR::isError($this->conn->rcptTo($recipient, $recipient_params))) {
+ $result = $this->conn->rcptTo($recipient, $recipient_params);
+ if (is_a($result, 'PEAR_Error')) {
$err = $this->conn->getResponse();
$this->error = array('label' => 'smtptoerror', 'vars' => array(
'to' => $recipient, 'code' => $err[0], 'msg' => $err[1]));
@@ -288,7 +290,8 @@ class rcube_smtp
}
// Send the message's headers and the body as SMTP data.
- if (PEAR::isError($this->conn->data($data, $text_headers))) {
+ $result = $this->conn->data($data, $text_headers);
+ if (is_a($result, 'PEAR_Error')) {
$err = $this->conn->getResponse();
if (!in_array($err[0], array(354, 250, 221))) {
$msg = sprintf('[%d] %s', $err[0], $err[1]);
diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index f4c0e90ca..0ca2a9e31 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -917,7 +917,7 @@ class rcube_utils
*/
public static function tokenize_string($str, $minlen = 2)
{
- $expr = array('/[\s;\/+-]+/ui', '/(\d)[-.\s]+(\d)/u');
+ $expr = array('/[\s;,"\'\/+-]+/ui', '/(\d)[-.\s]+(\d)/u');
$repl = array(' ', '\\1\\2');
if ($minlen > 1) {
@@ -985,6 +985,28 @@ class rcube_utils
}
/**
+ * Compare two strings for matching words (order not relevant)
+ *
+ * @param string Haystack
+ * @param string Needle
+ * @return boolen True if match, False otherwise
+ */
+ public static function words_match($haystack, $needle)
+ {
+ $a_needle = self::tokenize_string($needle, 1);
+ $haystack = join(" ", self::tokenize_string($haystack, 1));
+
+ $hits = 0;
+ foreach ($a_needle as $w) {
+ if (stripos($haystack, $w) !== false) {
+ $hits++;
+ }
+ }
+
+ return $hits >= count($a_needle);
+ }
+
+ /**
* Parse commandline arguments into a hash array
*
* @param array $aliases Argument alias names
diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php
index 7f6b11851..c0e261df4 100644
--- a/program/lib/Roundcube/rcube_vcard.php
+++ b/program/lib/Roundcube/rcube_vcard.php
@@ -393,6 +393,10 @@ class rcube_vcard
$this->raw[$tag][$index]['type'] = explode(',', ($typemap[$type_uc] ? $typemap[$type_uc] : $type));
}
}
+ else {
+ unset($this->raw[$tag]);
+ }
+
break;
}
}
diff --git a/program/lib/Roundcube/rcube_washtml.php b/program/lib/Roundcube/rcube_washtml.php
index e0cce685b..b042f5f80 100644
--- a/program/lib/Roundcube/rcube_washtml.php
+++ b/program/lib/Roundcube/rcube_washtml.php
@@ -403,16 +403,23 @@ class rcube_washtml
{
// special replacements (not properly handled by washtml class)
$html_search = array(
- '/(<\/nobr>)(\s+)(<nobr>)/i', // space(s) between <NOBR>
- '/<title[^>]*>[^<]*<\/title>/i', // PHP bug #32547 workaround: remove title tag
- '/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', // byte-order mark (only outlook?)
- '/<html\s[^>]+>/i', // washtml/DOMDocument cannot handle xml namespaces
+ // space(s) between <NOBR>
+ '/(<\/nobr>)(\s+)(<nobr>)/i',
+ // PHP bug #32547 workaround: remove title tag
+ '/<title[^>]*>[^<]*<\/title>/i',
+ // remove <!doctype> before BOM (#1490291)
+ '/<\!doctype[^>]+>[^<]*/im',
+ // byte-order mark (only outlook?)
+ '/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/',
+ // washtml/DOMDocument cannot handle xml namespaces
+ '/<html\s[^>]+>/i',
);
$html_replace = array(
'\\1'.' &nbsp; '.'\\3',
'',
'',
+ '',
'<html>',
);
$html = preg_replace($html_search, $html_replace, trim($html));