File indexing completed on 2024-12-22 04:52:52
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "messagetest.h" 0008 #include "messageflags.h" 0009 #include <Akonadi/Item> 0010 #include <QFile> 0011 #include <QTest> 0012 using namespace KMime; 0013 0014 QTEST_GUILESS_MAIN(MessageTest) 0015 0016 void MessageTest::testCopyFlags() 0017 { 0018 { 0019 KMime::Message::Ptr msg = readAndParseMail(QStringLiteral("x-pkcs7.mbox")); 0020 0021 Akonadi::Item item; 0022 Akonadi::MessageFlags::copyMessageFlags(*msg, item); 0023 0024 QVERIFY(item.hasFlag(Akonadi::MessageFlags::Signed) == false); 0025 QVERIFY(item.hasFlag(Akonadi::MessageFlags::Encrypted) == true); 0026 QVERIFY(item.hasFlag(Akonadi::MessageFlags::HasInvitation) == false); 0027 QVERIFY(item.hasFlag(Akonadi::MessageFlags::HasAttachment) == false); 0028 } 0029 0030 { 0031 KMime::Message::Ptr msg = readAndParseMail(QStringLiteral("signed.mbox")); 0032 0033 Akonadi::Item item; 0034 Akonadi::MessageFlags::copyMessageFlags(*msg, item); 0035 0036 QVERIFY(item.hasFlag(Akonadi::MessageFlags::Signed) == true); 0037 QVERIFY(item.hasFlag(Akonadi::MessageFlags::Encrypted) == false); 0038 QVERIFY(item.hasFlag(Akonadi::MessageFlags::HasInvitation) == true); 0039 QVERIFY(item.hasFlag(Akonadi::MessageFlags::HasAttachment) == true); 0040 } 0041 } 0042 0043 KMime::Message::Ptr MessageTest::readAndParseMail(const QString &mailFile) const 0044 { 0045 QFile file(QLatin1StringView(TEST_DATA_DIR) + QLatin1StringView("/mails/") + mailFile); 0046 const bool ok = file.open(QIODevice::ReadOnly); 0047 if (!ok) { 0048 qWarning() << file.fileName() << "not found"; 0049 } 0050 Q_ASSERT(ok); 0051 const QByteArray data = KMime::CRLFtoLF(file.readAll()); 0052 Q_ASSERT(!data.isEmpty()); 0053 KMime::Message::Ptr msg(new KMime::Message); 0054 msg->setContent(data); 0055 msg->parse(); 0056 return msg; 0057 } 0058 0059 #include "moc_messagetest.cpp"