• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.14
  • kdepim
  • mailcommon
  • filter
  • filteractions
filteractionremoveheader.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  */
19 
20 #include "filteractionremoveheader.h"
21 
22 #include "pimcommon/widgets/minimumcombobox.h"
23 
24 #include <KDE/KLocale>
25 #include <KDE/KLineEdit>
26 
27 using namespace MailCommon;
28 
29 FilterAction* FilterActionRemoveHeader::newAction()
30 {
31  return new FilterActionRemoveHeader;
32 }
33 
34 FilterActionRemoveHeader::FilterActionRemoveHeader( QObject *parent )
35  : FilterActionWithStringList( QLatin1String("remove header"), i18n( "Remove Header" ), parent )
36 {
37  mParameterList << QLatin1String("")
38  << QLatin1String("Reply-To")
39  << QLatin1String("Delivered-To")
40  << QLatin1String("X-KDE-PR-Message")
41  << QLatin1String("X-KDE-PR-Package")
42  << QLatin1String("X-KDE-PR-Keywords");
43 
44  mParameter = mParameterList.at( 0 );
45 }
46 
47 QWidget* FilterActionRemoveHeader::createParamWidget( QWidget *parent ) const
48 {
49  PimCommon::MinimumComboBox *comboBox = new PimCommon::MinimumComboBox( parent );
50  comboBox->setEditable( true );
51  comboBox->setInsertPolicy( QComboBox::InsertAtBottom );
52  setParamWidgetValue( comboBox );
53 
54  connect( comboBox, SIGNAL(currentIndexChanged(int)),
55  this, SIGNAL(filterActionModified()) );
56  connect( comboBox->lineEdit(), SIGNAL(textChanged(QString)),
57  this, SIGNAL(filterActionModified()) );
58 
59  return comboBox;
60 }
61 
62 FilterAction::ReturnCode FilterActionRemoveHeader::process(ItemContext &context , bool) const
63 {
64  if ( isEmpty() )
65  return ErrorButGoOn;
66 
67  KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
68  const QByteArray param(mParameter.toLatin1());
69  bool headerRemove = false;
70  while ( msg->headerByType( param ) ) {
71  headerRemove = true;
72  msg->removeHeader( param );
73  }
74  if (headerRemove) {
75  msg->assemble();
76 
77  context.setNeedsPayloadStore();
78  }
79 
80  return GoOn;
81 }
82 
83 SearchRule::RequiredPart FilterActionRemoveHeader::requiredPart() const
84 {
85  return SearchRule::CompleteMessage;
86 }
87 
88 void FilterActionRemoveHeader::setParamWidgetValue( QWidget *paramWidget ) const
89 {
90  PimCommon::MinimumComboBox *comboBox = dynamic_cast<PimCommon::MinimumComboBox*>(paramWidget );
91  Q_ASSERT( comboBox );
92 
93  const int index = mParameterList.indexOf( mParameter );
94  comboBox->clear();
95  comboBox->addItems( mParameterList );
96  if ( index < 0 ) {
97  comboBox->addItem( mParameter );
98  comboBox->setCurrentIndex( comboBox->count() - 1 );
99  } else {
100  comboBox->setCurrentIndex( index );
101  }
102 }
103 
104 QStringList FilterActionRemoveHeader::sieveRequires() const
105 {
106  return QStringList() << QLatin1String("editheader");
107 }
108 
109 QString FilterActionRemoveHeader::sieveCode() const
110 {
111  return QString::fromLatin1("deleteheader \"%1\";").arg(mParameter);
112 }
113 
114 QString FilterActionRemoveHeader::informationAboutNotValidAction() const
115 {
116  //KF5 add i18n
117  return QLatin1String("Header name undefined.");
118 }
119 
QWidget
MailCommon::FilterAction::GoOn
Go on with applying filter actions.
Definition: filteraction.h:62
MailCommon::FilterActionWithStringList
Abstract base class for filter actions with a fixed set of string parameters.
Definition: filteractionwithstringlist.h:49
QByteArray
MailCommon::FilterActionRemoveHeader::sieveCode
QString sieveCode() const
Definition: filteractionremoveheader.cpp:109
QList::at
const T & at(int i) const
MailCommon::ItemContext::setNeedsPayloadStore
void setNeedsPayloadStore()
Marks that the item's payload has been changed and needs to be written back.
Definition: itemcontext.cpp:44
MailCommon::FilterActionRemoveHeader::setParamWidgetValue
void setParamWidgetValue(QWidget *paramWidget) const
The filter action shall set it's widget's contents from it's parameter.
Definition: filteractionremoveheader.cpp:88
MailCommon::SearchRule::CompleteMessage
Definition: searchrule.h:82
MailCommon::FilterActionRemoveHeader::informationAboutNotValidAction
QString informationAboutNotValidAction() const
Definition: filteractionremoveheader.cpp:114
MailCommon::FilterAction
Abstract base class for mail filter actions.
Definition: filteraction.h:52
MailCommon::FilterActionWithStringList::mParameterList
QStringList mParameterList
Definition: filteractionwithstringlist.h:85
MailCommon::FilterAction::ErrorButGoOn
A non-critical error occurred.
Definition: filteraction.h:63
MailCommon::FilterActionRemoveHeader::sieveRequires
QStringList sieveRequires() const
Definition: filteractionremoveheader.cpp:104
QObject
MailCommon::FilterActionRemoveHeader::FilterActionRemoveHeader
FilterActionRemoveHeader(QObject *parent=0)
Definition: filteractionremoveheader.cpp:34
MailCommon::SearchRule::RequiredPart
RequiredPart
Definition: searchrule.h:79
QString
MailCommon::FilterActionRemoveHeader::requiredPart
SearchRule::RequiredPart requiredPart() const
Returns the required part from the item that is needed for the action to operate. ...
Definition: filteractionremoveheader.cpp:83
QStringList
MailCommon::FilterActionRemoveHeader::createParamWidget
QWidget * createParamWidget(QWidget *parent) const
Creates a widget for setting the filter action parameter.
Definition: filteractionremoveheader.cpp:47
MailCommon::FilterActionWithString::mParameter
QString mParameter
Definition: filteractionwithstring.h:91
MailCommon::FilterActionRemoveHeader::newAction
static FilterAction * newAction()
Definition: filteractionremoveheader.cpp:29
MailCommon::FilterAction::ReturnCode
ReturnCode
Describes the possible return codes of filter processing:
Definition: filteraction.h:60
QString::toLatin1
QByteArray toLatin1() const
QLatin1String
MailCommon::ItemContext::item
Akonadi::Item & item()
Returns the item of the context.
Definition: itemcontext.cpp:29
MailCommon::FilterAction::filterActionModified
void filterActionModified()
Called to notify that the current FilterAction has had some value modification.
filteractionremoveheader.h
context
const char * context
Definition: searchpatternedit.cpp:54
MailCommon::FilterActionRemoveHeader::process
ReturnCode process(ItemContext &context, bool applyOnOutbound) const
Execute action on given message (inside the item context).
Definition: filteractionremoveheader.cpp:62
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QStringList::indexOf
int indexOf(const QRegExp &rx, int from) const
MailCommon::ItemContext
A helper class for the filtering process.
Definition: itemcontext.h:39
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
MailCommon::FilterActionWithString::isEmpty
virtual bool isEmpty() const
Determines whether this action is valid.
Definition: filteractionwithstring.cpp:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal