File indexing completed on 2025-02-16 04:57:35

0001 /*
0002   SPDX-FileCopyrightText: 2015 Volker Krause <vkrause@kde.org>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "objecttreeparser.h"
0007 #include "util.h"
0008 
0009 #include "setupenv.h"
0010 #include <MimeTreeParser/SimpleObjectTreeSource>
0011 
0012 #include <QTest>
0013 
0014 using namespace MimeTreeParser;
0015 
0016 class AttachmentTest : public QObject
0017 {
0018     Q_OBJECT
0019 private Q_SLOTS:
0020     void initTestCase();
0021     void testEncryptedAttachment_data();
0022     void testEncryptedAttachment();
0023 };
0024 
0025 QTEST_MAIN(AttachmentTest)
0026 
0027 void AttachmentTest::initTestCase()
0028 {
0029     MimeTreeParser::Test::setupEnv();
0030 }
0031 
0032 void AttachmentTest::testEncryptedAttachment_data()
0033 {
0034     QTest::addColumn<QString>("mbox");
0035     QTest::newRow("encrypted") << "openpgp-encrypted-two-attachments.mbox";
0036     QTest::newRow("signed") << "openpgp-signed-two-attachments.mbox";
0037     QTest::newRow("signed+encrypted") << "openpgp-signed-encrypted-two-attachments.mbox";
0038     QTest::newRow("encrypted+partial signed") << "openpgp-encrypted-partially-signed-attachments.mbox";
0039 }
0040 
0041 void AttachmentTest::testEncryptedAttachment()
0042 {
0043     QFETCH(QString, mbox);
0044     auto msg = readAndParseMail(mbox);
0045     NodeHelper nodeHelper;
0046     SimpleObjectTreeSource testSource;
0047     testSource.setDecryptMessage(true);
0048     ObjectTreeParser otp(&testSource, &nodeHelper);
0049     otp.parseObjectTree(msg.data());
0050 
0051     auto attachments = msg->attachments();
0052     auto encAtts = nodeHelper.attachmentsOfExtraContents();
0053     QCOMPARE(attachments.size() + encAtts.size(), 2);
0054     msg.clear();
0055 }
0056 
0057 #include "attachmenttest.moc"