+
+ /** Look for an unread message in the thread rooted by the message
+ * @param id INTEGER message number
+ */
+ function _nextUnread($id)
+ {
+ if (!$this->overview[$id]->isread) {
+ return $id;
+ }
+ foreach ($this->overview[$id]->children as $child) {
+ $unread = $this->_nextUnread($child);
+ if (!is_null($unread)) {
+ return $unread;
+ }
+ }
+ return null;
+ }
+
+ /** Find next unread message
+ * @param id INTEGER message number
+ */
+ function nextUnread($id = null)
+ {
+ if (!is_null($id)) {
+ // Look in message children
+ foreach ($this->overview[$id]->children as $child) {
+ $next = $this->_nextUnread($child);
+ if (!is_null($next)) {
+ return $next;
+ }
+ }
+ }
+
+ // Look in current thread
+ $cur = $id;
+ do {
+ $parent = is_null($cur) ? null : $this->overview[$cur]->parent;
+ $ok = is_null($cur) ? true : false;
+ if (!is_null($parent)) {
+ $array = &$this->overview[$parent]->children;
+ } else {
+ $array = &$this->roots;
+ }
+ foreach ($array as $child) {
+ if ($ok) {
+ $next = $this->_nextUnread($child);
+ if (!is_null($next)) {
+ return $next;
+ }
+ }
+ if ($child == $cur) {
+ $ok = true;
+ }
+ }
+ $cur = $parent;
+ } while(!is_null($cur));
+ return null;
+ }