Get all UIDs of a single thread (not the whole all messages threads).
If you want to list just a conversation thread.
First, we must find the root element, using an UID included in these conversation in whatever message.
Then recursivelly we list all UIDs messages in an array.
<?php
function FindThread($mailbox, $uid) {
$mails = array();
$thread = imap_thread($mailbox, SE_UID);
$i = array_search($uid, $thread);
while(($tree = explode('.', $i)) && ($j = array_search($tree[0], $thread)) &&
($treej = explode('.', $j)) && $treej[0] && ($k = array_search($treej[0], $thread)) && ($treek = explode('.', $k)) &&
($thread[$treej[0] . '.next'] != 0 || $thread[$treek[0] . '.next'] != 0))
$i = $j;
$mails = FindThreadAll($thread, $tree[0]);
return $mails;
}
function FindThreadAll(&$thread, $i, $n = 0) {
$mails = array();
while($i) {
if(!($j = $thread[$i . '.next']) && !$n)
break;
$mails[] = $thread[$i . '.num'];
if($j)
$mails = array_merge($mails, FindThreadAll($thread, $j, $n + 1));
$i = $thread[$i . '.branch'];
}
return $mails;
}
if(($mails = FindThread(64851))) print_r(imap_fetch_overview($mailbox, implode(',', $mails), SE_UID));
?>
Eduardo Ruiz (Spain)