summaryrefslogtreecommitdiff
path: root/program/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-05-08 14:28:36 +0200
committerAleksander Machniak <alec@alec.pl>2013-05-08 14:28:36 +0200
commita522971cf853b2f0ccd1b569491a06218ebbaee9 (patch)
treecf0e8c6bbe0978cf302b112080370b9a01cf5900 /program/lib
parentea6d6958e0a32c88bf8c00cbd118cfcd48fae096 (diff)
parentc4723999e21da0b266b0467de6e58cbd26c4b5bf (diff)
Merge branch 'master' of github.com:roundcube/roundcubemail
Conflicts: program/js/list.js
Diffstat (limited to 'program/lib')
-rw-r--r--program/lib/Roundcube/html.php34
-rw-r--r--program/lib/Roundcube/rcube_addressbook.php26
-rw-r--r--program/lib/Roundcube/rcube_contacts.php36
-rw-r--r--program/lib/Roundcube/rcube_csv2vcard.php53
-rw-r--r--program/lib/Roundcube/rcube_db.php13
-rw-r--r--program/lib/Roundcube/rcube_db_mysql.php4
-rw-r--r--program/lib/Roundcube/rcube_enriched.php2
-rw-r--r--program/lib/Roundcube/rcube_imap.php9
-rw-r--r--program/lib/Roundcube/rcube_imap_cache.php4
-rw-r--r--program/lib/Roundcube/rcube_imap_generic.php18
-rw-r--r--program/lib/Roundcube/rcube_ldap.php74
-rw-r--r--program/lib/Roundcube/rcube_message.php2
-rw-r--r--program/lib/Roundcube/rcube_mime.php50
-rw-r--r--program/lib/Roundcube/rcube_output.php2
-rw-r--r--program/lib/Roundcube/rcube_plugin_api.php1
-rw-r--r--program/lib/Roundcube/rcube_smtp.php6
-rw-r--r--program/lib/Roundcube/rcube_spellchecker.php17
-rw-r--r--program/lib/Roundcube/rcube_utils.php2
-rw-r--r--program/lib/Roundcube/rcube_vcard.php27
-rw-r--r--program/lib/utf8.class.php4
20 files changed, 264 insertions, 120 deletions
diff --git a/program/lib/Roundcube/html.php b/program/lib/Roundcube/html.php
index dbc9ca51f..830ada9c2 100644
--- a/program/lib/Roundcube/html.php
+++ b/program/lib/Roundcube/html.php
@@ -678,6 +678,11 @@ class html_table extends html
{
$default_attrib = self::$doctype == 'xhtml' ? array('summary' => '', 'border' => 0) : array();
$this->attrib = array_merge($attrib, $default_attrib);
+
+ if (!empty($attrib['tagname']) && $attrib['tagname'] != 'table') {
+ $this->tagname = $attrib['tagname'];
+ $this->allowed = self::$common_attrib;
+ }
}
/**
@@ -816,19 +821,20 @@ class html_table extends html
if (!empty($this->header)) {
$rowcontent = '';
foreach ($this->header as $c => $col) {
- $rowcontent .= self::tag('td', $col->attrib, $col->content);
+ $rowcontent .= self::tag($this->_col_tagname(), $col->attrib, $col->content);
}
- $thead = self::tag('thead', null, self::tag('tr', null, $rowcontent, parent::$common_attrib));
+ $thead = $this->tagname == 'table' ? self::tag('thead', null, self::tag('tr', null, $rowcontent, parent::$common_attrib)) :
+ self::tag($this->_row_tagname(), array('class' => 'thead'), $rowcontent, parent::$common_attrib);
}
foreach ($this->rows as $r => $row) {
$rowcontent = '';
foreach ($row->cells as $c => $col) {
- $rowcontent .= self::tag('td', $col->attrib, $col->content);
+ $rowcontent .= self::tag($this->_col_tagname(), $col->attrib, $col->content);
}
if ($r < $this->rowindex || count($row->cells)) {
- $tbody .= self::tag('tr', $row->attrib, $rowcontent, parent::$common_attrib);
+ $tbody .= self::tag($this->_row_tagname(), $row->attrib, $rowcontent, parent::$common_attrib);
}
}
@@ -837,7 +843,7 @@ class html_table extends html
}
// add <tbody>
- $this->content = $thead . self::tag('tbody', null, $tbody);
+ $this->content = $thead . ($this->tagname == 'table' ? self::tag('tbody', null, $tbody) : $tbody);
unset($this->attrib['cols'], $this->attrib['rowsonly']);
return parent::show();
@@ -862,4 +868,22 @@ class html_table extends html
$this->rowindex = 0;
}
+ /**
+ * Getter for the corresponding tag name for table row elements
+ */
+ private function _row_tagname()
+ {
+ static $row_tagnames = array('table' => 'tr', 'ul' => 'li', '*' => 'div');
+ return $row_tagnames[$this->tagname] ?: $row_tagnames['*'];
+ }
+
+ /**
+ * Getter for the corresponding tag name for table cell elements
+ */
+ private function _col_tagname()
+ {
+ static $col_tagnames = array('table' => 'td', '*' => 'span');
+ return $col_tagnames[$this->tagname] ?: $col_tagnames['*'];
+ }
+
}
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php
index cbc3c6773..d23ad3687 100644
--- a/program/lib/Roundcube/rcube_addressbook.php
+++ b/program/lib/Roundcube/rcube_addressbook.php
@@ -309,9 +309,14 @@ abstract class rcube_addressbook
* List all active contact groups of this source
*
* @param string Optional search string to match group name
+ * @param int Matching mode:
+ * 0 - partial (*abc*),
+ * 1 - strict (=),
+ * 2 - prefix (abc*)
+ *
* @return array Indexed list of contact groups, each a hash array
*/
- function list_groups($search = null)
+ function list_groups($search = null, $mode = 0)
{
/* empty for address books don't supporting groups */
return array();
@@ -370,9 +375,10 @@ abstract class rcube_addressbook
/**
* Add the given contact records the a certain group
*
- * @param string Group identifier
- * @param array List of contact identifiers to be added
- * @return int Number of contacts added
+ * @param string Group identifier
+ * @param array|string List of contact identifiers to be added
+ *
+ * @return int Number of contacts added
*/
function add_to_group($group_id, $ids)
{
@@ -383,9 +389,10 @@ abstract class rcube_addressbook
/**
* Remove the given contact records from a certain group
*
- * @param string Group identifier
- * @param array List of contact identifiers to be removed
- * @return int Number of deleted group members
+ * @param string Group identifier
+ * @param array|string List of contact identifiers to be removed
+ *
+ * @return int Number of deleted group members
*/
function remove_from_group($group_id, $ids)
{
@@ -425,7 +432,7 @@ abstract class rcube_addressbook
$out = array_merge($out, (array)$values);
}
else {
- list($f, $type) = explode(':', $c);
+ list(, $type) = explode(':', $c);
$out[$type] = array_merge((array)$out[$type], (array)$values);
}
}
@@ -528,7 +535,7 @@ abstract class rcube_addressbook
*/
public static function compose_contact_key($contact, $sort_col)
{
- $key = $contact[$sort_col] . ':' . $row['sourceid'];
+ $key = $contact[$sort_col] . ':' . $contact['sourceid'];
// add email to a key to not skip contacts with the same name (#1488375)
if (!empty($contact['email'])) {
@@ -538,7 +545,6 @@ abstract class rcube_addressbook
return $key;
}
-
/**
* Compare search value with contact data
*
diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php
index e4fd7dc10..3919cdc6e 100644
--- a/program/lib/Roundcube/rcube_contacts.php
+++ b/program/lib/Roundcube/rcube_contacts.php
@@ -137,16 +137,34 @@ class rcube_contacts extends rcube_addressbook
* List all active contact groups of this source
*
* @param string Search string to match group name
+ * @param int Matching mode:
+ * 0 - partial (*abc*),
+ * 1 - strict (=),
+ * 2 - prefix (abc*)
+ *
* @return array Indexed list of contact groups, each a hash array
*/
- function list_groups($search = null)
+ function list_groups($search = null, $mode = 0)
{
$results = array();
if (!$this->groups)
return $results;
- $sql_filter = $search ? " AND " . $this->db->ilike('name', '%'.$search.'%') : '';
+ if ($search) {
+ switch (intval($mode)) {
+ case 1:
+ $sql_filter = $this->db->ilike('name', $search);
+ break;
+ case 2:
+ $sql_filter = $this->db->ilike('name', $search . '%');
+ break;
+ default:
+ $sql_filter = $this->db->ilike('name', '%' . $search . '%');
+ }
+
+ $sql_filter = " AND $sql_filter";
+ }
$sql_result = $this->db->query(
"SELECT * FROM ".$this->db->table_name($this->db_groups).
@@ -879,9 +897,10 @@ class rcube_contacts extends rcube_addressbook
/**
* Add the given contact records the a certain group
*
- * @param string Group identifier
- * @param array List of contact identifiers to be added
- * @return int Number of contacts added
+ * @param string Group identifier
+ * @param array|string List of contact identifiers to be added
+ *
+ * @return int Number of contacts added
*/
function add_to_group($group_id, $ids)
{
@@ -926,9 +945,10 @@ class rcube_contacts extends rcube_addressbook
/**
* Remove the given contact records from a certain group
*
- * @param string Group identifier
- * @param array List of contact identifiers to be removed
- * @return int Number of deleted group members
+ * @param string Group identifier
+ * @param array|string List of contact identifiers to be removed
+ *
+ * @return int Number of deleted group members
*/
function remove_from_group($group_id, $ids)
{
diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php
index 0d3276b84..fb8d8f103 100644
--- a/program/lib/Roundcube/rcube_csv2vcard.php
+++ b/program/lib/Roundcube/rcube_csv2vcard.php
@@ -130,6 +130,21 @@ class rcube_csv2vcard
'work_state' => 'region:work',
'home_city_short' => 'locality:home',
'home_state_short' => 'region:home',
+
+ // Atmail
+ 'date_of_birth' => 'birthday',
+ 'email' => 'email:pref',
+ 'home_mobile' => 'phone:cell',
+ 'home_zip' => 'zipcode:home',
+ 'info' => 'notes',
+ 'user_photo' => 'photo',
+ 'url' => 'website:homepage',
+ 'work_company' => 'organization',
+ 'work_dept' => 'departament',
+ 'work_fax' => 'phone:work,fax',
+ 'work_mobile' => 'phone:work,cell',
+ 'work_title' => 'jobtitle',
+ 'work_zip' => 'zipcode:work',
);
/**
@@ -230,8 +245,29 @@ class rcube_csv2vcard
'work_phone' => "Work Phone",
'work_address' => "Work Address",
//'work_address_2' => "Work Address 2",
+ 'work_city' => "Work City",
'work_country' => "Work Country",
+ 'work_state' => "Work State",
'work_zipcode' => "Work ZipCode",
+
+ // Atmail
+ 'date_of_birth' => "Date of Birth",
+ 'email' => "Email",
+ //'email_2' => "Email2",
+ //'email_3' => "Email3",
+ //'email_4' => "Email4",
+ //'email_5' => "Email5",
+ 'home_mobile' => "Home Mobile",
+ 'home_zip' => "Home Zip",
+ 'info' => "Info",
+ 'user_photo' => "User Photo",
+ 'url' => "URL",
+ 'work_company' => "Work Company",
+ 'work_dept' => "Work Dept",
+ 'work_fax' => "Work Fax",
+ 'work_mobile' => "Work Mobile",
+ 'work_title' => "Work Title",
+ 'work_zip' => "Work Zip",
);
protected $local_label_map = array();
@@ -268,7 +304,6 @@ class rcube_csv2vcard
{
// convert to UTF-8
$head = substr($csv, 0, 4096);
- $fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1'); // fallback to Latin-1?
$charset = rcube_charset::detect($head, RCUBE_CHARSET);
$csv = rcube_charset::convert($csv, $charset);
$head = '';
@@ -276,7 +311,7 @@ class rcube_csv2vcard
$this->map = array();
// Parse file
- foreach (preg_split("/[\r\n]+/", $csv) as $i => $line) {
+ foreach (preg_split("/[\r\n]+/", $csv) as $line) {
$elements = $this->parse_line($line);
if (empty($elements)) {
continue;
@@ -353,6 +388,12 @@ class rcube_csv2vcard
if (!empty($this->local_label_map)) {
for ($i = 0; $i < $size; $i++) {
$label = $this->local_label_map[$elements[$i]];
+
+ // special localization label
+ if ($label && $label[0] == '_') {
+ $label = substr($label, 1);
+ }
+
if ($label && !empty($this->csv2vcard_map[$label])) {
$map2[$i] = $this->csv2vcard_map[$label];
}
@@ -384,9 +425,13 @@ class rcube_csv2vcard
$contact['birthday'] = $contact['birthday-y'] .'-' .$contact['birthday-m'] . '-' . $contact['birthday-d'];
}
+ // Empty dates, e.g. "0/0/00", "0000-00-00 00:00:00"
foreach (array('birthday', 'anniversary') as $key) {
- if (!empty($contact[$key]) && $contact[$key] == '0/0/00') { // @TODO: localization?
- unset($contact[$key]);
+ if (!empty($contact[$key])) {
+ $date = preg_replace('/[0[:^word:]]/', '', $contact[$key]);
+ if (empty($date)) {
+ unset($contact[$key]);
+ }
}
}
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index d86e3dd98..4b9ab131c 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -128,7 +128,7 @@ class rcube_db
$dsn_string = $this->dsn_string($dsn);
$dsn_options = $this->dsn_options($dsn);
- if ($db_pconn) {
+ if ($this->db_pconn) {
$dsn_options[PDO::ATTR_PERSISTENT] = true;
}
@@ -405,21 +405,22 @@ class rcube_db
$this->db_error_msg = null;
// send query
- $query = $this->dbh->query($query);
+ $result = $this->dbh->query($query);
- if ($query === false) {
+ if ($result === false) {
$error = $this->dbh->errorInfo();
$this->db_error = true;
$this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);
rcube::raise_error(array('code' => 500, 'type' => 'db',
'line' => __LINE__, 'file' => __FILE__,
- 'message' => $this->db_error_msg), true, false);
+ 'message' => $this->db_error_msg . " (SQL Query: $query)"
+ ), true, false);
}
- $this->last_result = $query;
+ $this->last_result = $result;
- return $query;
+ return $result;
}
/**
diff --git a/program/lib/Roundcube/rcube_db_mysql.php b/program/lib/Roundcube/rcube_db_mysql.php
index 8ab6403c8..b2cbab271 100644
--- a/program/lib/Roundcube/rcube_db_mysql.php
+++ b/program/lib/Roundcube/rcube_db_mysql.php
@@ -127,7 +127,7 @@ class rcube_db_mysql extends rcube_db
$result[PDO::MYSQL_ATTR_FOUND_ROWS] = true;
// Enable AUTOCOMMIT mode (#1488902)
- $dsn_options[PDO::ATTR_AUTOCOMMIT] = true;
+ $result[PDO::ATTR_AUTOCOMMIT] = true;
return $result;
}
@@ -147,7 +147,7 @@ class rcube_db_mysql extends rcube_db
$result = $this->query('SHOW VARIABLES');
- while ($sql_arr = $this->fetch_array($result)) {
+ while ($row = $this->fetch_array($result)) {
$this->variables[$row[0]] = $row[1];
}
}
diff --git a/program/lib/Roundcube/rcube_enriched.php b/program/lib/Roundcube/rcube_enriched.php
index 8c628c912..12deb33ce 100644
--- a/program/lib/Roundcube/rcube_enriched.php
+++ b/program/lib/Roundcube/rcube_enriched.php
@@ -118,7 +118,7 @@ class rcube_enriched
$quoted = '';
$lines = explode('<br>', $a[2]);
- foreach ($lines as $n => $line)
+ foreach ($lines as $line)
$quoted .= '&gt;'.$line.'<br>';
$body = $a[1].'<span class="quotes">'.$quoted.'</span>'.$a[3];
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index c67985186..43c61fd81 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -981,7 +981,7 @@ class rcube_imap extends rcube_storage
// use memory less expensive (and quick) method for big result set
$index = clone $this->index('', $this->sort_field, $this->sort_order);
// get messages uids for one page...
- $index->slice($start_msg, min($cnt-$from, $this->page_size));
+ $index->slice($from, min($cnt-$from, $this->page_size));
if ($slice) {
$index->slice(-$slice, $slice);
@@ -1423,8 +1423,6 @@ class rcube_imap extends rcube_storage
*/
protected function search_index($folder, $criteria='ALL', $charset=NULL, $sort_field=NULL)
{
- $orig_criteria = $criteria;
-
if (!$this->check_connection()) {
if ($this->threading) {
return new rcube_result_thread();
@@ -2727,7 +2725,7 @@ class rcube_imap extends rcube_storage
// filter folders list according to rights requirements
if ($rights && $this->get_capability('ACL')) {
- $a_folders = $this->filter_rights($a_folders, $rights);
+ $a_mboxes = $this->filter_rights($a_mboxes, $rights);
}
// filter folders and sort them
@@ -2783,7 +2781,6 @@ class rcube_imap extends rcube_storage
*/
private function list_folders_update(&$result, $type = null)
{
- $delim = $this->get_hierarchy_delimiter();
$namespace = $this->get_namespace();
$search = array();
@@ -3846,7 +3843,7 @@ class rcube_imap extends rcube_storage
$delimiter = $this->get_hierarchy_delimiter();
// find default folders and skip folders starting with '.'
- foreach ($a_folders as $i => $folder) {
+ foreach ($a_folders as $folder) {
if ($folder[0] == '.') {
continue;
}
diff --git a/program/lib/Roundcube/rcube_imap_cache.php b/program/lib/Roundcube/rcube_imap_cache.php
index 748474af2..47d9aaf4a 100644
--- a/program/lib/Roundcube/rcube_imap_cache.php
+++ b/program/lib/Roundcube/rcube_imap_cache.php
@@ -430,7 +430,7 @@ class rcube_imap_cache
." AND uid = ?",
$flags, $msg, $this->userid, $mailbox, (int) $message->uid);
- if ($this->db->affected_rows()) {
+ if ($this->db->affected_rows($res)) {
return;
}
}
@@ -983,7 +983,7 @@ class rcube_imap_cache
$uids, true, array('FLAGS'), $index['modseq'], $qresync);
if (!empty($result)) {
- foreach ($result as $id => $msg) {
+ foreach ($result as $msg) {
$uid = $msg->uid;
// Remove deleted message
if ($this->skip_deleted && !empty($msg->flags['DELETED'])) {
diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php
index db50ffbab..6c1b85552 100644
--- a/program/lib/Roundcube/rcube_imap_generic.php
+++ b/program/lib/Roundcube/rcube_imap_generic.php
@@ -746,7 +746,7 @@ class rcube_imap_generic
}
if ($this->prefs['timeout'] <= 0) {
- $this->prefs['timeout'] = ini_get('default_socket_timeout');
+ $this->prefs['timeout'] = max(0, intval(ini_get('default_socket_timeout')));
}
// Connect
@@ -1077,7 +1077,7 @@ class rcube_imap_generic
}
if (!$this->data['READ-WRITE']) {
- $this->setError(self::ERROR_READONLY, "Mailbox is read-only", 'EXPUNGE');
+ $this->setError(self::ERROR_READONLY, "Mailbox is read-only");
return false;
}
@@ -1652,7 +1652,6 @@ class rcube_imap_generic
}
if (!empty($criteria)) {
- $modseq = stripos($criteria, 'MODSEQ') !== false;
$params .= ($params ? ' ' : '') . $criteria;
}
else {
@@ -1791,7 +1790,6 @@ class rcube_imap_generic
if ($skip_deleted && preg_match('/FLAGS \(([^)]+)\)/', $line, $matches)) {
$flags = explode(' ', strtoupper($matches[1]));
if (in_array('\\DELETED', $flags)) {
- $deleted[$id] = $id;
continue;
}
}
@@ -1936,7 +1934,7 @@ class rcube_imap_generic
}
if (!$this->data['READ-WRITE']) {
- $this->setError(self::ERROR_READONLY, "Mailbox is read-only", 'STORE');
+ $this->setError(self::ERROR_READONLY, "Mailbox is read-only");
return false;
}
@@ -1997,7 +1995,7 @@ class rcube_imap_generic
}
if (!$this->data['READ-WRITE']) {
- $this->setError(self::ERROR_READONLY, "Mailbox is read-only", 'STORE');
+ $this->setError(self::ERROR_READONLY, "Mailbox is read-only");
return false;
}
@@ -2172,7 +2170,7 @@ class rcube_imap_generic
// create array with header field:data
if (!empty($headers)) {
$headers = explode("\n", trim($headers));
- foreach ($headers as $hid => $resln) {
+ foreach ($headers as $resln) {
if (ord($resln[0]) <= 32) {
$lines[$ln] .= (empty($lines[$ln]) ? '' : "\n") . trim($resln);
} else {
@@ -2180,7 +2178,7 @@ class rcube_imap_generic
}
}
- while (list($lines_key, $str) = each($lines)) {
+ foreach ($lines as $str) {
list($field, $string) = explode(':', $str, 2);
$field = strtolower($field);
@@ -2508,7 +2506,7 @@ class rcube_imap_generic
$tokens = $this->tokenizeResponse(preg_replace('/(^\(|\)$)/', '', $line));
for ($i=0; $i<count($tokens); $i+=2) {
- if (preg_match('/^(BODY|BINARY)/i', $token)) {
+ if (preg_match('/^(BODY|BINARY)/i', $tokens[$i])) {
$result = $tokens[$i+1];
$found = true;
break;
@@ -3540,7 +3538,7 @@ class rcube_imap_generic
if (is_array($element)) {
reset($element);
- while (list($key, $value) = each($element)) {
+ foreach ($element as $value) {
$string .= ' ' . self::r_implode($value);
}
}
diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php
index a2dd163e9..70163b21c 100644
--- a/program/lib/Roundcube/rcube_ldap.php
+++ b/program/lib/Roundcube/rcube_ldap.php
@@ -169,7 +169,7 @@ class rcube_ldap extends rcube_addressbook
// Build sub_fields filter
if (!empty($this->prop['sub_fields']) && is_array($this->prop['sub_fields'])) {
$this->sub_filter = '';
- foreach ($this->prop['sub_fields'] as $attr => $class) {
+ foreach ($this->prop['sub_fields'] as $class) {
if (!empty($class)) {
$class = is_array($class) ? array_pop($class) : $class;
$this->sub_filter .= '(objectClass=' . $class . ')';
@@ -1035,7 +1035,6 @@ class rcube_ldap extends rcube_addressbook
$mail_field = $this->fieldmap['email'];
// try to extract surname and firstname from displayname
- $reverse_map = array_flip($this->fieldmap);
$name_parts = preg_split('/[\s,.]+/', $save_data['name']);
if ($sn_field && $missing[$sn_field]) {
@@ -1107,7 +1106,7 @@ class rcube_ldap extends rcube_addressbook
// Remove attributes that need to be added separately (child objects)
$xfields = array();
if (!empty($this->prop['sub_fields']) && is_array($this->prop['sub_fields'])) {
- foreach ($this->prop['sub_fields'] as $xf => $xclass) {
+ foreach (array_keys($this->prop['sub_fields']) as $xf) {
if (!empty($newentry[$xf])) {
$xfields[$xf] = $newentry[$xf];
unset($newentry[$xf]);
@@ -1170,7 +1169,7 @@ class rcube_ldap extends rcube_addressbook
}
}
- foreach ($this->fieldmap as $col => $fld) {
+ foreach ($this->fieldmap as $fld) {
if ($fld) {
$val = $ldap_data[$fld];
$old = $old_data[$fld];
@@ -1396,6 +1395,10 @@ class rcube_ldap extends rcube_addressbook
*/
protected function add_autovalues(&$attrs)
{
+ if (empty($this->prop['autovalues'])) {
+ return;
+ }
+
$attrvals = array();
foreach ($attrs as $k => $v) {
$attrvals['{'.$k.'}'] = is_array($v) ? $v[0] : $v;
@@ -1403,13 +1406,24 @@ class rcube_ldap extends rcube_addressbook
foreach ((array)$this->prop['autovalues'] as $lf => $templ) {
if (empty($attrs[$lf])) {
- // replace {attr} placeholders with concrete attribute values
- $templ = preg_replace('/\{\w+\}/', '', strtr($templ, $attrvals));
+ if (strpos($templ, '(') !== false) {
+ // replace {attr} placeholders with (escaped!) attribute values to be safely eval'd
+ $code = preg_replace('/\{\w+\}/', '', strtr($templ, array_map('addslashes', $attrvals)));
+ $fn = create_function('', "return ($code);");
+ if (!$fn) {
+ rcube::raise_error(array(
+ 'code' => 505, 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Expression parse error on: ($code)"), true, false);
+ continue;
+ }
- if (strpos($templ, '(') !== false)
- $attrs[$lf] = eval("return ($templ);");
- else
- $attrs[$lf] = $templ;
+ $attrs[$lf] = $fn();
+ }
+ else {
+ // replace {attr} placeholders with concrete attribute values
+ $attrs[$lf] = preg_replace('/\{\w+\}/', '', strtr($templ, $attrvals));
+ }
}
}
}
@@ -1715,9 +1729,14 @@ class rcube_ldap extends rcube_addressbook
* List all active contact groups of this source
*
* @param string Optional search string to match group name
+ * @param int Matching mode:
+ * 0 - partial (*abc*),
+ * 1 - strict (=),
+ * 2 - prefix (abc*)
+ *
* @return array Indexed list of contact groups, each a hash array
*/
- function list_groups($search = null)
+ function list_groups($search = null, $mode = 0)
{
if (!$this->groups)
return array();
@@ -1729,10 +1748,10 @@ class rcube_ldap extends rcube_addressbook
$groups = array();
if ($search) {
- $search = mb_strtolower($search);
foreach ($group_cache as $group) {
- if (strpos(mb_strtolower($group['name']), $search) !== false)
+ if ($this->compare_search_value('name', $group['name'], $search, $mode)) {
$groups[] = $group;
+ }
}
}
else
@@ -1763,7 +1782,7 @@ class rcube_ldap extends rcube_addressbook
$vlv_active = $this->_vlv_set_controls($this->prop['groups'], $vlv_page+1, $page_size);
}
- $function = $this->_scope2func($this->prop['groups']['scope'], $ns_function);
+ $function = $this->_scope2func($this->prop['groups']['scope']);
$res = @$function($this->conn, $base_dn, $filter, array_unique(array('dn', 'objectClass', $name_attr, $email_attr, $sort_attr)));
if ($res === false)
{
@@ -1921,9 +1940,10 @@ class rcube_ldap extends rcube_addressbook
/**
* Add the given contact records the a certain group
*
- * @param string Group identifier
- * @param array List of contact identifiers to be added
- * @return int Number of contacts added
+ * @param string Group identifier
+ * @param array|string List of contact identifiers to be added
+ *
+ * @return int Number of contacts added
*/
function add_to_group($group_id, $contact_ids)
{
@@ -1937,8 +1957,8 @@ class rcube_ldap extends rcube_addressbook
$group_name = $group_cache[$group_id]['name'];
$member_attr = $group_cache[$group_id]['member_attr'];
$group_dn = "cn=$group_name,$base_dn";
+ $new_attrs = array();
- $new_attrs = array();
foreach ($contact_ids as $id)
$new_attrs[$member_attr][] = self::dn_decode($id);
@@ -1949,28 +1969,32 @@ class rcube_ldap extends rcube_addressbook
$this->cache->remove('groups');
- return count($new_attrs['member']);
+ return count($new_attrs[$member_attr]);
}
/**
* Remove the given contact records from a certain group
*
- * @param string Group identifier
- * @param array List of contact identifiers to be removed
- * @return int Number of deleted group members
+ * @param string Group identifier
+ * @param array|string List of contact identifiers to be removed
+ *
+ * @return int Number of deleted group members
*/
function remove_from_group($group_id, $contact_ids)
{
if (($group_cache = $this->cache->get('groups')) === null)
$group_cache = $this->_fetch_groups();
+ if (!is_array($contact_ids))
+ $contact_ids = explode(',', $contact_ids);
+
$base_dn = $this->groups_base_dn;
$group_name = $group_cache[$group_id]['name'];
$member_attr = $group_cache[$group_id]['member_attr'];
$group_dn = "cn=$group_name,$base_dn";
+ $del_attrs = array();
- $del_attrs = array();
- foreach (explode(",", $contact_ids) as $id)
+ foreach ($contact_ids as $id)
$del_attrs[$member_attr][] = self::dn_decode($id);
if (!$this->ldap_mod_del($group_dn, $del_attrs)) {
@@ -1980,7 +2004,7 @@ class rcube_ldap extends rcube_addressbook
$this->cache->remove('groups');
- return count($del_attrs['member']);
+ return count($del_attrs[$member_attr]);
}
/**
diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php
index 9db1fa30a..a42d3fb28 100644
--- a/program/lib/Roundcube/rcube_message.php
+++ b/program/lib/Roundcube/rcube_message.php
@@ -362,7 +362,7 @@ class rcube_message
// parse headers from message/rfc822 part
if (!isset($structure->headers['subject']) && !isset($structure->headers['from'])) {
- list($headers, $dump) = explode("\r\n\r\n", $this->get_part_content($structure->mime_id, null, true, 32768));
+ list($headers, ) = explode("\r\n\r\n", $this->get_part_content($structure->mime_id, null, true, 32768));
$structure->headers = rcube_mime::parse_headers($headers);
}
}
diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php
index 96296a57c..63549fbec 100644
--- a/program/lib/Roundcube/rcube_mime.php
+++ b/program/lib/Roundcube/rcube_mime.php
@@ -127,10 +127,11 @@ class rcube_mime
* @param int $max List only this number of addresses
* @param boolean $decode Decode address strings
* @param string $fallback Fallback charset if none specified
+ * @param boolean $addronly Return flat array with e-mail addresses only
*
- * @return array Indexed list of addresses
+ * @return array Indexed list of addresses
*/
- static function decode_address_list($input, $max = null, $decode = true, $fallback = null)
+ static function decode_address_list($input, $max = null, $decode = true, $fallback = null, $addronly = false)
{
$a = self::parse_address_list($input, $decode, $fallback);
$out = array();
@@ -145,20 +146,21 @@ class rcube_mime
foreach ($a as $val) {
$j++;
$address = trim($val['address']);
- $name = trim($val['name']);
- if ($name && $address && $name != $address)
- $string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address);
- else if ($address)
- $string = $address;
- else if ($name)
- $string = $name;
-
- $out[$j] = array(
- 'name' => $name,
- 'mailto' => $address,
- 'string' => $string
- );
+ if ($addronly) {
+ $out[$j] = $address;
+ }
+ else {
+ $name = trim($val['name']);
+ if ($name && $address && $name != $address)
+ $string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address);
+ else if ($address)
+ $string = $address;
+ else if ($name)
+ $string = $name;
+
+ $out[$j] = array('name' => $name, 'mailto' => $address, 'string' => $string);
+ }
if ($max && $j==$max)
break;
@@ -476,9 +478,10 @@ class rcube_mime
$q_level = 0;
foreach ($text as $idx => $line) {
- if ($line[0] == '>') {
- // remove quote chars, store level in $q
- $line = preg_replace('/^>+/', '', $line, -1, $q);
+ if (preg_match('/^(>+)/', $line, $m)) {
+ // remove quote chars
+ $q = strlen($m[1]);
+ $line = preg_replace('/^>+/', '', $line);
// remove (optional) space-staffing
$line = preg_replace('/^ /', '', $line);
@@ -541,9 +544,10 @@ class rcube_mime
foreach ($text as $idx => $line) {
if ($line != '-- ') {
- if ($line[0] == '>') {
- // remove quote chars, store level in $level
- $line = preg_replace('/^>+/', '', $line, -1, $level);
+ if (preg_match('/^(>+)/', $line, $m)) {
+ // remove quote chars
+ $level = strlen($m[1]);
+ $line = preg_replace('/^>+/', '', $line);
// remove (optional) space-staffing and spaces before the line end
$line = preg_replace('/(^ | +$)/', '', $line);
$prefix = str_repeat('>', $level) . ' ';
@@ -657,8 +661,8 @@ class rcube_mime
$cutLength = $spacePos + 1;
}
else {
- $subString = $string;
- $cutLength = null;
+ $subString = $substr_func($string, 0, $breakPos, $charset);
+ $cutLength = $breakPos + 1;
}
}
else {
diff --git a/program/lib/Roundcube/rcube_output.php b/program/lib/Roundcube/rcube_output.php
index b8ae86cf6..7ccf9a02e 100644
--- a/program/lib/Roundcube/rcube_output.php
+++ b/program/lib/Roundcube/rcube_output.php
@@ -162,7 +162,7 @@ abstract class rcube_output
header("Cache-Control: private, must-revalidate");
}
else {
- header("Cache-Control: private, no-cache, must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: private, no-cache, no-store, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
}
}
diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php
index 4bb6c6677..33f04eaa5 100644
--- a/program/lib/Roundcube/rcube_plugin_api.php
+++ b/program/lib/Roundcube/rcube_plugin_api.php
@@ -313,7 +313,6 @@ class rcube_plugin_api
$doc->loadXML($file);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('rc', "http://pear.php.net/dtd/package-2.0");
- $data = array();
// XPaths of plugin metadata elements
$metadata = array(
diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php
index 5c7d2203c..0f3ac0407 100644
--- a/program/lib/Roundcube/rcube_smtp.php
+++ b/program/lib/Roundcube/rcube_smtp.php
@@ -119,7 +119,7 @@ class rcube_smtp
}
// try to connect to server and exit on failure
- $result = $this->conn->connect($smtp_timeout);
+ $result = $this->conn->connect($CONFIG['smtp_timeout']);
if (PEAR::isError($result)) {
$this->response[] = "Connection failed: ".$result->getMessage();
@@ -433,9 +433,9 @@ class rcube_smtp
$recipients = rcube_utils::explode_quoted_string(',', $recipients);
reset($recipients);
- while (list($k, $recipient) = each($recipients)) {
+ foreach ($recipients as $recipient) {
$a = rcube_utils::explode_quoted_string(' ', $recipient);
- while (list($k2, $word) = each($a)) {
+ foreach ($a as $word) {
if (strpos($word, "@") > 0 && $word[strlen($word)-1] != '"') {
$word = preg_replace('/^<|>$/', '', trim($word));
if (in_array($word, $addresses) === false) {
diff --git a/program/lib/Roundcube/rcube_spellchecker.php b/program/lib/Roundcube/rcube_spellchecker.php
index 816bcad2f..60aec500f 100644
--- a/program/lib/Roundcube/rcube_spellchecker.php
+++ b/program/lib/Roundcube/rcube_spellchecker.php
@@ -314,11 +314,6 @@ class rcube_spellchecker
if (!$this->plink) {
if (!extension_loaded('pspell')) {
$this->error = "Pspell extension not available";
- rcube::raise_error(array(
- 'code' => 500, 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => $this->error), true, false);
-
return;
}
@@ -372,9 +367,19 @@ class rcube_spellchecker
fclose($fp);
}
+ // parse HTTP response
+ if (preg_match('!^HTTP/1.\d (\d+)(.+)!', $store, $m)) {
+ $http_status = $m[1];
+ if ($http_status != '200')
+ $this->error = 'HTTP ' . $m[1] . $m[2];
+ }
+
if (!$store) {
$this->error = "Empty result from spelling engine";
}
+ else if (preg_match('/<spellresult error="([^"]+)"/', $store, $m)) {
+ $this->error = "Error code $m[1] returned";
+ }
preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $store, $matches, PREG_SET_ORDER);
@@ -588,7 +593,7 @@ class rcube_spellchecker
if (empty($plugin['abort'])) {
$dict = array();
- $this->rc->db->query(
+ $sql_result = $this->rc->db->query(
"SELECT data FROM ".$this->rc->db->table_name('dictionary')
." WHERE user_id ". ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
." AND " . $this->rc->db->quoteIdentifier('language') . " = ?",
diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index fabe0f060..8467107fe 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -404,7 +404,7 @@ class rcube_utils
$out = array();
$src = $mode == self::INPUT_GET ? $_GET : ($mode == self::INPUT_POST ? $_POST : $_REQUEST);
- foreach ($src as $key => $value) {
+ foreach (array_keys($src) as $key) {
$fname = $key[0] == '_' ? substr($key, 1) : $key;
if ($ignore && !preg_match('/^(' . $ignore . ')$/', $fname)) {
$out[$fname] = self::get_input_value($key, $mode);
diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php
index 54bb9521d..90acb2110 100644
--- a/program/lib/Roundcube/rcube_vcard.php
+++ b/program/lib/Roundcube/rcube_vcard.php
@@ -90,7 +90,7 @@ class rcube_vcard
*/
public function __construct($vcard = null, $charset = RCUBE_CHARSET, $detect = false, $fieldmap = array())
{
- if (!empty($fielmap)) {
+ if (!empty($fieldmap)) {
$this->extend_fieldmap($fieldmap);
}
@@ -481,7 +481,7 @@ class rcube_vcard
$vcard_block = '';
$in_vcard_block = false;
- foreach (preg_split("/[\r\n]+/", $data) as $i => $line) {
+ foreach (preg_split("/[\r\n]+/", $data) as $line) {
if ($in_vcard_block && !empty($line)) {
$vcard_block .= $line . "\n";
}
@@ -784,9 +784,30 @@ class rcube_vcard
}
return $result;
}
+
+ $s = strtr($s, $rep2);
+ }
+
+ // some implementations (GMail) use non-standard backslash before colon (#1489085)
+ // we will handle properly any backslashed character - removing dummy backslahes
+ // return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';'));
+
+ $s = str_replace("\r", '', $s);
+ $pos = 0;
+
+ while (($pos = strpos($s, '\\', $pos)) !== false) {
+ $next = substr($s, $pos + 1, 1);
+ if ($next == 'n' || $next == 'N') {
+ $s = substr_replace($s, "\n", $pos, 2);
+ }
+ else {
+ $s = substr_replace($s, '', $pos, 1);
+ }
+
+ $pos += 1;
}
- return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';'));
+ return $s;
}
/**
diff --git a/program/lib/utf8.class.php b/program/lib/utf8.class.php
index e0dc9e2bd..0446159c7 100644
--- a/program/lib/utf8.class.php
+++ b/program/lib/utf8.class.php
@@ -60,8 +60,8 @@ Class utf8 {
function loadCharset($charset) {
$charset = preg_replace(array('/^WINDOWS-*125([0-8])$/', '/^CP-/'), array('CP125\\1', 'CP'), $charset);
- if (isset($aliases[$charset]))
- $charset = $aliases[$charset];
+ if (isset($this->aliases[$charset]))
+ $charset = $this->aliases[$charset];
$this->charset = $charset;