Rocco Rutte:
[apps/madmutt.git] / pgpkey.c
index 4fd24ac..8bf2534 100644 (file)
--- a/pgpkey.c
+++ b/pgpkey.c
@@ -1,23 +1,11 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
  * Copyright (c) 1998,1999 Thomas Roessler <roessler@does-not-exist.org>
- * 
- *     This program is free software; you can redistribute it
- *     and/or modify it under the terms of the GNU General Public
- *     License as published by the Free Software Foundation; either
- *     version 2 of the License, or (at your option) any later
- *     version.
- * 
- *     This program is distributed in the hope that it will be
- *     useful, but WITHOUT ANY WARRANTY; without even the implied
- *     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- *     PURPOSE.  See the GNU General Public License for more
- *     details.
- * 
- *     You should have received a copy of the GNU General Public
- *     License along with this program; if not, write to the Free
- *     Software Foundation, Inc., 59 Temple Place - Suite 330,
- *     Boston, MA  02111, USA.
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
  */
 
 #if HAVE_CONFIG_H
 #include "pager.h"
 #include "sort.h"
 
+#include "lib/mem.h"
+#include "lib/intl.h"
+#include "lib/str.h"
+#include "lib/debug.h"
+
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
@@ -285,10 +278,10 @@ static int _pgp_compare_address (const void *a, const void *b)
   pgp_uid_t **s = (pgp_uid_t **) a;
   pgp_uid_t **t = (pgp_uid_t **) b;
 
-  if ((r = mutt_strcasecmp ((*s)->addr, (*t)->addr)))
+  if ((r = safe_strcasecmp ((*s)->addr, (*t)->addr)))
     return r > 0;
   else
-    return (mutt_strcasecmp (_pgp_keyid ((*s)->parent),
+    return (safe_strcasecmp (_pgp_keyid ((*s)->parent),
                              _pgp_keyid ((*t)->parent)) > 0);
 }
 
@@ -307,11 +300,11 @@ static int _pgp_compare_keyid (const void *a, const void *b)
   pgp_uid_t **s = (pgp_uid_t **) a;
   pgp_uid_t **t = (pgp_uid_t **) b;
 
-  if ((r = mutt_strcasecmp (_pgp_keyid ((*s)->parent),
+  if ((r = safe_strcasecmp (_pgp_keyid ((*s)->parent),
                             _pgp_keyid ((*t)->parent))))
     return r > 0;
   else
-    return (mutt_strcasecmp ((*s)->addr, (*t)->addr)) > 0;
+    return (safe_strcasecmp ((*s)->addr, (*t)->addr)) > 0;
 }
 
 static int pgp_compare_keyid (const void *a, const void *b)
@@ -328,7 +321,7 @@ static int _pgp_compare_date (const void *a, const void *b)
 
   if ((r = ((*s)->parent->gen_time - (*t)->parent->gen_time)))
     return r > 0;
-  return (mutt_strcasecmp ((*s)->addr, (*t)->addr)) > 0;
+  return (safe_strcasecmp ((*s)->addr, (*t)->addr)) > 0;
 }
 
 static int pgp_compare_date (const void *a, const void *b)
@@ -353,9 +346,9 @@ static int _pgp_compare_trust (const void *a, const void *b)
     return r < 0;
   if ((r = ((*s)->parent->gen_time - (*t)->parent->gen_time)))
     return r < 0;
-  if ((r = mutt_strcasecmp ((*s)->addr, (*t)->addr)))
+  if ((r = safe_strcasecmp ((*s)->addr, (*t)->addr)))
     return r > 0;
-  return (mutt_strcasecmp (_pgp_keyid ((*s)->parent),
+  return (safe_strcasecmp (_pgp_keyid ((*s)->parent),
                            _pgp_keyid ((*t)->parent))) > 0;
 }
 
@@ -414,11 +407,11 @@ static int pgp_id_matches_addr (ADDRESS * addr, ADDRESS * u_addr,
     rv |= PGP_KV_STRONGID;
 
   if (addr->mailbox && u_addr->mailbox
-      && mutt_strcasecmp (addr->mailbox, u_addr->mailbox) == 0)
+      && safe_strcasecmp (addr->mailbox, u_addr->mailbox) == 0)
     rv |= PGP_KV_ADDR;
 
   if (addr->personal && u_addr->personal
-      && mutt_strcasecmp (addr->personal, u_addr->personal) == 0)
+      && safe_strcasecmp (addr->personal, u_addr->personal) == 0)
     rv |= PGP_KV_STRING;
 
   return rv;
@@ -526,13 +519,13 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s)
 
       mutt_mktemp (tempfile);
       if ((devnull = fopen ("/dev/null", "w")) == NULL) {       /* __FOPEN_CHECKED__ */
-        mutt_perror _("Can't open /dev/null");
+        mutt_perror (_("Can't open /dev/null"));
 
         break;
       }
       if ((fp = safe_fopen (tempfile, "w")) == NULL) {
         fclose (devnull);
-        mutt_perror _("Can't create temporary file");
+        mutt_perror (_("Can't create temporary file"));
 
         break;
       }
@@ -546,7 +539,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s)
       if ((thepid = pgp_invoke_verify_key (NULL, NULL, NULL, -1,
                                            fileno (fp), fileno (devnull),
                                            tmpbuf)) == -1) {
-        mutt_perror _("Can't create filter");
+        mutt_perror (_("Can't create filter"));
 
         unlink (tempfile);
         fclose (fp);
@@ -649,7 +642,7 @@ pgp_key_t pgp_ask_for_key (char *tag, char *whatfor,
   if (whatfor) {
 
     for (l = id_defaults; l; l = l->next)
-      if (!mutt_strcasecmp (whatfor, l->what)) {
+      if (!safe_strcasecmp (whatfor, l->what)) {
         strfcpy (resp, NONULL (l->dflt), sizeof (resp));
         break;
       }
@@ -663,7 +656,7 @@ pgp_key_t pgp_ask_for_key (char *tag, char *whatfor,
 
     if (whatfor) {
       if (l)
-        mutt_str_replace (&l->dflt, resp);
+        str_replace (&l->dflt, resp);
       else {
         l = safe_malloc (sizeof (struct pgp_cache));
         l->next = id_defaults;
@@ -711,13 +704,13 @@ BODY *pgp_make_key_attachment (char *tempf)
   }
 
   if ((tempfp = safe_fopen (tempf, tempf == tempfb ? "w" : "a")) == NULL) {
-    mutt_perror _("Can't create temporary file");
+    mutt_perror (_("Can't create temporary file"));
 
     return NULL;
   }
 
   if ((devnull = fopen ("/dev/null", "w")) == NULL) {   /* __FOPEN_CHECKED__ */
-    mutt_perror _("Can't open /dev/null");
+    mutt_perror (_("Can't open /dev/null"));
 
     fclose (tempfp);
     if (tempf == tempfb)
@@ -731,7 +724,7 @@ BODY *pgp_make_key_attachment (char *tempf)
   if ((thepid =
        pgp_invoke_export (NULL, NULL, NULL, -1,
                           fileno (tempfp), fileno (devnull), tmp)) == -1) {
-    mutt_perror _("Can't create filter");
+    mutt_perror (_("Can't create filter"));
 
     unlink (tempf);
     fclose (tempfp);
@@ -770,7 +763,7 @@ static LIST *pgp_add_string_to_hints (LIST * hints, const char *str)
 
   for (t = strtok (scratch, " ,.:\"()<>\n"); t;
        t = strtok (NULL, " ,.:\"()<>\n")) {
-    if (strlen (t) > 3)
+    if (mutt_strlen (t) > 3)
       hints = mutt_add_list (hints, t);
   }
 
@@ -819,17 +812,15 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring)
   if (!keys)
     return NULL;
 
-  dprint (5, (debugfile, "pgp_getkeybyaddr: looking for %s <%s>.",
-              a->personal, a->mailbox));
-
+  debug_print (5, ("looking for %s <%s>\n", a->personal, a->mailbox));
 
   for (k = keys; k; k = kn) {
     kn = k->next;
 
-    dprint (5, (debugfile, "  looking at key: %s\n", pgp_keyid (k)));
+    debug_print (5, ("  looking at key: %s\n", pgp_keyid (k)));
 
     if (abilities && !(k->flags & abilities)) {
-      dprint (5, (debugfile, "  insufficient abilities: Has %x, want %x\n",
+      debug_print (5, ("  insufficient abilities: Has %x, want %x\n",
                   k->flags, abilities));
       continue;
     }
@@ -936,17 +927,14 @@ pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring)
     match = 0;
 
     for (a = k->address; a; a = a->next) {
-      dprint (5,
-              (debugfile,
-               "pgp_getkeybystr: matching \"%s\" against key %s, \"%s\": ", p,
-               pgp_keyid (k), a->addr));
-      if (!*p || mutt_strcasecmp (p, pgp_keyid (k)) == 0
-          || (!mutt_strncasecmp (p, "0x", 2)
-              && !mutt_strcasecmp (p + 2, pgp_keyid (k)))
-          || (option (OPTPGPLONGIDS) && !mutt_strncasecmp (p, "0x", 2)
-              && !mutt_strcasecmp (p + 2, k->keyid + 8))
-          || mutt_stristr (a->addr, p)) {
-        dprint (5, (debugfile, "match.\n"));
+      debug_print (5, ("matching \"%s\" against key %s, \"%s\":\n", p, pgp_keyid (k), a->addr));
+      if (!*p || safe_strcasecmp (p, pgp_keyid (k)) == 0
+          || (!safe_strncasecmp (p, "0x", 2)
+              && !safe_strcasecmp (p + 2, pgp_keyid (k)))
+          || (option (OPTPGPLONGIDS) && !safe_strncasecmp (p, "0x", 2)
+              && !safe_strcasecmp (p + 2, k->keyid + 8))
+          || str_isstr (a->addr, p)) {
+        debug_print (5, ("match.\n"));
         match = 1;
         break;
       }