summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/domain/mail.cpp6
-rw-r--r--common/mail/threadindexer.cpp34
-rw-r--r--common/mailpreprocessor.cpp7
3 files changed, 29 insertions, 18 deletions
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp
index 6926711..3dd9093 100644
--- a/common/domain/mail.cpp
+++ b/common/domain/mail.cpp
@@ -59,8 +59,10 @@ void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMappe
59 indexPropertyMapper.addIndexLookupProperty<Mail::ThreadId>([](TypeIndex &index, const ApplicationDomain::BufferAdaptor &entity) { 59 indexPropertyMapper.addIndexLookupProperty<Mail::ThreadId>([](TypeIndex &index, const ApplicationDomain::BufferAdaptor &entity) {
60 auto messageId = entity.getProperty(Mail::MessageId::name); 60 auto messageId = entity.getProperty(Mail::MessageId::name);
61 auto thread = index.secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); 61 auto thread = index.secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId);
62 Q_ASSERT(!thread.isEmpty()); 62 if (!thread.isEmpty()) {
63 return thread.first(); 63 return thread.first();
64 }
65 return QByteArray{};
64 }); 66 });
65} 67}
66 68
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
diff --git a/common/mailpreprocessor.cpp b/common/mailpreprocessor.cpp
index bde8a64..1366718 100644
--- a/common/mailpreprocessor.cpp
+++ b/common/mailpreprocessor.cpp
@@ -127,6 +127,13 @@ static void updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail, KMime:
127 parentMessageId = inReplyTo.first(); 127 parentMessageId = inReplyTo.first();
128 } 128 }
129 } 129 }
130 if (messageId.isEmpty()) {
131 auto tmp = KMime::Message::Ptr::create();
132 auto header = tmp->messageID(true);
133 header->generate("kube.kde.org");
134 messageId = header->as7BitString();
135 SinkWarning() << "Message id is empty, generating one: " << messageId;
136 }
130 137
131 mail.setExtractedMessageId(messageId); 138 mail.setExtractedMessageId(messageId);
132 if (!parentMessageId.isEmpty()) { 139 if (!parentMessageId.isEmpty()) {