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

On request, save decrypted file with embedded file name

If the "original" file name of the encrypted file is embedded in the
encrypted data and if it differs from the automatically chosen file name
derived from the encrypted file, then we ask the user whether the
decrypted file shall be saved with the "original" file name?
To minimize trouble for unattentive users, we do not use the embedded
file name if the default button is clicked.

Embedded file names containing backslashes are ignored to avoid trouble.
Any Unix-style paths are stripped from the embedded file names.

GnuPG-bug-id: 6056
parent c6d235f2
Pipeline #200540 passed with stage
in 2 minutes and 59 seconds
......@@ -43,6 +43,7 @@
#include <QFileDialog>
#include <QTemporaryDir>
#include <gpgme++/decryptionresult.h>
using namespace GpgME;
using namespace Kleo;
......@@ -58,6 +59,7 @@ public:
void slotDialogCanceled();
void schedule();
QString getEmbeddedFileName(const QString &fileName) const;
void exec();
std::vector<std::shared_ptr<Task> > buildTasks(const QStringList &, QStringList &);
......@@ -113,6 +115,24 @@ void AutoDecryptVerifyFilesController::Private::schedule()
QString AutoDecryptVerifyFilesController::Private::getEmbeddedFileName(const QString &fileName) const
auto it = std::find_if(m_results.cbegin(), m_results.cend(), [fileName](const auto &r) {
return r->fileName() == fileName;
if (it != m_results.cend()) {
const auto embeddedFilePath = QString::fromUtf8((*it)->decryptionResult().fileName());
if (embeddedFilePath.contains(QLatin1Char{'\\'})) {
// ignore embedded file names containing '\'
return {};
// strip the path from the embedded file name
return QFileInfo{embeddedFilePath}.fileName();
} else {
return {};
void AutoDecryptVerifyFilesController::Private::exec()
......@@ -183,7 +203,24 @@ void AutoDecryptVerifyFilesController::Private::exec()
const auto outpath = outDir.absoluteFilePath(fi.fileName());
const auto embeddedFileName = getEmbeddedFileName(inpath);
QString outFileName = fi.fileName();
if (!embeddedFileName.isEmpty() && embeddedFileName != fi.fileName()) {
// we switch "Yes" and "No" because Yes is default, but saving with embedded file name could be dangerous
const auto answer = KMessageBox::questionYesNoCancel(m_dialog,
xi18n("Shall the file be saved with the original file name <filename>%1</filename>?", embeddedFileName),
i18n("Use Original File Name?"),
KGuiItem(xi18n("No, Save As <filename>%1</filename>", fi.fileName())),
KGuiItem(xi18n("Yes, Save As <filename>%1</filename>", embeddedFileName)));
if (answer == KMessageBox::Cancel) {
qCDebug(KLEOPATRA_LOG) << "Saving canceled for:" << inpath;
} else if (answer == KMessageBox::No) {
outFileName = embeddedFileName;
const auto outpath = outDir.absoluteFilePath(outFileName);
qCDebug(KLEOPATRA_LOG) << "Moving " << inpath << " to " << outpath;
const QFileInfo ofi(outpath);
if (ofi.exists()) {
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