summaryrefslogtreecommitdiffstats
path: root/common/mailpreprocessor.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-13 18:38:35 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-02-11 23:03:17 +0100
commit6051c1247cde61bcc8e483eb4166e5a297c0ecc6 (patch)
treedf3aba1ef4011f2640b17c8cf7a9b106933231ab /common/mailpreprocessor.cpp
parent8740a007515dcf1b315d69ab5c64fcfd40ec980c (diff)
downloadsink-6051c1247cde61bcc8e483eb4166e5a297c0ecc6.tar.gz
sink-6051c1247cde61bcc8e483eb4166e5a297c0ecc6.zip
Xapian based fulltext indexing
This cuts into the sync performance by about 40%, but gives us fast fulltext searching for all local content.
Diffstat (limited to 'common/mailpreprocessor.cpp')
-rw-r--r--common/mailpreprocessor.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/common/mailpreprocessor.cpp b/common/mailpreprocessor.cpp
index 8f5a77d..58cb15b 100644
--- a/common/mailpreprocessor.cpp
+++ b/common/mailpreprocessor.cpp
@@ -21,9 +21,11 @@
21 21
22#include <QFile> 22#include <QFile>
23#include <QDir> 23#include <QDir>
24#include <QTextDocument>
24#include <KMime/KMime/KMimeMessage> 25#include <KMime/KMime/KMimeMessage>
25 26
26#include "pipeline.h" 27#include "pipeline.h"
28#include "fulltextindex.h"
27#include "definitions.h" 29#include "definitions.h"
28#include "applicationdomaintype.h" 30#include "applicationdomaintype.h"
29 31
@@ -45,13 +47,34 @@ static QList<Sink::ApplicationDomain::Mail::Contact> getContactList(const KMime:
45 return list; 47 return list;
46} 48}
47 49
50static QList<QPair<QString, QString>> processPart(KMime::Content* content)
51{
52 if (KMime::Headers::ContentType* type = content->contentType(false)) {
53 if (type->isMultipart() && !type->isSubtype("encrypted")) {
54 QList<QPair<QString, QString>> list;
55 for (const auto c : content->contents()) {
56 list << processPart(c);
57 }
58 return list;
59 } else if (type->isHTMLText()) {
60 // Only get HTML content, if no plain text content
61 QTextDocument doc;
62 doc.setHtml(content->decodedText());
63 return {{{}, {doc.toPlainText()}}};
64 } else if (type->isEmpty()) {
65 return {{{}, {content->decodedText()}}};
66 }
67 }
68 return {};
69}
70
48void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail, const QByteArray &data) 71void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail, const QByteArray &data)
49{ 72{
50 if (data.isEmpty()) { 73 if (data.isEmpty()) {
51 return; 74 return;
52 } 75 }
53 auto msg = KMime::Message::Ptr(new KMime::Message); 76 auto msg = KMime::Message::Ptr(new KMime::Message);
54 msg->setHead(KMime::CRLFtoLF(data)); 77 msg->setContent(KMime::CRLFtoLF(data));
55 msg->parse(); 78 msg->parse();
56 if (!msg) { 79 if (!msg) {
57 return; 80 return;
@@ -103,6 +126,20 @@ void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Ma
103 if (!parentMessageId.isEmpty()) { 126 if (!parentMessageId.isEmpty()) {
104 mail.setExtractedParentMessageId(parentMessageId); 127 mail.setExtractedParentMessageId(parentMessageId);
105 } 128 }
129 QList<QPair<QString, QString>> contentToIndex;
130 contentToIndex.append({{}, msg->subject()->asUnicodeString()});
131 if (KMime::Content* mainBody = msg->mainBodyPart("text/plain")) {
132 contentToIndex.append({{}, mainBody->decodedText()});
133 } else {
134 contentToIndex << processPart(msg.data());
135 }
136 contentToIndex.append({{}, msg->from(true)->asUnicodeString()});
137 contentToIndex.append({{}, msg->to(true)->asUnicodeString()});
138 contentToIndex.append({{}, msg->cc(true)->asUnicodeString()});
139 contentToIndex.append({{}, msg->bcc(true)->asUnicodeString()});
140
141 //Prepare content for indexing;
142 mail.setProperty("index", QVariant::fromValue(contentToIndex));
106} 143}
107 144
108void MailPropertyExtractor::newEntity(Sink::ApplicationDomain::Mail &mail) 145void MailPropertyExtractor::newEntity(Sink::ApplicationDomain::Mail &mail)
@@ -114,4 +151,3 @@ void MailPropertyExtractor::modifiedEntity(const Sink::ApplicationDomain::Mail &
114{ 151{
115 updatedIndexedProperties(newMail, newMail.getMimeMessage()); 152 updatedIndexedProperties(newMail, newMail.getMimeMessage());
116} 153}
117