Commit 3b0079c5 authored by Laurent Montel's avatar Laurent Montel 😁

Move hasMissingAttachments to util class so we can create autotests for this method

parent 784bfdff
......@@ -1691,38 +1691,7 @@ bool ComposerViewBase::hasMissingAttachments(const QStringList &attachmentKeywor
return false;
}
QStringList attachWordsList = attachmentKeywords;
QRegExp rx(QLatin1String("\\b") +
attachWordsList.join(QStringLiteral("\\b|\\b")) +
QLatin1String("\\b"));
rx.setCaseSensitivity(Qt::CaseInsensitive);
// check whether the subject contains one of the attachment key words
// unless the message is a reply or a forwarded message
const QString subj = subject();
bool gotMatch = (MessageHelper::stripOffPrefixes(subj) == subj) && (rx.indexIn(subj) >= 0);
if (!gotMatch) {
// check whether the non-quoted text contains one of the attachment key
// words
QRegExp quotationRx(QStringLiteral("^([ \\t]*([|>:}#]|[A-Za-z]+>))+"));
QTextDocument *doc = m_editor->document();
QTextBlock end(doc->end());
for (QTextBlock it = doc->begin(); it != end; it = it.next()) {
const QString line = it.text();
gotMatch = (quotationRx.indexIn(line) < 0) &&
(rx.indexIn(line) >= 0);
if (gotMatch) {
break;
}
}
}
if (!gotMatch) {
return false;
}
return true;
return MessageComposer::Util::hasMissingAttachments(attachmentKeywords, m_editor->document(), subject());
}
ComposerViewBase::MissingAttachment ComposerViewBase::checkForMissingAttachments(const QStringList &attachmentKeywords)
......
......@@ -29,6 +29,8 @@
#include "job/singlepartjob.h"
#include <QTextCodec>
#include <QTextDocument>
#include <QTextBlock>
#include <KCharsets>
#include "messagecomposer_debug.h"
......@@ -41,6 +43,7 @@
#include <AkonadiCore/agentinstance.h>
#include <AkonadiCore/agentinstancecreatejob.h>
#include <AkonadiCore/agentmanager.h>
#include <MessageComposer/MessageHelper>
KMime::Content *setBodyAndCTE(QByteArray &encodedBody, KMime::Headers::ContentType *contentType, KMime::Content *ret)
{
......@@ -422,3 +425,40 @@ KMime::Message::Ptr MessageComposer::Util::message(const Akonadi::Item &item)
return item.payload<KMime::Message::Ptr>();
}
bool MessageComposer::Util::hasMissingAttachments(const QStringList &attachmentKeywords, QTextDocument *doc, const QString &subj)
{
if (!doc) {
return false;
}
QStringList attachWordsList = attachmentKeywords;
QRegExp rx(QLatin1String("\\b") +
attachWordsList.join(QStringLiteral("\\b|\\b")) +
QLatin1String("\\b"));
rx.setCaseSensitivity(Qt::CaseInsensitive);
// check whether the subject contains one of the attachment key words
// unless the message is a reply or a forwarded message
bool gotMatch = (MessageHelper::stripOffPrefixes(subj) == subj) && (rx.indexIn(subj) >= 0);
if (!gotMatch) {
// check whether the non-quoted text contains one of the attachment key
// words
QRegExp quotationRx(QStringLiteral("^([ \\t]*([|>:}#]|[A-Za-z]+>))+"));
QTextBlock end(doc->end());
for (QTextBlock it = doc->begin(); it != end; it = it.next()) {
const QString line = it.text();
gotMatch = (quotationRx.indexIn(line) < 0) &&
(rx.indexIn(line) >= 0);
if (gotMatch) {
break;
}
}
}
if (!gotMatch) {
return false;
}
return true;
}
......@@ -28,6 +28,8 @@
#include <AkonadiCore/Item>
#include <Akonadi/KMime/MessageStatus>
class QTextDocument;
namespace KMime
{
class Content;
......@@ -92,6 +94,8 @@ MESSAGECOMPOSER_EXPORT bool isStandaloneMessage(const Akonadi::Item &item);
*/
MESSAGECOMPOSER_EXPORT KMime::Message::Ptr message(const Akonadi::Item &item);
MESSAGECOMPOSER_EXPORT bool hasMissingAttachments(const QStringList &attachmentKeywords, QTextDocument *doc, const QString &subj);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment