more include simplifications
[apps/madmutt.git] / lib-crypt / pgp.c
index 0a35e6b..8875ed9 100644 (file)
  * a message.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
 
-#include <lib-lib/mem.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/str.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/file.h>
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
 
 #include <lib-mime/mime.h>
 
 #include <lib-ui/curses.h>
 #include <lib-ui/enter.h>
 #include <lib-ui/menu.h>
-#include <lib-lib/debug.h>
 
 #include "mutt.h"
 #include "handler.h"
 #include "copy.h"
 #include "attach.h"
 
-
-#include <sys/wait.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <ctype.h>
-
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-
-#ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif
-
 #include "crypt.h"
 
 
@@ -148,15 +122,12 @@ static int pgp_copy_checksig (FILE * fpin, FILE * fpout)
   if (PgpGoodSign.pattern) {
     char *line = NULL;
     int lineno = 0;
-    size_t linelen;
+    ssize_t linelen;
 
     while ((line = mutt_read_line (line, &linelen, fpin, &lineno)) != NULL) {
       if (regexec (PgpGoodSign.rx, line, 0, NULL, 0) == 0) {
-        debug_print (2, ("\"%s\" matches regexp.\n", line));
         rv = 0;
       }
-      else
-        debug_print (2, ("\"%s\" doesn't match regexp.\n", line));
 
       if (strncmp (line, "[GNUPG:] ", 9) == 0)
         continue;
@@ -166,7 +137,6 @@ static int pgp_copy_checksig (FILE * fpin, FILE * fpout)
     p_delete(&line);
   }
   else {
-    debug_print (2, ("No pattern.\n"));
     mutt_copy_stream (fpin, fpout);
     rv = 1;
   }
@@ -192,7 +162,7 @@ static void pgp_copy_clearsigned (FILE * fpin, STATE * s, char *charset)
   char buf[HUGE_STRING];
   short complete, armor_header;
 
-  FGETCONV *fc;
+  fgetconv_t *fc;
 
   rewind (fpin);
 
@@ -419,7 +389,7 @@ int pgp_application_pgp_handler (BODY * m, STATE * s)
           pgp_copy_clearsigned (tmpfp, s, body_charset);
       }
       else if (pgpout) {
-        FGETCONV *fc;
+        fgetconv_t *fc;
 
         rewind (pgpout);
         state_set_prefix (s);
@@ -523,13 +493,13 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b,
 
   /* fix the content type */
 
-  mutt_set_parameter ("format", "fixed", &b->parameter);
+  parameter_setval(&b->parameter, "format", "fixed");
   if (enc)
-    mutt_set_parameter ("x-action", "pgp-encrypted", &b->parameter);
+    parameter_setval(&b->parameter, "x-action", "pgp-encrypted");
   else if (sgn)
-    mutt_set_parameter ("x-action", "pgp-signed", &b->parameter);
+    parameter_setval(&b->parameter, "x-action", "pgp-signed");
   else if (key)
-    mutt_set_parameter ("x-action", "pgp-keys", &b->parameter);
+    parameter_setval(&b->parameter, "x-action", "pgp-keys");
 
   return 1;
 }
@@ -601,8 +571,6 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
 
     if ((rv = mutt_wait_filter (thepid)))
       badsig = -1;
-
-    debug_print (1, ("mutt_wait_filter returned %d.\n", rv));
   }
 
   safe_fclose (&pgperr);
@@ -612,8 +580,6 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
   mutt_unlink (sigfile);
   mutt_unlink (pgperrfile);
 
-  debug_print (1, ("returning %d.\n", badsig));
-
   return badsig;
 }
 
@@ -923,7 +889,7 @@ int pgp_encrypted_handler (BODY * a, STATE * s)
       state_attach_puts (_("[-- End of PGP/MIME encrypted data --]\n"), s);
     }
 
-    mutt_free_body (&tattach);
+    body_list_wipe(&tattach);
     /* clear 'Invoking...' message, since there's no error */
     mutt_message _("PGP message successfully decrypted.");
   } else {
@@ -1032,21 +998,21 @@ BODY *pgp_sign_message (BODY * a)
     return (NULL);              /* fatal error while signing */
   }
 
-  t = mutt_new_body ();
+  t = body_new();
   t->type = TYPEMULTIPART;
   t->subtype = m_strdup("signed");
   t->encoding = ENC7BIT;
   t->use_disp = 0;
   t->disposition = DISPINLINE;
 
-  mutt_generate_boundary (&t->parameter);
-  mutt_set_parameter ("protocol", "application/pgp-signature", &t->parameter);
-  mutt_set_parameter ("micalg", pgp_micalg (sigfile), &t->parameter);
+  parameter_set_boundary(&t->parameter);
+  parameter_setval(&t->parameter, "protocol", "application/pgp-signature");
+  parameter_setval(&t->parameter, "micalg", pgp_micalg (sigfile));
 
   t->parts = a;
   a = t;
 
-  t->parts->next = mutt_new_body ();
+  t->parts->next = body_new();
   t = t->parts->next;
   t->type = TYPEAPPLICATION;
   t->subtype = m_strdup("pgp-signature");
@@ -1112,7 +1078,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc)
   if (fqdn)
     rfc822_qualify (tmp, fqdn);
 
-  tmp = mutt_remove_duplicates (tmp);
+  address_list_uniq(&tmp);
 
   for (p = tmp; p; p = p->next) {
     char buf[LONG_STRING];
@@ -1144,8 +1110,8 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc)
       }
       else if (r == -1) {
         p_delete(&keylist);
-        address_delete (&tmp);
-        address_delete (&addr);
+        address_list_wipe(&tmp);
+        address_list_wipe(&addr);
         return NULL;
       }
     }
@@ -1161,8 +1127,8 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc)
       if ((key = pgp_ask_for_key (buf, q->mailbox,
                                   KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) {
         p_delete(&keylist);
-        address_delete (&tmp);
-        address_delete (&addr);
+        address_list_wipe(&tmp);
+        address_list_wipe(&addr);
         return NULL;
       }
     }
@@ -1179,10 +1145,10 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc)
     keylist_used = m_strlen(keylist);
 
     pgp_free_key (&key);
-    address_delete (&addr);
+    address_list_wipe(&addr);
 
   }
-  address_delete (&tmp);
+  address_list_wipe(&tmp);
   return (keylist);
 }
 
@@ -1278,22 +1244,22 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign)
     return (NULL);
   }
 
-  t = mutt_new_body ();
+  t = body_new();
   t->type = TYPEMULTIPART;
   t->subtype = m_strdup("encrypted");
   t->encoding = ENC7BIT;
   t->use_disp = 0;
   t->disposition = DISPINLINE;
 
-  mutt_generate_boundary (&t->parameter);
-  mutt_set_parameter ("protocol", "application/pgp-encrypted", &t->parameter);
+  parameter_set_boundary(&t->parameter);
+  parameter_setval(&t->parameter, "protocol", "application/pgp-encrypted");
 
-  t->parts = mutt_new_body ();
+  t->parts = body_new();
   t->parts->type = TYPEAPPLICATION;
   t->parts->subtype = m_strdup("pgp-encrypted");
   t->parts->encoding = ENC7BIT;
 
-  t->parts->next = mutt_new_body ();
+  t->parts->next = body_new();
   t->parts->next->type = TYPEAPPLICATION;
   t->parts->next->subtype = m_strdup("octet-stream");
   t->parts->next->encoding = ENC7BIT;
@@ -1357,9 +1323,9 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
   else
     from_charset = Charset;
 
-  if (!mutt_is_us_ascii (body_charset)) {
+  if (!charset_is_us_ascii (body_charset)) {
     int c;
-    FGETCONV *fc;
+    fgetconv_t *fc;
 
     if (flags & ENCRYPT)
       send_charset = "us-ascii";
@@ -1446,30 +1412,19 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
     return NULL;
   }
 
-  b = mutt_new_body ();
+  b = body_new();
 
   b->encoding = ENC7BIT;
 
   b->type = TYPETEXT;
   b->subtype = m_strdup("plain");
 
-  mutt_set_parameter ("x-action",
-                      flags & ENCRYPT ? "pgp-encrypted" : "pgp-signed",
-                      &b->parameter);
-  mutt_set_parameter ("charset", send_charset, &b->parameter);
+  parameter_setval(&b->parameter, "x-action",
+                   flags & ENCRYPT ? "pgp-encrypted" : "pgp-signed");
+  parameter_setval(&b->parameter, "charset", send_charset);
 
   b->filename = m_strdup(pgpoutfile);
 
-#if 0
-  /* The following is intended to give a clue to some completely brain-dead 
-   * "mail environments" which are typically used by large corporations.
-   */
-
-  b->d_filename = m_strdup("msg.pgp");
-  b->use_disp = 1;
-
-#endif
-
   b->disposition = DISPINLINE;
   b->unlink = 1;