File indexing completed on 2024-11-10 04:50:00
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "filteractionreplytotest.h" 0008 #include "../filteractions/filteractionreplyto.h" 0009 #include <QTest> 0010 #include <QWidget> 0011 FilterActionReplyToTest::FilterActionReplyToTest(QObject *parent) 0012 : QObject(parent) 0013 { 0014 } 0015 0016 FilterActionReplyToTest::~FilterActionReplyToTest() = default; 0017 0018 void FilterActionReplyToTest::shouldHaveDefaultValue() 0019 { 0020 MailCommon::FilterActionReplyTo filter; 0021 QWidget *w = filter.createParamWidget(nullptr); 0022 QCOMPARE(w->objectName(), QStringLiteral("emailaddressrequester")); 0023 } 0024 0025 void FilterActionReplyToTest::shouldBeEmpty() 0026 { 0027 MailCommon::FilterActionReplyTo filter; 0028 QVERIFY(filter.isEmpty()); 0029 } 0030 0031 void FilterActionReplyToTest::shouldHadReplyToHeader() 0032 { 0033 const QString replyTo = QStringLiteral("fooreply@kde.org"); 0034 0035 const QByteArray data = 0036 "From: foo@kde.org\n" 0037 "To: foo@kde.org\n" 0038 "Subject: test\n" 0039 "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" 0040 "MIME-Version: 1.0\n" 0041 "Content-Type: text/plain; charset=\"us-ascii\"\n" 0042 "\n" 0043 "test"; 0044 const QByteArray output = 0045 "From: foo@kde.org\n" 0046 "To: foo@kde.org\n" 0047 "Subject: test\n" 0048 "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" 0049 "MIME-Version: 1.0\n" 0050 "Content-Type: text/plain; charset=\"us-ascii\"\n" 0051 "Reply-To: fooreply@kde.org\n" 0052 "\n" 0053 "test"; 0054 0055 MailCommon::FilterActionReplyTo filter(this); 0056 KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); 0057 msgPtr->setContent(data); 0058 msgPtr->parse(); 0059 Akonadi::Item item; 0060 item.setPayload<KMime::Message::Ptr>(msgPtr); 0061 MailCommon::ItemContext context(item, true); 0062 0063 filter.argsFromString(replyTo); 0064 QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); 0065 QCOMPARE(context.needsPayloadStore(), true); 0066 QCOMPARE(msgPtr->encodedContent(), output); 0067 } 0068 0069 void FilterActionReplyToTest::shouldReplaceReplyToHeader() 0070 { 0071 const QString replyTo = QStringLiteral("fooreply@kde.org"); 0072 0073 const QByteArray data = 0074 "From: foo@kde.org\n" 0075 "To: foo@kde.org\n" 0076 "Subject: test\n" 0077 "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" 0078 "MIME-Version: 1.0\n" 0079 "Content-Type: text/plain; charset=\"us-ascii\"\n" 0080 "Reply-To: oldfooreply@kde.org\n" 0081 "\n" 0082 "test"; 0083 const QByteArray output = 0084 "From: foo@kde.org\n" 0085 "To: foo@kde.org\n" 0086 "Subject: test\n" 0087 "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" 0088 "MIME-Version: 1.0\n" 0089 "Content-Type: text/plain; charset=\"us-ascii\"\n" 0090 "Reply-To: fooreply@kde.org\n" 0091 "\n" 0092 "test"; 0093 0094 MailCommon::FilterActionReplyTo filter(this); 0095 KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); 0096 msgPtr->setContent(data); 0097 msgPtr->parse(); 0098 Akonadi::Item item; 0099 item.setPayload<KMime::Message::Ptr>(msgPtr); 0100 MailCommon::ItemContext context(item, true); 0101 0102 filter.argsFromString(replyTo); 0103 QCOMPARE(filter.process(context, false), MailCommon::FilterAction::GoOn); 0104 QCOMPARE(context.needsPayloadStore(), true); 0105 QCOMPARE(msgPtr->encodedContent(), output); 0106 } 0107 0108 void FilterActionReplyToTest::shouldHaveRequiredPart() 0109 { 0110 MailCommon::FilterActionReplyTo filter; 0111 QCOMPARE(filter.requiredPart(), MailCommon::SearchRule::CompleteMessage); 0112 } 0113 0114 void FilterActionReplyToTest::shouldNotCreateReplyToWhenAddressIsEmpty() 0115 { 0116 const QByteArray data = 0117 "From: foo@kde.org\n" 0118 "To: foo@kde.org\n" 0119 "Subject: test\n" 0120 "Date: Wed, 01 Apr 2015 09:33:01 +0200\n" 0121 "MIME-Version: 1.0\n" 0122 "Content-Type: text/plain; charset=\"us-ascii\"\n" 0123 "Reply-To: oldfooreply@kde.org\n" 0124 "\n" 0125 "test"; 0126 0127 MailCommon::FilterActionReplyTo filter(this); 0128 KMime::Message::Ptr msgPtr = KMime::Message::Ptr(new KMime::Message()); 0129 msgPtr->setContent(data); 0130 msgPtr->parse(); 0131 Akonadi::Item item; 0132 item.setPayload<KMime::Message::Ptr>(msgPtr); 0133 MailCommon::ItemContext context(item, true); 0134 0135 filter.argsFromString(QString()); 0136 QCOMPARE(filter.process(context, false), MailCommon::FilterAction::ErrorButGoOn); 0137 QCOMPARE(context.needsPayloadStore(), false); 0138 QCOMPARE(msgPtr->encodedContent(), data); 0139 } 0140 0141 QTEST_MAIN(FilterActionReplyToTest) 0142 0143 #include "moc_filteractionreplytotest.cpp"