Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F36623342
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
8 KB
Subscribers
None
View Options
diff --git a/src/commands/exportopenpgpcerttoprovidercommand.cpp b/src/commands/exportopenpgpcerttoprovidercommand.cpp
index 2043a072d..dee767f25 100644
--- a/src/commands/exportopenpgpcerttoprovidercommand.cpp
+++ b/src/commands/exportopenpgpcerttoprovidercommand.cpp
@@ -1,170 +1,162 @@
/* -*- mode: c++; c-basic-offset:4 -*-
commands/exportopenpgpcerttoprovidercommand.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2019-2022 Felix Tiede
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config-kleopatra.h>
#include "exportopenpgpcerttoprovidercommand.h"
#include "command_p.h"
#include <Libkleo/GnuPG>
#include <gpgme++/key.h>
#include <kidentitymanagement/identity.h>
#include <MailTransport/TransportManager>
#include <MailTransportAkonadi/MessageQueueJob>
#include <KLocalizedString>
#include <KMessageBox>
#include <QString>
using namespace Kleo;
using namespace Kleo::Commands;
using namespace GpgME;
const KIdentityManagement::IdentityManager *ExportOpenPGPCertToProviderCommand::mailIdManager = new KIdentityManagement::IdentityManager(true);
ExportOpenPGPCertToProviderCommand::ExportOpenPGPCertToProviderCommand(QAbstractItemView *v, KeyListController *c)
: GnuPGProcessCommand(v, c)
{
wksMail.open();
wksMail.close();
}
ExportOpenPGPCertToProviderCommand::ExportOpenPGPCertToProviderCommand(const UserID &uid)
: GnuPGProcessCommand(uid.parent()),
uid(uid)
{
wksMail.open();
wksMail.close();
}
ExportOpenPGPCertToProviderCommand::~ExportOpenPGPCertToProviderCommand() {}
bool ExportOpenPGPCertToProviderCommand::preStartHook(QWidget *parent) const
{
- QString sender;
- if (uid.isNull())
- sender = QString::fromLatin1(d->keys().at(0).userID(0).addrSpec().data());
- else
- sender = QString::fromLatin1(uid.addrSpec().data());
+ QString sender = senderAddress();
KIdentityManagement::Identity identity = ExportOpenPGPCertToProviderCommand::mailIdManager->identityForAddress(sender);
if (identity.isNull())
identity = ExportOpenPGPCertToProviderCommand::mailIdManager->defaultIdentity();
if (identity.transport().isEmpty()) {
KMessageBox::error(parent,
xi18nc("@warning",
"<para><email>%1</email> has no usable transport for mailing a key available, "
"WKS upload not possible.</para>", sender),
i18nc("@title:window", "OpenPGP Certificate Export"));
return false;
}
return KMessageBox::warningContinueCancel(parent,
xi18nc("@info",
"<para>Not every mail provider supports WKS, so any key being "
"exported this way may fail individually.</para><para>If exported, "
"a confirmation request mail will be sent to <email>%1</email> "
"which needs to be acknowledged with a mail program to complete the "
"export process.</para><para><application>KMail</application> "
"can handle these mails, but not all mail programs can.</para>"
"<para>Once exported, the standard does not (yet) allow for "
"automated removal of a published key.</para>"
"<para>Are you sure you want to continue?</para>", sender),
i18nc("@title:window", "OpenPGP Certificate Export"),
KStandardGuiItem::cont(), KStandardGuiItem::cancel(),
QStringLiteral("warn-export-openpgp-wks-unsupported"))
== KMessageBox::Continue;
}
void ExportOpenPGPCertToProviderCommand::postSuccessHook(QWidget *parent)
{
- QString sender;
- if (uid.isNull())
- sender = QString::fromLatin1(d->keys().at(0).userID(0).addrSpec().data());
- else
- sender = QString::fromLatin1(uid.addrSpec().data());
+ QString sender = senderAddress();
KIdentityManagement::Identity identity = ExportOpenPGPCertToProviderCommand::mailIdManager->identityForAddress(sender);
if (identity.isNull())
identity = ExportOpenPGPCertToProviderCommand::mailIdManager->defaultIdentity();
MailTransport::Transport *transport = MailTransport::TransportManager::self()->transportByName(
identity.transport());
if (!transport)
return;
wksMail.open();
KMime::Message *msg = new KMime::Message();
msg->setContent(KMime::CRLFtoLF(wksMail.readAll()));
msg->parse();
wksMail.close();
MailTransport::MessageQueueJob *job = new MailTransport::MessageQueueJob(parent);
job->transportAttribute().setTransportId(transport->id());
job->addressAttribute().setFrom(msg->from()->asUnicodeString());
job->addressAttribute().setTo(msg->to()->displayNames());
job->setMessage(KMime::Message::Ptr(msg));
job->start();
}
QStringList ExportOpenPGPCertToProviderCommand::arguments() const
{
QStringList result;
result << gpgWksClientPath();
result << QStringLiteral("--output") << wksMail.fileName();
result << QStringLiteral("--create");
- Q_FOREACH (const Key &key, d->keys()) {
- result << QLatin1String(key.primaryFingerprint());
- if (!uid.isNull()) {
- result << QLatin1String(uid.addrSpec().data());
- }
- else {
- result << QLatin1String(key.userID(0).email());
- }
- }
+ result << QString::fromUtf8(d->keys().at(0).primaryFingerprint());
+ result << senderAddress();
return result;
}
QString ExportOpenPGPCertToProviderCommand::errorCaption() const
{
return i18nc("@title:window", "OpenPGP Certificate Export Error");
}
QString ExportOpenPGPCertToProviderCommand::successCaption() const
{
return i18nc("@title:window", "OpenPGP Certificate Export Finished");
}
QString ExportOpenPGPCertToProviderCommand::crashExitMessage(const QStringList &args) const
{
return xi18nc("@info",
"<para>The GPG process that tried to export OpenPGP certificates "
"ended prematurely because of an unexpected error.</para>"
"<para>Please check the output of <icode>%1</icode> for details.</para>", args.join(QLatin1Char(' ')));
}
QString ExportOpenPGPCertToProviderCommand::errorExitMessage(const QStringList &args) const
{
return xi18nc("@info",
"<para>An error occurred while trying to export OpenPGP certificates.</para> "
"<para>The output from <command>%1</command> was: <message>%2</message></para>",
args[0], errorString());
}
QString ExportOpenPGPCertToProviderCommand::successMessage(const QStringList&) const
{
return i18nc("@info", "OpenPGP certificates exported successfully.");
}
+QString ExportOpenPGPCertToProviderCommand::senderAddress() const
+{
+ if (uid.isNull())
+ return QString::fromUtf8(d->keys().at(0).userID(0).addrSpec().data());
+ else
+ return QString::fromUtf8(uid.addrSpec().data());
+}
diff --git a/src/commands/exportopenpgpcerttoprovidercommand.h b/src/commands/exportopenpgpcerttoprovidercommand.h
index 7f162f327..a77564360 100644
--- a/src/commands/exportopenpgpcerttoprovidercommand.h
+++ b/src/commands/exportopenpgpcerttoprovidercommand.h
@@ -1,60 +1,62 @@
/* -*- mode: c++; c-basic-offset:4 -*-
commands/exportopenpgpcertstoservercommand.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2019 Felix Tiede
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <commands/gnupgprocesscommand.h>
#include <kidentitymanagement/identitymanager.h>
#include <QtCore/QTemporaryFile>
#include <gpgme++/key.h>
namespace Kleo
{
namespace Commands
{
class ExportOpenPGPCertToProviderCommand : public GnuPGProcessCommand
{
Q_OBJECT
public:
explicit ExportOpenPGPCertToProviderCommand(QAbstractItemView *view, KeyListController *parent);
explicit ExportOpenPGPCertToProviderCommand(const GpgME::UserID &uid);
~ExportOpenPGPCertToProviderCommand() override;
static Restrictions restrictions()
{
return OnlyOneKey | NeedSecretKey | MustBeOpenPGP;
}
private:
bool preStartHook(QWidget *) const override;
void postSuccessHook(QWidget *) override;
QStringList arguments() const override;
QString errorCaption() const override;
QString successCaption() const override;
QString crashExitMessage(const QStringList &) const override;
QString errorExitMessage(const QStringList &) const override;
QString successMessage(const QStringList &) const override;
+ QString senderAddress() const;
+
GpgME::UserID uid;
QTemporaryFile wksMail;
static const KIdentityManagement::IdentityManager *mailIdManager;
};
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Feb 26, 6:44 PM (8 h, 52 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bb/ea/9ef2e609772995b2a1b362dd370d
Attached To
rKLEOPATRA Kleopatra
Event Timeline
Log In to Comment