diff --git a/src/commands/exportopenpgpcerttoprovidercommand.cpp b/src/commands/exportopenpgpcerttoprovidercommand.cpp index 19b362a54..91a45fd4f 100644 --- a/src/commands/exportopenpgpcerttoprovidercommand.cpp +++ b/src/commands/exportopenpgpcerttoprovidercommand.cpp @@ -1,167 +1,163 @@ /* -*- 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 #include "exportopenpgpcerttoprovidercommand.h" #include "command_p.h" #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Commands; using namespace GpgME; -static const KIdentityManagement::Identity identityForAddress(const QString &senderAddress) { +static const QString identityTransportForAddress(const QString &senderAddress) { static const KIdentityManagement::IdentityManager *idManager = new KIdentityManagement::IdentityManager(true); const KIdentityManagement::Identity identity = idManager->identityForAddress(senderAddress); if (identity.isNull()) - return idManager->defaultIdentity(); + return idManager->defaultIdentity().transport(); else - return identity; + return identity.transport(); } 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 = senderAddress(); + const QString sender = senderAddress(); + const QString transportName = identityTransportForAddress(sender); - KIdentityManagement::Identity identity = identityForAddress(sender); - - if (identity.transport().isEmpty()) { + if (transportName.isEmpty()) { KMessageBox::error(parent, xi18nc("@warning", "%1 has no usable transport for mailing a key available, " "WKS upload not possible.", sender), i18nc("@title:window", "OpenPGP Certificate Export")); return false; } return KMessageBox::warningContinueCancel(parent, xi18nc("@info", "Not every mail provider supports WKS, so any key being " "exported this way may fail individually.If exported, " "a confirmation request mail will be sent to %1 " "which needs to be acknowledged with a mail program to complete the " "export process.KMail " "can handle these mails, but not all mail programs can." "Once exported, the standard does not (yet) allow for " "automated removal of a published key." "Are you sure you want to continue?", 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 = senderAddress(); - - KIdentityManagement::Identity identity = identityForAddress(sender); MailTransport::Transport *transport = MailTransport::TransportManager::self()->transportByName( - identity.transport()); + identityTransportForAddress(senderAddress())); 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"); 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", "The GPG process that tried to export OpenPGP certificates " "ended prematurely because of an unexpected error." "Please check the output of %1 for details.", args.join(QLatin1Char(' '))); } QString ExportOpenPGPCertToProviderCommand::errorExitMessage(const QStringList &args) const { return xi18nc("@info", "An error occurred while trying to export OpenPGP certificates. " "The output from %1 was: %2", 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()); }