diff options
-rw-r--r-- | framework/src/domain/mime/mailcrypto.cpp | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/framework/src/domain/mime/mailcrypto.cpp b/framework/src/domain/mime/mailcrypto.cpp index a4723199..62a71e42 100644 --- a/framework/src/domain/mime/mailcrypto.cpp +++ b/framework/src/domain/mime/mailcrypto.cpp | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <QGpgME/SignJob> | 24 | #include <QGpgME/SignJob> |
25 | #include <QGpgME/EncryptJob> | 25 | #include <QGpgME/EncryptJob> |
26 | #include <QGpgME/SignEncryptJob> | 26 | #include <QGpgME/SignEncryptJob> |
27 | #include <QGpgME/KeyListJob> | ||
28 | #include <QGpgME/ImportFromKeyserverJob> | 27 | #include <QGpgME/ImportFromKeyserverJob> |
29 | #include <gpgme++/global.h> | 28 | #include <gpgme++/global.h> |
30 | #include <gpgme++/signingresult.h> | 29 | #include <gpgme++/signingresult.h> |
@@ -32,8 +31,6 @@ | |||
32 | #include <gpgme++/keylistresult.h> | 31 | #include <gpgme++/keylistresult.h> |
33 | #include <gpgme++/importresult.h> | 32 | #include <gpgme++/importresult.h> |
34 | #include <QDebug> | 33 | #include <QDebug> |
35 | #include <QMutex> | ||
36 | #include <QMutexLocker> | ||
37 | 34 | ||
38 | /* | 35 | /* |
39 | * FIXME: | 36 | * FIXME: |
@@ -473,22 +470,41 @@ void MailCrypto::importKeys(const std::vector<GpgME::Key> &keys) | |||
473 | job->exec(keys); | 470 | job->exec(keys); |
474 | } | 471 | } |
475 | 472 | ||
476 | QMutex sMutex; | 473 | static GpgME::KeyListResult listKeys(GpgME::Protocol protocol, const QStringList &patterns, bool secretOnly, int keyListMode, std::vector<GpgME::Key> &keys) |
477 | |||
478 | std::vector<GpgME::Key> MailCrypto::findKeys(const QStringList &filter, bool findPrivate, bool remote, Protocol protocol) | ||
479 | { | 474 | { |
480 | QMutexLocker locker{&sMutex}; | 475 | QByteArrayList list; |
481 | const QGpgME::Protocol *const backend = protocol == SMIME ? QGpgME::smime() : QGpgME::openpgp(); | 476 | std::transform(patterns.constBegin(), patterns.constEnd(), std::back_inserter(list), [] (const QString &s) { return s.toUtf8(); }); |
482 | Q_ASSERT(backend); | 477 | std::vector<char const *> pattern; |
483 | QGpgME::KeyListJob *job = backend->keyListJob(remote); | 478 | std::transform(list.constBegin(), list.constEnd(), std::back_inserter(pattern), [] (const QByteArray &s) { return s.constData(); }); |
484 | Q_ASSERT(job); | 479 | pattern.push_back(0); |
485 | locker.unlock(); | 480 | |
481 | GpgME::initializeLibrary(); | ||
482 | auto ctx = QSharedPointer<GpgME::Context>{GpgME::Context::createForProtocol(protocol)}; | ||
483 | ctx->setKeyListMode(keyListMode); | ||
484 | if (const GpgME::Error err = ctx->startKeyListing(pattern.data(), secretOnly)) { | ||
485 | return GpgME::KeyListResult(0, err); | ||
486 | } | ||
486 | 487 | ||
487 | std::vector<GpgME::Key> keys; | 488 | GpgME::Error err; |
488 | GpgME::KeyListResult res = job->exec(filter, findPrivate, keys); | 489 | do { |
490 | keys.push_back( ctx->nextKey(err)); | ||
491 | } while ( !err ); | ||
492 | |||
493 | keys.pop_back(); | ||
489 | 494 | ||
490 | Q_ASSERT(!res.error()); | 495 | const GpgME::KeyListResult result = ctx->endKeyListing(); |
496 | ctx->cancelPendingOperation(); | ||
497 | return result; | ||
498 | } | ||
491 | 499 | ||
500 | std::vector<GpgME::Key> MailCrypto::findKeys(const QStringList &filter, bool findPrivate, bool remote, Protocol protocol) | ||
501 | { | ||
502 | std::vector<GpgME::Key> keys; | ||
503 | GpgME::KeyListResult res = listKeys(protocol == SMIME ? GpgME::CMS : GpgME::OpenPGP, filter, findPrivate, remote ? GpgME::Extern : GpgME::Local, keys); | ||
504 | if (res.error()) { | ||
505 | qWarning() << "Failed to lookup keys: " << res.error().asString(); | ||
506 | return keys; | ||
507 | } | ||
492 | qWarning() << "got keys:" << keys.size(); | 508 | qWarning() << "got keys:" << keys.size(); |
493 | 509 | ||
494 | for (std::vector< GpgME::Key >::iterator i = keys.begin(); i != keys.end(); ++i) { | 510 | for (std::vector< GpgME::Key >::iterator i = keys.begin(); i != keys.end(); ++i) { |