From af3c045ecf4865361981f4c9aa392dfe1f93ac90 Mon Sep 17 00:00:00 2001 From: alecpl Date: Fri, 3 Dec 2010 10:58:40 +0000 Subject: - New Folder Manager UI - Fix invalid Request when creating a folder (#1487443) - Add folder size and quota indicator in folder manager (#1485780) - Add possibility to move a subfolder into root folder (#1486791) --- program/include/main.inc | 68 ++++++++++++++++++++++++++++++++++++++++-- program/include/rcube_imap.php | 57 ++++++++++++++++++++++------------- 2 files changed, 103 insertions(+), 22 deletions(-) (limited to 'program/include') diff --git a/program/include/main.inc b/program/include/main.inc index 7ea4ae20f..6d4e19c36 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -1314,8 +1314,13 @@ function rcmail_mailbox_select($p = array()) $p += array('maxlength' => 100, 'realnames' => false); $a_mailboxes = array(); - - foreach ($RCMAIL->imap->list_mailboxes() as $folder) + + if ($p['unsubscribed']) + $list = $RCMAIL->imap->list_unsubscribed(); + else + $list = $RCMAIL->imap->list_mailboxes(); + + foreach ($list as $folder) if (empty($p['exceptions']) || !in_array($folder, $p['exceptions'])) rcmail_build_folder_tree($a_mailboxes, $folder, $RCMAIL->imap->get_hierarchy_delimiter()); @@ -1551,6 +1556,65 @@ function rcmail_localize_foldername($name) } +function rcmail_quota_display($attrib) +{ + global $OUTPUT; + + if (!$attrib['id']) + $attrib['id'] = 'rcmquotadisplay'; + + if(isset($attrib['display'])) + $_SESSION['quota_display'] = $attrib['display']; + + $OUTPUT->add_gui_object('quotadisplay', $attrib['id']); + + $quota = rcmail_quota_content($attrib); + + $OUTPUT->add_script('$(document).ready(function(){ + rcmail.set_quota('.json_serialize($quota).')});', 'foot'); + + return html::span($attrib, ''); +} + + +function rcmail_quota_content($attrib=NULL) +{ + global $RCMAIL; + + $quota = $RCMAIL->imap->get_quota(); + $quota = $RCMAIL->plugins->exec_hook('quota', $quota); + + $quota_result = (array) $quota; + $quota_result['type'] = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : ''; + + if (!$quota['total'] && $RCMAIL->config->get('quota_zero_as_unlimited')) { + $quota_result['title'] = rcube_label('unlimited'); + $quota_result['percent'] = 0; + } + else if ($quota['total']) { + if (!isset($quota['percent'])) + $quota_result['percent'] = min(100, round(($quota['used']/max(1,$quota['total']))*100)); + + $title = sprintf('%s / %s (%.0f%%)', + show_bytes($quota['used'] * 1024), show_bytes($quota['total'] * 1024), + $quota_result['percent']); + + $quota_result['title'] = $title; + + if ($attrib['width']) + $quota_result['width'] = $attrib['width']; + if ($attrib['height']) + $quota_result['height'] = $attrib['height']; + } + else { + $quota_result['title'] = rcube_label('unknown'); + $quota_result['percent'] = 0; + } + + return $quota_result; +} + + /** * Output HTML editor scripts * diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 212e8865e..dd9f81b86 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2553,6 +2553,9 @@ class rcube_imap $to_mbox = $this->mod_mailbox($to_mbox); $from_mbox = strlen($from_mbox) ? $this->mod_mailbox($from_mbox) : $this->mailbox; + if ($to_mbox === $from_mbox) + return false; + list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox); // exit if no message uids are specified @@ -3008,6 +3011,26 @@ class rcube_imap } + /** + * Get mailbox size (size of all messages in a mailbox) + * + * @param string $name Mailbox name + * @return int Mailbox size in bytes, False on error + */ + function get_mailbox_size($name) + { + $name = $this->mod_mailbox($name); + + // @TODO: could we try to use QUOTA here? + $result = $this->conn->fetchHeaderIndex($name, '1:*', 'SIZE', false); + + if (is_array($result)) + $result = array_sum($result); + + return $result; + } + + /** * Subscribe to a specific mailbox(es) * @@ -3043,48 +3066,42 @@ class rcube_imap /** * Create a new mailbox on the server and register it in local cache * - * @param string $name New mailbox name (as utf-7 string) + * @param string $name New mailbox name * @param boolean $subscribe True if the new mailbox should be subscribed - * @param string Name of the created mailbox, false on error + * @param boolean True on success */ function create_mailbox($name, $subscribe=false) { - $result = false; - - // reduce mailbox name to 100 chars - $name = substr($name, 0, 100); + $result = false; $abs_name = $this->mod_mailbox($name); - $result = $this->conn->createFolder($abs_name); + $result = $this->conn->createFolder($abs_name); // try to subscribe it if ($result && $subscribe) $this->subscribe($name); - return $result ? $name : false; + return $result; } /** * Set a new name to an existing mailbox * - * @param string $mbox_name Mailbox to rename (as utf-7 string) - * @param string $new_name New mailbox name (as utf-7 string) - * @return string Name of the renames mailbox, False on error + * @param string $mbox_name Mailbox to rename + * @param string $new_name New mailbox name + * @return boolean True on success */ function rename_mailbox($mbox_name, $new_name) { $result = false; - // encode mailbox name and reduce it to 100 chars - $name = substr($new_name, 0, 100); - // make absolute path - $mailbox = $this->mod_mailbox($mbox_name); - $abs_name = $this->mod_mailbox($name); + $mailbox = $this->mod_mailbox($mbox_name); + $abs_name = $this->mod_mailbox($new_name); // check if mailbox is subscribed $a_subscribed = $this->_list_mailboxes(); - $subscribed = in_array($mailbox, $a_subscribed); + $subscribed = in_array($mailbox, $a_subscribed); // unsubscribe folder if ($subscribed) @@ -3113,14 +3130,14 @@ class rcube_imap if ($result && $subscribed) $this->conn->subscribe($abs_name); - return $result ? $name : false; + return $result; } /** * Remove mailboxes from server * - * @param string|array $mbox_name sMailbox name(s) string/array + * @param string|array $mbox_name Mailbox name(s) string/array * @return boolean True on success */ function delete_mailbox($mbox_name) @@ -3208,7 +3225,7 @@ class rcube_imap } else { $a_folders = $this->conn->listMailboxes('', $mbox); - } + } if (is_array($a_folders) && in_array($mbox, $a_folders)) { $this->icache[$key][] = $mbox; -- cgit v1.2.3