X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-crypt%2Fcrypt-gpgme.c;h=70d07135afb928bd51bbe9cf0cdb32256c9f4063;hb=1e73e3243b4a748ee98b58f6f2512a14785bb36d;hp=949d1eb7690f093257e999d22edf86fcd4f3b753;hpb=16534e98723674fa391e3fc29d2a07ce419c13dd;p=apps%2Fmadmutt.git diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index 949d1eb..70d0713 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -14,8 +14,6 @@ #include -#ifdef CRYPT_BACKEND_GPGME - #ifdef HAVE_LOCALE_H # include #endif @@ -3887,4 +3885,69 @@ int smime_gpgme_verify_sender (HEADER * h) return verify_sender (h, GPGME_PROTOCOL_CMS); } -#endif +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); +} +