Mailcommon

filteractionremoveheader.cpp
1/*
2 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 */
7
8#include "filteractionremoveheader.h"
9
10#include <KComboBox>
11#include <KLocalizedString>
12#include <QLineEdit>
13
14using namespace MailCommon;
15
16FilterAction *FilterActionRemoveHeader::newAction()
17{
18 return new FilterActionRemoveHeader;
19}
20
21FilterActionRemoveHeader::FilterActionRemoveHeader(QObject *parent)
22 : FilterActionWithStringList(QStringLiteral("remove header"), i18n("Remove Header"), parent)
23{
24 mParameterList << QString() << QStringLiteral("Reply-To") << QStringLiteral("Delivered-To") << QStringLiteral("X-KDE-PR-Message")
25 << QStringLiteral("X-KDE-PR-Package") << QStringLiteral("X-KDE-PR-Keywords");
26
27 mParameter = mParameterList.at(0);
28}
29
30QWidget *FilterActionRemoveHeader::createParamWidget(QWidget *parent) const
31{
32 auto comboBox = new KComboBox(parent);
33 comboBox->setEditable(true);
34 comboBox->setMinimumWidth(50);
35 comboBox->setInsertPolicy(QComboBox::InsertAtBottom);
36 setParamWidgetValue(comboBox);
39
40 return comboBox;
41}
42
43FilterAction::ReturnCode FilterActionRemoveHeader::process(ItemContext &context, bool) const
44{
45 if (isEmpty()) {
46 return ErrorButGoOn;
47 }
48
49 auto msg = context.item().payload<KMime::Message::Ptr>();
50 const QByteArray param(mParameter.toLatin1());
51 bool headerRemove = false;
52 while (msg->removeHeader(param.constData())) {
53 headerRemove = true;
54 }
55 if (headerRemove) {
56 msg->assemble();
57 context.setNeedsPayloadStore();
58 }
59
60 return GoOn;
61}
62
63SearchRule::RequiredPart FilterActionRemoveHeader::requiredPart() const
64{
66}
67
68void FilterActionRemoveHeader::setParamWidgetValue(QWidget *paramWidget) const
69{
70 const auto comboBox = qobject_cast<KComboBox *>(paramWidget);
71 Q_ASSERT(comboBox);
72
73 const int index = mParameterList.indexOf(mParameter);
74 comboBox->clear();
75 comboBox->addItems(mParameterList);
76 if (index < 0) {
77 comboBox->addItem(mParameter);
78 comboBox->setCurrentIndex(comboBox->count() - 1);
79 } else {
80 comboBox->setCurrentIndex(index);
81 }
82}
83
84QStringList FilterActionRemoveHeader::sieveRequires() const
85{
86 return QStringList() << QStringLiteral("editheader");
87}
88
89QString FilterActionRemoveHeader::sieveCode() const
90{
91 return QStringLiteral("deleteheader \"%1\";").arg(mParameter);
92}
93
94QString FilterActionRemoveHeader::informationAboutNotValidAction() const
95{
96 return i18n("Header name undefined.");
97}
98
99#include "moc_filteractionremoveheader.cpp"
T payload() const
Abstract base class for filter actions with a fixed set of string parameters.
bool isEmpty() const override
Determines whether this action is valid.
Abstract base class for mail filter actions.
ReturnCode
Describes the possible return codes of filter processing:
@ ErrorButGoOn
A non-critical error occurred.
@ GoOn
Go on with applying filter actions.
void filterActionModified()
Called to notify that the current FilterAction has had some value modification.
A helper class for the filtering process.
Definition itemcontext.h:27
void setNeedsPayloadStore()
Marks that the item's payload has been changed and needs to be written back.
Akonadi::Item & item()
Returns the item of the context.
RequiredPart
Possible required parts.
Definition searchrule.h:68
@ CompleteMessage
Whole message.
Definition searchrule.h:71
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
void currentIndexChanged(int index)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
QString arg(Args &&... args) const const
QByteArray toLatin1() const const
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.