diff options
Diffstat (limited to 'common/domain/mail.cpp')
-rw-r--r-- | common/domain/mail.cpp | 99 |
1 files changed, 3 insertions, 96 deletions
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 9d58767..4b33f06 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "entitybuffer.h" | 35 | #include "entitybuffer.h" |
36 | #include "datastorequery.h" | 36 | #include "datastorequery.h" |
37 | #include "entity_generated.h" | 37 | #include "entity_generated.h" |
38 | #include "mail/threadindexer.h" | ||
38 | 39 | ||
39 | #include "mail_generated.h" | 40 | #include "mail_generated.h" |
40 | 41 | ||
@@ -59,6 +60,8 @@ void TypeImplementation<Mail>::configureIndex(TypeIndex &index) | |||
59 | index.addProperty<QByteArray>(Mail::ParentMessageId::name); | 60 | index.addProperty<QByteArray>(Mail::ParentMessageId::name); |
60 | 61 | ||
61 | index.addProperty<Mail::MessageId>(); | 62 | index.addProperty<Mail::MessageId>(); |
63 | |||
64 | index.addSecondaryPropertyIndexer<Mail::MessageId, Mail::ThreadId, ThreadIndexer>(); | ||
62 | index.addSecondaryProperty<Mail::MessageId, Mail::ThreadId>(); | 65 | index.addSecondaryProperty<Mail::MessageId, Mail::ThreadId>(); |
63 | index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>(); | 66 | index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>(); |
64 | } | 67 | } |
@@ -74,102 +77,6 @@ static TypeIndex &getIndex() | |||
74 | return *index; | 77 | return *index; |
75 | } | 78 | } |
76 | 79 | ||
77 | static QString stripOffPrefixes(const QString &subject) | ||
78 | { | ||
79 | //TODO this hardcoded list is probably not good enough (especially regarding internationalization) | ||
80 | //TODO this whole routine, including internationalized re/fwd ... should go into some library. | ||
81 | //We'll require the same for generating reply/forward subjects in kube | ||
82 | static QStringList defaultReplyPrefixes = QStringList() << QLatin1String("Re\\s*:") | ||
83 | << QLatin1String("Re\\[\\d+\\]:") | ||
84 | << QLatin1String("Re\\d+:"); | ||
85 | |||
86 | static QStringList defaultForwardPrefixes = QStringList() << QLatin1String("Fwd:") | ||
87 | << QLatin1String("FW:"); | ||
88 | |||
89 | QStringList replyPrefixes; // = GlobalSettings::self()->replyPrefixes(); | ||
90 | if (replyPrefixes.isEmpty()) { | ||
91 | replyPrefixes = defaultReplyPrefixes; | ||
92 | } | ||
93 | |||
94 | QStringList forwardPrefixes; // = GlobalSettings::self()->forwardPrefixes(); | ||
95 | if (forwardPrefixes.isEmpty()) { | ||
96 | forwardPrefixes = defaultReplyPrefixes; | ||
97 | } | ||
98 | |||
99 | const QStringList prefixRegExps = replyPrefixes + forwardPrefixes; | ||
100 | |||
101 | // construct a big regexp that | ||
102 | // 1. is anchored to the beginning of str (sans whitespace) | ||
103 | // 2. matches at least one of the part regexps in prefixRegExps | ||
104 | const QString bigRegExp = QString::fromLatin1("^(?:\\s+|(?:%1))+\\s*").arg(prefixRegExps.join(QLatin1String(")|(?:"))); | ||
105 | |||
106 | static QString regExpPattern; | ||
107 | static QRegExp regExp; | ||
108 | |||
109 | regExp.setCaseSensitivity(Qt::CaseInsensitive); | ||
110 | if (regExpPattern != bigRegExp) { | ||
111 | // the prefixes have changed, so update the regexp | ||
112 | regExpPattern = bigRegExp; | ||
113 | regExp.setPattern(regExpPattern); | ||
114 | } | ||
115 | |||
116 | if(regExp.isValid()) { | ||
117 | QString tmp = subject; | ||
118 | if (regExp.indexIn( tmp ) == 0) { | ||
119 | return tmp.remove(0, regExp.matchedLength()); | ||
120 | } | ||
121 | } else { | ||
122 | SinkWarning() << "bigRegExp = \"" | ||
123 | << bigRegExp << "\"\n" | ||
124 | << "prefix regexp is invalid!"; | ||
125 | } | ||
126 | |||
127 | return subject; | ||
128 | } | ||
129 | |||
130 | |||
131 | static void updateThreadingIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction) | ||
132 | { | ||
133 | auto messageId = bufferAdaptor.getProperty(Mail::MessageId::name); | ||
134 | auto parentMessageId = bufferAdaptor.getProperty(Mail::ParentMessageId::name); | ||
135 | auto subject = bufferAdaptor.getProperty(Mail::Subject::name); | ||
136 | |||
137 | auto normalizedSubject = stripOffPrefixes(subject.toString()).toUtf8(); | ||
138 | |||
139 | QVector<QByteArray> thread; | ||
140 | |||
141 | //a child already registered our thread. | ||
142 | thread = getIndex().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId, transaction); | ||
143 | |||
144 | //If parent is already available, add to thread of parent | ||
145 | if (thread.isEmpty() && parentMessageId.isValid()) { | ||
146 | thread = getIndex().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId, transaction); | ||
147 | SinkTrace() << "Found parent"; | ||
148 | } | ||
149 | if (thread.isEmpty()) { | ||
150 | //Try to lookup the thread by subject: | ||
151 | thread = getIndex().secondaryLookup<Mail::Subject, Mail::ThreadId>(normalizedSubject, transaction); | ||
152 | if (thread.isEmpty()) { | ||
153 | SinkTrace() << "Created a new thread "; | ||
154 | thread << QUuid::createUuid().toByteArray(); | ||
155 | } else { | ||
156 | } | ||
157 | } | ||
158 | |||
159 | //We should have found the thread by now | ||
160 | if (!thread.isEmpty()) { | ||
161 | if (parentMessageId.isValid()) { | ||
162 | //Register parent with thread for when it becomes available | ||
163 | getIndex().index<Mail::MessageId, Mail::ThreadId>(parentMessageId, thread.first(), transaction); | ||
164 | } | ||
165 | getIndex().index<Mail::MessageId, Mail::ThreadId>(messageId, thread.first(), transaction); | ||
166 | getIndex().index<Mail::ThreadId, Mail::MessageId>(thread.first(), messageId, transaction); | ||
167 | getIndex().index<Mail::Subject, Mail::ThreadId>(normalizedSubject, thread.first(), transaction); | ||
168 | } else { | ||
169 | SinkWarning() << "Couldn't find a thread for: " << messageId; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() | 80 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() |
174 | { | 81 | { |
175 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); | 82 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); |