Pass address book overrides to keyresolver
authorAndre Heinecke <aheinecke@intevation.de>
Mon, 15 Oct 2018 06:59:05 +0000 (08:59 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Mon, 15 Oct 2018 06:59:05 +0000 (08:59 +0200)
* src/cryptcontroller.cpp (CryptController::resolve_keys): Pass
overrides.
* src/keycache.cpp, src/keycache.h (KeyCache::getOverrides): Expose
overrides directly.

--

GnuPG-Bug-Id: T4122

src/cryptcontroller.cpp
src/keycache.cpp
src/keycache.h

index 39ac448..217bc87 100644 (file)
@@ -534,13 +534,29 @@ CryptController::resolve_keys ()
       // Get the recipients that are cached from OOM
       for (const auto &addr: m_recipient_addrs)
         {
-          args.push_back (GpgME::UserID::addrSpecFromString (addr.c_str()));
+          const auto mbox = GpgME::UserID::addrSpecFromString (addr.c_str());
+          const auto overrides = KeyCache::instance ()->getOverrides (mbox);
+          if (overrides.size())
+            {
+              std::string overrideStr = mbox + ":";
+              for (const auto &key: overrides)
+                {
+                  if (key.isNull())
+                    {
+                      TRACEPOINT;
+                      continue;
+                    }
+                  overrideStr += key.primaryFingerprint();
+                  overrideStr += ",";
+                }
+              overrideStr.erase(overrideStr.size() - 1, 1);
+              args.push_back (std::string ("-o"));
+              args.push_back (overrideStr);
+            }
+          args.push_back (mbox);
         }
     }
 
-  args.push_back (std::string ("--lang"));
-  args.push_back (std::string (gettext_localename ()));
-
   // Args are prepared. Spawn the resolver.
   auto ctx = GpgME::Context::createForEngine (GpgME::SpawnEngine);
   if (!ctx)
index 523ab31..69171c6 100644 (file)
@@ -1264,3 +1264,9 @@ KeyCache::onAddrBookImportJobDone (const std::string &mbox,
 {
   return d->onAddrBookImportJobDone (mbox, result_fprs);
 }
+
+std::vector<GpgME::Key>
+KeyCache::getOverrides (const std::string &mbox)
+{
+  return d->getPGPOverrides (mbox.c_str ());
+}
index e67bcf4..cc5ab77 100644 (file)
@@ -121,6 +121,10 @@ public:
                              const char *key_data,
                              Mail *mail) const;
 
+    /* Get optional overrides for an address. */
+    std::vector<GpgME::Key> getOverrides (const std::string &mbox);
+
+
     // Internal for thread
     void setSmimeKey(const std::string &mbox, const GpgME::Key &key);
     void setPgpKey(const std::string &mbox, const GpgME::Key &key);