add support for import key from gpgme as well !
[apps/madmutt.git] / lib-crypt / pgp.c
index c58664c..8db2a5d 100644 (file)
@@ -167,7 +167,7 @@ static void pgp_copy_clearsigned (FILE * fpin, STATE * s, char *charset)
 
   rewind (fpin);
 
-  fc = fgetconv_open (fpin, charset, Charset, M_ICONV_HOOK_FROM);
+  fc = fgetconv_open (fpin, charset, MCharset.charset, M_ICONV_HOOK_FROM);
 
   for (complete = 1, armor_header = 1;
        fgetconvs (buf, sizeof (buf), fc) != NULL;
@@ -266,7 +266,7 @@ int pgp_application_pgp_handler (BODY * m, STATE * s)
       have_any_sigs = have_any_sigs || (clearsign && (s->flags & M_VERIFY));
 
       /* Copy PGP material to temporary file */
-      tmpfp = m_tempfile(tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL);
+      tmpfp = m_tempfile(tmpfname, sizeof(tmpfname), NONULL(MCore.tmpdir), NULL);
       if (tmpfp == NULL) {
         mutt_perror (tmpfname);
         return (-1);
@@ -295,7 +295,7 @@ int pgp_application_pgp_handler (BODY * m, STATE * s)
 
       /* Invoke PGP if needed */
       if (!clearsign || (s->flags & M_VERIFY)) {
-        pgpout = m_tempfile(outfile, sizeof(outfile), NONULL(Tempdir), NULL);
+        pgpout = m_tempfile(outfile, sizeof(outfile), NONULL(MCore.tmpdir), NULL);
         if (pgpout == NULL) {
           mutt_perror (outfile);
           return (-1);
@@ -394,7 +394,7 @@ int pgp_application_pgp_handler (BODY * m, STATE * s)
 
         rewind (pgpout);
         state_set_prefix (s);
-        fc = fgetconv_open (pgpout, "utf-8", Charset, 0);
+        fc = fgetconv_open (pgpout, "utf-8", MCharset.charset, 0);
         while ((c = fgetconv (fc)) != EOF)
           state_prefix_putc (c, s);
         fgetconv_close (&fc);
@@ -454,6 +454,7 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b,
   char tempfile[_POSIX_PATH_MAX];
   char buf[HUGE_STRING];
   FILE *tfp;
+  int tempfd;
 
   short sgn = 0;
   short enc = 0;
@@ -465,14 +466,14 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b,
   if (tagged_only && !b->tagged)
     return 0;
 
-  mutt_mktemp (tempfile);
-  if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0) {
+  tempfd = m_tempfd(tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
+  if (mutt_decode_save_attachment (fp, b, tempfd, 0) != 0) {
     unlink (tempfile);
     return 0;
   }
 
-  if ((tfp = fopen (tempfile, "r")) == NULL) {
-    unlink (tempfile);
+  if (!(tfp = fopen(tempfile, "r"))) {
+    unlink(tempfile);
     return 0;
   }
 
@@ -547,7 +548,7 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
   mutt_copy_bytes (s->fpin, fp, sigbdy->length);
   m_fclose(&fp);
 
-  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(MCore.tmpdir), NULL);
   if (pgperr == NULL) {
     mutt_perror (pgperrfile);
     unlink (sigfile);
@@ -593,7 +594,7 @@ static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top)
   FILE *tempfp;
   char tempfname[_POSIX_PATH_MAX];
 
-  tempfp = m_tempfile(tempfname, sizeof(tempfname), NONULL(Tempdir), NULL);
+  tempfp = m_tempfile(tempfname, sizeof(tempfname), NONULL(MCore.tmpdir), NULL);
   if (tempfp == NULL) {
     mutt_perror (_("Can't create temporary file"));
     return;
@@ -608,8 +609,10 @@ static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top)
 
   m_fclose(&tempfp);
 
-  pgp_invoke_import (tempfname);
-  mutt_any_key_to_continue (NULL);
+  if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import)) {
+    (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
+    mutt_any_key_to_continue (NULL);
+  }
 
   mutt_unlink (tempfname);
 }
@@ -648,14 +651,14 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p)
   pid_t thepid;
   int rv;
 
-  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(MCore.tmpdir), NULL);
   if (!pgperr) {
     mutt_perror (pgperrfile);
     return NULL;
   }
   unlink (pgperrfile);
 
-  pgptmp = m_tempfile(pgptmpfile, sizeof(pgptmpfile), NONULL(Tempdir), NULL);
+  pgptmp = m_tempfile(pgptmpfile, sizeof(pgptmpfile), NONULL(MCore.tmpdir), NULL);
   if (!pgptmp) {
     mutt_perror (pgptmpfile);
     m_fclose(&pgperr);
@@ -756,7 +759,7 @@ int pgp_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur)
 
   p_clear(&s, 1);
   s.fpin = fpin;
-  *fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  *fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
   if (*fpout == NULL) {
     mutt_perror (_("Can't create temporary file"));
     return (-1);
@@ -797,7 +800,7 @@ int pgp_encrypted_handler (BODY * a, STATE * s)
    */
   a = a->next;
 
-  fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
   if (fpout == NULL) {
     if (s->flags & M_DISPLAY)
       state_attach_puts (_
@@ -867,12 +870,12 @@ BODY *pgp_sign_message (BODY * a)
 
   convert_to_7bit (a);          /* Signed data _must_ be in 7-bit format. */
 
-  fp = m_tempfile(sigfile, sizeof(sigfile), NONULL(Tempdir), NULL);
+  fp = m_tempfile(sigfile, sizeof(sigfile), NONULL(MCore.tmpdir), NULL);
   if (fp == NULL) {
     return (NULL);
   }
 
-  sfp = m_tempfile(signedfile, sizeof(signedfile), NONULL(Tempdir), NULL);
+  sfp = m_tempfile(signedfile, sizeof(signedfile), NONULL(MCore.tmpdir), NULL);
   if (sfp == NULL) {
     mutt_perror (signedfile);
     m_fclose(&fp);
@@ -1111,13 +1114,13 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign)
   int empty = 0;
   pid_t thepid;
 
-  fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+  fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
   if (fpout == NULL) {
     mutt_perror (_("Can't create temporary file"));
     return (NULL);
   }
 
-  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(MCore.tmpdir), NULL);
   if (pgperr == NULL) {
     mutt_perror (pgperrfile);
     m_fclose(&fpout);
@@ -1126,7 +1129,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign)
   }
   unlink (pgperrfile);
 
-  fptmp = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL);
+  fptmp = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(MCore.tmpdir), NULL);
   if (fptmp == NULL) {
     mutt_perror (pgpinfile);
     m_fclose(&fpout);
@@ -1250,7 +1253,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
     return NULL;
   }
 
-  pgpin = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL);
+  pgpin = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(MCore.tmpdir), NULL);
   if (pgpin == NULL) {
     mutt_perror (pgpinfile);
     m_fclose(&fp);
@@ -1267,7 +1270,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
   if (a->noconv)
     from_charset = body_charset;
   else
-    from_charset = Charset;
+    from_charset = MCharset.charset;
 
   if (!charset_is_us_ascii (body_charset)) {
     int c;
@@ -1291,8 +1294,8 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
   m_fclose(&fp);
   m_fclose(&pgpin);
 
-  pgpout = m_tempfile(pgpoutfile, sizeof(pgpoutfile), NONULL(Tempdir), NULL);
-  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+  pgpout = m_tempfile(pgpoutfile, sizeof(pgpoutfile), NONULL(MCore.tmpdir), NULL);
+  pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(MCore.tmpdir), NULL);
   if (pgpout == NULL || pgperr == NULL) {
     mutt_perror (pgpout ? pgperrfile : pgpoutfile);
     m_fclose(&pgpin);
@@ -1386,7 +1389,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
 int pgp_send_menu (HEADER * msg, int *redraw)
 {
   pgp_key_t p;
-  char input_signas[SHORT_STRING];
+  char input_signas[STRING];
 
   char prompt[LONG_STRING];