From 3831821cb8b02318946e9503df2ee0a16e833244 Mon Sep 17 00:00:00 2001 From: alec Date: Thu, 18 Dec 2008 12:00:06 +0000 Subject: - Support multiple quota values in QUOTAROOT resonse (#1485626) git-svn-id: https://svn.roundcube.net/trunk@2172 208e9e7b-5314-0410-a742-e7e81cd9613c --- roundcubemail/program/lib/imap.inc | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'roundcubemail/program') diff --git a/roundcubemail/program/lib/imap.inc b/roundcubemail/program/lib/imap.inc index 87773d37d..329db0534 100644 --- a/roundcubemail/program/lib/imap.inc +++ b/roundcubemail/program/lib/imap.inc @@ -75,6 +75,7 @@ - optimize iil_C_FetchHeaders() to use only one FETCH command - added 4th argument to iil_Connect() - allow setting rootdir and delimiter before connect + - support multiquota result ********************************************************/ @@ -2656,31 +2657,41 @@ function iil_C_GetQuota(&$conn) { * GETQUOTAROOT "INBOX" * QUOTAROOT INBOX user/rchijiiwa1 * QUOTA user/rchijiiwa1 (STORAGE 654 9765) - b OK Completed + * OK Completed */ $fp = $conn->fp; $result = false; - $quota_line = ''; + $quota_lines = array(); - //get line containing quota info + // get line(s) containing quota info if (iil_PutLine($fp, 'QUOT1 GETQUOTAROOT "INBOX"')) { do { $line=chop(iil_ReadLine($fp, 5000)); if (iil_StartsWith($line, '* QUOTA ')) { - $quota_line = $line; + $quota_lines[] = $line; } } while (!iil_StartsWith($line, 'QUOT1', true)); } - //return false if not found, parse if found - if (!empty($quota_line)) { + // return false if not found, parse if found + $min_free = PHP_INT_MAX; + foreach ($quota_lines as $key => $quota_line) { $quota_line = eregi_replace('[()]', '', $quota_line); $parts = explode(' ', $quota_line); $storage_part = array_search('STORAGE', $parts); - if ($storage_part > 0) { - $result['used'] = intval($parts[$storage_part+1]); - $result['total'] = intval($parts[$storage_part+2]); - $result['percent'] = min(100, round(($result['used']/max(1,$result['total']))*100)); + + if (!$storage_part) continue; + + $used = intval($parts[$storage_part+1]); + $total = intval($parts[$storage_part+2]); + $free = $total - $used; + + // return lowest available space from all quotas + if ($free < $min_free) { + $min_free = $free; + $result['used'] = $used; + $result['total'] = $total; + $result['percent'] = min(100, round(($used/max(1,$total))*100)); $result['free'] = 100 - $result['percent']; } } -- cgit v1.2.3