Hi,
I'm playing a bit with this webmail and I've implemented the displaying
of subfolders. I've done the patch on the latest release since the CVS
source seem to be badly broken when I checked out.
I added three new functions to 'program/steps/mail/func.inc'
----
function rcmail_build_folder_tree( &$arrFolders, $folder, $path = '' ) {
$pos = strpos($folder, '/');
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' => $currentFolder,
'folders' => array(),
);
}
if (!empty($subFolders)) {
rcmail_build_folder_tree(
$arrFolders[$currentFolder]['folders'], $subFolders, $path.'/' );
}
}
function rcmail_render_folder_tree_html( &$arrFolders, &$special,
&$mbox, $nestLevel = 0 ) {
global $JS_OBJECT_NAME, $IMAP;
$idx = 0;
$out = '';
foreach ($arrFolders as $key=>$folder) {
$zebra_class = ($nestLevel*$idx)%2 ? 'even' : 'odd';
$folder_lc = strtolower($folder['id']);
if (in_array($folder_lc, $special))
$foldername = rcube_label($folder_lc);
else
$foldername = $folder['name'];
if ($unread_count = $IMAP->messagecount($folder['id'], 'UNSEEN'))
$foldername .= sprintf(' (%d)', $unread_count);
$out .= sprintf('<li class="mailbox %s %s%s%s"><a href="#%s"
onclick="return %s.command(\'list\',\'%s\')" onmouseup="return
%s.mbox_mouse_up(\'%s\')">%s</a>'."\n",
preg_replace('/[^a-z0-9\-_]/', '', $folder_lc),
$zebra_class,
$unread_count ? ' unread' : '',
$folder['id']==$mbox ? ' selected' : '',
$folder['id'],
$JS_OBJECT_NAME,
$folder['id'],
$JS_OBJECT_NAME,
$folder['id'],
rep_specialchars_output($foldername));
if (! empty($folder['folders']))
$out .= '<ul>' . rcmail_render_folder_tree_html(
$folder['folders'], $special, $mbox, $nestLevel+1 ) . "</ul>\n";
$out .= "</li>\n";
$idx++;
}
return $out;
}
function rcmail_render_folder_tree_select( &$arrFolders, &$special,
&$mbox, $nestLevel = 0 ) {
global $IMAP;
$idx = 0;
$out = '';
foreach ($arrFolders as $key=>$folder) {
$out .= sprintf('<option value="%s">%s%s</option>'."\n",
$folder['id'],
str_pad('', $nestLevel*2*6, ' '),
rep_specialchars_output($folder['name']));
if (! empty($folder['folders']))
$out .= rcmail_render_folder_tree_select(
$folder['folders'], $special, $mbox, $nestLevel+1 );
$idx++;
}
return $out;
}
-------
Then changed quite a bit the function rcmail_mailbox_list()
-------
function rcmail_mailbox_list($attrib)
{
global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH;
static $s_added_script = FALSE;
static $arrFolders;
$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']));
$mbox = $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($arrFolders)) {
// get mailbox list
$a_folders = $IMAP->list_mailboxes();
foreach ($a_folders as $folder) {
rcmail_build_folder_tree( $arrFolders, $folder );
}
}
if ($type=='select') {
$out .= rcmail_render_folder_tree_select( $arrFolders,
$special_mailboxes, $mbox );
} else {
$out .= rcmail_render_folder_tree_html( $arrFolders,
$special_mailboxes, $mbox );
}
if ($type=='ul')
$OUTPUT->add_script(sprintf("%s.gui_object('mailboxlist', '%s');",
$JS_OBJECT_NAME, $attrib['id']));
return $out . "</$type>";
}
----
The css also needs a bit of tweaking, basically just add the following
rules to 'mail.css'
-----
#mailboxlist ul {
list-style: none;
padding:0; margin:0;
}
#mailboxlist ul li {
padding-left: 15px;
background-position: 25px 1px;
}
#mailboxlist li.selected li {
background-color: #F9F9F9;
}
#mailboxlist li.unread li {
font-weight: normal;
}
#mailboxlist li.unread li.unread {
font-weight: bold;
}
#mailboxlist li.selected li a{
color: black;
font-weight: normal;
}
-----
And remove the 'height' propery from '#mailboxlist li' !
Finally, in 'program/js/app.js' replace the method
'this.select_mailbox()' with the next one
------
this.select_mailbox = function(mbox)
{
if (this.gui_objects.mailboxlist)
{
var item, reg, text_obj;
var s_mbox =
String(mbox).toLowerCase().replace(this.mbox_expression, '');
var s_current =
this.env.mailbox.toLowerCase().replace(this.mbox_expression, '');
var nodes = this.gui_objects.mailboxlist.getElementsByTagName('LI');
for (var n=0; n<nodes.length; n++) {
item = nodes[n];
if (item.className && item.className.indexOf('mailbox
'+s_mbox+' ')>=0)
this.set_classname(item, 'selected', true);
else if (item.className && item.className.indexOf('mailbox
'+s_current)>=0)
this.set_classname(item, 'selected', false);
}
}
this.env.mailbox = mbox;
};
------
I'm sorry for this way of sending the patch but it's late and knowing
myself, if I wait for the CVS version to be fixed I will forget to send
it :(
ciao,
ivan