summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
Diffstat (limited to 'program/include')
-rw-r--r--program/include/rcube.php17
-rw-r--r--program/include/rcube_addressbook.php21
-rw-r--r--program/include/rcube_contacts.php8
-rw-r--r--program/include/rcube_imap.php38
-rw-r--r--program/include/rcube_mime.php8
-rw-r--r--program/include/rcube_utils.php41
6 files changed, 94 insertions, 39 deletions
diff --git a/program/include/rcube.php b/program/include/rcube.php
index 272136fa8..e9add8d5a 100644
--- a/program/include/rcube.php
+++ b/program/include/rcube.php
@@ -1050,6 +1050,18 @@ class rcube
*/
public static function raise_error($arg = array(), $log = false, $terminate = false)
{
+ // handle PHP exceptions
+ if (is_object($arg) && is_a($arg, 'Exception')) {
+ $err = array(
+ 'type' => 'php',
+ 'code' => $arg->getCode(),
+ 'line' => $arg->getLine(),
+ 'file' => $arg->getFile(),
+ 'message' => $arg->getMessage(),
+ );
+ $arg = $err;
+ }
+
// installer
if (class_exists('rcube_install', false)) {
$rci = rcube_install::get_instance();
@@ -1057,7 +1069,8 @@ class rcube
return;
}
- if ($log && $arg['type'] && $arg['message']) {
+ if (($log || $terminate) && $arg['type'] && $arg['message']) {
+ $arg['fatal'] = $terminate;
self::log_bug($arg);
}
@@ -1085,7 +1098,7 @@ class rcube
}
// write error to local log file
- if ($level & 1) {
+ if (($level & 1) || !empty($arg_arr['fatal'])) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$post_query = '?_task='.urlencode($_POST['_task']).'&_action='.urlencode($_POST['_action']);
}
diff --git a/program/include/rcube_addressbook.php b/program/include/rcube_addressbook.php
index 2f264f974..8e104ddee 100644
--- a/program/include/rcube_addressbook.php
+++ b/program/include/rcube_addressbook.php
@@ -447,30 +447,13 @@ abstract class rcube_addressbook
*
* @param string Input string (UTF-8)
* @return string Normalized string
+ * @deprecated since 0.9-beta
*/
protected static function normalize_string($str)
{
- // split by words
- $arr = explode(" ", preg_replace(
- array('/[\s;\+\-\/]+/i', '/(\d)[-.\s]+(\d)/', '/\s\w{1,3}\s/'),
- array(' ', '\\1\\2', ' '),
- $str));
-
- foreach ($arr as $i => $part) {
- if (utf8_encode(utf8_decode($part)) == $part) { // is latin-1 ?
- $arr[$i] = utf8_encode(strtr(strtolower(strtr(utf8_decode($part),
- '',
- 'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')),
- array('' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')));
- }
- else
- $arr[$i] = mb_strtolower($part);
- }
-
- return join(" ", $arr);
+ return rcbe_utils::normalize_string($str);
}
-
/**
* Compose a valid display name from the given structured contact data
*
diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php
index 8834a7dbc..4ebe1b15e 100644
--- a/program/include/rcube_contacts.php
+++ b/program/include/rcube_contacts.php
@@ -313,7 +313,7 @@ class rcube_contacts extends rcube_addressbook
// fulltext search in all fields
else if ($col == '*') {
$words = array();
- foreach (explode($WS, self::normalize_string($value)) as $word) {
+ foreach (explode($WS, rcube_utils::normalize_string($value)) as $word) {
switch ($mode) {
case 1: // strict
$words[] = '(' . $this->db->ilike('words', $word . '%')
@@ -352,7 +352,7 @@ class rcube_contacts extends rcube_addressbook
// vCard field
else {
if (in_array($col, $this->fulltext_cols)) {
- foreach (explode(" ", self::normalize_string($val)) as $word) {
+ foreach (rcube_utils::normalize_string($val, true) as $word) {
switch ($mode) {
case 1: // strict
$words[] = '(' . $this->db->ilike('words', $word . $WS . '%')
@@ -728,9 +728,9 @@ class rcube_contacts extends rcube_addressbook
if (isset($value))
$vcard->set($field, $value, $section);
if ($fulltext && is_array($value))
- $words .= ' ' . self::normalize_string(join(" ", $value));
+ $words .= ' ' . rcube_utils::normalize_string(join(" ", $value));
else if ($fulltext && strlen($value) >= 3)
- $words .= ' ' . self::normalize_string($value);
+ $words .= ' ' . rcube_utils::normalize_string($value);
}
}
$out['vcard'] = $vcard->export(false);
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index f401f3707..b966aa348 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -3424,7 +3424,7 @@ class rcube_imap extends rcube_storage
return false;
}
- $this->clear_cache('mailboxes.metadata.' . $folder);
+ $this->clear_cache('mailboxes.metadata.', true);
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
@@ -3458,9 +3458,9 @@ class rcube_imap extends rcube_storage
return false;
}
- $this->clear_cache('mailboxes.metadata.' . $folder);
+ $this->clear_cache('mailboxes.metadata.', true);
- if ($this->get_capability('METADATA') ||
+ if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
) {
return $this->conn->deleteMetadata($folder, $entries);
@@ -3489,27 +3489,38 @@ class rcube_imap extends rcube_storage
*/
public function get_metadata($folder, $entries, $options=array())
{
+ $entries = (array)$entries;
+
+ // create cache key
+ // @TODO: this is the simplest solution, but we do the same with folders list
+ // maybe we should store data per-entry and merge on request
+ sort($options);
+ sort($entries);
+ $cache_key = 'mailboxes.metadata.' . $folder;
+ $cache_key .= '.' . md5(serialize($options).serialize($entries));
+
+ // get cached data
+ $cached_data = $this->get_cache($cache_key);
+
+ if (is_array($cached_data)) {
+ return $cached_data;
+ }
+
if (!$this->check_connection()) {
return null;
}
- $cache_key = 'mailboxes.metadata.' . $folder;
- if ($cached = $this->get_cache($cache_key))
- return $cached;
-
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
) {
$res = $this->conn->getMetadata($folder, $entries, $options);
- $this->update_cache($cache_key, $res);
- return $res;
}
else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) {
$queries = array();
$res = array();
// Convert entry names
- foreach ((array)$entries as $entry) {
+ foreach ($entries as $entry) {
list($ent, $attr) = $this->md2annotate($entry);
$queries[$attr][] = $ent;
}
@@ -3520,7 +3531,9 @@ class rcube_imap extends rcube_storage
$res = array_merge_recursive($res, $result);
}
}
+ }
+ if (isset($res)) {
$this->update_cache($cache_key, $res);
return $res;
}
@@ -3955,6 +3968,11 @@ class rcube_imap extends rcube_storage
return $this->list_messages($folder, $page, $sort_field, $sort_order, $slice);
}
+ public function get_headers($uid, $folder = null, $force = false)
+ {
+ return $this->get_message_headers($uid, $folder, $force);
+ }
+
public function mailbox_status($folder = null)
{
return $this->folder_status($folder);
diff --git a/program/include/rcube_mime.php b/program/include/rcube_mime.php
index 64ce67d5f..864d25599 100644
--- a/program/include/rcube_mime.php
+++ b/program/include/rcube_mime.php
@@ -214,7 +214,7 @@ class rcube_mime
// Append everything that is before the text to be decoded
if ($start != $pos) {
$substr = substr($input, $start, $pos-$start);
- $out .= rcube_charset_convert($substr, $default_charset);
+ $out .= rcube_charset::convert($substr, $default_charset);
$start = $pos;
}
$start += $length;
@@ -255,13 +255,13 @@ class rcube_mime
$text = quoted_printable_decode($text);
}
- $out .= rcube_charset_convert($text, $charset);
+ $out .= rcube_charset::convert($text, $charset);
$tmp = array();
}
// add the last part of the input string
if ($start != strlen($input)) {
- $out .= rcube_charset_convert(substr($input, $start), $default_charset);
+ $out .= rcube_charset::convert(substr($input, $start), $default_charset);
}
// return the results
@@ -269,7 +269,7 @@ class rcube_mime
}
// no encoding information, use fallback
- return rcube_charset_convert($input, $default_charset);
+ return rcube_charset::convert($input, $default_charset);
}
diff --git a/program/include/rcube_utils.php b/program/include/rcube_utils.php
index 5b31537fd..c6d4805c8 100644
--- a/program/include/rcube_utils.php
+++ b/program/include/rcube_utils.php
@@ -790,4 +790,45 @@ class rcube_utils
return $at ? $user . '@' . $domain : $domain;
}
+ /**
+ * Split the given string into word tokens
+ *
+ * @param string Input to tokenize
+ * @return array List of tokens
+ */
+ public static function tokenize_string($str)
+ {
+ return explode(" ", preg_replace(
+ array('/[\s;\/+-]+/i', '/(\d)[-.\s]+(\d)/', '/\s\w{1,3}\s/u'),
+ array(' ', '\\1\\2', ' '),
+ $str));
+ }
+
+ /**
+ * Normalize the given string for fulltext search.
+ * Currently only optimized for Latin-1 characters; to be extended
+ *
+ * @param string Input string (UTF-8)
+ * @param boolean True to return list of words as array
+ * @return mixed Normalized string or a list of normalized tokens
+ */
+ public static function normalize_string($str, $as_array = false)
+ {
+ // split by words
+ $arr = self::tokenize_string($str);
+
+ foreach ($arr as $i => $part) {
+ if (utf8_encode(utf8_decode($part)) == $part) { // is latin-1 ?
+ $arr[$i] = utf8_encode(strtr(strtolower(strtr(utf8_decode($part),
+ 'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ',
+ 'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')),
+ array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')));
+ }
+ else
+ $arr[$i] = mb_strtolower($part);
+ }
+
+ return $as_array ? $arr : join(" ", $arr);
+ }
+
}