summaryrefslogtreecommitdiff
path: root/program/include/main.inc
diff options
context:
space:
mode:
Diffstat (limited to 'program/include/main.inc')
-rw-r--r--program/include/main.inc216
1 files changed, 216 insertions, 0 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 53d4d8560..e46cb5385 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -1658,4 +1658,220 @@ function rcube_print_time($timer, $label='Timer')
console(sprintf("%s: %0.4f sec", $label, $diff));
}
+
+// return the mailboxlist in HTML
+function rcmail_mailbox_list($attrib)
+ {
+ global $IMAP, $CONFIG, $OUTPUT, $COMM_PATH;
+ static $s_added_script = FALSE;
+ static $a_mailboxes;
+
+ // add some labels to client
+ rcube_add_label('purgefolderconfirm');
+ rcube_add_label('deletemessagesconfirm');
+
+// $mboxlist_start = rcube_timer();
+
+ $type = $attrib['type'] ? $attrib['type'] : 'ul';
+ $add_attrib = $type=='select' ? array('style', 'class', 'id', 'name', 'onchange') :
+ array('style', 'class', 'id');
+
+ if ($type=='ul' && !$attrib['id'])
+ $attrib['id'] = 'rcmboxlist';
+
+ // allow the following attributes to be added to the <ul> tag
+ $attrib_str = create_attrib_string($attrib, $add_attrib);
+
+ $out = '<' . $type . $attrib_str . ">\n";
+
+ // add no-selection option
+ if ($type=='select' && $attrib['noselection'])
+ $out .= sprintf('<option value="0">%s</option>'."\n",
+ rcube_label($attrib['noselection']));
+
+ // get mailbox list
+ $mbox_name = $IMAP->get_mailbox_name();
+
+ // for these mailboxes we have localized labels
+ $special_mailboxes = array('inbox', 'sent', 'drafts', 'trash', 'junk');
+
+
+ // build the folders tree
+ if (empty($a_mailboxes))
+ {
+ // get mailbox list
+ $a_folders = $IMAP->list_mailboxes();
+ $delimiter = $IMAP->get_hierarchy_delimiter();
+ $a_mailboxes = array();
+
+// rcube_print_time($mboxlist_start, 'list_mailboxes()');
+
+ foreach ($a_folders as $folder)
+ rcmail_build_folder_tree($a_mailboxes, $folder, $delimiter);
+ }
+
+// var_dump($a_mailboxes);
+
+ if ($type=='select')
+ $out .= rcmail_render_folder_tree_select($a_mailboxes, $special_mailboxes, $mbox_name, $attrib['maxlength']);
+ else
+ $out .= rcmail_render_folder_tree_html($a_mailboxes, $special_mailboxes, $mbox_name, $attrib['maxlength']);
+
+// rcube_print_time($mboxlist_start, 'render_folder_tree()');
+
+
+ if ($type=='ul')
+ $OUTPUT->add_gui_object('mailboxlist', $attrib['id']);
+
+ return $out . "</$type>";
+ }
+
+
+
+
+// create a hierarchical array of the mailbox list
+function rcmail_build_folder_tree(&$arrFolders, $folder, $delm='/', $path='')
+ {
+ $pos = strpos($folder, $delm);
+ if ($pos !== false)
+ {
+ $subFolders = substr($folder, $pos+1);
+ $currentFolder = substr($folder, 0, $pos);
+ }
+ else
+ {
+ $subFolders = false;
+ $currentFolder = $folder;
+ }
+
+ $path .= $currentFolder;
+
+ if (!isset($arrFolders[$currentFolder]))
+ {
+ $arrFolders[$currentFolder] = array('id' => $path,
+ 'name' => rcube_charset_convert($currentFolder, 'UTF-7'),
+ 'folders' => array());
+ }
+
+ if (!empty($subFolders))
+ rcmail_build_folder_tree($arrFolders[$currentFolder]['folders'], $subFolders, $delm, $path.$delm);
+ }
+
+
+// return html for a structured list <ul> for the mailbox tree
+function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox_name, $maxlength, $nestLevel=0)
+ {
+ global $COMM_PATH, $IMAP, $CONFIG, $OUTPUT;
+
+ $idx = 0;
+ $out = '';
+ foreach ($arrFolders as $key => $folder)
+ {
+ $zebra_class = ($nestLevel*$idx)%2 ? 'even' : 'odd';
+ $title = '';
+
+ $folder_lc = strtolower($folder['id']);
+ if (in_array($folder_lc, $special))
+ $foldername = rcube_label($folder_lc);
+ else
+ {
+ $foldername = $folder['name'];
+
+ // shorten the folder name to a given length
+ if ($maxlength && $maxlength>1)
+ {
+ $fname = abbrevate_string($foldername, $maxlength);
+ if ($fname != $foldername)
+ $title = ' title="'.Q($foldername).'"';
+ $foldername = $fname;
+ }
+ }
+
+ // add unread message count display
+ if ($unread_count = $IMAP->messagecount($folder['id'], 'RECENT', ($folder['id']==$mbox_name)))
+ $foldername .= sprintf(' (%d)', $unread_count);
+
+ // make folder name safe for ids and class names
+ $folder_id = preg_replace('/[^A-Za-z0-9\-_]/', '', $folder['id']);
+ $class_name = preg_replace('/[^a-z0-9\-_]/', '', $folder_lc);
+
+ // set special class for Sent, Drafts, Trash and Junk
+ if ($folder['id']==$CONFIG['sent_mbox'])
+ $class_name = 'sent';
+ else if ($folder['id']==$CONFIG['drafts_mbox'])
+ $class_name = 'drafts';
+ else if ($folder['id']==$CONFIG['trash_mbox'])
+ $class_name = 'trash';
+ else if ($folder['id']==$CONFIG['junk_mbox'])
+ $class_name = 'junk';
+
+ $js_name = htmlspecialchars(JQ($folder['id']));
+ $out .= sprintf('<li id="rcmli%s" class="mailbox %s %s%s%s"><a href="%s"'.
+ ' onclick="return %s.command(\'list\',\'%s\',this)"'.
+ ' onmouseover="return %s.focus_folder(\'%s\')"' .
+ ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
+ ' onmouseup="return %s.folder_mouse_up(\'%s\')"%s>%s</a>',
+ $folder_id,
+ $class_name,
+ $zebra_class,
+ $unread_count ? ' unread' : '',
+ $folder['id']==$mbox_name ? ' selected' : '',
+ Q(rcmail_url('', array('_mbox' => $folder['id']))),
+ JS_OBJECT_NAME,
+ $js_name,
+ JS_OBJECT_NAME,
+ $js_name,
+ JS_OBJECT_NAME,
+ $js_name,
+ JS_OBJECT_NAME,
+ $js_name,
+ $title,
+ Q($foldername));
+
+ if (!empty($folder['folders']))
+ $out .= "\n<ul>\n" . rcmail_render_folder_tree_html($folder['folders'], $special, $mbox_name, $maxlength, $nestLevel+1) . "</ul>\n";
+
+ $out .= "</li>\n";
+ $idx++;
+ }
+
+ return $out;
+ }
+
+
+// return html for a flat list <select> for the mailbox tree
+function rcmail_render_folder_tree_select(&$arrFolders, &$special, &$mbox_name, $maxlength, $nestLevel=0)
+ {
+ global $IMAP, $OUTPUT;
+
+ $idx = 0;
+ $out = '';
+ foreach ($arrFolders as $key=>$folder)
+ {
+ $folder_lc = strtolower($folder['id']);
+ if (in_array($folder_lc, $special))
+ $foldername = rcube_label($folder_lc);
+ else
+ {
+ $foldername = $folder['name'];
+
+ // shorten the folder name to a given length
+ if ($maxlength && $maxlength>1)
+ $foldername = abbrevate_string($foldername, $maxlength);
+ }
+
+ $out .= sprintf('<option value="%s">%s%s</option>'."\n",
+ htmlspecialchars($folder['id']),
+ str_repeat('&nbsp;', $nestLevel*4),
+ Q($foldername));
+
+ if (!empty($folder['folders']))
+ $out .= rcmail_render_folder_tree_select($folder['folders'], $special, $mbox_name, $maxlength, $nestLevel+1);
+
+ $idx++;
+ }
+
+ return $out;
+ }
+
?>