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

Omit entries for unresolved recipients in encryption keys result

Previously, the result contained empty key lists for unresolved
recipients.

GnuPG-bug-id: 5283
parent a40b7a07
......@@ -132,6 +132,22 @@ private Q_SLOTS:
testKey("sender-mixed@example.net", CMS).primaryFingerprint());
}
void test_encryption_keys_result_has_no_entry_for_unresolved_recipients()
{
KeyResolverCore resolver(/*encrypt=*/ true, /*sign=*/ false);
resolver.setRecipients({"prefer-smime@example.net", "unknown@example.net"});
const bool success = resolver.resolve();
QVERIFY(!success);
QCOMPARE(resolver.encryptionKeys().value(OpenPGP).size(), 1);
QVERIFY(resolver.encryptionKeys().value(OpenPGP).contains("prefer-smime@example.net"));
QVERIFY(!resolver.encryptionKeys().value(OpenPGP).contains("unknown@example.net"));
QCOMPARE(resolver.encryptionKeys().value(CMS).size(), 1);
QVERIFY(resolver.encryptionKeys().value(CMS).contains("prefer-smime@example.net"));
QVERIFY(!resolver.encryptionKeys().value(CMS).contains("unknown@example.net"));
}
void test_overrides_openpgp()
{
const QString override = testKey("prefer-openpgp@example.net", OpenPGP).primaryFingerprint();
......
......@@ -121,10 +121,6 @@ void KeyResolver::Private::showApprovalDialog(QWidget *parent)
for (auto it = map.cbegin(); it != map.cend(); ++it) {
const QString &addr = it.key();
const auto &keys = it.value();
if (keys.empty()) {
// skip unresolved recipients
continue;
}
if (!resolvedRecp.contains(addr) || !resolvedRecp[addr].size()) {
resolvedRecp.insert(addr, keys);
} else {
......
......@@ -486,7 +486,9 @@ QMap<Protocol, QMap<QString, std::vector<Key>>> KeyResolverCore::encryptionKeys(
for (auto protocolIt = protocolKeysMap.cbegin(); protocolIt != protocolKeysMap.cend(); ++protocolIt) {
const Protocol protocol = protocolIt.key();
const auto &keys = protocolIt.value();
result[protocol][address] = keys;
if (!keys.empty()) {
result[protocol][address] = keys;
}
}
}
......
Markdown is supported
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