diff options
Diffstat (limited to 'common/mailpreprocessor.cpp')
-rw-r--r-- | common/mailpreprocessor.cpp | 40 |
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 | ||
50 | static 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 | |||
48 | void MailPropertyExtractor::updatedIndexedProperties(Sink::ApplicationDomain::Mail &mail, const QByteArray &data) | 71 | void 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 | ||
108 | void MailPropertyExtractor::newEntity(Sink::ApplicationDomain::Mail &mail) | 145 | void 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 | |||