Bug 185796

Summary: [Patch] Subject threading does not work (Subject prefix is not ignored)
Product: [Unmaintained] kmail Reporter: A. Pfaller <apfaller>
Component: new message listAssignee: Szymon Stefanek <pragma>
Status: RESOLVED FIXED    
Severity: normal CC: apfaller
Priority: NOR    
Version: 1.11.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Fix for subject threading problem
backtrace of crash during deletion of message

Description A. Pfaller 2009-02-28 13:09:26 UTC
Version:            (using KDE 4.2.0)
OS:                Linux
Installed from:    Compiled From Sources

I am subscribed to a mailing list where all messages contain no "References" or "In-Reply-To" header. Because of this threading by subject is the only possible threading method. However the "thread starter" message is never grouped with the replies (i.e. all replies starting with "Re:" are displayed correctly threaded but the first message is not part of this display). Deleting the index files of the relevant folder did not help. Also setting the reply prefixes explicitly in "Configure->Composer->Subject->Reply Subject Prefixes" did not fix the issue.
Comment 1 A. Pfaller 2009-03-06 16:56:43 UTC
Created attachment 31842 [details]
Fix for subject threading problem

My original description regarding the subject threading
was not entirely correct (since there was always an additional
blank added to "thread starter" subject headers by the mailing
list SW). However even after correcting this (via a "rewrite
header" filter) subject threading was still mostly incomplete
and changing constantly (e.g. afer a kmail restart or arrival
of new messages). 

For me the attached patch fixes the problem completely.
Comment 2 Szymon Stefanek 2009-03-08 21:49:43 UTC
SVN commit 937009 by stefanek:

Fix date-based sorting of the subject threading cache.

BUG: 185796



 M  +42 -20    model.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=937009
Comment 3 Szymon Stefanek 2009-03-08 21:51:57 UTC
The real bug is that the cache really should be sorted by date.
Please check if the fix introduced in revision 937009 works for you.
Comment 4 A. Pfaller 2009-03-09 00:28:50 UTC
I use 4.2 branch where the fix is not available. However
a quick check with model.cpp and model.h copied from trunk
to my 4.2 checkout looks like everything works fine with
your fix.

However after a further look at the code I think that
the (delta<120) check is wrong (it should be delta<0).
It is quite possible that two replies (in the same thread)
for a previous message of this thread are sent within
2 minutes (e.g. by different senders). I did a quick check with
"<60*60" to increase my chances of observing this condition
and threading for many threads was now again wrong (i.e.
several threads are now again split in multiple threads, e.g.

  Subject
    Re: Subject
      Re: Subject
  Some other subject
  Re: Subject
    Re: Subject

I would understand the 2 minute heuristic if the above sample
would result in something like

1)  Subject
2)    Re: Subject
3)      Re: Subject
4)    Re: Subject
5)      Re: Subject
6)  Some other subject

assuming 2) and 4) have dates within a 2 minute range although I
think to second guess the real hierarchy is not worth the effort
since it is most probably wrong.

Andreas
Comment 5 Szymon Stefanek 2009-03-09 13:26:08 UTC
> However after a further look at the code I think that
> the (delta<120) check is wrong (it should be delta<0).
> It is quite possible that two replies (in the same thread)
> for a previous message of this thread are sent within
> 2 minutes (e.g. by different senders).

The delta considers only parent-child relationships, not
child-child relationships. This means that when looking
for the parent of message A we discard all the parent
candidates that have been sent less than 120 seconds earlier
than message A. This is a reasonable heuristic.

Two replies to the same message sent within the same
second will still be correctly threaded (unless
the 120 second check fails for both).
Comment 6 A. Pfaller 2009-03-09 15:39:51 UTC
Ok, it seems that in my test with the increased delta the
original message which started the thread was discarded by
several replies leading to broken threads. This probably
doesn't happen in reality.

Something more serious: 
While experimenting I had reproducible crashes when trying
to delete messages with the new code. See attached backtrace.
Comment 7 A. Pfaller 2009-03-09 15:41:58 UTC
Created attachment 31949 [details]
backtrace of crash during deletion of message
Comment 8 Szymon Stefanek 2009-03-09 17:25:50 UTC
Yep. Looks like the yesterday's fix was incomplete...

This assert() has been fixed this morning.
Comment 9 Thomas McGuire 2009-03-11 15:19:46 UTC
SVN commit 938208 by tmcguire:

Backport r937009 by stefanek from trunk to the 4.2 branch:

Fix date-based sorting of the subject threading cache.

CCBUG: 185796




 M  +42 -20    model.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=938208