]> granicus.if.org Git - neomutt/commitdiff
Cleaning up the fcc_attach hack. From Liviu.
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 28 Aug 1998 19:09:20 +0000 (19:09 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 28 Aug 1998 19:09:20 +0000 (19:09 +0000)
pgp.c
pgp.h
send.c

diff --git a/pgp.c b/pgp.c
index 35b17038aff9f089a630fc366015893060b88ac3..c77a0859dd21c99f015c49895505e201eacb6977 100644 (file)
--- a/pgp.c
+++ b/pgp.c
@@ -955,10 +955,9 @@ static void convert_to_7bit (BODY *a)
     if (a->type == TYPEMULTIPART)
     {
       if (a->encoding != ENC7BIT)
-      {
         a->encoding = ENC7BIT;
-        convert_to_7bit (a->parts);
-      }
+      if (option (OPTPGPSTRICTENC))
+       convert_to_7bit (a->parts);
     } 
     else if (a->type == TYPEMESSAGE
             && strcasecmp(a->subtype, "delivery-status"))
@@ -976,7 +975,7 @@ static void convert_to_7bit (BODY *a)
   }
 }
 
-BODY *pgp_sign_message (BODY *a)
+static BODY *pgp_sign_message (BODY *a)
 {
   PARAMETER *p;
   BODY *t;
@@ -1183,7 +1182,7 @@ char *pgp_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
 
 /* Warning: "a" is no longer free()d in this routine, you need
  * to free() it later.  This is necessary for $fcc_attach. */
-BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign)
+static BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign)
 {
   char buf[LONG_STRING];
   char tempfile[_POSIX_PATH_MAX], pgperrfile[_POSIX_PATH_MAX];
@@ -1310,42 +1309,43 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign)
   return (t);
 }
 
-int pgp_protect (HEADER *msg, char **pgpkeylist)
+int pgp_get_keys (HEADER *msg, char **pgpkeylist)
 {
-  BODY *pbody = NULL;
-
   /* Do a quick check to make sure that we can find all of the encryption
    * keys if the user has requested this service.
    */
 
   set_option (OPTPGPCHECKTRUST);
 
+  *pgpkeylist = NULL;
   if (msg->pgp & PGPENCRYPT)
   {
-    if ((*pgpkeylist = pgp_findKeys (msg->env->to, msg->env->cc, msg->env->bcc)) == NULL)
+    if ((*pgpkeylist = pgp_findKeys (msg->env->to, msg->env->cc,
+                                     msg->env->bcc)) == NULL)
       return (-1);
   }
 
+  return (0);
+}
+
+int pgp_protect (HEADER *msg, char *pgpkeylist)
+{
+  BODY *pbody = NULL;
+
   if ((msg->pgp & PGPSIGN) && !pgp_valid_passphrase ())
     return (-1);
 
-  endwin ();
+  if (!isendwin ())
+    endwin ();
   if (msg->pgp & PGPENCRYPT)
-  {
-    pbody = pgp_encrypt_message (msg->content, *pgpkeylist, msg->pgp & PGPSIGN);
-    if (!pbody)
-    {
-      FREE (pgpkeylist);
-      return (-1);
-    }
-  }
+    pbody = pgp_encrypt_message (msg->content, pgpkeylist, msg->pgp & PGPSIGN);
   else if (msg->pgp & PGPSIGN)
-  {
-    if ((pbody = pgp_sign_message (msg->content)) == NULL)
-      return (-1);
-  }
+    pbody = pgp_sign_message (msg->content);
+
+  if (!pbody)
+    return (-1);
   msg->content = pbody;
-  return 0;
+  return (0);
 }
 
 #endif /* _PGPPATH */
diff --git a/pgp.h b/pgp.h
index 22d747c15f090de515f603e81e32da6159c6e432..1bf98d06503c35a6debaafa68ab8d52c23ffc4c6 100644 (file)
--- a/pgp.h
+++ b/pgp.h
@@ -153,14 +153,11 @@ WHERE short PgpTimeout;
 
 
 BODY *pgp_decrypt_part (BODY *, STATE *, FILE *);
-BODY *pgp_encrypt_message (BODY *, char *, int);
 BODY *pgp_make_key_attachment (char *);
-BODY *pgp_sign_message (BODY *);
 
 const char *pgp_pkalg_to_mic(const char *);
 
 char *pgp_ask_for_key (struct pgp_vinfo *, KEYINFO *, char *, char *, short, char **);
-
 char *pgp_keyid(KEYINFO *);
 char *_pgp_keyid(KEYINFO *);
 
@@ -169,7 +166,8 @@ struct pgp_vinfo *pgp_get_vinfo(enum pgp_ops);
 int mutt_check_pgp (HEADER *h);
 int mutt_parse_pgp_hdr (char *, int);
 
-int pgp_protect (HEADER *, char **);
+int pgp_get_keys (HEADER *, char **);
+int pgp_protect (HEADER *, char *);
 int pgp_query (BODY *);
 int pgp_valid_passphrase (void);
 
diff --git a/send.c b/send.c
index 2a15e5320b1331b82ba0e7a49748b991070286ca..5109f7cfe7296e92f276bbf601f14bec0f0509e2 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1180,13 +1180,20 @@ main_loop:
   if (msg->content->next)
     msg->content = mutt_make_multipart (msg->content);
 
+  /* Ok, we need to do it this way instead of handling all fcc stuff in
+   * one place in order to avoid going to main_loop with encoded "env"
+   * in case of error.  Ugh.
+   */
 #ifdef _PGPPATH
   if (msg->pgp)
   {
+    if (pgp_get_keys (msg, &pgpkeylist) == -1)
+      goto main_loop;
+
     /* save the decrypted attachments */
     save_content = msg->content;
 
-    if (pgp_protect (msg, &pgpkeylist) == -1)
+    if (pgp_protect (msg, pgpkeylist) == -1)
     {
       if (msg->content->parts)
       {
@@ -1196,12 +1203,14 @@ main_loop:
        pbody->parts = NULL;
        mutt_free_body (&pbody);
       }
+      if (pgpkeylist)
+       FREE (&pgpkeylist);
       goto main_loop;
     }
   }
 #endif /* _PGPPATH */
 
-  if (!option (OPTNOCURSES) && ! (flags & SENDMAILX))
+  if (!option (OPTNOCURSES) && !(flags & SENDMAILX))
     mutt_message ("Sending message...");
 
   mutt_prepare_envelope (msg->env);
@@ -1226,27 +1235,37 @@ main_loop:
       {
        if (save_content->type == TYPEMULTIPART)
        {
-         if (!isendwin())
-           endwin ();
+         if (!(msg->pgp & PGPENCRYPT) && (msg->pgp & PGPSIGN))
+         {
+           /* save initial signature and attachments */
+           save_sig = msg->content->parts->next;
+           save_parts = msg->content->parts->parts->next;
+         }
+
+         /* this means writing only the main part */
+         msg->content = save_content->parts;
+
+         if (pgp_protect (msg, pgpkeylist) == -1)
+         {
+           /* we can't do much about it at this point, so
+            * fallback to saving the whole thing to fcc
+            */
+           msg->content = tmpbody;
+           save_sig = NULL;
+           goto full_fcc;
+         }
+
          if (msg->pgp & PGPENCRYPT)
          {
-           /* encrypt the main part again */
-           msg->content = pgp_encrypt_message (save_content->parts, 
-               pgpkeylist, msg->pgp & PGPSIGN);
            /* not released in pgp_encrypt_message() */
            mutt_free_body (&save_content->parts);
-           encode_descriptions (msg->content);
+           /* make sure we release the right thing later */
            save_content->parts = msg->content;
+
+           encode_descriptions (msg->content);
          }
          else
-         {
-           /* save initial signature and attachments */
-           save_sig = msg->content->parts->next;
-           save_parts = msg->content->parts->parts->next;
-           /* sign the main part without attachments */
-           msg->content = pgp_sign_message (save_content->parts);
            save_content = msg->content;
-         }
        }
       }
       else
@@ -1254,9 +1273,11 @@ main_loop:
        msg->content = msg->content->parts;
     }
 
+full_fcc:
     if (msg->content)
       mutt_write_fcc (fcc, msg, NULL, 0);
     msg->content = tmpbody;
+
 #ifdef _PGPPATH
     if (save_sig)
     {
@@ -1264,6 +1285,7 @@ main_loop:
       mutt_free_body (&save_content->parts->next);
       save_content->parts = NULL;
       mutt_free_body (&save_content);
+
       /* restore old signature and attachments */
       msg->content->parts->next = save_sig;
       msg->content->parts->parts->next = save_parts;