From 26bc46d9b671ea069fc779ecb8b4ac90323c2291 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 07 Sep 2011 02:59:48 -0400
Subject: [PATCH] - Move two entries from 0.6-rc to trunk's changelog part
---
program/include/rcube_imap.php | 109 +++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 82 insertions(+), 27 deletions(-)
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index c2a4a0d..97b080a 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -5,7 +5,8 @@
| program/include/rcube_imap.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2005-2010, The Roundcube Dev Team |
+ | Copyright (C) 2005-2011, The Roundcube Dev Team |
+ | Copyright (C) 2011, Kolab Systems AG |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -80,24 +81,22 @@
private $db_header_fields = array('idx', 'uid', 'subject', 'from', 'to', 'cc', 'date', 'size');
private $options = array('auth_method' => 'check');
private $host, $user, $pass, $port, $ssl;
+ private $caching = false;
/**
* All (additional) headers used (in any way) by Roundcube
- * Not listed here: DATE, FROM, TO, SUBJECT, CONTENT-TYPE, LIST-POST
+ * Not listed here: DATE, FROM, TO, CC, REPLY-TO, SUBJECT, CONTENT-TYPE, LIST-POST
* (used for messages listing) are hardcoded in rcube_imap_generic::fetchHeaders()
*
* @var array
* @see rcube_imap::fetch_add_headers
*/
private $all_headers = array(
- 'REPLY-TO',
'IN-REPLY-TO',
- 'CC',
'BCC',
'MESSAGE-ID',
'CONTENT-TRANSFER-ENCODING',
'REFERENCES',
- 'X-PRIORITY',
'X-DRAFT-INFO',
'MAIL-FOLLOWUP-TO',
'MAIL-REPLY-TO',
@@ -2164,7 +2163,7 @@
if (strtolower($part[$i][0]) == 'message' && strtolower($part[$i][1]) == 'rfc822') {
$mime_part_headers[] = $tmp_part_id;
}
- else if (in_array('name', (array)$part[$i][2]) && (empty($part[$i][3]) || $part[$i][3]=='NIL')) {
+ else if (in_array('name', (array)$part[$i][2]) && empty($part[$i][3])) {
$mime_part_headers[] = $tmp_part_id;
}
}
@@ -2232,13 +2231,13 @@
}
// read content encoding
- if (!empty($part[5]) && $part[5]!='NIL') {
+ if (!empty($part[5])) {
$struct->encoding = strtolower($part[5]);
$struct->headers['content-transfer-encoding'] = $struct->encoding;
}
// get part size
- if (!empty($part[6]) && $part[6]!='NIL')
+ if (!empty($part[6]))
$struct->size = intval($part[6]);
// read part disposition
@@ -2265,7 +2264,7 @@
}
// get part ID
- if (!empty($part[3]) && $part[3]!='NIL') {
+ if (!empty($part[3])) {
$struct->content_id = $part[3];
$struct->headers['content-id'] = $part[3];
@@ -3075,6 +3074,9 @@
if (isset($data['folders'])) {
$a_folders = $data['folders'];
}
+ else if (!$this->conn->connected()) {
+ return array();
+ }
else {
// Server supports LIST-EXTENDED, we can use selection options
$config = rcmail::get_instance()->config;
@@ -3084,20 +3086,36 @@
$a_folders = $this->conn->listMailboxes($root, $name,
NULL, array('SUBSCRIBED'));
- // remove non-existent folders
- if (is_array($a_folders)) {
+ // unsubscribe non-existent folders, remove from the list
+ if (is_array($a_folders) && $name == '*') {
foreach ($a_folders as $idx => $folder) {
if ($this->conn->data['LIST'] && ($opts = $this->conn->data['LIST'][$folder])
&& in_array('\\NonExistent', $opts)
) {
+ $this->conn->unsubscribe($folder);
unset($a_folders[$idx]);
- }
+ }
}
}
}
// retrieve list of folders from IMAP server using LSUB
else {
$a_folders = $this->conn->listSubscribed($root, $name);
+
+ // unsubscribe non-existent folders, remove from the list
+ if (is_array($a_folders) && $name == '*') {
+ foreach ($a_folders as $idx => $folder) {
+ if ($this->conn->data['LIST'] && ($opts = $this->conn->data['LIST'][$folder])
+ && in_array('\\Noselect', $opts)
+ ) {
+ // Some servers returns \Noselect for existing folders
+ if (!$this->mailbox_exists($folder)) {
+ $this->conn->unsubscribe($folder);
+ unset($a_folders[$idx]);
+ }
+ }
+ }
+ }
}
}
@@ -3498,6 +3516,10 @@
*/
function mailbox_info($mailbox)
{
+ if ($this->icache['options'] && $this->icache['options']['name'] == $mailbox) {
+ return $this->icache['options'];
+ }
+
$acl = $this->get_capability('ACL');
$namespace = $this->get_namespace();
$options = array();
@@ -3510,8 +3532,21 @@
foreach ($ns as $item) {
if ($item[0] === $mbox) {
$options['is_root'] = true;
- break;
+ break 2;
}
+ }
+ }
+ }
+ }
+ // check if the folder is other user virtual-root
+ if (!$options['is_root'] && !empty($namespace) && !empty($namespace['other'])) {
+ $parts = explode($this->delimiter, $mailbox);
+ if (count($parts) == 2) {
+ $mbox = $parts[0] . $this->delimiter;
+ foreach ($namespace['other'] as $item) {
+ if ($item[0] === $mbox) {
+ $options['is_root'] = true;
+ break;
}
}
}
@@ -3523,6 +3558,7 @@
$options['rights'] = $acl && !$options['is_root'] ? (array)$this->my_rights($mailbox) : array();
$options['special'] = in_array($mailbox, $this->default_folders);
+ // Set 'noselect' and 'norename' flags
if (is_array($options['options'])) {
foreach ($options['options'] as $opt) {
$opt = strtolower($opt);
@@ -3536,12 +3572,16 @@
}
if (!empty($options['rights'])) {
- $options['norename'] = !in_array('x', $options['rights']) &&
- (!in_array('c', $options['rights']) || !in_array('d', $options['rights']));
+ $options['norename'] = !in_array('x', $options['rights']);
if (!$options['noselect']) {
$options['noselect'] = !in_array('r', $options['rights']);
}
}
+ else {
+ $options['norename'] = $options['is_root'] || $options['namespace'] != 'personal';
+ }
+
+ $this->icache['options'] = $options;
return $options;
}
@@ -3797,22 +3837,34 @@
/**
* Enable or disable indexes caching
*
- * @param boolean $type Cache type (@see rcmail::get_cache)
+ * @param string $type Cache type (@see rcmail::get_cache)
* @access public
*/
function set_caching($type)
{
if ($type) {
- $rcmail = rcmail::get_instance();
- $this->cache = $rcmail->get_cache('IMAP', $type);
+ $this->caching = $type;
}
else {
if ($this->cache)
$this->cache->close();
$this->cache = null;
+ $this->caching = false;
}
}
+ /**
+ * Getter for IMAP cache object
+ */
+ private function get_cache_engine()
+ {
+ if ($this->caching && !$this->cache) {
+ $rcmail = rcmail::get_instance();
+ $this->cache = $rcmail->get_cache('IMAP', $this->caching);
+ }
+
+ return $this->cache;
+ }
/**
* Returns cached value
@@ -3823,8 +3875,8 @@
*/
function get_cache($key)
{
- if ($this->cache) {
- return $this->cache->get($key);
+ if ($cache = $this->get_cache_engine()) {
+ return $cache->get($key);
}
}
@@ -3837,8 +3889,8 @@
*/
function update_cache($key, $data)
{
- if ($this->cache) {
- $this->cache->set($key, $data);
+ if ($cache = $this->get_cache_engine()) {
+ $cache->set($key, $data);
}
}
@@ -3852,8 +3904,8 @@
*/
function clear_cache($key=null, $prefix_mode=false)
{
- if ($this->cache) {
- $this->cache->remove($key, $prefix_mode);
+ if ($cache = $this->get_cache_engine()) {
+ $cache->remove($key, $prefix_mode);
}
}
@@ -4733,16 +4785,19 @@
$str = self::explode_header_string(',;', $str, true);
$result = array();
+ // simplified regexp, supporting quoted local part
+ $email_rx = '(\S+|("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+"))@\S+';
+
foreach ($str as $key => $val) {
$name = '';
$address = '';
$val = trim($val);
- if (preg_match('/(.*)<(\S+@\S+)>$/', $val, $m)) {
+ if (preg_match('/(.*)<('.$email_rx.')>$/', $val, $m)) {
$address = $m[2];
$name = trim($m[1]);
}
- else if (preg_match('/^(\S+@\S+)$/', $val, $m)) {
+ else if (preg_match('/^('.$email_rx.')$/', $val, $m)) {
$address = $m[1];
$name = '';
}
@@ -4752,7 +4807,7 @@
// dequote and/or decode name
if ($name) {
- if ($name[0] == '"') {
+ if ($name[0] == '"' && $name[strlen($name)-1] == '"') {
$name = substr($name, 1, -1);
$name = stripslashes($name);
}
--
Gitblit v1.9.1