Commit 82dec469 authored by Volker Krause's avatar Volker Krause

No need to manually decode content per type anymore in the cli extractor

That's now entirely possible inside ExtractorEngine.
parent a8daba19
......@@ -20,19 +20,11 @@
#include <KItinerary/ExtractorEngine>
#include <KItinerary/ExtractorPostprocessor>
#include <KItinerary/HtmlDocument>
#include <KItinerary/JsonLdDocument>
#include <KItinerary/PdfDocument>
#include <KPkPass/Pass>
#include <KMime/Message>
#include <KCalCore/MemoryCalendar>
#include <KCalCore/ICalFormat>
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QFile>
#include <QJsonArray>
......@@ -135,42 +127,18 @@ int main(int argc, char** argv)
ExtractorEngine engine;
engine.setContextDate(contextDt);
std::unique_ptr<KPkPass::Pass> pass;
std::unique_ptr<HtmlDocument> htmlDoc;
std::unique_ptr<PdfDocument> pdfDoc;
KCalCore::Calendar::Ptr calendar;
std::unique_ptr<KMime::Message> mimeMsg;
QJsonArray jsonResult;
if (parser.value(typeOpt) == QLatin1String("pkpass")) {
pass.reset(KPkPass::Pass::fromData(f.readAll()));
engine.setPass(pass.get());
} else if (parser.value(typeOpt) == QLatin1String("pdf")) {
pdfDoc.reset(PdfDocument::fromData(f.readAll()));
engine.setPdfDocument(pdfDoc.get());
} else if (parser.value(typeOpt) == QLatin1String("html")) {
htmlDoc.reset(HtmlDocument::fromData(f.readAll()));
engine.setHtmlDocument(htmlDoc.get());
} else if (parser.value(typeOpt) == QLatin1String("ical")) {
calendar.reset(new KCalCore::MemoryCalendar(QTimeZone()));
KCalCore::ICalFormat format;
if (!format.fromRawString(calendar, f.readAll())) {
std::cerr << "Failed to parse iCal file." << std::endl;
return 1;
auto fileName = f.fileName();
const auto typeArg = parser.value(typeOpt);
if (!typeArg.isEmpty()) {
if (typeArg == QLatin1String("mime")) {
fileName = QStringLiteral("dummy.eml");
} else {
fileName = QLatin1String("dummy.") + typeArg;
}
calendar->setProductId(format.loadedProductId());
engine.setCalendar(calendar);
} else if (parser.value(typeOpt) == QLatin1String("mime")) {
mimeMsg.reset(new KMime::Message);
mimeMsg->setContent(f.readAll());
mimeMsg->parse();
engine.setContent(mimeMsg.get());
} else {
engine.setData(f.readAll(), f.fileName());
}
jsonResult = engine.extract();
const auto result = JsonLdDocument::fromJson(jsonResult);
engine.setData(f.readAll(), fileName);
const auto result = JsonLdDocument::fromJson(engine.extract());
ExtractorPostprocessor postproc;
postproc.setContextDate(contextDt);
postproc.process(result);
......
......@@ -273,6 +273,7 @@ void ExtractorEngine::setData(const QByteArray &data, const QString &fileName)
}
if (fileName.endsWith(QLatin1String(".ics"), Qt::CaseInsensitive)
|| fileName.endsWith(QLatin1String(".ical"), Qt::CaseInsensitive)
|| contentStartsWith(data, "BEGIN:VCALENDAR"))
{
#ifdef HAVE_KCAL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment