• 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
  • autotests
filteractionreplytotest.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "filteractionreplytotest.h"
19 #include "../filteractions/filteractionreplyto.h"
20 #include <qtest_kde.h>
21 #include <QWidget>
22 FilterActionReplyToTest::FilterActionReplyToTest(QObject *parent)
23  : QObject(parent)
24 {
25 
26 }
27 
28 FilterActionReplyToTest::~FilterActionReplyToTest()
29 {
30 
31 }
32 
33 void FilterActionReplyToTest::shouldHaveDefaultValue()
34 {
35  MailCommon::FilterActionReplyTo filter;
36  QWidget *w = filter.createParamWidget(0);
37  QCOMPARE(w->objectName(), QLatin1String("emailaddressrequester"));
38 }
39 
40 void FilterActionReplyToTest::shouldBeEmpty()
41 {
42  MailCommon::FilterActionReplyTo filter;
43  QVERIFY(filter.isEmpty());
44 }
45 
46 void FilterActionReplyToTest::shouldHadReplyToHeader()
47 {
48  const QString replyTo = QLatin1String("fooreply@kde.org");
49 
50  const QByteArray data = "From: foo@kde.org\n"
51  "To: foo@kde.org\n"
52  "Subject: test\n"
53  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
54  "MIME-Version: 1.0\n"
55  "\n"
56  "test";
57  const QByteArray output = "From: foo@kde.org\n"
58  "To: foo@kde.org\n"
59  "Subject: test\n"
60  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
61  "MIME-Version: 1.0\n"
62  "Reply-To: fooreply@kde.org\n"
63  "\n"
64  "test";
65 
66  MailCommon::FilterActionReplyTo filter(this);
67  KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
68  msgPtr->setContent(data);
69  msgPtr->parse();
70  Akonadi::Item item;
71  item.setPayload<KMime::Message::Ptr>(msgPtr);
72  MailCommon::ItemContext context(item, true);
73 
74  filter.argsFromString(replyTo);
75  QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn);
76  QCOMPARE(context.needsPayloadStore(), true);
77  QCOMPARE(msgPtr->encodedContent(), output);
78 
79 }
80 
81 void FilterActionReplyToTest::shouldReplaceReplyToHeader()
82 {
83  const QString replyTo = QLatin1String("fooreply@kde.org");
84 
85  const QByteArray data = "From: foo@kde.org\n"
86  "To: foo@kde.org\n"
87  "Subject: test\n"
88  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
89  "MIME-Version: 1.0\n"
90  "Reply-To: oldfooreply@kde.org\n"
91  "\n"
92  "test";
93  const QByteArray output = "From: foo@kde.org\n"
94  "To: foo@kde.org\n"
95  "Subject: test\n"
96  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
97  "MIME-Version: 1.0\n"
98  "Reply-To: fooreply@kde.org\n"
99  "\n"
100  "test";
101 
102  MailCommon::FilterActionReplyTo filter(this);
103  KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
104  msgPtr->setContent(data);
105  msgPtr->parse();
106  Akonadi::Item item;
107  item.setPayload<KMime::Message::Ptr>(msgPtr);
108  MailCommon::ItemContext context(item, true);
109 
110  filter.argsFromString(replyTo);
111  QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn);
112  QCOMPARE(context.needsPayloadStore(), true);
113  QCOMPARE(msgPtr->encodedContent(), output);
114 }
115 
116 void FilterActionReplyToTest::shouldHaveRequiredPart()
117 {
118  MailCommon::FilterActionReplyTo filter;
119  QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage);
120 }
121 
122 void FilterActionReplyToTest::shouldNotCreateReplyToWhenAddressIsEmpty()
123 {
124  const QByteArray data = "From: foo@kde.org\n"
125  "To: foo@kde.org\n"
126  "Subject: test\n"
127  "Date: Wed, 01 Apr 2015 09:33:01 +0200\n"
128  "MIME-Version: 1.0\n"
129  "Reply-To: oldfooreply@kde.org\n"
130  "\n"
131  "test";
132 
133  MailCommon::FilterActionReplyTo filter(this);
134  KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message());
135  msgPtr->setContent(data);
136  msgPtr->parse();
137  Akonadi::Item item;
138  item.setPayload<KMime::Message::Ptr>(msgPtr);
139  MailCommon::ItemContext context(item, true);
140 
141  filter.argsFromString(QString());
142  QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn);
143  QCOMPARE(context.needsPayloadStore(), false);
144  QCOMPARE(msgPtr->encodedContent(), data);
145 }
146 
147 QTEST_KDEMAIN(FilterActionReplyToTest, GUI)
QWidget
MailCommon::FilterAction::GoOn
Go on with applying filter actions.
Definition: filteraction.h:62
FilterActionReplyToTest::~FilterActionReplyToTest
~FilterActionReplyToTest()
Definition: filteractionreplytotest.cpp:28
FilterActionReplyToTest::FilterActionReplyToTest
FilterActionReplyToTest(QObject *parent=0)
Definition: filteractionreplytotest.cpp:22
MailCommon::FilterActionWithAddress::createParamWidget
virtual QWidget * createParamWidget(QWidget *parent) const
Creates a widget for setting the filter action parameter.
Definition: filteractionwithaddress.cpp:31
QByteArray
MailCommon::SearchRule::CompleteMessage
Definition: searchrule.h:82
FilterActionReplyToTest
Definition: filteractionreplytotest.h:23
MailCommon::FilterAction::ErrorButGoOn
A non-critical error occurred.
Definition: filteraction.h:63
QObject
QObject::objectName
objectName
QString
MailCommon::FilterActionReplyTo::process
ReturnCode process(ItemContext &context, bool applyOnOutbound) const
Execute action on given message (inside the item context).
Definition: filteractionreplyto.cpp:36
MailCommon::FilterActionReplyTo::requiredPart
SearchRule::RequiredPart requiredPart() const
Returns the required part from the item that is needed for the action to operate. ...
Definition: filteractionreplyto.cpp:57
MailCommon::FilterActionReplyTo
Definition: filteractionreplyto.h:31
QLatin1String
context
const char * context
Definition: searchpatternedit.cpp:54
filteractionreplytotest.h
MailCommon::ItemContext
A helper class for the filtering process.
Definition: itemcontext.h:39
MailCommon::FilterActionWithString::isEmpty
virtual bool isEmpty() const
Determines whether this action is valid.
Definition: filteractionwithstring.cpp:33
MailCommon::FilterActionWithString::argsFromString
virtual void argsFromString(const QString &argsStr)
Read extra arguments from given string.
Definition: filteractionwithstring.cpp:66
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