File indexing completed on 2024-12-22 04:52:56
0001 /* 0002 SPDX-FileCopyrightText: 2007 Robert Zwerus <arzie@dds.nl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "headfetcher.h" 0008 0009 #include <Akonadi/CollectionFetchJob> 0010 #include <Akonadi/ItemFetchJob> 0011 #include <Akonadi/ItemFetchScope> 0012 0013 #include "messageparts.h" 0014 0015 #include <QApplication> 0016 #include <QDebug> 0017 #include <QTimer> 0018 0019 #include <KMime/KMimeMessage> 0020 0021 #include <KAboutData> 0022 #include <KLocalizedString> 0023 #include <QCommandLineOption> 0024 #include <QCommandLineParser> 0025 #include <chrono> 0026 0027 using namespace std::chrono_literals; 0028 0029 using namespace Akonadi; 0030 0031 HeadFetcher::HeadFetcher(bool multipart) 0032 { 0033 // fetch all headers from each folder 0034 timer.start(); 0035 qDebug() << "Listing all headers of every folder, using" << (multipart ? "multi" : "single") << "part."; 0036 auto clj = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive); 0037 clj->exec(); 0038 const Collection::List list = clj->collections(); 0039 for (const Collection &collection : list) { 0040 auto ifj = new ItemFetchJob(collection, this); 0041 if (multipart) { 0042 ifj->fetchScope().fetchPayloadPart(MessagePart::Envelope); 0043 } else { 0044 ifj->fetchScope().fetchFullPayload(); 0045 } 0046 ifj->exec(); 0047 qDebug() << " Listing" << ifj->items().count() << "item headers."; 0048 const auto items = ifj->items(); 0049 for (const Item &item : items) { 0050 qDebug() << item.payload<KMime::Message::Ptr>()->subject()->asUnicodeString(); 0051 } 0052 } 0053 0054 qDebug() << "Took:" << timer.elapsed() << "ms."; 0055 QTimer::singleShot(1s, this, &HeadFetcher::stop); 0056 } 0057 0058 void HeadFetcher::stop() 0059 { 0060 qApp->quit(); 0061 } 0062 0063 int main(int argc, char *argv[]) 0064 { 0065 KAboutData aboutData(QStringLiteral("headfetcher"), i18n("Headfetcher"), QStringLiteral("1.0")); 0066 aboutData.setShortDescription(i18n("header fetching application")); 0067 QApplication app(argc, argv); 0068 QCommandLineParser parser; 0069 KAboutData::setApplicationData(aboutData); 0070 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("multipart"), i18n("Run test on multipart data (default is singlepart)."))); 0071 0072 aboutData.setupCommandLine(&parser); 0073 parser.process(app); 0074 aboutData.processCommandLine(&parser); 0075 0076 bool multipart = parser.isSet(QStringLiteral("multipart")); 0077 0078 HeadFetcher d(multipart); 0079 0080 return app.exec(); 0081 } 0082 0083 #include "moc_headfetcher.cpp"