Closed Bug 262316 Opened 17 years ago Closed 14 years ago

Sort by date does not sort messages in thread by date


(MailNews Core :: Database, defect)

Not set


(Not tracked)



(Reporter: kaushy, Assigned: wicked)




(3 files, 1 obsolete file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10
Build Identifier: Mozilla Thunderbird version 0.8 (20040913)

In the sort by thread view,
i.e. View->Sort By->Date, Ascending, Threaded

the messages in an individual thread are sorted by order received and not by date.

Reproducible: Always
Steps to Reproduce:
1. Send yourself 3 messages in the same thread.
2. Switch to View->Sort By->Date, Ascending, Threaded
3. Move these messages to another folder in the reverse order (starting from the
latest first)
4. Click the thread to view the messages

Actual Results:  
The messages are sorted in the reverse order i.e. the thread lists the message
that with the last received date as the first message in the thread (because it
was moved to this folder first).

Expected Results:  
The messages in the thread should also have been sorted by date ascending.
There is no way to sort items within a thread *other* than by Order Received.
When Sort by Date is used with Threaded, the *threads* are placed in order 
according to the most recent message in the thread.
Closed: 17 years ago
Resolution: --- → INVALID
Why *should* the messages within threads be sorted by "Order Received"?
They could be sorted by date received (possible but not ideal).

Or they could be sorted by using the References and In-Reply-To headers, which
are the "true" threads especially if threading by subject is turned off
see bug 164115.

message 1
message 2 replies to message 1
message 3 replies to message 2
message 4 replies to message 1
message 5 replies to message 3
should be sorted as

- message 1
|-- message 2
  |--message 3
    |--message 5
|-- message 4

Reopening bug. Marking as enhancement.
Severity: normal → enhancement
Resolution: INVALID → ---
(In reply to comment #2)

> Or they could be sorted by using the References and In-Reply-To headers, which
> are the "true" threads especially if threading by subject is turned off
> see bug 164115.

In fact, the References and In-Reply-To headers *are* used when available.

> Why *should* the messages within threads be sorted by "Order Received"?
> They could be sorted by date received (possible but not ideal).
> Reopening bug. Marking as enhancement.

Whatever.  Don't expect to see any action on this.
This is an automated message, with ID "auto-resolve01".

This bug has had no comments for a long time. Statistically, we have found that
bug reports that have not been confirmed by a second user after three months are
highly unlikely to be the source of a fix to the code.

While your input is very important to us, our resources are limited and so we
are asking for your help in focussing our efforts. If you can still reproduce
this problem in the latest version of the product (see below for how to obtain a
copy) or, for feature requests, if it's not present in the latest version and
you still believe we should implement it, please visit the URL of this bug
(given at the top of this mail) and add a comment to that effect, giving more
reproduction information if you have it.

If it is not a problem any longer, you need take no action. If this bug is not
changed in any way in the next two weeks, it will be automatically resolved.
Thank you for your help in this matter.

The latest beta releases can be obtained from:
This bug has been automatically resolved after a period of inactivity (see above
comment). If anyone thinks this is incorrect, they should feel free to reopen it.
Closed: 17 years ago16 years ago
Resolution: --- → EXPIRED
*** Bug 324319 has been marked as a duplicate of this bug. ***
Reopening, this needs to be done because current sorting is stupid. At the very least date sorting should be used. I'm not sure if any other sorting is usable inside threads.

Scott, planning to do this any time soon? Attitude in comment #3 is not very promising if that's the way hole TB "dev team" thinks.. :(
OS: Windows XP → All
Hardware: PC → All
Resolution: EXPIRED → ---
Summary: sort by date does not sort messages in thread by date → Sort by date does not sort messages in thread by date
when reading an rss fed forum, this is a particular problem.  scrolling down through a threaded topic results in seeing replies before the prior post(s).  for an active topic, minutes between posts, it's actually impossible to follow the conversation..

i think it deserves a bug, not an enh.
Confirming, this is very annoying in cases when mail arrive out of order. And a real pain for times you want to use threading in feeds - like for a mailing list as atom with subjects that have Re:. (E.g.

Assignee: mscott → bienvenu
Severity: enhancement → normal
Component: Mail Window Front End → MailNews: Database
Ever confirmed: true
Product: Thunderbird → Core
QA Contact: database
Version: unspecified → Trunk
Blocks: 236849
This certainly isn't expected behaviour.
(In reply to comment #11)
> Created an attachment (id=246472) [edit]
> screenshot of the thread
> This certainly isn't expected behaviour.
What was the sort criterion when that screenshot was made?
(In reply to comment #12)
> What was the sort criterion when that screenshot was made?

For some reason it doesn't seem to show, but it's sorted by Date (Threaded + Ascending).
This patch sorts messages within thread in date order instead of order received. Basicly it adds logic to calculate and move a row to sorted position when adding a child to a thread. This works for threads that have less than 1000 childs because it uses same loop that was limited in bug 90452. Thoughts?
Assignee: bienvenu → wicked+bz
Attachment #257495 - Flags: review?(bienvenu)
Thx for the patch! I need to look at this patch in the context of the rest of the method, but it looks ok at first glance.

one nit:

+  if (!hdrMoved && moveIndex > 0) {
+    mdb_pos outPos;
+    m_mdbTable->MoveRow(m_mdbDB->GetEnv(), hdrRow, -1, moveIndex, &outPos);
+  }

please use the prevailing brace style, which is
if (a)
Comment on attachment 257495 [details] [diff] [review]
Sort messages within thread (1.8 branch), V1

I think we should move the retrieving of the child date to outside the big for loop, so that we only do it once.

Other than that, and the {} style, this looks OK to me.  It took me a while to convince myself that it does the right thing when we discover we're the parent of an existing message, which is nothing.

Thx again for the patch. I'd like to run with a bit, and if you could attach a new patch addressing my minor comments (or I can fix them myself if you want), I'll check this in after I've run with it for a bit.
Attachment #257495 - Flags: review?(bienvenu) → review-
Here's an updated patch that moves child GetDate call before the loop and fixes the brace style. Next if block was also using child date so I removed duplicated GetDate call from it too.
Attachment #257495 - Attachment is obsolete: true
Attachment #258121 - Flags: review?(bienvenu)
Comment on attachment 258121 [details] [diff] [review]
Sort messages within thread (trunk), V1.1

thx for the patch - do you need me to land it?
Attachment #258121 - Flags: review?(bienvenu) → review+
I've just checked this in on behalf of Teemu. I'll leave resolving to someone who knows if its fully resolved or not ;-)

Checking in mailnews/db/msgdb/src/nsMsgThread.cpp;
/cvsroot/mozilla/mailnews/db/msgdb/src/nsMsgThread.cpp,v  <--  nsMsgThread.cpp
new revision: 1.84; previous revision: 1.83
marking fixed
Closed: 16 years ago14 years ago
Resolution: --- → FIXED
Does this mean that this bug is resolved now, and when will the respective code turn up in Thunderbird?

Any chance that we get to see this before TB v.3?

Thanks for a short clarification,
It's unlikely that this fix would end up in a security release, so for now, it's most likely not going to show up before TB v.3
Thanks David, for the quick response.

I have just tried the nightly build of TB 3, where threading seems to be much better already.

However, sometimes even TB 3 seems to get the message order within the thread wrong, see below screenshot:

See, the last message in the thread (highlighted yellow) gets sorted almost topmost where it ought to be placed at the bottom.

Maybe you or someone who is working on the threading can have a look at this.

There also seems to be a problem with the thread lines/graphics. At least the thread lines look much clearer e.g. in the below Mozilla example:

I think proper threading is THE upcoming thing in the near future. Keeping sent and received messages in different folders (and unthreaded) soon will be a thing of the past, if not considered an anachronism -- cp. Google Mail.

This is why I think TB should offer the best and most robust threading available as early as possible. TB already made me quit outlook 2007 for this very reason.

Thank you and hopefully we will see top of the line threading very soon in TB -

> There also seems to be a problem with the thread lines/graphics.

See bug 349212.
However, I would not mind to bear with the broken graphics if only the threading did work properly.

As an affirmation of my 'pleading for threading' I was just going to show a screenshot of my current Thunderbird setup (on a dual monitor system) as linked below:

Seeing e-mail conversations of all parties including oneself's in visual threads in *one* folder is just so incredibly more useful than keeping sent and received messages in different folders. (The latter is kind of like if a web board had about every second post of a continuous discussion on a different website - isn't it just as stupid, in a sense, with todays "Inbox" and "Sent"-folders in e-mail clients?)

Anyway, together with the great TB-extension "Show InOut" of Guenter Gersdorf, threading makes an entire new wealth of experience, and fun, in e-mail conversation.

i too would add a plea to sneak this fix into branch builds..  correct threading is just so core to usability.

david, using a filter to immediately move all messages from inbox into a Current type folder, and then using Guenter's Copy Sent To Current lets you achieve the single folder usability you describe.
Read more about threading, single folder usage as well as unified "who"-column [url=]here[/url].

It could be beneficial if the developers would have a look into this major improvement regarding entire e-mail usability.

This is going to be the upcoming paradigm in e-mail. Be prepared.

Oops, BBCode doesn't work. Here is the link again.
Product: Core → MailNews Core
No longer blocks: 236849
You need to log in before you can comment on or make changes to this bug.