Commit a2bc1fec authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Factor invokeMailer helper from ResultPage

Changes:
* Use QFileInfo instead of QString for the attachment parameter
* Leave showing a message box to inform the user about possible problems
with the attachment to the caller (because different text is needed for
the two callers).
* Use more appropriate text to inform the user when sending an OpenPGP
public key. In this case "save the request to a file" makes no sense and
there is nothing to drag because the Kleopatra icon is hidden if an
OpenPGP certificate is created.

GnuPG-bug-id: 5832
parent 31d45a54
......@@ -415,6 +415,8 @@ set(_kleopatra_SRCS
utils/clipboardmenu.h
utils/dragqueen.cpp
utils/dragqueen.h
utils/email.cpp
utils/email.h
utils/filedialog.cpp
utils/filedialog.h
utils/gui-helper.cpp
......
......@@ -23,6 +23,7 @@
# include "commands/exportsecretkeycommand_old.h"
#endif
#include "utils/dragqueen.h"
#include "utils/email.h"
#include "utils/filedialog.h"
#include "utils/scrollarea.h"
......@@ -274,7 +275,15 @@ void ResultPage::slotSendRequestByEMail()
invokeMailer(config.readEntry("CAEmailAddress"), // to
i18n("Please process this certificate."), // subject
i18n("Please process this certificate and inform the sender about the location to fetch the resulting certificate.\n\nThanks,\n"), // body
QUrl(url()).toLocalFile()); // attachment
QFileInfo{QUrl(url()).toLocalFile()}); // attachment
KMessageBox::information(this,
xi18nc("@info",
"<para><application>Kleopatra</application> tried to send a mail via your default mail client.</para>"
"<para>Some mail clients are known not to support attachments when invoked this way.</para>"
"<para>If your mail client does not have an attachment, then drag the <application>Kleopatra</application> icon and drop it on the message compose window of your mail client.</para>"
"<para>If that does not work, either, save the request to a file, and then attach that.</para>"),
i18nc("@title", "Sending Mail"),
QStringLiteral("newcertificatewizard-mailto-troubles"));
}
void ResultPage::slotSendCertificateByEMail()
......@@ -301,41 +310,16 @@ void ResultPage::slotSendCertificateByEMailContinuation()
if (fileName.isEmpty()) {
return;
}
invokeMailer(QString(), // to
i18n("My new public OpenPGP key"), // subject
invokeMailer(i18n("My new public OpenPGP key"), // subject
i18n("Please find attached my new public OpenPGP key."), // body
fileName);
}
void ResultPage::invokeMailer(const QString &to, const QString &subject, const QString &body, const QString &attachment)
{
qCDebug(KLEOPATRA_LOG) << "to:" << to << "subject:" << subject
<< "body:" << body << "attachment:" << attachment;
// RFC 2368 says body's linebreaks need to be encoded as
// "%0D%0A", so normalize body to CRLF:
//body.replace(QLatin1Char('\n'), QStringLiteral("\r\n")).remove(QStringLiteral("\r\r"));
QUrlQuery query;
query.addQueryItem(QStringLiteral("subject"), subject);
query.addQueryItem(QStringLiteral("body"), body);
if (!attachment.isEmpty()) {
query.addQueryItem(QStringLiteral("attach"), attachment);
}
QUrl url;
url.setScheme(QStringLiteral("mailto"));
url.setPath(to);
url.setQuery(query);
qCDebug(KLEOPATRA_LOG) << "openUrl" << url;
QDesktopServices::openUrl(url);
QFileInfo{fileName});
KMessageBox::information(this,
xi18nc("@info",
"<para><application>Kleopatra</application> tried to send a mail via your default mail client.</para>"
"<para>Some mail clients are known not to support attachments when invoked this way.</para>"
"<para>If your mail client does not have an attachment, then drag the <application>Kleopatra</application> icon and drop it on the message compose window of your mail client.</para>"
"<para>If that does not work, either, save the request to a file, and then attach that.</para>"),
"<para>If your mail client does not have an attachment, then attach the file <filename>%1</filename> manually.</para>", fileName),
i18nc("@title", "Sending Mail"),
QStringLiteral("newcertificatewizard-mailto-troubles"));
QStringLiteral("newcertificatewizard-openpgp-mailto-troubles"));
}
void ResultPage::slotUploadCertificateToDirectoryServer()
......
......@@ -45,7 +45,6 @@ private Q_SLOTS:
void slotSendRequestByEMail();
void slotSendCertificateByEMail();
void slotSendCertificateByEMailContinuation();
void invokeMailer(const QString &to, const QString &subject, const QString &body, const QString &attachment);
void slotUploadCertificateToDirectoryServer();
void slotBackupCertificate();
void slotCreateRevocationRequest();
......
/* -*- mode: c++; c-basic-offset:4 -*-
utils/email.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2016, 2017 Bundesamt für Sicherheit in der Informationstechnik
SPDX-FileContributor: Intevation GmbH
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "email.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <QDesktopServices>
#include <QFileInfo>
#include <QUrlQuery>
#include <kleopatra_debug.h>
void Kleo::invokeMailer(const QString &subject, const QString &body, const QFileInfo &attachment)
{
invokeMailer({}, subject, body, attachment);
}
void Kleo::invokeMailer(const QString &to, const QString &subject, const QString &body, const QFileInfo &attachment)
{
const auto attachmentPath = attachment.filePath();
qCDebug(KLEOPATRA_LOG) << __func__ << "to:" << to << "subject:" << subject
<< "body:" << body << "attachment:" << attachmentPath;
// RFC 2368 says body's linebreaks need to be encoded as
// "%0D%0A", so normalize body to CRLF:
//body.replace(QLatin1Char('\n'), QStringLiteral("\r\n")).remove(QStringLiteral("\r\r"));
QUrlQuery query;
query.addQueryItem(QStringLiteral("subject"), subject);
query.addQueryItem(QStringLiteral("body"), body);
if (!attachmentPath.isEmpty()) {
query.addQueryItem(QStringLiteral("attach"), attachmentPath);
}
QUrl url;
url.setScheme(QStringLiteral("mailto"));
url.setPath(to);
url.setQuery(query);
qCDebug(KLEOPATRA_LOG) << __func__ << "Calling QDesktopServices::openUrl" << url;
QDesktopServices::openUrl(url);
}
/* -*- mode: c++; c-basic-offset:4 -*-
utils/email.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2016, 2017 Bundesamt für Sicherheit in der Informationstechnik
SPDX-FileContributor: Intevation GmbH
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
class QFileInfo;
class QString;
namespace Kleo
{
void invokeMailer(const QString &subject, const QString &body, const QFileInfo &attachment);
void invokeMailer(const QString &to, const QString &subject, const QString &body, const QFileInfo &attachment);
}
Supports Markdown
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