From be9aacaa5296dfca63fb3a01c2dc52538d1546aa Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Sat, 17 Nov 2012 12:31:31 -0500
Subject: [PATCH] Bring back lost localization for the about page
---
program/include/rcube_imap_generic.php | 236 +++++++++++++++++++++++++++++++---------------------------
1 files changed, 125 insertions(+), 111 deletions(-)
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index cffb250..a0a8f3b 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -5,8 +5,8 @@
| program/include/rcube_imap_generic.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2005-2010, The Roundcube Dev Team |
- | Copyright (C) 2011, Kolab Systems AG |
+ | Copyright (C) 2005-2012, The Roundcube Dev Team |
+ | Copyright (C) 2011-2012, Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -24,53 +24,14 @@
| Author: Aleksander Machniak <alec@alec.pl> |
| Author: Ryo Chijiiwa <Ryo@IlohaMail.org> |
+-----------------------------------------------------------------------+
-
- $Id$
-
*/
-/**
- * Struct representing an e-mail message header
- *
- * @package Mail
- * @author Aleksander Machniak <alec@alec.pl>
- */
-class rcube_mail_header
-{
- public $id;
- public $uid;
- public $subject;
- public $from;
- public $to;
- public $cc;
- public $replyto;
- public $in_reply_to;
- public $date;
- public $messageID;
- public $size;
- public $encoding;
- public $charset;
- public $ctype;
- public $timestamp;
- public $bodystructure;
- public $internaldate;
- public $references;
- public $priority;
- public $mdn_to;
- public $others = array();
- public $flags = array();
-}
-
-// For backward compatibility with cached messages (#1486602)
-class iilBasicHeader extends rcube_mail_header
-{
-}
/**
* PHP based wrapper class to connect to an IMAP server
*
- * @package Mail
- * @author Aleksander Machniak <alec@alec.pl>
+ * @package Framework
+ * @subpackage Storage
*/
class rcube_imap_generic
{
@@ -352,8 +313,12 @@
else {
$this->resultcode = null;
// parse response for [APPENDUID 1204196876 3456]
- if (preg_match("/^\[APPENDUID [0-9]+ ([0-9,:*]+)\]/i", $str, $m)) {
+ if (preg_match("/^\[APPENDUID [0-9]+ ([0-9]+)\]/i", $str, $m)) {
$this->data['APPENDUID'] = $m[1];
+ }
+ // parse response for [COPYUID 1204196876 3456:3457 123:124]
+ else if (preg_match("/^\[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\]/i", $str, $m)) {
+ $this->data['COPYUID'] = array($m[1], $m[2]);
}
}
$this->result = $str;
@@ -565,6 +530,7 @@
}
else {
$authc = $user;
+ $user = '';
}
$auth_sasl = Auth_SASL::factory('digestmd5');
$reply = base64_encode($auth_sasl->getResponse($authc, $pass,
@@ -603,6 +569,7 @@
}
else {
$authc = $user;
+ $user = '';
}
$reply = base64_encode($user . chr(0) . $authc . chr(0) . $pass);
@@ -1511,14 +1478,31 @@
*/
function enable($extension)
{
- if (empty($extension))
+ if (empty($extension)) {
return false;
+ }
- if (!$this->hasCapability('ENABLE'))
+ if (!$this->hasCapability('ENABLE')) {
return false;
+ }
- if (!is_array($extension))
+ if (!is_array($extension)) {
$extension = array($extension);
+ }
+
+ if (!empty($this->extensions_enabled)) {
+ // check if all extensions are already enabled
+ $diff = array_diff($extension, $this->extensions_enabled);
+
+ if (empty($diff)) {
+ return $extension;
+ }
+
+ // Make sure the mailbox isn't selected, before enabling extension(s)
+ if ($this->selected !== null) {
+ $this->close();
+ }
+ }
list($code, $response) = $this->execute('ENABLE', $extension);
@@ -1526,7 +1510,9 @@
$response = substr($response, 10); // remove prefix "* ENABLED "
$result = (array) $this->tokenizeResponse($response);
- return $result;
+ $this->extensions_enabled = array_unique(array_merge((array)$this->extensions_enabled, $result));
+
+ return $this->extensions_enabled;
}
return false;
@@ -1545,8 +1531,6 @@
*/
function sort($mailbox, $field, $add='', $return_uid=false, $encoding = 'US-ASCII')
{
- require_once dirname(__FILE__) . '/rcube_result_index.php';
-
$field = strtoupper($field);
if ($field == 'INTERNALDATE') {
$field = 'ARRIVAL';
@@ -1595,8 +1579,6 @@
*/
function thread($mailbox, $algorithm='REFERENCES', $criteria='', $return_uid=false, $encoding='US-ASCII')
{
- require_once dirname(__FILE__) . '/rcube_result_thread.php';
-
$old_sel = $this->selected;
if (!$this->select($mailbox)) {
@@ -1635,8 +1617,6 @@
*/
function search($mailbox, $criteria, $return_uid=false, $items=array())
{
- require_once dirname(__FILE__) . '/rcube_result_index.php';
-
$old_sel = $this->selected;
if (!$this->select($mailbox)) {
@@ -1650,7 +1630,7 @@
// If ESEARCH is supported always use ALL
// but not when items are specified or using simple id2uid search
- if (empty($items) && ((int) $criteria != $criteria)) {
+ if (empty($items) && preg_match('/[^0-9]/', $criteria)) {
$items = array('ALL');
}
@@ -1696,8 +1676,6 @@
function index($mailbox, $message_set, $index_field='', $skip_deleted=true,
$uidfetch=false, $return_uid=false)
{
- require_once dirname(__FILE__) . '/rcube_result_index.php';
-
$msg_index = $this->fetchHeaderIndex($mailbox, $message_set,
$index_field, $skip_deleted, $uidfetch, $return_uid);
@@ -1978,6 +1956,9 @@
*/
function copy($messages, $from, $to)
{
+ // Clear last COPYUID data
+ unset($this->data['COPYUID']);
+
if (!$this->select($from)) {
return false;
}
@@ -2034,7 +2015,7 @@
* @param string $mod_seq Modification sequence for CHANGEDSINCE (RFC4551) query
* @param bool $vanished Enables VANISHED parameter (RFC5162) for CHANGEDSINCE query
*
- * @return array List of rcube_mail_header elements, False on error
+ * @return array List of rcube_message_header elements, False on error
* @since 0.6
*/
function fetch($mailbox, $message_set, $is_uid = false, $query_items = array(),
@@ -2074,14 +2055,15 @@
if (preg_match('/^\* ([0-9]+) FETCH/', $line, $m)) {
$id = intval($m[1]);
- $result[$id] = new rcube_mail_header;
+ $result[$id] = new rcube_message_header;
$result[$id]->id = $id;
$result[$id]->subject = '';
$result[$id]->messageID = 'mid:' . $id;
- $lines = array();
- $line = substr($line, strlen($m[0]) + 2);
- $ln = 0;
+ $headers = null;
+ $lines = array();
+ $line = substr($line, strlen($m[0]) + 2);
+ $ln = 0;
// get complete entry
while (preg_match('/\{([0-9]+)\}\r\n$/', $line, $m)) {
@@ -2198,7 +2180,7 @@
$result[$id]->encoding = $string;
break;
case 'content-type':
- $ctype_parts = preg_split('/[; ]/', $string);
+ $ctype_parts = preg_split('/[; ]+/', $string);
$result[$id]->ctype = strtolower(array_shift($ctype_parts));
if (preg_match('/charset\s*=\s*"?([a-z0-9\-\.\_]+)"?/i', $string, $regs)) {
$result[$id]->charset = $regs[1];
@@ -2397,7 +2379,7 @@
return $this->handlePartBody($mailbox, $id, $is_uid, $part);
}
- function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL)
+ function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=false)
{
if (!$this->select($mailbox)) {
return false;
@@ -2420,15 +2402,23 @@
$mode = 0;
}
+ // Use BINARY extension when possible (and safe)
+ $binary = $mode && preg_match('/^[0-9.]+$/', $part) && $this->hasCapability('BINARY');
+ $fetch_mode = $binary ? 'BINARY' : 'BODY';
+
// format request
- $reply_key = '* ' . $id;
$key = $this->nextTag();
- $request = $key . ($is_uid ? ' UID' : '') . " FETCH $id (BODY.PEEK[$part])";
+ $request = $key . ($is_uid ? ' UID' : '') . " FETCH $id ($fetch_mode.PEEK[$part])";
// send request
if (!$this->putLine($request)) {
$this->setError(self::ERROR_COMMAND, "Unable to send command: $request");
return false;
+ }
+
+ if ($binary) {
+ // WARNING: Use $formatting argument with care, this may break binary data stream
+ $mode = -1;
}
// receive reply line
@@ -2475,13 +2465,13 @@
$prev = '';
while ($bytes > 0) {
- $line = $this->readLine(4096);
+ $line = $this->readLine(8192);
if ($line === NULL) {
break;
}
- $len = strlen($line);
+ $len = strlen($line);
if ($len > $bytes) {
$line = substr($line, 0, $bytes);
@@ -2514,7 +2504,7 @@
continue;
$line = convert_uudecode($line);
// default
- } else {
+ } else if ($formatted) {
$line = rtrim($line, "\t\r\n\0\x0B") . "\n";
}
@@ -2551,14 +2541,16 @@
*
* @param string $mailbox Mailbox name
* @param string $message Message content
+ * @param array $flags Message flags
+ * @param string $date Message internal date
*
* @return string|bool On success APPENDUID response (if available) or True, False on failure
*/
- function append($mailbox, &$message)
+ function append($mailbox, &$message, $flags = array(), $date = null)
{
unset($this->data['APPENDUID']);
- if (!$mailbox) {
+ if ($mailbox === null || $mailbox === '') {
return false;
}
@@ -2570,12 +2562,17 @@
return false;
}
+ // build APPEND command
$key = $this->nextTag();
- $request = sprintf("$key APPEND %s (\\Seen) {%d%s}", $this->escape($mailbox),
- $len, ($this->prefs['literal+'] ? '+' : ''));
+ $request = "$key APPEND " . $this->escape($mailbox) . ' (' . $this->flagsToStr($flags) . ')';
+ if (!empty($date)) {
+ $request .= ' ' . $this->escape($date);
+ }
+ $request .= ' {' . $len . ($this->prefs['literal+'] ? '+' : '') . '}';
+ // send APPEND command
if ($this->putLine($request)) {
- // Don't wait when LITERAL+ is supported
+ // Do not wait when LITERAL+ is supported
if (!$this->prefs['literal+']) {
$line = $this->readReply();
@@ -2616,14 +2613,16 @@
* @param string $mailbox Mailbox name
* @param string $path Path to the file with message body
* @param string $headers Message headers
+ * @param array $flags Message flags
+ * @param string $date Message internal date
*
* @return string|bool On success APPENDUID response (if available) or True, False on failure
*/
- function appendFromFile($mailbox, $path, $headers=null)
+ function appendFromFile($mailbox, $path, $headers=null, $flags = array(), $date = null)
{
unset($this->data['APPENDUID']);
- if (!$mailbox) {
+ if ($mailbox === null || $mailbox === '') {
return false;
}
@@ -2632,6 +2631,7 @@
if (file_exists(realpath($path))) {
$in_fp = fopen($path, 'r');
}
+
if (!$in_fp) {
$this->setError(self::ERROR_UNKNOWN, "Couldn't open $path for reading");
return false;
@@ -2649,11 +2649,15 @@
$len += strlen($headers) + strlen($body_separator);
}
- // send APPEND command
+ // build APPEND command
$key = $this->nextTag();
- $request = sprintf("$key APPEND %s (\\Seen) {%d%s}", $this->escape($mailbox),
- $len, ($this->prefs['literal+'] ? '+' : ''));
+ $request = "$key APPEND " . $this->escape($mailbox) . ' (' . $this->flagsToStr($flags) . ')';
+ if (!empty($date)) {
+ $request .= ' ' . $this->escape($date);
+ }
+ $request .= ' {' . $len . ($this->prefs['literal+'] ? '+' : '') . '}';
+ // send APPEND command
if ($this->putLine($request)) {
// Don't wait when LITERAL+ is supported
if (!$this->prefs['literal+']) {
@@ -3222,10 +3226,10 @@
*/
static function getStructurePartData($structure, $part)
{
- $part_a = self::getStructurePartArray($structure, $part);
- $data = array();
+ $part_a = self::getStructurePartArray($structure, $part);
+ $data = array();
- if (empty($part_a)) {
+ if (empty($part_a)) {
return $data;
}
@@ -3258,13 +3262,13 @@
static function getStructurePartArray($a, $part)
{
- if (!is_array($a)) {
+ if (!is_array($a)) {
return false;
}
if (empty($part)) {
- return $a;
- }
+ return $a;
+ }
$ctype = is_string($a[0]) && is_string($a[1]) ? $a[0] . '/' . $a[1] : '';
@@ -3272,20 +3276,17 @@
$a = $a[8];
}
- if (strpos($part, '.') > 0) {
- $orig_part = $part;
- $pos = strpos($part, '.');
- $rest = substr($orig_part, $pos+1);
- $part = substr($orig_part, 0, $pos);
+ if (strpos($part, '.') > 0) {
+ $orig_part = $part;
+ $pos = strpos($part, '.');
+ $rest = substr($orig_part, $pos+1);
+ $part = substr($orig_part, 0, $pos);
- return self::getStructurePartArray($a[$part-1], $rest);
- }
+ return self::getStructurePartArray($a[$part-1], $rest);
+ }
else if ($part > 0) {
- if (is_array($a[$part-1]))
- return $a[$part-1];
- else
- return $a;
- }
+ return (is_array($a[$part-1])) ? $a[$part-1] : $a;
+ }
}
/**
@@ -3530,6 +3531,10 @@
*/
static function uncompressMessageSet($messages)
{
+ if (empty($messages)) {
+ return array();
+ }
+
$result = array();
$messages = explode(',', $messages);
@@ -3538,7 +3543,7 @@
$max = max($items[0], $items[1]);
for ($x=$items[0]; $x<=$max; $x++) {
- $result[] = $x;
+ $result[] = (int)$x;
}
unset($messages[$idx]);
}
@@ -3556,6 +3561,24 @@
}
return $result;
+ }
+
+ /**
+ * Converts flags array into string for inclusion in IMAP command
+ *
+ * @param array $flags Flags (see self::flags)
+ *
+ * @return string Space-separated list of flags
+ */
+ private function flagsToStr($flags)
+ {
+ foreach ((array)$flags as $idx => $flag) {
+ if ($flag = $this->flags[strtoupper($flag)]) {
+ $flags[$idx] = $flag;
+ }
+ }
+
+ return implode(' ', (array)$flags);
}
/**
@@ -3616,13 +3639,16 @@
if ($string === null) {
return 'NIL';
}
+
if ($string === '') {
return '""';
}
+
// atom-string (only safe characters)
- if (!$force_quotes && !preg_match('/[\x00-\x20\x22\x28-\x2A\x5B-\x5D\x7B\x7D\x80-\xFF]/', $string)) {
+ if (!$force_quotes && !preg_match('/[\x00-\x20\x22\x25\x28-\x2A\x5B-\x5D\x7B\x7D\x80-\xFF]/', $string)) {
return $string;
}
+
// quoted-string
if (!preg_match('/[\r\n\x00\x80-\xFF]/', $string)) {
return '"' . addcslashes($string, '\\"') . '"';
@@ -3630,18 +3656,6 @@
// literal-string
return sprintf("{%d}\r\n%s", strlen($string), $string);
- }
-
- /**
- * Unescapes quoted-string
- *
- * @param string $string IMAP string
- *
- * @return string String
- */
- static function unEscape($string)
- {
- return stripslashes($string);
}
/**
--
Gitblit v1.9.1