Improved threading display in MIMP
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 9 Oct 2009 22:12:18 +0000 (16:12 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 11 Oct 2009 19:31:33 +0000 (13:31 -0600)
imp/lib/Imap/Thread.php
imp/mailbox-mimp.php
imp/templates/mailbox/mailbox-mimp.inc

index b783814..84d48df 100644 (file)
@@ -132,4 +132,56 @@ class IMP_Imap_Thread
         return $tree;
     }
 
+    /**
+     * Generate the thread representation text for the given index list.
+     *
+     * @param array $indices    The list of indices to create a tree for.
+     * @param boolean $sortdir  True for newest first, false for oldest first.
+     *
+     * @return array  An array with the index as the key and the thread image
+     *                representation as the value.
+     */
+    public function getThreadTextTree($indices, $sortdir)
+    {
+        $tree = array();
+
+        foreach ($this->getThreadTreeOb($indices, $sortdir) as $k => $v) {
+            $tmp = '';
+
+            if (!empty($v)) {
+                foreach (str_split($v) as $c) {
+                    switch (intval($c)) {
+                    case 0:
+                        $tmp .= '  ';
+                        break;
+
+                    case '1':
+                        $tmp .= '| ';
+                        break;
+
+                    case '2':
+                        $tmp .= '|-';
+                        break;
+
+                    case '3':
+                        $tmp .= '/-';
+                        break;
+
+                    case '4':
+                        $tmp .= '\-';
+                        break;
+
+                    case '5':
+                        // TODO
+                        break;
+                    }
+                }
+            }
+
+            $tree[$k] = $tmp;
+        }
+
+        return $tree;
+    }
+
 }
index c125c2a..068323c 100644 (file)
@@ -80,6 +80,9 @@ $mailbox_url = IMP::generateIMPUrl('mailbox-mimp.php', $imp_mbox['mailbox']);
 $imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox']);
 $pageOb = $imp_mailbox->buildMailboxPage(Horde_Util::getFormData('p'), Horde_Util::getFormData('s'));
 
+/* Need Horde_Mobile init here for autoloading purposes. */
+$mimp_render = new Horde_Mobile();
+
 /* Generate page links. */
 $pages_first = $pages_prev = $pages_last = $pages_next = null;
 if ($pageOb['page'] != 1) {
@@ -93,7 +96,6 @@ if ($pageOb['page'] != $pageOb['pagecount']) {
 
 /* Generate mailbox summary string. */
 $title = IMP::getLabel($imp_mbox['mailbox']);
-$mimp_render = new Horde_Mobile();
 $mimp_render->set('title', $title);
 if ($pageOb['msgcount']) {
     $msgcount = $pageOb['msgcount'];
@@ -111,11 +113,14 @@ $imp_ui = new IMP_UI_Mailbox($imp_mbox['mailbox']);
 $mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array('headers' => array('x-priority')));
 
 /* Get thread information. */
-$threadob = ($sortpref['by'] == Horde_Imap_Client::SORT_THREAD)
-    ? $imp_mailbox->getThreadOb()
-    : null;
+if ($sortpref['by'] == Horde_Imap_Client::SORT_THREAD) {
+    $imp_thread = new IMP_Imap_Thread($imp_mailbox->getThreadOb());
+    $threadtree = $imp_thread->getThreadTextTree(reset($mbox_info['uids']), $sortpref['dir']);
+} else {
+    $imp_thread = null;
+    $threadtree = array();
+}
 
-reset($mbox_info);
 while (list(,$ob) = each($mbox_info['overview'])) {
     /* Initialize the header fields. */
     $msg = array(
@@ -151,8 +156,8 @@ while (list(,$ob) = each($mbox_info['overview'])) {
         }
     }
 
-    if ($threadob && $threadob->getThreadIndent($ob['uid'])) {
-        $msg['subject'] = '>> ' . ltrim($msg['subject']);
+    if (!empty($threadtree[$ob['uid']])) {
+        $msg['subject'] = $threadtree[$ob['uid']] . trim($msg['subject']);
     }
 
     if (Horde_String::length($msg['subject']) > $conf['mimp']['mailbox']['max_subj_chars']) {
@@ -194,7 +199,7 @@ foreach ($sort_list as $key => $val) {
         if (($key == Horde_Imap_Client::SORT_SUBJECT) &&
             IMP::threadSortAvailable($mailbox) &&
             !$search_mbox) {
-            if (is_null($threadob)) {
+            if (is_null($imp_thread)) {
                 $items[Horde_Util::addParameter($mailbox, array('a' => 'c', 'sb' => Horde_Imap_Client::SORT_THREAD, 'sd' => $sortdir))] = _("Sort by Thread");
             } else {
                 $sortkey = Horde_Imap_Client::SORT_THREAD;
index b668cba..af7af16 100644 (file)
@@ -19,7 +19,8 @@ $imp_notify->setMobileObject($c);
 $notification->notify(array('listeners' => 'status'));
 
 if (!empty($pageOb['end'])) {
-    $t = &$c->add(new Horde_Mobile_table());
+    $elts = null;
+    $t = &$c->add(new Horde_Mobile_table($elts));
     $t->set('border', 0);
     $t->set('padding', 1);
     $t->set('spacing', 1);