- Improved IMAP errors handling

release-0.6
alecpl 14 years ago
parent 1c1e1e39f3
commit 8fcc3e1ad6

@ -118,8 +118,9 @@ if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') {
$OUTPUT->redirect($redir); $OUTPUT->redirect($redir);
} }
else { else {
$OUTPUT->show_message($IMAP->error_code < -1 ? 'imaperror' : 'loginfailed', 'warning'); $OUTPUT->show_message($IMAP->get_error_code() < -1 ? 'imaperror' : 'loginfailed', 'warning');
$RCMAIL->plugins->exec_hook('login_failed', array('code' => $IMAP->error_code, 'host' => $auth['host'], 'user' => $auth['user'])); $RCMAIL->plugins->exec_hook('login_failed', array(
'code' => $IMAP->get_error_code(), 'host' => $auth['host'], 'user' => $auth['user']));
$RCMAIL->kill_session(); $RCMAIL->kill_session();
} }
} }

@ -32,7 +32,6 @@
class rcube_imap class rcube_imap
{ {
public $debug_level = 1; public $debug_level = 1;
public $error_code = 0;
public $skip_deleted = false; public $skip_deleted = false;
public $root_dir = ''; public $root_dir = '';
public $page_size = 10; public $page_size = 10;
@ -173,7 +172,6 @@ class rcube_imap
} }
// write error log // write error log
else if ($this->conn->error) { else if ($this->conn->error) {
$this->error_code = $this->conn->errornum;
if ($pass && $user) if ($pass && $user)
raise_error(array('code' => 403, 'type' => 'imap', raise_error(array('code' => 403, 'type' => 'imap',
'file' => __FILE__, 'line' => __LINE__, 'file' => __FILE__, 'line' => __LINE__,
@ -213,7 +211,29 @@ class rcube_imap
$this->conn->select($this->mailbox); $this->conn->select($this->mailbox);
} }
/**
* Returns code of last error
*
* @return int Error code
*/
function get_error_code()
{
return ($this->conn) ? $this->conn->errornum : 0;
}
/**
* Returns message of last error
*
* @return string Error message
*/
function get_error_str()
{
return ($this->conn) ? $this->conn->error : '';
}
/** /**
* Set options to be used in rcube_imap_generic::connect() * Set options to be used in rcube_imap_generic::connect()
* *
@ -568,11 +588,11 @@ class rcube_imap
if (!empty($this->icache['threads'])) if (!empty($this->icache['threads']))
return count($this->icache['threads']['tree']); return count($this->icache['threads']['tree']);
list ($thread_tree, $msg_depth, $has_children) = $this->_fetch_threads($mailbox); if (is_array($result = $this->_fetch_threads($mailbox)))
$thread_tree = array_shift($result);
$msg_count = count($msg_depth);
// $this->update_thread_cache($mailbox, $thread_tree, $msg_depth, $has_children); // list ($thread_tree, $msg_depth, $has_children) = $result;
// $this->update_thread_cache($mailbox, $thread_tree, $msg_depth, $has_children);
return count($thread_tree); return count($thread_tree);
} }

@ -112,6 +112,13 @@ class rcube_imap_generic
private $capability_readed = false; private $capability_readed = false;
private $prefs; private $prefs;
const ERROR_OK = 0;
const ERROR_NO = -1;
const ERROR_BAD = -2;
const ERROR_BYE = -3;
const ERROR_COMMAND = -5;
const ERROR_UNKNOWN = -4;
/** /**
* Object constructor * Object constructor
*/ */
@ -264,24 +271,36 @@ class rcube_imap_generic
return $line; return $line;
} }
function parseResult($string) function parseResult($string, $err_prefix='')
{ {
$a = explode(' ', trim($string)); if (preg_match('/^[a-z0-9*]+ (OK|NO|BAD|BYE)(.*)$/i', trim($string), $matches)) {
if (count($a) >= 2) { $res = strtoupper($matches[1]);
$res = strtoupper($a[1]); $str = trim($matches[2]);
if ($res == 'OK') { if ($res == 'OK') {
return 0; return self::ERROR_OK;
} else if ($res == 'NO') { } else if ($res == 'NO') {
return -1; $this->errornum = self::ERROR_NO;
} else if ($res == 'BAD') { } else if ($res == 'BAD') {
return -2; $this->errornum = self::ERROR_BAD;
} else if ($res == 'BYE') { } else if ($res == 'BYE') {
@fclose($this->fp); @fclose($this->fp);
$this->fp = null; $this->fp = null;
return -3; $this->errornum = self::ERROR_BYE;
} }
if ($str)
$this->error = $err_prefix ? $err_prefix.$str : $str;
return $this->errornum;
} }
return -4; return self::ERROR_UNKNOWN;
}
private function set_error($code, $msg='')
{
$this->errornum = $code;
$this->error = $msg;
} }
// check if $string starts with $match (or * BYE/BAD) // check if $string starts with $match (or * BYE/BAD)
@ -377,13 +396,11 @@ class rcube_imap_generic
// process result // process result
$result = $this->parseResult($line); $result = $this->parseResult($line);
if ($result == 0) { if ($result == self::ERROR_OK) {
$this->errornum = 0;
return $this->fp; return $this->fp;
} }
$this->error = "Authentication for $user failed (AUTH): $line"; $this->error = "Authentication for $user failed (AUTH): $line";
$this->errornum = $result;
return $result; return $result;
} }
@ -402,16 +419,13 @@ class rcube_imap_generic
// process result // process result
$result = $this->parseResult($line); $result = $this->parseResult($line);
if ($result == 0) { if ($result == self::ERROR_OK) {
$this->errornum = 0;
return $this->fp; return $this->fp;
} }
@fclose($this->fp); @fclose($this->fp);
$this->fp = false; $this->fp = false;
$this->error = "Authentication for $user failed (LOGIN): $line";
$this->error = "Authentication for $user failed (LOGIN): $line";
$this->errornum = $result;
return $result; return $result;
} }
@ -550,7 +564,7 @@ class rcube_imap_generic
// initialize connection // initialize connection
$this->error = ''; $this->error = '';
$this->errornum = 0; $this->errornum = self::ERROR_OK;
$this->selected = ''; $this->selected = '';
$this->user = $user; $this->user = $user;
$this->host = $host; $this->host = $host;
@ -558,18 +572,15 @@ class rcube_imap_generic
// check input // check input
if (empty($host)) { if (empty($host)) {
$this->error = "Empty host"; $this->set_error(self::ERROR_BAD, "Empty host");
$this->errornum = -2;
return false; return false;
} }
if (empty($user)) { if (empty($user)) {
$this->error = "Empty user"; $this->set_error(self::ERROR_NO, "Empty user");
$this->errornum = -1;
return false; return false;
} }
if (empty($password)) { if (empty($password)) {
$this->error = "Empty password"; $this->set_error(self::ERROR_NO, "Empty password");
$this->errornum = -1;
return false; return false;
} }
@ -588,8 +599,7 @@ class rcube_imap_generic
$this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr); $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr);
if (!$this->fp) { if (!$this->fp) {
$this->error = sprintf("Could not connect to %s:%d: %s", $host, $this->prefs['port'], $errstr); $this->set_error(self::ERROR_BAD, sprintf("Could not connect to %s:%d: %s", $host, $this->prefs['port'], $errstr));
$this->errornum = -2;
return false; return false;
} }
@ -608,7 +618,7 @@ class rcube_imap_generic
$this->error = sprintf("Wrong startup greeting (%s:%d): %s", $host, $this->prefs['port'], $line); $this->error = sprintf("Wrong startup greeting (%s:%d): %s", $host, $this->prefs['port'], $line);
else else
$this->error = sprintf("Empty startup greeting (%s:%d)", $host, $this->prefs['port']); $this->error = sprintf("Empty startup greeting (%s:%d)", $host, $this->prefs['port']);
$this->errornum = -2; $this->errornum = self::ERROR_BAD;
return false; return false;
} }
@ -626,14 +636,12 @@ class rcube_imap_generic
$line = $this->readLine(4096); $line = $this->readLine(4096);
if (!preg_match('/^tls0 OK/', $line)) { if (!preg_match('/^tls0 OK/', $line)) {
$this->error = "Server responded to STARTTLS with: $line"; $this->set_error(self::ERROR_BAD, "Server responded to STARTTLS with: $line");
$this->errornum = -2;
return false; return false;
} }
if (!stream_socket_enable_crypto($this->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { if (!stream_socket_enable_crypto($this->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
$this->error = "Unable to negotiate TLS"; $this->set_error(self::ERROR_BAD, "Unable to negotiate TLS");
$this->errornum = -2;
return false; return false;
} }
@ -665,7 +673,7 @@ class rcube_imap_generic
$result = $this->authenticate($user, $password, substr($line,2)); $result = $this->authenticate($user, $password, substr($line,2));
// stop if server sent BYE response // stop if server sent BYE response
if ($result == -3) { if ($result == self::ERROR_BYE) {
return false; return false;
} }
} }
@ -717,26 +725,30 @@ class rcube_imap_generic
return true; return true;
} }
if ($this->putLine("sel1 SELECT \"".$this->escape($mailbox).'"')) { $command = "sel1 SELECT \"".$this->escape($mailbox).'"';
do {
$line = rtrim($this->readLine(512));
if (preg_match('/^\* ([0-9]+) (EXISTS|RECENT)$/', $line, $m)) { if (!$this->putLine($command)) {
$token = strtolower($m[2]); $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
$this->$token = (int) $m[1]; return false;
} }
else if (preg_match('/\[?PERMANENTFLAGS\s+\(([^\)]+)\)\]/U', $line, $match)) {
$this->permanentflags = explode(' ', $match[1]);
}
} while (!$this->startsWith($line, 'sel1', true, true));
if ($this->parseResult($line) == 0) { do {
$this->selected = $mailbox; $line = rtrim($this->readLine(512));
return true;
} if (preg_match('/^\* ([0-9]+) (EXISTS|RECENT)$/', $line, $m)) {
} $token = strtolower($m[2]);
$this->$token = (int) $m[1];
}
else if (preg_match('/\[?PERMANENTFLAGS\s+\(([^\)]+)\)\]/U', $line, $match)) {
$this->permanentflags = explode(' ', $match[1]);
}
} while (!$this->startsWith($line, 'sel1', true, true));
if ($this->parseResult($line, 'SELECT: ') == self::ERROR_OK) {
$this->selected = $mailbox;
return true;
}
$this->error = "Couldn't select $mailbox";
return false; return false;
} }
@ -801,6 +813,7 @@ class rcube_imap_generic
$command .= ' '.$add; $command .= ' '.$add;
if (!$this->putLineC($command)) { if (!$this->putLineC($command)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return false; return false;
} }
do { do {
@ -812,9 +825,8 @@ class rcube_imap_generic
} }
} while (!$this->startsWith($line, 's ', true, true)); } while (!$this->startsWith($line, 's ', true, true));
$result_code = $this->parseResult($line); $result_code = $this->parseResult($line, 'SORT: ');
if ($result_code != 0) { if ($result_code != self::ERROR_OK) {
$this->error = "Sort: $line";
return false; return false;
} }
@ -882,6 +894,7 @@ class rcube_imap_generic
$request = $key . $request; $request = $key . $request;
if (!$this->putLine($request)) { if (!$this->putLine($request)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $request");
return false; return false;
} }
@ -1015,14 +1028,19 @@ class rcube_imap_generic
} }
$result = -1; $result = -1;
if ($this->putLine("fuid FETCH $id (UID)")) { $command = "fuid FETCH $id (UID)";
do {
$line = rtrim($this->readLine(1024)); if (!$this->putLine($command)) {
if (preg_match("/^\* $id FETCH \(UID (.*)\)/i", $line, $r)) { $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
$result = $r[1]; return -1;
} }
} while (!$this->startsWith($line, 'fuid', true, true));
} do {
$line = rtrim($this->readLine(1024));
if (preg_match("/^\* $id FETCH \(UID (.*)\)/i", $line, $r)) {
$result = $r[1];
}
} while (!$this->startsWith($line, 'fuid', true, true));
return $result; return $result;
} }
@ -1063,6 +1081,7 @@ class rcube_imap_generic
$request .= "LIST-POST DISPOSITION-NOTIFICATION-TO".$add.")])"; $request .= "LIST-POST DISPOSITION-NOTIFICATION-TO".$add.")])";
if (!$this->putLine($request)) { if (!$this->putLine($request)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $request");
return false; return false;
} }
do { do {
@ -1368,9 +1387,10 @@ class rcube_imap_generic
} }
$c = 0; $c = 0;
$command = $messages ? "UID EXPUNGE $messages" : "EXPUNGE"; $command = $messages ? "exp1 UID EXPUNGE $messages" : "exp1 EXPUNGE";
if (!$this->putLine("exp1 $command")) { if (!$this->putLine($command)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return -1; return -1;
} }
@ -1381,11 +1401,11 @@ class rcube_imap_generic
} }
} while (!$this->startsWith($line, 'exp1', true, true)); } while (!$this->startsWith($line, 'exp1', true, true));
if ($this->parseResult($line) == 0) { if ($this->parseResult($line, 'EXPUNGE: ') == self::ERROR_OK) {
$this->selected = ''; // state has changed, need to reselect $this->selected = ''; // state has changed, need to reselect
return $c; return $c;
} }
$this->error = $line;
return -1; return -1;
} }
@ -1402,7 +1422,9 @@ class rcube_imap_generic
} }
$c = 0; $c = 0;
if (!$this->putLine("flg UID STORE $messages {$mod}FLAGS ($flag)")) { $command = "flg UID STORE $messages {$mod}FLAGS ($flag)";
if (!$this->putLine($command)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return false; return false;
} }
@ -1413,11 +1435,10 @@ class rcube_imap_generic
} }
} while (!$this->startsWith($line, 'flg', true, true)); } while (!$this->startsWith($line, 'flg', true, true));
if ($this->parseResult($line) == 0) { if ($this->parseResult($line, 'STORE: ') == self::ERROR_OK) {
return $c; return $c;
} }
$this->error = $line;
return -1; return -1;
} }
@ -1443,9 +1464,14 @@ class rcube_imap_generic
return -1; return -1;
} }
$this->putLine("cpy1 UID COPY $messages \"".$this->escape($to)."\""); $command = "cpy1 UID COPY $messages \"".$this->escape($to)."\"";
$line = $this->readReply();
return $this->parseResult($line); if (!$this->putLine($command)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
}
$line = $this->readReply();
return $this->parseResult($line, 'COPY: ');
} }
function countUnseen($folder) function countUnseen($folder)
@ -1525,7 +1551,10 @@ class rcube_imap_generic
$criteria = $criteria ? 'ALL '.trim($criteria) : 'ALL'; $criteria = $criteria ? 'ALL '.trim($criteria) : 'ALL';
$data = ''; $data = '';
if (!$this->putLineC("thrd1 THREAD $algorithm $encoding $criteria")) { $command = "thrd1 THREAD $algorithm $encoding $criteria";
if (!$this->putLineC($command)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return false; return false;
} }
do { do {
@ -1537,15 +1566,14 @@ class rcube_imap_generic
} }
} while (!$this->startsWith($line, 'thrd1', true, true)); } while (!$this->startsWith($line, 'thrd1', true, true));
$result_code = $this->parseResult($line); $result_code = $this->parseResult($line, 'THREAD: ');
if ($result_code == 0) { if ($result_code == self::ERROR_OK) {
$depthmap = array(); $depthmap = array();
$haschildren = array(); $haschildren = array();
$tree = $this->parseThread($data, 0, strlen($data), null, null, 0, $depthmap, $haschildren); $tree = $this->parseThread($data, 0, strlen($data), null, null, 0, $depthmap, $haschildren);
return array($tree, $depthmap, $haschildren); return array($tree, $depthmap, $haschildren);
} }
$this->error = "Thread: $line";
return false; return false;
} }
@ -1566,6 +1594,7 @@ class rcube_imap_generic
$query = 'srch1 ' . ($return_uid ? 'UID ' : '') . 'SEARCH ' . trim($criteria); $query = 'srch1 ' . ($return_uid ? 'UID ' : '') . 'SEARCH ' . trim($criteria);
if (!$this->putLineC($query)) { if (!$this->putLineC($query)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $query");
return false; return false;
} }
@ -1578,12 +1607,11 @@ class rcube_imap_generic
} }
} while (!$this->startsWith($line, 'srch1', true, true)); } while (!$this->startsWith($line, 'srch1', true, true));
$result_code = $this->parseResult($line); $result_code = $this->parseResult($line, 'SEARCH: ');
if ($result_code == 0) { if ($result_code == self::ERROR_OK) {
return preg_split('/\s+/', $data, -1, PREG_SPLIT_NO_EMPTY); return preg_split('/\s+/', $data, -1, PREG_SPLIT_NO_EMPTY);
} }
$this->error = "Search: $line";
return false; return false;
} }
@ -1632,10 +1660,11 @@ class rcube_imap_generic
$ref = $this->escape($ref); $ref = $this->escape($ref);
$mailbox = $this->escape($mailbox); $mailbox = $this->escape($mailbox);
$query = $key." ".$command." \"". $ref ."\" \"". $mailbox ."\"";
// send command // send command
if (!$this->putLine($key." ".$command." \"". $ref ."\" \"". $mailbox ."\"")) { if (!$this->putLine($query)) {
$this->error = "Couldn't send $command command"; $this->set_error(self::ERROR_COMMAND, "Unable to send command: $query");
return false; return false;
} }
@ -1657,11 +1686,10 @@ class rcube_imap_generic
if (is_array($folders)) { if (is_array($folders)) {
return $folders; return $folders;
} else if ($this->parseResult($line) == 0) { } else if ($this->parseResult($line, $command.': ') == self::ERROR_OK) {
return array(); return array();
} }
$this->error = $line;
return false; return false;
} }
@ -1686,6 +1714,7 @@ class rcube_imap_generic
// send request // send request
if (!$this->putLine($request)) { if (!$this->putLine($request)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $request");
return false; return false;
} }
@ -1741,6 +1770,7 @@ class rcube_imap_generic
// send request // send request
if (!$this->putLine($request)) { if (!$this->putLine($request)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $request");
return false; return false;
} }
@ -1866,35 +1896,48 @@ class rcube_imap_generic
function createFolder($folder) function createFolder($folder)
{ {
if ($this->putLine('c CREATE "' . $this->escape($folder) . '"')) { $command = 'c CREATE "' . $this->escape($folder) . '"';
do {
$line = $this->readLine(300); if (!$this->putLine($command)) {
} while (!$this->startsWith($line, 'c ', true, true)); $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return ($this->parseResult($line) == 0); return false;
} }
return false;
do {
$line = $this->readLine(300);
} while (!$this->startsWith($line, 'c ', true, true));
return ($this->parseResult($line, 'CREATE: ') == self::ERROR_OK);
} }
function renameFolder($from, $to) function renameFolder($from, $to)
{ {
if ($this->putLine('r RENAME "' . $this->escape($from) . '" "' . $this->escape($to) . '"')) { $command = 'r RENAME "' . $this->escape($from) . '" "' . $this->escape($to) . '"';
do {
$line = $this->readLine(300); if (!$this->putLine($command)) {
} while (!$this->startsWith($line, 'r ', true, true)); $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return ($this->parseResult($line) == 0); return false;
} }
return false; do {
$line = $this->readLine(300);
} while (!$this->startsWith($line, 'r ', true, true));
return ($this->parseResult($line, 'RENAME: ') == self::ERROR_OK);
} }
function deleteFolder($folder) function deleteFolder($folder)
{ {
if ($this->putLine('d DELETE "' . $this->escape($folder). '"')) { $command = 'd DELETE "' . $this->escape($folder). '"';
do {
$line = $this->readLine(300); if (!$this->putLine($command)) {
} while (!$this->startsWith($line, 'd ', true, true)); $this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return ($this->parseResult($line) == 0); return false;
} }
return false; do {
$line = $this->readLine(300);
} while (!$this->startsWith($line, 'd ', true, true));
return ($this->parseResult($line, 'DELETE: ') == self::ERROR_OK);
} }
function clearFolder($folder) function clearFolder($folder)
@ -1908,20 +1951,28 @@ class rcube_imap_generic
function subscribe($folder) function subscribe($folder)
{ {
$query = 'sub1 SUBSCRIBE "' . $this->escape($folder). '"'; $command = 'sub1 SUBSCRIBE "' . $this->escape($folder). '"';
$this->putLine($query);
if (!$this->putLine($command)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return false;
}
$line = trim($this->readLine(512)); $line = trim($this->readLine(512));
return ($this->parseResult($line) == 0); return ($this->parseResult($line, 'SUBSCRIBE: ') == self::ERROR_OK);
} }
function unsubscribe($folder) function unsubscribe($folder)
{ {
$query = 'usub1 UNSUBSCRIBE "' . $this->escape($folder) . '"'; $command = 'usub1 UNSUBSCRIBE "' . $this->escape($folder) . '"';
$this->putLine($query);
if (!$this->putLine($command)) {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
return false;
}
$line = trim($this->readLine(512)); $line = trim($this->readLine(512));
return ($this->parseResult($line) == 0); return ($this->parseResult($line, 'UNSUBSCRIBE: ') == self::ERROR_OK);
} }
function append($folder, &$message) function append($folder, &$message)
@ -1944,8 +1995,7 @@ class rcube_imap_generic
$line = $this->readLine(512); $line = $this->readLine(512);
if ($line[0] != '+') { if ($line[0] != '+') {
// $errornum = $this->parseResult($line); $this->parseResult($line, 'APPEND: ');
$this->error = "Cannot write to folder: $line";
return false; return false;
} }
@ -1957,14 +2007,12 @@ class rcube_imap_generic
$line = $this->readLine(); $line = $this->readLine();
} while (!$this->startsWith($line, 'a ', true, true)); } while (!$this->startsWith($line, 'a ', true, true));
$result = ($this->parseResult($line) == 0); return ($this->parseResult($line, 'APPEND: ') == self::ERROR_OK);
if (!$result) {
$this->error = $line;
}
return $result;
} }
else {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $request");
}
$this->error = "Couldn't send command \"$request\"";
return false; return false;
} }
@ -1980,7 +2028,7 @@ class rcube_imap_generic
$in_fp = fopen($path, 'r'); $in_fp = fopen($path, 'r');
} }
if (!$in_fp) { if (!$in_fp) {
$this->error = "Couldn't open $path for reading"; $this->set_error(self::ERROR_UNKNOWN, "Couldn't open $path for reading");
return false; return false;
} }
@ -2002,8 +2050,7 @@ class rcube_imap_generic
$line = $this->readLine(512); $line = $this->readLine(512);
if ($line[0] != '+') { if ($line[0] != '+') {
//$errornum = $this->parseResult($line); $this->parseResult($line, 'APPEND: ');
$this->error = "Cannot write to folder: $line";
return false; return false;
} }
@ -2028,15 +2075,13 @@ class rcube_imap_generic
$line = $this->readLine(); $line = $this->readLine();
} while (!$this->startsWith($line, 'a ', true, true)); } while (!$this->startsWith($line, 'a ', true, true));
$result = ($this->parseResult($line) == 0);
if (!$result) { return ($this->parseResult($line, 'APPEND: ') == self::ERROR_OK);
$this->error = $line;
}
return $result;
} }
else {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $request");
}
$this->error = "Couldn't send command \"$request\"";
return false; return false;
} }
@ -2048,8 +2093,9 @@ class rcube_imap_generic
$key = 'F1247'; $key = 'F1247';
$result = false; $result = false;
$command = $key . ($is_uid ? ' UID' : '') ." FETCH $id (BODYSTRUCTURE)";
if ($this->putLine($key . ($is_uid ? ' UID' : '') ." FETCH $id (BODYSTRUCTURE)")) { if ($this->putLine($command)) {
do { do {
$line = $this->readLine(5000); $line = $this->readLine(5000);
$line = $this->multLine($line, true); $line = $this->multLine($line, true);
@ -2059,6 +2105,9 @@ class rcube_imap_generic
$result = trim(substr($result, strpos($result, 'BODYSTRUCTURE')+13, -1)); $result = trim(substr($result, strpos($result, 'BODYSTRUCTURE')+13, -1));
} }
else {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
}
return $result; return $result;
} }
@ -2073,9 +2122,10 @@ class rcube_imap_generic
*/ */
$result = false; $result = false;
$quota_lines = array(); $quota_lines = array();
$command = 'QUOT1 GETQUOTAROOT "INBOX"';
// get line(s) containing quota info // get line(s) containing quota info
if ($this->putLine('QUOT1 GETQUOTAROOT "INBOX"')) { if ($this->putLine($command)) {
do { do {
$line = rtrim($this->readLine(5000)); $line = rtrim($this->readLine(5000));
if (preg_match('/^\* QUOTA /', $line)) { if (preg_match('/^\* QUOTA /', $line)) {
@ -2083,6 +2133,9 @@ class rcube_imap_generic
} }
} while (!$this->startsWith($line, 'QUOT1', true, true)); } while (!$this->startsWith($line, 'QUOT1', true, true));
} }
else {
$this->set_error(self::ERROR_COMMAND, "Unable to send command: $command");
}
// return false if not found, parse if found // return false if not found, parse if found
$min_free = PHP_INT_MAX; $min_free = PHP_INT_MAX;

Loading…
Cancel
Save