diff --git a/plugins/messageviewer/bodypartformatter/autotests/data-akonadi/boarding-pass-pkpass.mbox b/plugins/messageviewer/bodypartformatter/autotests/data/boarding-pass-pkpass.mbox similarity index 100% rename from plugins/messageviewer/bodypartformatter/autotests/data-akonadi/boarding-pass-pkpass.mbox rename to plugins/messageviewer/bodypartformatter/autotests/data/boarding-pass-pkpass.mbox diff --git a/plugins/messageviewer/bodypartformatter/autotests/data-akonadi/boarding-pass-pkpass.mbox.html b/plugins/messageviewer/bodypartformatter/autotests/data/boarding-pass-pkpass.mbox.html similarity index 100% rename from plugins/messageviewer/bodypartformatter/autotests/data-akonadi/boarding-pass-pkpass.mbox.html rename to plugins/messageviewer/bodypartformatter/autotests/data/boarding-pass-pkpass.mbox.html diff --git a/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp b/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp index 15ee8cb2..d11f583b 100644 --- a/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp +++ b/plugins/messageviewer/bodypartformatter/autotests/rendertest.cpp @@ -1,180 +1,181 @@ /* Copyright (c) 2010 Volker Krause Copyright (c) 2016 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "rendertest.h" #include "rendertest-common.cpp" #include "testobjecttreesource.h" #include #include #include #include #include #include #include #include #include #include #include #ifndef Q_OS_WIN void initLocale() { setenv("KDEHOME", QFile::encodeName(QDir::homePath() + QLatin1String( "/.qttest")).constData(), 1); setenv("LC_ALL", "en_US.utf-8", 1); setenv("TZ", "UTC", 1); + setenv("BPF_ITINERARY_NO_AKONADI", "1", 1); // avoid itinerary plugin doing calendar lookups QStandardPaths::setTestModeEnabled(true); QLocale::setDefault(QLocale(QStringLiteral("en_US"))); } Q_CONSTRUCTOR_FUNCTION(initLocale) #endif void RenderTest::initTestCase() { QIcon::setThemeName(QStringLiteral("breeze")); QApplication::setStyle(QStyleFactory::create(QStringLiteral("Fusion"))); QPalette p(QApplication::style()->standardPalette()); p.setCurrentColorGroup(QPalette::Normal); p.setColor(QPalette::Button, QColor::fromRgb(0xef, 0xeb, 0xe7)); p.setColor(QPalette::ButtonText, QColor::fromRgb(0, 0, 0)); p.setColor(QPalette::Shadow, QColor::fromRgb(0x76, 0x74, 0x72)); QApplication::setPalette(p); } void RenderTest::testRender_data() { QTest::addColumn("mailFileName"); QTest::addColumn("referenceFileName"); QTest::addColumn("outFileName"); QDir dir(QStringLiteral(MAIL_DATA_DIR)); const QStringList lst = dir.entryList(QStringList(QStringLiteral("*.mbox")), QDir::Files | QDir::Readable | QDir::NoSymLinks); for (const QString &file : lst) { if (!QFile::exists(dir.path() + QLatin1Char('/') + file + QStringLiteral(".html"))) { continue; } QTest::newRow(file.toLatin1().constData()) << QString(dir.path() + QLatin1Char('/') + file) << QString(dir.path() + QLatin1Char('/') + file + QStringLiteral(".html")) << QString(file + QStringLiteral(".out")); } } void RenderTest::testRender() { QFETCH(QString, mailFileName); QFETCH(QString, referenceFileName); QFETCH(QString, outFileName); // load input mail QFile mailFile(mailFileName); QVERIFY(mailFile.open(QIODevice::ReadOnly)); const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll()); QVERIFY(!mailData.isEmpty()); KMime::Message::Ptr msg(new KMime::Message); msg->setContent(mailData); msg->parse(); // render the mail MessageViewer::FileHtmlWriter fileWriter(outFileName); fileWriter.begin(); QImage paintDevice; MessageViewer::CSSHelperBase cssHelper(&paintDevice); MimeTreeParser::NodeHelper nodeHelper; TestObjectTreeSource testSource(&fileWriter, &cssHelper); MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper); fileWriter.write(QStringLiteral("\n" "\n" "\n")); otp.parseObjectTree(msg.data()); fileWriter.write(QStringLiteral("")); fileWriter.end(); compareFile(outFileName, referenceFileName); } void RenderTest::testRenderKeyDetails_data() { QTest::addColumn("basename"); QTest::newRow("message-with-openpgp-key.mbox") << QStringLiteral("message-with-openpgp-key.mbox"); QTest::newRow("message-with-two-openpgp-key.mbox") << QStringLiteral("message-with-two-openpgp-key.mbox"); } void RenderTest::testRenderKeyDetails() { QFETCH(QString, basename); QString mailFileName = QStringLiteral(MAIL_DATA_DIR) + QLatin1Char('/') + basename; QString referenceFileName = QStringLiteral(MAIL_DATA_DIR) + QLatin1Char('/') + basename + QStringLiteral(".html"); QString outFileName = basename + QStringLiteral(".out"); // load input mail QFile mailFile(mailFileName); QVERIFY(mailFile.open(QIODevice::ReadOnly)); const QByteArray mailData = KMime::CRLFtoLF(mailFile.readAll()); QVERIFY(!mailData.isEmpty()); KMime::Message::Ptr msg(new KMime::Message); msg->setContent(mailData); msg->parse(); // render the mail QEventLoop loop; MessageViewer::FileHtmlWriter fileWriter(outFileName); fileWriter.begin(); QImage paintDevice; MessageViewer::CSSHelperBase cssHelper(&paintDevice); MimeTreeParser::NodeHelper nodeHelper; TestObjectTreeSource testSource(&fileWriter, &cssHelper); testSource.setShowSignatureDetails(true); MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper); fileWriter.write(QStringLiteral("\n" "\n" "\n")); connect(&nodeHelper, &MimeTreeParser::NodeHelper::update, &loop, &QEventLoop::quit); otp.parseObjectTree(msg.data()); fileWriter.write(QStringLiteral("")); fileWriter.end(); compareFile(outFileName, referenceFileName + QStringLiteral(".running")); loop.exec(); { MimeTreeParser::ObjectTreeParser otp(&testSource, &nodeHelper); fileWriter.begin(); fileWriter.write(QStringLiteral("\n" "\n" "\n")); otp.parseObjectTree(msg.data()); fileWriter.write(QStringLiteral("")); fileWriter.end(); compareFile(outFileName, referenceFileName + QStringLiteral(".details")); } } QTEST_MAIN(RenderTest) diff --git a/plugins/messageviewer/bodypartformatter/itinerary/itinerarymemento.cpp b/plugins/messageviewer/bodypartformatter/itinerary/itinerarymemento.cpp index 7244e184..e00cf551 100644 --- a/plugins/messageviewer/bodypartformatter/itinerary/itinerarymemento.cpp +++ b/plugins/messageviewer/bodypartformatter/itinerary/itinerarymemento.cpp @@ -1,154 +1,154 @@ /* Copyright (c) 2017 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "itinerarymemento.h" #include #include #include #include #include #include #include using namespace KItinerary; void ItineraryMemento::detach() { } const char* ItineraryMemento::identifier() { return "org.kde.messageviewer.itineraryData"; } bool ItineraryMemento::isParsed(const KMime::ContentIndex &index) const { return m_parsedParts.contains(index); } void ItineraryMemento::setParsed(const KMime::ContentIndex &index) { m_parsedParts.insert(index); } void ItineraryMemento::setMessageDate(const QDateTime &contextDt) { m_postProc.setContextDate(contextDt); } void ItineraryMemento::appendData(const QVector &data) { m_postProc.process(data); } bool ItineraryMemento::hasData() const { return !m_data.isEmpty() || !m_postProc.result().isEmpty(); } QVector ItineraryMemento::data() { if (m_data.isEmpty() && !m_postProc.result().isEmpty()) { // perform calendar lookup and merge results std::vector > resolvedEvents; resolvedEvents.reserve(m_postProc.result().size()); - const auto calendar = CalendarSupport::calendarSingleton(true); + const auto calendar = CalendarSupport::calendarSingleton(qEnvironmentVariableIsSet("BPF_ITINERARY_NO_AKONADI") ? false : true); for (const auto &r : m_postProc.result()) { auto e = std::make_pair(r, CalendarHandler::findEvent(calendar, r)); if (e.second) { const auto existingRes = CalendarHandler::reservationsForEvent(e.second); for (const auto &ev : existingRes) { if (MergeUtil::isSame(ev, e.first)) { e.first = MergeUtil::merge(ev, e.first); break; } } } resolvedEvents.push_back(e); } // merge multi-traveler elements for (auto it = resolvedEvents.begin(); it != resolvedEvents.end();) { TripData data; data.reservations.push_back((*it).first); data.event = (*it).second; data.expanded = false; ++it; if (JsonLd::canConvert(data.reservations.at(0))) { const auto trip = JsonLd::convert(data.reservations.at(0)).reservationFor(); for (; it != resolvedEvents.end(); ++it) { if (!JsonLd::canConvert((*it).first) || !MergeUtil::isSame(JsonLd::convert((*it).first).reservationFor(), trip)) { break; } data.reservations.push_back((*it).first); } // add other traveler we already know about from previous data in the calendar // but that aren't in the currently extracted data set if (data.event) { for (const auto &prev : CalendarHandler::reservationsForEvent(data.event)) { const auto notFound = std::find_if(data.reservations.constBegin(), data.reservations.constEnd(), [prev](const QVariant &v) { return MergeUtil::isSame(v, prev); }) == data.reservations.constEnd(); if (notFound) { data.reservations.push_back(prev); } } } } m_data.push_back(data); } } return m_data; } void ItineraryMemento::toggleExpanded(int index) { if (index >= m_data.size()) { return; } m_data[index].expanded = !m_data.at(index).expanded; } void ItineraryMemento::addPass(KPkPass::Pass *pass, const QByteArray &rawData) { m_passes.emplace_back(PassData{pass->passTypeIdentifier(), pass->serialNumber(), rawData}); } QByteArray ItineraryMemento::rawPassData(const QString &passTypeIdentifier, const QString &serialNumber) const { for (const auto &pass : m_passes) { if (pass.passTypeIdentifier == passTypeIdentifier && pass.serialNumber == serialNumber) { return pass.rawData; } } return {}; } void ItineraryMemento::addDocument(const QString &docId, const QVariant &docInfo, const QByteArray &docData) { m_docs.push_back({docId, docInfo, docData}); }