the-djmaze / snappymail

Simple, modern & fast web-based email client
https://snappymail.eu
GNU Affero General Public License v3.0
998 stars 121 forks source link

Last message is not used to sort the thread group in the inbox #1568

Closed Massedil closed 5 months ago

Massedil commented 5 months ago

Describe the bug

I have a thread with 6 messages. Last is 2024-04-29 at 20:00. But in the inbox it is the 2024-04-24 01:09 that is showed and used for sorting. In k9 mail on Android, the last message is well used for sort and display. In Thunderbird on Linux, it is the first message of the thread that is displayed but the last message is used for sort.

I don't know if it can help, but the "2024-04-24 01:09" message is a message I sent and copy from Sent to the Inbox after the sending of the "2024-04-29 at 20:00" (that I also sent and copied from Sent to the Inbox before "2024-04-24 01:09"). I have done this to have my thread "complete".

I have read #1507, but it seems

Screenshots

Thread view : 2024-04-29_20-19

Inbox : 2024-04-29_20-20

Please complete the following information:

the-djmaze commented 5 months ago

Does SORT works for you? afbeelding

Massedil commented 5 months ago

Does SORT works for you?

I tried all type of SORT and all works fine, yes !

the-djmaze commented 5 months ago

the "2024-04-24 01:09" message is a message I sent and copy from Sent to the Inbox after the sending of the "2024-04-29 at 20:00" (that I also sent and copied from Sent to the Inbox before "2024-04-24 01:09"). I have done this to have my thread "complete".

What happens here is:

"2024-04-29 at 20:00" has UID 5 (just a fake number as example) The next message in the inbox will get UID 6, then 7, then 8 etc. Now you copy "2024-04-24 01:09" to the inbox and it will have UID 6

When sort on DATE is not possible (servers without sort capability), it will show you messages sorted on UID. So in the mailbox you first get UID 6 and then 5 Since 6 is found in the THREAD capability it will remove the other UID's from view.

  1. Open snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php
  2. Change private bool $bThreadSort = false; value to true
  3. Try again

Here's what happens when it is false (by default) https://github.com/the-djmaze/snappymail/blob/cc360837b1df0382065ed78e2fb10335def2161c/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php#L549-L556

It is false by default because of the speed impact the true setting will have. https://github.com/the-djmaze/snappymail/blob/cc360837b1df0382065ed78e2fb10335def2161c/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php#L522-L548

Massedil commented 5 months ago

I don't know exactly how IMAP protocol works.

What I understand is that you need extra IMAP command if $bThreadSort = true ;. I imagine there is a LIST command when you want to see what is in a folder, but I don't know if you get details like a thread id and a date in the same time or if you need anyway extra IMAP command for each message to get dates and other info.

When sort on DATE is not possible (servers without sort capability), it will show you messages sorted on UID.

So my dovecot server does not support sort on DATE ?

Change private bool $bThreadSort = false; value to true

Without understanding well the impact, I can confirm that $bThreadSort = true ; solves the problem, the good message is displayed and well sorted in the INBOX for the thread.

the-djmaze commented 5 months ago

Your dovecot does support SORT, so the issue is THREAD. Threads are sorted by response structure tree. Say:

- UID 1: Message 1
-- UID 2: Message 2 response to 1
--- UID 4: Message 5 response to 1
--- UID 6: Message 4 response to 1
-- UID 3: Message 3 response to 1
-- UID 5: Message 6 response to 1

From this, we don't know which UID has the highest "date" to show in our LIST. $bThreadSort = true will do additional IMAP commands to SORT DATE all the UID's and then remove the most recent message UID so that LIST will not show the others.

That's why it solves your problem.

Now the impact could be huge on large mailboxes with many threads, as it needs to call those SORT DATE commands on all threads everytime the mailbox is altered (add/remove message).

Since it doesn't happen often that older messages get a newer UID, the default is false (and have the bug you mentioned).