gpgrt_lock_unlock (&fpr_map_lock);
return ret;
}
+
+/* static */
+bool
+KeyCache::import_pgp_key_data (const GpgME::Data &data)
+{
+ TSTART;
+ if (data.isNull())
+ {
+ STRANGEPOINT;
+ TRETURN false;
+ }
+ auto ctx = GpgME::Context::create(GpgME::OpenPGP);
+
+ if (!ctx)
+ {
+ STRANGEPOINT;
+ TRETURN false;
+ }
+
+ const auto type = data.type();
+
+ if (type != GpgME::Data::PGPKey)
+ {
+ log_debug ("%s:%s: Data does not look like PGP Keys",
+ SRCNAME, __func__);
+ TRETURN false;
+ }
+ const auto keys = data.toKeys();
+
+ if (keys.empty())
+ {
+ log_debug ("%s:%s: Data does not contain PGP Keys",
+ SRCNAME, __func__);
+ TRETURN false;
+ }
+
+ if (opt.enable_debug & DBG_DATA)
+ {
+ std::stringstream ss;
+ for (const auto &key: keys)
+ {
+ ss << key << '\n';
+ }
+ log_debug ("Importing keys: %s", ss.str().c_str());
+ }
+ const auto result = ctx->importKeys(keys);
+
+ log_debug ("%s:%s: Import result from attached key err: %s",
+ SRCNAME, __func__, result.error ().asString ());
+ TRETURN !result.error();
+}
namespace GpgME
{
class Key;
+ class Data;
};
class Mail;
/* Get a vector of ultimately trusted keys. */
std::vector<GpgME::Key> getUltimateKeys ();
+ /* Import PGP Keys from a Data object. Returns
+ true on success. */
+ static bool import_pgp_key_data(const GpgME::Data &data);
+
// Internal for thread
void setSmimeKey(const std::string &mbox, const GpgME::Key &key);
void setPgpKey(const std::string &mbox, const GpgME::Key &key);
m_block_html = true;
}
+ /* Import any application/pgp-keys attachments if the option is set. */
+ if (opt.autoimport)
+ {
+ for (const auto &attach: get_attachments())
+ {
+ if (attach->get_content_type () == "application/pgp-keys")
+ {
+#ifndef BUILD_TESTS
+ KeyCache::import_pgp_key_data (attach->get_data());
+#endif
+ }
+ }
+ }
+
if (opt.enable_debug & DBG_DATA)
{
std::stringstream ss;