Summary | Sort messages by arrival date not working correctly |
Queue | IMP |
Queue Version | 4.3.6 |
Type | Bug |
State | Not A Bug |
Priority | 2. Medium |
Owners | |
Requester | Valentin.Vidic (at) carnet (dot) hr |
Created | 03/19/2010 (5539 days ago) |
Due | |
Updated | 04/01/2010 (5526 days ago) |
Assigned | |
Resolved | 03/19/2010 (5539 days ago) |
Milestone | |
Patch | No |
improved/tweaked - hence the new ticket. However, these changes
will take place solely in IMP 5. Thus, this ticket will remain as
'Not a Bug'.
IMP 5 is going to be released so we can try it out?
"arrival" sort. See
Ticket #8936for 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 'Not a
Bug'.
nothing more than providing a keyword to use for SORT to do the same
thing as a regular arrival sort.
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->msgno, md2->msgno);
break;
case SORT_ARRIVAL:
ret = numcmp(INTERNALDATE(md1->msgno), INTERNALDATE(md2->msgno));
break;
at least be a configuration option to select between _arrival cache
and ARRIVAL SORT?
message sequence number/UID?
track their message sequence numbers, so sorting by this value is
"free" (as opposed to date sort - this requires each message's header
to be parsed to get the date value).
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.
nothing more than providing a keyword to use for SORT to do the same
thing as a regular arrival sort.
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.
type". 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'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't support SORT. It'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.
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.
State ⇒ Not A Bug
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.
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 "arrived" 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.
Priority ⇒ 2. Medium
Type ⇒ Bug
Summary ⇒ Sort messages by arrival date not working correctly
Queue ⇒ IMP
Milestone ⇒
Patch ⇒ No
State ⇒ Unconfirmed
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->getMailboxArrival) in imp/lib/Mailbox.php seems to solve
the issue. Now IMP issues "UID SORT (ARRIVAL)" or "UID SORT (REVERSE
ARRIVAL)" 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 && $sortpref['by'] == SORTARRIVAL) {
require_once IMP_BASE . '/lib/IMAP/Cache.php';
$imap_cache = &IMP_IMAP_Cache::singleton();
$this->_sorted =
$imap_cache->getMailboxArrival($this->_mailbox);
if ($sortpref['dir']) {
$this->_sorted = array_reverse($this->_sorted);
}
} else {
$this->_sorted =
$imap_search->searchSortMailbox($query, null, $this->_mailbox,
$sortpref['by'], $sortpref['dir']);
}