<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet href="https://dev.horde.org/themes/horde//default/feed-rss.xsl" type="text/xsl"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
 <channel> 
  <title>Sort messages by arrival date not working correctly</title> 
  <pubDate>Thu, 09 Apr 2026 20:04:47 +0000</pubDate> 
  <link>https://bugs.horde.org/ticket/8922</link> 
  <atom:link rel="self" type="application/rss+xml" title="Sort messages by arrival date not working correctly" href="https://bugs.horde.org/ticket/8922/rss" /> 
  <description>Sort messages by arrival date not working correctly</description> 
 
   
   
  <item> 
   <title>It seems that IMP assumes that sorting the messages by UID i</title> 
   <description>It seems that IMP assumes that sorting the messages by UID is the same as sorting them by arrival date. But this is not always the case. For example if I copy an old message to an IMAP folder it will get a new high UID but the arrival date stays in the past and should be sorted accordingly. Disabling the special handling of SORTARRIVAL ($imap_cache-&gt;getMailboxArrival) in imp/lib/Mailbox.php seems to solve the issue. Now IMP issues &quot;UID SORT (ARRIVAL)&quot; or &quot;UID SORT (REVERSE ARRIVAL)&quot; and messages appear properly sorted. Or perhaps the messages should be sorted by arrival date before putting them into the _arrival cache? There relevant part of the code:

                if (false &amp;&amp; $sortpref[&#039;by&#039;] == SORTARRIVAL) {
                    require_once IMP_BASE . &#039;/lib/IMAP/Cache.php&#039;;
                    $imap_cache = &amp;IMP_IMAP_Cache::singleton();
                    $this-&gt;_sorted = $imap_cache-&gt;getMailboxArrival($this-&gt;_mailbox);
                    if ($sortpref[&#039;dir&#039;]) {
                        $this-&gt;_sorted = array_reverse($this-&gt;_sorted);
                    }
                } else {
                    $this-&gt;_sorted = $imap_search-&gt;searchSortMailbox($query, null, $this-&gt;_mailbox, $sortpref[&#039;by&#039;], $sortpref[&#039;dir&#039;]);
                }</description> 
   <pubDate>Fri, 19 Mar 2010 12:06:41 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8922#t58261</link> 
  </item> 
   
  <item> 
   <title>&gt; It seems that IMP assumes that sorting the messages by UID</title> 
   <description>&gt; It seems that IMP assumes that sorting the messages by UID is the 
&gt; same as sorting them by arrival date. But this is not always the 
&gt; case. For example if I copy an old message to an IMAP folder it will 
&gt; get a new high UID but the arrival date stays in the past and should 
&gt; be sorted accordingly.

You have an incorrect assumption as to how IMAP arrival times work.  Arrival sort, otherwise known as the message sequence number, is the order in which messages are received in that mailbox.  If you copy an old message into a mailbox, that message &quot;arrived&quot; in that mailbox at the time you moved it, not the time the original message was sent.

It sounds like you want date sort, not arrival sort.</description> 
   <pubDate>Fri, 19 Mar 2010 16:12:49 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8922#t58266</link> 
  </item> 
   
  <item> 
   <title>But why would users be interested in IMAP servers internal i</title> 
   <description>But why would users be interested in IMAP servers internal info like message sequence number/UID? Looking at the IMAP SORT RFC (http://www.faqs.org/rfcs/rfc5256.html) I found the ARRIVAL sort type:

      ARRIVAL
         Internal date and time of the message.  This differs from the
         ON criteria in SEARCH, which uses just the internal date.

And this is exactly what gets called if I disable the IMP _arrival cache. So _arrival cache pretends to implement this IMAP search type but does something different - sorts on UID instead of IMAP internal date. As a result our users see messages that are almost randomly sorted. The worst thing is that arrival sort type is the default.</description> 
   <pubDate>Fri, 19 Mar 2010 16:25:02 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8922#t58267</link> 
  </item> 
   
  <item> 
   <title>&gt; But why would users be interested in IMAP servers internal</title> 
   <description>&gt; But why would users be interested in IMAP servers internal info like 
&gt; message sequence number/UID?

Because it is the fastest sort.  All IMAP servers necessarily need to track their message sequence numbers, so sorting by this value is &quot;free&quot; (as opposed to date sort - this requires each message&#039;s header to be parsed to get the date value).

&gt; Looking at the IMAP SORT RFC 
&gt; (http://www.faqs.org/rfcs/rfc5256.html) I found the ARRIVAL sort type:
&gt;
&gt;       ARRIVAL
&gt;          Internal date and time of the message.  This differs from the
&gt;          ON criteria in SEARCH, which uses just the internal date.

Yes.  ARRIVAL SORT = message sequence number.  This statement is nothing more than providing a keyword to use for SORT to do the same thing as a regular arrival sort.

&gt; And this is exactly what gets called if I disable the IMP _arrival 
&gt; cache. So _arrival cache pretends to implement this IMAP search type 
&gt; but does something different - sorts on UID instead of IMAP internal 
&gt; date. As a result our users see messages that are almost randomly 
&gt; sorted. The worst thing is that arrival sort type is the default.

_arrival cache does not to &quot;pretend to implement this IMAP search type&quot;.  The arrival cache implements a cache of the message sequence numbers.

Arrival sort is on by default because it is the *only* sort that can reasonably be used on large mailboxes on ALL IMAP servers.

Unfortunately, you are assuming a lot of things about IMAP servers.  First, the SORT extension wasn&#039;t standardized until June *2008*.  So there can be no assumption that the IMAP server supports SORT (not to mention IMP 4 was first released 5-6 years ago, before SORT existed on most IMAP servers).

Second, many IMAP servers don&#039;t support SORT.  It&#039;s not required of an IMAP 4rev1 server.  Thus, to sort by anything other than internal arrival time requires the IMAP server to parse *EVERY* header of *EVERY* message in the mailbox (a MUA can use FETCH to only return the text of the desired header, but this still requires the IMAP server to internally parse every header to collate this information).

Third, even for IMAP servers that support SORT, there is no guarantee that SORT is inexpensive.  Many IMAP servers may not cache this information, so every SORT call to the server requires parsing of the entire mailbox.

The issue with sorting a mailbox, at least with the original IMAP 4rev1 spec, is that IMAP was originally designed to act in a connected environment.  Meaning that you logged on once in the morning and your e-mail client handled issues like sorting ONCE (since further changes could be caught via untagged responses since the IMAP client was always connected to the IMAP server).  IMAP was NOT designed for disconnected clients, such as webmail, that were constantly connecting/disconnecting from the server.  Tools have slowly been developed to help this situation (imapproxy, RFC extensions, webmail server caching) but usage of these tools can not be guaranteed in any single installation. 

Thus, the only reasonable default sort is ARRIVAL.</description> 
   <pubDate>Fri, 19 Mar 2010 16:46:25 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8922#t58268</link> 
  </item> 
   
  <item> 
   <title>On Fri, Mar 19, 2010 at 12:46:25PM -0400, bugs@horde.org wro</title> 
   <description>On Fri, Mar 19, 2010 at 12:46:25PM -0400, bugs@horde.org wrote:
&gt; Yes.  ARRIVAL SORT = message sequence number.  This statement is
&gt; nothing more than providing a keyword to use for SORT to do the same
&gt; thing as a regular arrival sort.

We use cyrus here and it implements ARRIVAL SORT by comparing internal
dates from the mailbox index (no need to read header of every message).
It also implements a SEQUENCE SORT that uses just message numbers:

        switch (sortcrit[i].key) {
        case SORT_SEQUENCE:
            ret = numcmp(md1-&gt;msgno, md2-&gt;msgno);
            break;
        case SORT_ARRIVAL:
            ret = numcmp(INTERNALDATE(md1-&gt;msgno), INTERNALDATE(md2-&gt;msgno));
            break;

&gt; Unfortunately, you are assuming a lot of things about IMAP servers.
&gt; First, the SORT extension wasn&#039;t standardized until June *2008*.  So
&gt; there can be no assumption that the IMAP server supports SORT (not
&gt; to mention IMP 4 was first released 5-6 years ago, before SORT
&gt; existed on most IMAP servers).
&gt; 
&gt; Second, many IMAP servers don&#039;t support SORT.  It&#039;s not required of
&gt; an IMAP 4rev1 server.  Thus, to sort by anything other than internal
&gt; arrival time requires the IMAP server to parse *EVERY* header of
&gt; *EVERY* message in the mailbox (a MUA can use FETCH to only return
&gt; the text of the desired header, but this still requires the IMAP
&gt; server to internally parse every header to collate this
&gt; information).
&gt; 
&gt; Third, even for IMAP servers that support SORT, there is no
&gt; guarantee that SORT is inexpensive.  Many IMAP servers may not cache
&gt; this information, so every SORT call to the server requires parsing
&gt; of the entire mailbox.

Ok, but for those of use using servers like cyrus, perhaps there could
at least be a configuration option to select between _arrival cache
and ARRIVAL SORT?</description> 
   <pubDate>Mon, 22 Mar 2010 09:22:08 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8922#t58277</link> 
  </item> 
   
  <item> 
   <title>I think the issue is that you and I have different meanings </title> 
   <description>I think the issue is that you and I have different meanings for &quot;arrival&quot; sort.  See Ticket #8936 for a full recap.

In short, IMP 4.x is behaving correctly.  But that behavior can be improved/tweaked - hence the new ticket.  However, these changes will take place solely in IMP 5.  Thus, this ticket will remain as &#039;Not a Bug&#039;.</description> 
   <pubDate>Fri, 26 Mar 2010 22:16:04 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8922#t58319</link> 
  </item> 
   
  <item> 
   <title>&gt; In short, IMP 4.x is behaving correctly.  But that behavio</title> 
   <description>&gt; In short, IMP 4.x is behaving correctly.  But that behavior can be 
&gt; improved/tweaked - hence the new ticket.  However, these changes will 
&gt; take place solely in IMP 5.  Thus, this ticket will remain as &#039;Not a 
&gt; Bug&#039;.

Thank you, the changes seem to solve the issue. Any idea when
IMP 5 is going to be released so we can try it out?</description> 
   <pubDate>Thu, 01 Apr 2010 09:00:35 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8922#t58364</link> 
  </item> 
   
   
 
 </channel> 
</rss> 
