summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-15 10:06:28 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-15 10:06:28 +0200
commit192cb00abb964a07df2403513f527598b6791df2 (patch)
tree170bf69e26e3af9734f47598da4634ff63b2e5dd
parent78ff8574c3f481f8b0be248b153d55fe8c33eda5 (diff)
downloadsink-192cb00abb964a07df2403513f527598b6791df2.tar.gz
sink-192cb00abb964a07df2403513f527598b6791df2.zip
No more threading by subject
It seems to do more harm than good, creating huge threads, and the webclient doesn't do it either.
-rw-r--r--common/mail/threadindexer.cpp74
1 files changed, 2 insertions, 72 deletions
diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp
index 473f28e..ea2cf71 100644
--- a/common/mail/threadindexer.cpp
+++ b/common/mail/threadindexer.cpp
@@ -24,69 +24,12 @@
24using namespace Sink; 24using namespace Sink;
25using namespace Sink::ApplicationDomain; 25using namespace Sink::ApplicationDomain;
26 26
27static QString stripOffPrefixes(const QString &subject)
28{
29 //TODO this hardcoded list is probably not good enough (especially regarding internationalization)
30 //TODO this whole routine, including internationalized re/fwd ... should go into some library.
31 //We'll require the same for generating reply/forward subjects in kube
32 static QStringList defaultReplyPrefixes = QStringList() << QLatin1String("Re\\s*:")
33 << QLatin1String("Re\\[\\d+\\]:")
34 << QLatin1String("Re\\d+:");
35
36 static QStringList defaultForwardPrefixes = QStringList() << QLatin1String("Fwd:")
37 << QLatin1String("FW:");
38
39 QStringList replyPrefixes; // = GlobalSettings::self()->replyPrefixes();
40 if (replyPrefixes.isEmpty()) {
41 replyPrefixes = defaultReplyPrefixes;
42 }
43
44 QStringList forwardPrefixes; // = GlobalSettings::self()->forwardPrefixes();
45 if (forwardPrefixes.isEmpty()) {
46 forwardPrefixes = defaultReplyPrefixes;
47 }
48
49 const QStringList prefixRegExps = replyPrefixes + forwardPrefixes;
50
51 // construct a big regexp that
52 // 1. is anchored to the beginning of str (sans whitespace)
53 // 2. matches at least one of the part regexps in prefixRegExps
54 const QString bigRegExp = QString::fromLatin1("^(?:\\s+|(?:%1))+\\s*").arg(prefixRegExps.join(QLatin1String(")|(?:")));
55
56 static QString regExpPattern;
57 static QRegExp regExp;
58
59 regExp.setCaseSensitivity(Qt::CaseInsensitive);
60 if (regExpPattern != bigRegExp) {
61 // the prefixes have changed, so update the regexp
62 regExpPattern = bigRegExp;
63 regExp.setPattern(regExpPattern);
64 }
65
66 if(regExp.isValid()) {
67 QString tmp = subject;
68 if (regExp.indexIn( tmp ) == 0) {
69 return tmp.remove(0, regExp.matchedLength());
70 }
71 } else {
72 SinkWarning() << "bigRegExp = \""
73 << bigRegExp << "\"\n"
74 << "prefix regexp is invalid!";
75 }
76
77 return subject;
78}
79
80
81void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction) 27void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction)
82{ 28{
83 auto messageId = entity.getProperty(Mail::MessageId::name); 29 auto messageId = entity.getProperty(Mail::MessageId::name);
84 auto parentMessageId = entity.getProperty(Mail::ParentMessageId::name); 30 auto parentMessageId = entity.getProperty(Mail::ParentMessageId::name);
85 const auto subject = entity.getProperty(Mail::Subject::name);
86 const auto normalizedSubject = stripOffPrefixes(subject.toString()).toUtf8();
87 if (messageId.toByteArray().isEmpty()) { 31 if (messageId.toByteArray().isEmpty()) {
88 SinkWarning() << "Found an email without messageId. This is illegal and threading will break. Entity id: " << identifier; 32 SinkWarning() << "Found an email without messageId. This is illegal and threading will break. Entity id: " << identifier;
89 SinkWarning() << "Subject: " << subject;
90 } 33 }
91 34
92 QVector<QByteArray> thread; 35 QVector<QByteArray> thread;
@@ -99,18 +42,9 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App
99 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId); 42 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId);
100 SinkTrace() << "Found parent: " << thread; 43 SinkTrace() << "Found parent: " << thread;
101 } 44 }
102
103 if (thread.isEmpty()) { 45 if (thread.isEmpty()) {
104 //Try to lookup the thread by subject if not empty 46 thread << QUuid::createUuid().toByteArray();
105 if ( !normalizedSubject.isEmpty()) { 47 SinkTrace() << "Created a new thread: " << thread;
106 thread = index().secondaryLookup<Mail::Subject, Mail::ThreadId>(normalizedSubject);
107 }
108 if (thread.isEmpty()) {
109 thread << QUuid::createUuid().toByteArray();
110 SinkTrace() << "Created a new thread: " << thread;
111 } else {
112 SinkTrace() << "Found thread by subject: " << thread;
113 }
114 } 48 }
115 49
116 Q_ASSERT(!thread.isEmpty()); 50 Q_ASSERT(!thread.isEmpty());
@@ -122,9 +56,6 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App
122 } 56 }
123 index().index<Mail::MessageId, Mail::ThreadId>(messageId, thread.first(), transaction); 57 index().index<Mail::MessageId, Mail::ThreadId>(messageId, thread.first(), transaction);
124 index().index<Mail::ThreadId, Mail::MessageId>(thread.first(), messageId, transaction); 58 index().index<Mail::ThreadId, Mail::MessageId>(thread.first(), messageId, transaction);
125 if (!normalizedSubject.isEmpty()) {
126 index().index<Mail::Subject, Mail::ThreadId>(normalizedSubject, thread.first(), transaction);
127 }
128} 59}
129 60
130 61
@@ -146,7 +77,6 @@ void ThreadIndexer::remove(const ApplicationDomain::ApplicationDomainType &entit
146QMap<QByteArray, int> ThreadIndexer::databases() 77QMap<QByteArray, int> ThreadIndexer::databases()
147{ 78{
148 return {{"mail.index.messageIdthreadId", 1}, 79 return {{"mail.index.messageIdthreadId", 1},
149 {"mail.index.subjectthreadId", 1},
150 {"mail.index.threadIdmessageId", 1}}; 80 {"mail.index.threadIdmessageId", 1}};
151} 81}
152 82