/** * Sort threaded result, using THREAD=REFS method * * @param rcube_result_thread $threads Threads result set */ protected function sort_threads($threads) { if ($threads->is_empty()) { return; } // THREAD=ORDEREDSUBJECT: sorting by sent date of root message // THREAD=REFERENCES: sorting by sent date of root message // THREAD=REFS: sorting by the most recent date in each thread if ($this->sort_field && ($this->sort_field != 'date' || $this->get_capability('THREAD') != 'REFS')) { $index = $this->index_direct($this->folder, $this->sort_field, $this->sort_order, false); if (!$index->is_empty()) { $threads->sort($index); } } else { if ($this->sort_order != $threads->get_parameters('ORDER')) { $threads->revert(); } } }
/** * Sort threaded result, using THREAD=REFS method if available. * If not, use any method and re-sort the result in THREAD=REFS way. * * @param rcube_result_thread $threads Threads result set */ protected function sort_threads($threads) { if ($threads->is_empty()) { return; } // THREAD=ORDEREDSUBJECT: sorting by sent date of root message // THREAD=REFERENCES: sorting by sent date of root message // THREAD=REFS: sorting by the most recent date in each thread if ($this->threading != 'REFS' || $this->sort_field && $this->sort_field != 'date') { $sortby = $this->sort_field ? $this->sort_field : 'date'; $index = $this->index($this->folder, $sortby, $this->sort_order, true, true); if (!$index->is_empty()) { $threads->sort($index); } } else { if ($this->sort_order != $threads->get_parameters('ORDER')) { $threads->revert(); } } }
/** * thread parser test */ function test_parse_thread() { $text = file_get_contents(__DIR__ . '/../src/imap_thread.txt'); $object = new rcube_result_thread('INBOX', $text); $this->assertSame(false, $object->is_empty(), "Object is empty"); $this->assertSame(false, $object->is_error(), "Object is error"); $this->assertSame(1721, $object->max(), "Max message UID"); $this->assertSame(1, $object->min(), "Min message UID"); $this->assertSame(1721, $object->count_messages(), "Messages count"); $this->assertSame(1691, $object->exists(1720, true), "Message exists"); $this->assertSame(true, $object->exists(1720), "Message exists (bool)"); $this->assertSame(1, $object->get_element('FIRST'), "Get first element"); $this->assertSame(1719, $object->get_element('LAST'), "Get last element"); $this->assertSame(14, (int) $object->get_element(2), "Get specified element"); $clone = clone $object; $clone->filter(array(7)); $clone = $clone->get_tree(); $this->assertSame(1, count($clone), "Structure check"); $this->assertSame(3, count($clone[7]), "Structure check"); $this->assertSame(0, count($clone[7][12]), "Structure check"); $this->assertSame(1, count($clone[7][167]), "Structure check"); $this->assertSame(0, count($clone[7][167][197]), "Structure check"); $this->assertSame(2, count($clone[7][458]), "Structure check"); $this->assertSame(1, count($clone[7][458][460]), "Structure check"); $this->assertSame(0, count($clone[7][458][460][463]), "Structure check"); $this->assertSame(1, count($clone[7][458][464]), "Structure check"); $this->assertSame(0, count($clone[7][458][464][471]), "Structure check"); $object->filter(array(784)); $this->assertSame(118, $object->count_messages(), "Messages filter"); $this->assertSame(1, $object->count(), "Messages filter (count)"); }