From d3ac2f227a860ae895d726a42114d8cc8d8df4ac Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Thu, 20 Dec 2018 16:43:35 +0100 Subject: [PATCH] Fix Bug 402378 - mailto staement , uncomplete url past to kmail composer --- CMakeLists.txt | 2 +- src/job/handleclickedurljob.cpp | 55 +++++++++++++++++++-------------- src/kmkernel.cpp | 33 ++++++++++---------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cea40501e..38f33dc86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED DBus Network Test Widget set(LIBGRAVATAR_VERSION_LIB "5.10.0") set(MAILCOMMON_LIB_VERSION_LIB "5.10.0") set(KDEPIM_APPS_LIB_VERSION_LIB "5.10.0") -set(MESSAGELIB_LIB_VERSION_LIB "5.10.0") +set(MESSAGELIB_LIB_VERSION_LIB "5.10.1") set(LIBKLEO_LIB_VERSION_LIB "5.10.0") set(PIMCOMMON_LIB_VERSION_LIB "5.10.0") set(LIBKDEPIM_LIB_VERSION_LIB "5.10.0") diff --git a/src/job/handleclickedurljob.cpp b/src/job/handleclickedurljob.cpp index 43914c6c3..ebbe2d5d5 100644 --- a/src/job/handleclickedurljob.cpp +++ b/src/job/handleclickedurljob.cpp @@ -45,29 +45,38 @@ void HandleClickedUrlJob::start() MessageHelper::initHeader(mMsg, KMKernel::self()->identityManager(), mIdentity); mMsg->contentType()->setCharset("utf-8"); - const QMap fields = MessageCore::StringUtil::parseMailtoUrl(mUrl); - - mMsg->to()->fromUnicodeString(fields.value(QStringLiteral("to")), "utf-8"); - const QString subject = fields.value(QStringLiteral("subject")); - if (!subject.isEmpty()) { - mMsg->subject()->fromUnicodeString(subject, "utf-8"); - } - const QString body = fields.value(QStringLiteral("body")); - if (!body.isEmpty()) { - mMsg->setBody(body.toUtf8()); - } - const QString cc = fields.value(QStringLiteral("cc")); - if (!cc.isEmpty()) { - mMsg->cc()->fromUnicodeString(cc, "utf-8"); - } - const QString bcc = fields.value(QStringLiteral("bcc")); - if (!bcc.isEmpty()) { - mMsg->bcc()->fromUnicodeString(bcc, "utf-8"); - } - const QString attach = fields.value(QStringLiteral("attach")); - if (!attach.isEmpty()) { - qCDebug(KMAIL_LOG) << "Attachment not supported yet"; - //TODO + const QList > fields = MessageCore::StringUtil::parseMailtoUrl(mUrl); + for (int i = 0; i < fields.count(); ++i) { + const QPair element = fields.at(i); + if (element.first == QStringLiteral("to")) { + mMsg->to()->fromUnicodeString(element.second, "utf-8"); + } else if (element.first == QStringLiteral("subject")) { + const QString subject = element.second; + if (!subject.isEmpty()) { + mMsg->subject()->fromUnicodeString(subject, "utf-8"); + } + } else if (element.first == QStringLiteral("body")) { + const QString body = element.second; + if (!body.isEmpty()) { + mMsg->setBody(body.toUtf8()); + } + } else if (element.first == QStringLiteral("cc")) { + const QString cc = element.second; + if (!cc.isEmpty()) { + mMsg->cc()->fromUnicodeString(cc, "utf-8"); + } + } else if (element.first == QStringLiteral("bcc")) { + const QString bcc = element.second; + if (!bcc.isEmpty()) { + mMsg->bcc()->fromUnicodeString(bcc, "utf-8"); + } + } else if (element.first == QStringLiteral("attach")) { + const QString attach = element.second; + if (!attach.isEmpty()) { + qCDebug(KMAIL_LOG) << "Attachment not supported yet"; + //TODO + } + } } TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(mMsg, TemplateParser::TemplateParserJob::NewMessage, this); diff --git a/src/kmkernel.cpp b/src/kmkernel.cpp index 74ad8ca50..88fbc907b 100644 --- a/src/kmkernel.cpp +++ b/src/kmkernel.cpp @@ -388,37 +388,38 @@ bool KMKernel::handleCommandLine(bool noArgsOpensReader, const QStringList &args for (const QString &arg : parser.positionalArguments()) { if (arg.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) { const QUrl urlDecoded(QUrl::fromPercentEncoding(arg.toUtf8())); - QMap values = MessageCore::StringUtil::parseMailtoUrl(urlDecoded); + const QList > values = MessageCore::StringUtil::parseMailtoUrl(urlDecoded); QString previousKey; - for (auto it = values.cbegin(), end = values.cend(); it != end; ++it) { - const QString key = it.key().toLower(); + for (int i = 0; i < values.count(); ++i) { + const QPair element = values.at(i); + const QString key = element.first.toLower(); if (key == QLatin1Literal("to")) { - if (!it->isEmpty()) { - to += *it + QStringLiteral(", "); + if (!element.second.isEmpty()) { + to += element.second + QStringLiteral(", "); } previousKey.clear(); } else if (key == QLatin1Literal("cc")) { - if (!it->isEmpty()) { - cc += *it + QStringLiteral(", "); + if (!element.second.isEmpty()) { + cc += element.second + QStringLiteral(", "); } previousKey.clear(); } else if (key == QLatin1Literal("bcc")) { - if (!it->isEmpty()) { - bcc += *it + QStringLiteral(", "); + if (!element.second.isEmpty()) { + bcc += element.second + QStringLiteral(", "); } previousKey.clear(); } else if (key == QLatin1Literal("subject")) { - subj = it.value(); + subj = element.second; previousKey.clear(); } else if (key == QLatin1Literal("body")) { - body = it.value(); + body = element.second; previousKey = key; } else if (key == QLatin1Literal("in-reply-to")) { - inReplyTo = it.value(); + inReplyTo = element.second; previousKey.clear(); } else if (key == QLatin1Literal("attachment") || key == QLatin1Literal("attach")) { - if (!it->isEmpty()) { - attachURLs << makeAbsoluteUrl(*it, workingDir); + if (!element.second.isEmpty()) { + attachURLs << makeAbsoluteUrl(element.second, workingDir); } previousKey.clear(); } else { @@ -427,9 +428,9 @@ bool KMKernel::handleCommandLine(bool noArgsOpensReader, const QStringList &args //QMap parseMailtoUrl(const QUrl &url) parses correctly url //But if we have a "&" unknown key we lost it. if (previousKey == QLatin1Literal("body")) { - body += QLatin1Char('&') + key + QLatin1Char('=') + it.value(); + body += QLatin1Char('&') + key + QLatin1Char('=') + element.second; } - previousKey.clear(); + //Don't clear previous key. } } } else {