diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-20 00:17:00 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-20 00:17:00 +0100 |
commit | 44e3e7c5312e232c35403b5f8ad7cae0b4e6ddee (patch) | |
tree | a4902d07e465617a53a56f00aff66f4977964f9e /common/mail/threadindexer.cpp | |
parent | e6820f5b59a3d9615863740bb16cec150206e326 (diff) | |
download | sink-44e3e7c5312e232c35403b5f8ad7cae0b4e6ddee.tar.gz sink-44e3e7c5312e232c35403b5f8ad7cae0b4e6ddee.zip |
Fix threading for non-threaded messages.
Ensure we always have a messageId to work with,
and avoid grouping all non-threaded messages together.
Diffstat (limited to 'common/mail/threadindexer.cpp')
-rw-r--r-- | common/mail/threadindexer.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp index 17ee31e..3da2fdd 100644 --- a/common/mail/threadindexer.cpp +++ b/common/mail/threadindexer.cpp | |||
@@ -84,9 +84,12 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App | |||
84 | { | 84 | { |
85 | auto messageId = entity.getProperty(Mail::MessageId::name); | 85 | auto messageId = entity.getProperty(Mail::MessageId::name); |
86 | auto parentMessageId = entity.getProperty(Mail::ParentMessageId::name); | 86 | auto parentMessageId = entity.getProperty(Mail::ParentMessageId::name); |
87 | auto subject = entity.getProperty(Mail::Subject::name); | 87 | const auto subject = entity.getProperty(Mail::Subject::name); |
88 | 88 | const auto normalizedSubject = stripOffPrefixes(subject.toString()).toUtf8(); | |
89 | auto normalizedSubject = stripOffPrefixes(subject.toString()).toUtf8(); | 89 | if (messageId.toByteArray().isEmpty()) { |
90 | SinkError() << "Found an email without messageId. This is illegal and threading will break. Entity id: " << identifier; | ||
91 | SinkError() << "Subject: " << subject; | ||
92 | } | ||
90 | 93 | ||
91 | QVector<QByteArray> thread; | 94 | QVector<QByteArray> thread; |
92 | 95 | ||
@@ -96,30 +99,29 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App | |||
96 | //If parent is already available, add to thread of parent | 99 | //If parent is already available, add to thread of parent |
97 | if (thread.isEmpty() && parentMessageId.isValid()) { | 100 | if (thread.isEmpty() && parentMessageId.isValid()) { |
98 | thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId); | 101 | thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId); |
99 | SinkTrace() << "Found parent"; | 102 | SinkTrace() << "Found parent: " << thread; |
100 | } | 103 | } |
101 | if (thread.isEmpty()) { | 104 | if (thread.isEmpty()) { |
102 | //Try to lookup the thread by subject: | 105 | //Try to lookup the thread by subject: |
103 | thread = index().secondaryLookup<Mail::Subject, Mail::ThreadId>(normalizedSubject); | 106 | thread = index().secondaryLookup<Mail::Subject, Mail::ThreadId>(normalizedSubject); |
104 | if (thread.isEmpty()) { | 107 | if (thread.isEmpty()) { |
105 | SinkTrace() << "Created a new thread "; | ||
106 | thread << QUuid::createUuid().toByteArray(); | 108 | thread << QUuid::createUuid().toByteArray(); |
109 | SinkTrace() << "Created a new thread: " << thread; | ||
107 | } else { | 110 | } else { |
111 | SinkTrace() << "Found thread by subject: " << thread; | ||
108 | } | 112 | } |
109 | } | 113 | } |
110 | 114 | ||
111 | //We should have found the thread by now | 115 | Q_ASSERT(!thread.isEmpty()); |
112 | if (!thread.isEmpty()) { | 116 | |
113 | if (parentMessageId.isValid()) { | 117 | if (parentMessageId.isValid()) { |
114 | //Register parent with thread for when it becomes available | 118 | Q_ASSERT(!parentMessageId.toByteArray().isEmpty()); |
115 | index().index<Mail::MessageId, Mail::ThreadId>(parentMessageId, thread.first(), transaction); | 119 | //Register parent with thread for when it becomes available |
116 | } | 120 | index().index<Mail::MessageId, Mail::ThreadId>(parentMessageId, thread.first(), transaction); |
117 | index().index<Mail::MessageId, Mail::ThreadId>(messageId, thread.first(), transaction); | ||
118 | index().index<Mail::ThreadId, Mail::MessageId>(thread.first(), messageId, transaction); | ||
119 | index().index<Mail::Subject, Mail::ThreadId>(normalizedSubject, thread.first(), transaction); | ||
120 | } else { | ||
121 | SinkWarning() << "Couldn't find a thread for: " << messageId; | ||
122 | } | 121 | } |
122 | index().index<Mail::MessageId, Mail::ThreadId>(messageId, thread.first(), transaction); | ||
123 | index().index<Mail::ThreadId, Mail::MessageId>(thread.first(), messageId, transaction); | ||
124 | index().index<Mail::Subject, Mail::ThreadId>(normalizedSubject, thread.first(), transaction); | ||
123 | } | 125 | } |
124 | 126 | ||
125 | 127 | ||