Commit 8dc31a43 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Return info when we found a specific email

parent 695d3f0b
Pipeline #69372 passed with stage
in 53 minutes and 35 seconds
......@@ -6,7 +6,9 @@
#include "confirmbeforedeletingrule.h"
#include "confirmbeforedeletingplugin_debug.h"
#include <KMime/Message>
#include <KLocalizedString>
ConfirmBeforeDeletingRule::ConfirmBeforeDeletingRule()
{
}
......@@ -90,7 +92,7 @@ QString ConfirmBeforeDeletingRule::ruleTypeToString(ConfirmBeforeDeletingRule::R
return tmp;
}
bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item, QString &checkFound) const
bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item, QString &checkFoundInfo) const
{
bool needToConfirm = false;
if (item.hasPayload<KMime::Message::Ptr>()) {
......@@ -100,6 +102,7 @@ bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item,
const auto ba = msg->body();
if (QString::fromUtf8(ba).contains(pattern())) {
needToConfirm = true;
generateConfirmMessageInfo(msg, checkFoundInfo);
}
break;
}
......@@ -108,6 +111,7 @@ bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item,
const QString subjectStr = subject->asUnicodeString();
if (subjectStr.contains(pattern())) {
needToConfirm = true;
generateConfirmMessageInfo(msg, checkFoundInfo);
}
}
break;
......@@ -117,6 +121,7 @@ bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item,
const QString toStr = to->asUnicodeString();
if (toStr.contains(pattern())) {
needToConfirm = true;
generateConfirmMessageInfo(msg, checkFoundInfo);
}
}
break;
......@@ -126,6 +131,7 @@ bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item,
const QString ccStr = cc->asUnicodeString();
if (ccStr.contains(pattern())) {
needToConfirm = true;
generateConfirmMessageInfo(msg, checkFoundInfo);
}
}
break;
......@@ -139,6 +145,15 @@ bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item,
return needToConfirm;
}
void ConfirmBeforeDeletingRule::generateConfirmMessageInfo(const KMime::Message::Ptr &msg, QString &checkFoundInfo) const
{
QString subjectStr;
if (auto subject = msg->subject(false)) {
subjectStr = subject->asUnicodeString();
}
checkFoundInfo = i18n("The message with subject \'%2\' contains \'%1\'", pattern(), subjectStr);
}
QDebug operator<<(QDebug d, const ConfirmBeforeDeletingRule &t)
{
d << "Pattern " << t.pattern();
......
......@@ -8,6 +8,7 @@
#include "kmailconfirmbeforedeleting_export.h"
#include <AkonadiCore/Item>
#include <KConfigGroup>
#include <KMime/Message>
#include <QDebug>
#include <QString>
class KMAILCONFIRMBEFOREDELETING_EXPORT ConfirmBeforeDeletingRule
......@@ -32,7 +33,7 @@ public:
Q_REQUIRED_RESULT RuleType ruleType() const;
void setRuleType(RuleType newRuleType);
Q_REQUIRED_RESULT bool deletingNeedToConfirm(const Akonadi::Item &item, QString &checkFound) const;
Q_REQUIRED_RESULT bool deletingNeedToConfirm(const Akonadi::Item &item, QString &checkFoundInfo) const;
void save(KConfigGroup &group) const;
void load(const KConfigGroup &group);
......@@ -42,6 +43,7 @@ public:
static Q_REQUIRED_RESULT ConfirmBeforeDeletingRule::RuleType stringToRuleType(const QString &str);
private:
void generateConfirmMessageInfo(const KMime::Message::Ptr &msg, QString &checkFoundInfo) const;
QString mPattern;
RuleType mRuleType = RuleType::Unknown;
};
......
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