diff options
| author | Nathan Kinkade <nkinkade@nkinka.de> | 2009-03-05 20:48:46 +0000 |
|---|---|---|
| committer | Nathan Kinkade <nkinkade@nkinka.de> | 2009-03-11 12:51:51 +0000 |
| commit | 32ea464bdfe5f8a22f46bfac50dcdc26c36fc497 (patch) | |
| tree | 50b13882e43a778a9e9dcec19f18d18bc8bb1aa9 /roundcubemail/program/lib | |
| parent | 8013cb2424ca6912419dc7df73a9b8b77da7bdb0 (diff) | |
Applied message threading patch from Chris January: http://www.atomice.com/blog/?p=33
Diffstat (limited to 'roundcubemail/program/lib')
| -rw-r--r-- | roundcubemail/program/lib/imap.inc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/roundcubemail/program/lib/imap.inc b/roundcubemail/program/lib/imap.inc index 67a2b7b3c..2229f27f0 100644 --- a/roundcubemail/program/lib/imap.inc +++ b/roundcubemail/program/lib/imap.inc @@ -182,6 +182,9 @@ class iilBasicHeader var $forwarded = false; var $junk = false; var $flagged = false; + var $has_children = false; + var $depth = 0; + var $unread_children = 0; } /** @@ -2146,6 +2149,77 @@ function iil_C_ID2UID(&$conn, $folder, $id) { return $result; } +function iil_ParseThread($str, $root, $parent, $depth, &$depthmap, &$haschildren) { + $node = array(); + if (strlen($str) == 0) + return $node; + if (substr($str, 0, 1) != '(') { + $p = split('[^0-9]', $str, 2); + $msg = $p[0]; + $str = $p[1]; + if (is_null($root)) + $root = $msg; + $depthmap[$msg] = $depth; + $haschildren[$msg] = false; + if (!is_null($parent)) + $haschildren[$parent] = true; + $node[$msg] = iil_ParseThread($str, $root, $msg, $depth + 1, $depthmap, $haschildren); + } else { + $off = 0; + $len = strlen($str); + while ($off < $len) { + $start = $off; + $off++; + $n = 1; + while ($n > 0) { + $p = strpos($str, ')', $off); + if ($p === false) { + error_log("Can't parse (".substr($str, $off).") - mismatched brackets"); + return $node; + } + $p1 = strpos($str, '(', $off); + if ($p1 !== false && $p1 < $p) { + $off = $p1 + 1; + $n++; + } else { + $off = $p + 1; + $n--; + } + } + $s = substr($str, $start + 1, $off - $start - 2); + $node += iil_ParseThread($s, $root, $parent, $depth, $depthmap, $haschildren); + } + } + + return $node; +} + +function iil_C_Thread(&$conn, $folder, $algorithm, $criteria) { + $fp = $conn->fp; + if (iil_C_Select($conn, $folder)) { + $query = 'thrd1 THREAD ' . chop($algorithm). ' UTF-8 ' . chop($criteria); + iil_PutLineC($fp, $query); + do { + $line=trim(iil_ReadLine($fp, 10000)); + if (eregi("^\* THREAD", $line)) { + $str = trim(substr($line, 8)); + $depthmap = array(); + $haschildren = array(); + $tree = iil_ParseThread($str, null, null, 1, $depthmap, $haschildren); + } + } while (!iil_StartsWith($line, 'thrd1', true)); + + $result_code = iil_ParseResult($line); + if ($result_code == 0) { + return array($tree, $depthmap, $haschildren); + } + $conn->error = 'iil_C_Thread: ' . $line . "\n"; + return false; + } + $conn->error = "iil_C_Thread: Couldn't select \"$folder\"\n"; + return false; +} + function iil_C_Search(&$conn, $folder, $criteria) { $fp = $conn->fp; if (iil_C_Select($conn, $folder)) { |
