File indexing completed on 2025-03-09 04:53:56
0001 /* 0002 SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "skeletonmessagejobtest.h" 0008 0009 #include <QDebug> 0010 #include <QTest> 0011 0012 #include <KMime/KMimeMessage> 0013 0014 #include <MessageComposer/Composer> 0015 #include <MessageComposer/GlobalPart> 0016 #include <MessageComposer/InfoPart> 0017 #include <MessageComposer/SkeletonMessageJob> 0018 using namespace MessageComposer; 0019 0020 QTEST_MAIN(SkeletonMessageJobTest) 0021 0022 void SkeletonMessageJobTest::testSubject_data() 0023 { 0024 QTest::addColumn<QString>("subject"); 0025 0026 QTest::newRow("simple subject") << QStringLiteral("Antaa virrata sateen..."); 0027 QTest::newRow("non-ascii subject") << QStringLiteral("Muzicologă în bej, vând whisky și tequila, preț fix."); 0028 // NOTE: This works fine, but shows ??s in the debug output. Why? 0029 } 0030 0031 void SkeletonMessageJobTest::testSubject() 0032 { 0033 // An InfoPart should belong to a Composer, even if we don't use the composer itself. 0034 auto composer = new Composer; 0035 InfoPart *infoPart = composer->infoPart(); 0036 GlobalPart *globalPart = composer->globalPart(); 0037 Q_ASSERT(infoPart); 0038 0039 QFETCH(QString, subject); 0040 // qDebug() << subject; 0041 infoPart->setSubject(subject); 0042 auto sjob = new SkeletonMessageJob(infoPart, globalPart, composer); 0043 QVERIFY(sjob->exec()); 0044 KMime::Message *message = sjob->message(); 0045 QVERIFY(message->subject(false)); 0046 qDebug() << message->subject()->asUnicodeString(); 0047 QCOMPARE(subject, message->subject()->asUnicodeString()); 0048 delete message; 0049 delete composer; 0050 } 0051 0052 void SkeletonMessageJobTest::testAddresses_data() 0053 { 0054 QTest::addColumn<QString>("from"); 0055 QTest::addColumn<QStringList>("replyto"); 0056 QTest::addColumn<QStringList>("to"); 0057 QTest::addColumn<QStringList>("cc"); 0058 QTest::addColumn<QStringList>("bcc"); 0059 0060 { 0061 QString from = QStringLiteral("one@example.com"); 0062 QStringList to; 0063 to << QStringLiteral("two@example.com"); 0064 QStringList cc; 0065 cc << QStringLiteral("three@example.com"); 0066 QStringList bcc; 0067 bcc << QStringLiteral("four@example.com"); 0068 QString replyto = QStringLiteral("five@example.com"); 0069 0070 QTest::newRow("simple single address") << from << QStringList{replyto} << to << cc << bcc; 0071 } 0072 0073 { 0074 QString from = QStringLiteral("one@example.com"); 0075 QStringList to; 0076 to << QStringLiteral("two@example.com"); 0077 to << QStringLiteral("two.two@example.com"); 0078 QStringList cc; 0079 cc << QStringLiteral("three@example.com"); 0080 cc << QStringLiteral("three.three@example.com"); 0081 QStringList bcc; 0082 bcc << QStringLiteral("four@example.com"); 0083 bcc << QStringLiteral("four.four@example.com"); 0084 QString replyto = QStringLiteral("five@example.com"); 0085 0086 QTest::newRow("simple multi address") << from << QStringList{replyto} << to << cc << bcc; 0087 } 0088 0089 { 0090 QString from = QStringLiteral("Me <one@example.com>"); 0091 QStringList to; 0092 to << QStringLiteral("You <two@example.com>"); 0093 to << QStringLiteral("two.two@example.com"); 0094 QStringList cc; 0095 cc << QStringLiteral("And you <three@example.com>"); 0096 cc << QStringLiteral("three.three@example.com"); 0097 QStringList bcc; 0098 bcc << QStringLiteral("And you too <four@example.com>"); 0099 bcc << QStringLiteral("four.four@example.com"); 0100 QString replyto = QStringLiteral("You over there <five@example.com>"); 0101 0102 QTest::newRow("named multi address") << from << QStringList{replyto} << to << cc << bcc; 0103 } 0104 0105 { 0106 QString from = QStringLiteral("Şîşkin <one@example.com>"); 0107 QStringList to; 0108 to << QStringLiteral("Ivan Turbincă <two@example.com>"); 0109 to << QStringLiteral("two.two@example.com"); 0110 QStringList cc; 0111 cc << QStringLiteral("Luceafărul <three@example.com>"); 0112 cc << QStringLiteral("three.three@example.com"); 0113 QStringList bcc; 0114 bcc << QStringLiteral("Zburătorul <four@example.com>"); 0115 bcc << QStringLiteral("four.four@example.com"); 0116 QString replyto = QStringLiteral("Şîşzbură <five@example.com>"); 0117 0118 QTest::newRow("non-ascii named multi address") << from << QStringList{replyto} << to << cc << bcc; 0119 } 0120 } 0121 0122 void SkeletonMessageJobTest::testAddresses() 0123 { 0124 // An InfoPart should belong to a Composer, even if we don't use the composer itself. 0125 auto composer = new Composer; 0126 InfoPart *infoPart = composer->infoPart(); 0127 GlobalPart *globalPart = composer->globalPart(); 0128 Q_ASSERT(infoPart); 0129 0130 QFETCH(QString, from); 0131 QFETCH(QStringList, replyto); 0132 QFETCH(QStringList, to); 0133 QFETCH(QStringList, cc); 0134 QFETCH(QStringList, bcc); 0135 infoPart->setFrom(from); 0136 infoPart->setReplyTo(replyto); 0137 infoPart->setTo(to); 0138 infoPart->setCc(cc); 0139 infoPart->setBcc(bcc); 0140 auto sjob = new SkeletonMessageJob(infoPart, globalPart, composer); 0141 QVERIFY(sjob->exec()); 0142 KMime::Message *message = sjob->message(); 0143 0144 { 0145 QVERIFY(message->from(false)); 0146 // qDebug() << "From:" << message->from()->asUnicodeString(); 0147 QCOMPARE(from, message->from()->asUnicodeString()); 0148 } 0149 0150 { 0151 QVERIFY(message->replyTo(false)); 0152 // qDebug() << "Reply-To:" << message->replyTo()->asUnicodeString(); 0153 QCOMPARE(replyto.join(QLatin1Char(',')), message->replyTo()->asUnicodeString()); 0154 } 0155 0156 { 0157 QVERIFY(message->to(false)); 0158 // qDebug() << "To:" << message->to()->asUnicodeString(); 0159 const auto mailboxes{message->to()->mailboxes()}; 0160 for (const auto &addr : mailboxes) { 0161 // qDebug() << addr.prettyAddress(); 0162 QVERIFY(to.contains(addr.prettyAddress())); 0163 to.removeOne(addr.prettyAddress()); 0164 } 0165 QVERIFY(to.isEmpty()); 0166 } 0167 0168 { 0169 QVERIFY(message->cc(false)); 0170 // qDebug() << "Cc:" << message->cc()->asUnicodeString(); 0171 const auto mailboxes{message->cc()->mailboxes()}; 0172 for (const auto &addr : mailboxes) { 0173 // qDebug() << addr.prettyAddress(); 0174 QVERIFY(cc.contains(addr.prettyAddress())); 0175 cc.removeOne(addr.prettyAddress()); 0176 } 0177 QVERIFY(cc.isEmpty()); 0178 } 0179 0180 { 0181 QVERIFY(message->bcc(false)); 0182 // qDebug() << "Bcc:" << message->bcc()->asUnicodeString(); 0183 const auto mailboxes{message->bcc()->mailboxes()}; 0184 for (const auto &addr : mailboxes) { 0185 // qDebug() << addr.prettyAddress(); 0186 QVERIFY(bcc.contains(addr.prettyAddress())); 0187 bcc.removeOne(addr.prettyAddress()); 0188 } 0189 QVERIFY(bcc.isEmpty()); 0190 } 0191 delete message; 0192 delete composer; 0193 } 0194 0195 void SkeletonMessageJobTest::testMessageID() 0196 { 0197 auto composer = new Composer(); 0198 InfoPart *infoPart = composer->infoPart(); 0199 GlobalPart *globalPart = composer->globalPart(); 0200 Q_ASSERT(infoPart); 0201 0202 auto sjob = new SkeletonMessageJob(infoPart, globalPart, composer); 0203 QVERIFY(sjob->exec()); 0204 KMime::Message *message = sjob->message(); 0205 QVERIFY(message->messageID(false)); 0206 QVERIFY(!message->messageID(false)->isEmpty()); 0207 delete message; 0208 delete sjob; 0209 delete composer; 0210 } 0211 0212 #include "moc_skeletonmessagejobtest.cpp"