<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-15">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hello,<br>
<br>
we are developing a library to show last arrived messages of all
threads in a folder with more than 300k messages.<br>
<br>
As per the RFC 5256, the IMAP thread command has only the option
to specify the grouping criteria (REFERENCES vs ORDEREDSUBJECT).
So we implemented an algorithm which gets the full UID SORT
ordered by date in reverse order then gets all thread relations
and then post process all outputs to obtain the final result.<br>
Once we have both output we loop through the first uids set (which
is ordered) and for every item of it we loop through the other
uids set with all the thread relations. If the uid of the first
set is contained in one of the elements of the thread messages, we
pick it up and push it in the resulting array.<br>
This is a pseudo-code that shows what we are doing:<br>
<br>
array_of_latest_messages_in_thread = []<br>
array_of_sorted_uids = [n,n,n,n,...] // UID SORT (REVERSE DATE)
UTF-8 ALL<br>
array_of_thread_uids = [n,[n,n],n,[n,n,n],[n,n],n,n,...] // UID
THREAD (REFERENCES) UTF-8 ALL<br>
foreach(array_of_sorted_uids as s_uid){<br>
foreach(array_of_thread_uids as t_uids){<br>
if(t_uids contains s_uid){ // or a function to loop
recursively t_uids to search if a leaf is equal to s_uid<br>
array_of_latest_messages_in_thread.push(s_uid)<br>
break<br>
}<br>
}<br>
}<br>
<br>
We have also made some little optimizations in the above code like
for example skipping from the outer loop the uids already
processed in the inner loop that have not being selected. Anyway,
the loop is very expensive in term of computation and we are
wondering if there is a better approach to this issue directly
using IMAP instead of post processing the output of the two
commands at application level.<br>
<br>
Thanks.<br>
</p>
<pre class="moz-signature" cols="72">--
Alessio Cecchi
Postmaster @ <a class="moz-txt-link-freetext" href="http://www.qboxmail.it">http://www.qboxmail.it</a>
<a class="moz-txt-link-freetext" href="https://www.linkedin.com/in/alessice">https://www.linkedin.com/in/alessice</a></pre>
</body>
</html>