Commit 56a89c3c authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to implement rule support

parent 98d0b28f
Pipeline #68185 passed with stage
in 53 minutes and 31 seconds
......@@ -6,13 +6,23 @@
#include "confirmbeforedeletingcreaterulewidget.h"
#include <KLocalizedString>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingCreateRuleWidget(QWidget *parent)
: QWidget(parent)
, mPatternLineEdit(new QLineEdit(this))
{
auto mainLayout = new QVBoxLayout(this);
auto mainLayout = new QHBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainLayout"));
auto label = new QLabel(i18n("Pattern"), this);
label->setObjectName(QStringLiteral("label"));
mainLayout->addWidget(label);
mPatternLineEdit->setObjectName(QStringLiteral("mPatternLineEdit"));
mainLayout->addWidget(mPatternLineEdit);
}
ConfirmBeforeDeletingCreateRuleWidget::~ConfirmBeforeDeletingCreateRuleWidget()
......
......@@ -9,7 +9,7 @@
#include <QWidget>
#include "confirmbeforedeleting_private_export.h"
class QLineEdit;
class KMAILCONFIRMBEFOREDELETING_TESTS_EXPORT ConfirmBeforeDeletingCreateRuleWidget : public QWidget
{
Q_OBJECT
......@@ -20,4 +20,7 @@ public:
explicit ConfirmBeforeDeletingCreateRuleWidget(QWidget *parent = nullptr);
~ConfirmBeforeDeletingCreateRuleWidget() override;
Q_REQUIRED_RESULT ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo info() const;
private:
QLineEdit *const mPatternLineEdit;
};
......@@ -6,7 +6,7 @@
#include "confirmbeforedeletingrule.h"
#include "confirmbeforedeletingplugin_debug.h"
#include <KMime/Message>
ConfirmBeforeDeletingRule::ConfirmBeforeDeletingRule()
{
}
......@@ -37,20 +37,51 @@ void ConfirmBeforeDeletingRule::setRuleType(RuleType newRuleType)
bool ConfirmBeforeDeletingRule::deletingNeedToConfirm(const Akonadi::Item &item) const
{
switch (mRuleType) {
case Body:
break;
case Subject:
break;
case To:
break;
case Cc:
break;
case Unknown:
qCWarning(KMAIL_CONFIRMBEFOREDELETING_PLUGIN_LOG) << "Invalid rules!";
break;
bool needToConfirm = false;
if (item.hasPayload<KMime::Message::Ptr>()) {
auto msg = item.payload<KMime::Message::Ptr>();
switch (mRuleType) {
case Body: {
const auto ba = msg->body();
if (QString::fromUtf8(ba).contains(pattern())) {
needToConfirm = true;
}
break;
}
case Subject: {
if (auto subject = msg->subject(false)) {
const QString subjectStr = subject->asUnicodeString();
if (subjectStr.contains(pattern())) {
needToConfirm = true;
}
}
break;
}
case To: {
if (auto to = msg->to(false)) {
const QString toStr = to->asUnicodeString();
if (toStr.contains(pattern())) {
needToConfirm = true;
}
}
break;
}
case Cc: {
if (auto cc = msg->cc(false)) {
const QString ccStr = cc->asUnicodeString();
if (ccStr.contains(pattern())) {
needToConfirm = true;
}
}
break;
}
case Unknown:
qCWarning(KMAIL_CONFIRMBEFOREDELETING_PLUGIN_LOG) << "Invalid rules!";
break;
}
}
return false;
return needToConfirm;
}
QDebug operator<<(QDebug d, const ConfirmBeforeDeletingRule &t)
......
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