diff options
Diffstat (limited to 'program/lib/Roundcube')
-rw-r--r-- | program/lib/Roundcube/rcube_addressbook.php | 10 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_imap.php | 10 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_ldap.php | 20 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_ldap_generic.php | 26 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_mime.php | 16 |
5 files changed, 69 insertions, 13 deletions
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 71d556234..69027b0e8 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -562,21 +562,22 @@ abstract class rcube_addressbook * @param array Hash array with contact data as key-value pairs * @param string Optional email address * @param string Optional name (self::compose_list_name() result) + * @param string Optional template to use (defaults to the 'contact_search_name' config option) * * @return string Display name */ - public static function compose_search_name($contact, $email = null, $name = null) + public static function compose_search_name($contact, $email = null, $name = null, $templ = null) { static $template; - if (!isset($template)) { // cache this + if (empty($templ) && !isset($template)) { // cache this $template = rcube::get_instance()->config->get('contact_search_name'); if (empty($template)) { $template = '{name} <{email}>'; } } - $result = $template; + $result = $templ ?: $template; if (preg_match_all('/\{[a-z]+\}/', $result, $matches)) { foreach ($matches[0] as $key) { @@ -605,7 +606,8 @@ abstract class rcube_addressbook } $result = preg_replace('/\s+/', ' ', $result); - $result = trim($result); + $result = preg_replace('/\s*(<>|\(\)|\[\])/', '', $result); + $result = trim($result, '/ '); return $result; } diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index ec961c8d1..a66d2064d 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -3165,6 +3165,16 @@ class rcube_imap extends rcube_storage $result = $this->conn->createFolder($folder, $type ? array("\\" . ucfirst($type)) : null); + // it's quite often situation that we're trying to create and subscribe + // a folder that already exist, but is unsubscribed + if (!$result) { + if ($this->get_response_code() == rcube_storage::ALREADYEXISTS + || preg_match('/already exists/i', $this->get_error_str()) + ) { + $result = true; + } + } + // try to subscribe it if ($result) { // clear cache diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php index 274616a1f..6805c4902 100644 --- a/program/lib/Roundcube/rcube_ldap.php +++ b/program/lib/Roundcube/rcube_ldap.php @@ -906,7 +906,6 @@ class rcube_ldap extends rcube_addressbook return $this->result; } - /** * Get a specific contact record * @@ -948,6 +947,23 @@ class rcube_ldap extends rcube_addressbook return $assoc ? $res : $this->result; } + /** + * Returns the last error occurred (e.g. when updating/inserting failed) + * + * @return array Hash array with the following fields: type, message + */ + function get_error() + { + $err = $this->error; + + // check ldap connection for errors + if (!$err && $this->ldap->get_error()) { + $err = array(self::ERROR_SEARCH, $this->ldap->get_error()); + } + + return $err; + } + /** * Check the given data before saving. @@ -1609,7 +1625,7 @@ class rcube_ldap extends rcube_addressbook if ($search) { foreach ($group_cache as $group) { - if ($this->compare_search_value('name', $group['name'], $search, $mode)) { + if ($this->compare_search_value('name', $group['name'], mb_strtolower($search), $mode)) { $groups[] = $group; } } diff --git a/program/lib/Roundcube/rcube_ldap_generic.php b/program/lib/Roundcube/rcube_ldap_generic.php index 9823dbb66..a76ad6d06 100644 --- a/program/lib/Roundcube/rcube_ldap_generic.php +++ b/program/lib/Roundcube/rcube_ldap_generic.php @@ -32,6 +32,7 @@ class rcube_ldap_generic extends Net_LDAP3 /** private properties */ protected $cache = null; protected $attributes = array('dn'); + protected $error; function __construct($config = null) { @@ -88,12 +89,23 @@ class rcube_ldap_generic extends Net_LDAP3 case LOG_ERR: case LOG_WARNING: + $this->error = $msg; rcube::raise_error($msg, true, false); break; } } /** + * Returns the last LDAP error occurred + * + * @return mixed Error message string or null if no error occured + */ + function get_error() + { + return $this->error; + } + + /** * @deprecated */ public function set_debug($dbg = true) @@ -151,7 +163,7 @@ class rcube_ldap_generic extends Net_LDAP3 $this->_debug("C: Replace $dn: ".print_r($entry, true)); if (!ldap_mod_replace($this->conn, $dn, $entry)) { - $this->_debug("S: ".ldap_error($this->conn)); + $this->_error("ldap_mod_replace() failed with " . ldap_error($this->conn)); return false; } @@ -169,7 +181,7 @@ class rcube_ldap_generic extends Net_LDAP3 $this->_debug("C: Add $dn: ".print_r($entry, true)); if (!ldap_mod_add($this->conn, $dn, $entry)) { - $this->_debug("S: ".ldap_error($this->conn)); + $this->_error("ldap_mod_add() failed with " . ldap_error($this->conn)); return false; } @@ -187,7 +199,7 @@ class rcube_ldap_generic extends Net_LDAP3 $this->_debug("C: Delete $dn: ".print_r($entry, true)); if (!ldap_mod_del($this->conn, $dn, $entry)) { - $this->_debug("S: ".ldap_error($this->conn)); + $this->_error("ldap_mod_del() failed with " . ldap_error($this->conn)); return false; } @@ -205,7 +217,7 @@ class rcube_ldap_generic extends Net_LDAP3 $this->_debug("C: Rename $dn to $newrdn"); if (!ldap_rename($this->conn, $dn, $newrdn, $newparent, $deleteoldrdn)) { - $this->_debug("S: ".ldap_error($this->conn)); + $this->_error("ldap_rename() failed with " . ldap_error($this->conn)); return false; } @@ -228,7 +240,7 @@ class rcube_ldap_generic extends Net_LDAP3 $list = ldap_get_entries($this->conn, $result); if ($list === false) { - $this->_debug("S: ".ldap_error($this->conn)); + $this->_error("ldap_get_entries() failed with " . ldap_error($this->conn)); return array(); } @@ -238,7 +250,7 @@ class rcube_ldap_generic extends Net_LDAP3 $this->_debug("S: $count record(s)"); } else { - $this->_debug("S: ".ldap_error($this->conn)); + $this->_error("ldap_list() failed with " . ldap_error($this->conn)); } return $list; @@ -257,7 +269,7 @@ class rcube_ldap_generic extends Net_LDAP3 if ($this->conn && $dn) { $result = @ldap_read($this->conn, $dn, $filter, $attributes, 0, (int)$this->config['sizelimit'], (int)$this->config['timelimit']); if ($result === false) { - $this->_debug("S: ".ldap_error($this->conn)); + $this->_error("ldap_read() failed with " . ldap_error($this->conn)); return false; } diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index 14bc48336..f66cf1437 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -394,6 +394,7 @@ class rcube_mime } if ($address) { + $address = self::fix_email($address); $result[$key] = array('name' => $name, 'address' => $address); } } @@ -906,4 +907,19 @@ class rcube_mime return 'image/' . $type; } + /** + * Try to fix invalid email addresses + */ + public static function fix_email($email) + { + $parts = rcube_utils::explode_quoted_string('@', $email); + foreach ($parts as $idx => $part) { + // remove redundant quoting (#1490040) + if ($part[0] == '"' && preg_match('/^"([a-zA-Z0-9._+=-]+)"$/', $part, $m)) { + $parts[$idx] = $m[1]; + } + } + + return implode('@', $parts); + } } |