+void pgp_gpgme_invoke_import(const char *fname)
+{
+ gpgme_ctx_t ctx = create_gpgme_context(0);
+ gpgme_data_t data;
+ gpgme_error_t err;
+
+ err = gpgme_data_new_from_file(&data, fname, 1);
+ if (err) {
+ mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err));
+ gpgme_release(ctx);
+ return;
+ }
+
+ err = gpgme_op_import(ctx, data);
+ if (err) {
+ mutt_error(_("error importing gpg data: %s\n"), gpgme_strerror(err));
+ gpgme_data_release(data);
+ gpgme_release(ctx);
+ return;
+ }
+
+ gpgme_data_release(data);
+ gpgme_release(ctx);
+ return;
+}
+
+static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top)
+{
+ STATE s;
+ FILE *tempfp;
+ char tempfname[_POSIX_PATH_MAX];
+
+ tempfp = m_tempfile(tempfname, sizeof(tempfname), NONULL(MCore.tmpdir), NULL);
+ if (tempfp == NULL) {
+ mutt_perror (_("Can't create temporary file"));
+ return;
+ }
+
+ p_clear(&s, 1);
+
+ s.fpin = fp;
+ s.fpout = tempfp;
+
+ mutt_body_handler (top, &s);
+
+ m_fclose(&tempfp);
+ pgp_gpgme_invoke_import(tempfname);
+ mutt_unlink (tempfname);
+}
+
+void pgp_gpgme_from_attachment_list (FILE * fp, int tag, BODY * top)
+{
+ mutt_endwin (NULL);
+ set_option (OPTDONTHANDLEPGPKEYS);
+
+ for (; top; top = top->next) {
+ if (!tag || top->tagged)
+ pgp_extract_keys_from_attachment (fp, top);
+
+ if (!tag)
+ break;
+ }
+
+ unset_option (OPTDONTHANDLEPGPKEYS);
+}
+