Rocco Rutte:
[apps/madmutt.git] / mutt_idna.c
index b8bf8fd..4b42e32 100644 (file)
@@ -1,19 +1,10 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 2003 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 "charset.h"
 #include "mutt_idna.h"
 
+#include "lib/mem.h"
+#include "lib/intl.h"
+#include "lib/str.h"
+#include "lib/debug.h"
+
 /* The low-level interface we use. */
 
 #ifndef HAVE_LIBIDN
 
 int mutt_idna_to_local (const char *in, char **out, int flags)
 {
-  *out = safe_strdup (in);
+  *out = str_dup (in);
   return 1;
 }
 
 int mutt_local_to_idna (const char *in, char **out)
 {
-  *out = safe_strdup (in);
+  *out = str_dup (in);
   return 0;
 }
 
@@ -66,17 +62,14 @@ int mutt_idna_to_local (const char *in, char **out, int flags)
   if ((flags & MI_MAY_BE_IRREVERSIBLE) == 0) {
     int irrev = 0;
     char *t2 = NULL;
-    char *tmp = safe_strdup (*out);
+    char *tmp = str_dup (*out);
 
     if (mutt_convert_string (&tmp, Charset, "utf-8", M_ICONV_HOOK_FROM) == -1)
       irrev = 1;
     if (!irrev && idna_to_ascii_8z (tmp, &t2, 1) != IDNA_SUCCESS)
       irrev = 1;
     if (!irrev && ascii_strcasecmp (t2, in)) {
-      dprint (1,
-              (debugfile,
-               "mutt_idna_to_local: Not reversible. in = '%s', t2 = '%s'.\n",
-               in, t2));
+      debug_print (1, ("not reversible. in = '%s', t2 = '%s'.\n", in, t2));
       irrev = 1;
     }
 
@@ -91,14 +84,14 @@ int mutt_idna_to_local (const char *in, char **out, int flags)
 
 notrans:
   FREE (out);
-  *out = safe_strdup (in);
+  *out = str_dup (in);
   return 1;
 }
 
 int mutt_local_to_idna (const char *in, char **out)
 {
   int rv = 0;
-  char *tmp = safe_strdup (in);
+  char *tmp = str_dup (in);
 
   *out = NULL;
 
@@ -115,7 +108,7 @@ int mutt_local_to_idna (const char *in, char **out)
   FREE (&tmp);
   if (rv < 0) {
     FREE (out);
-    *out = safe_strdup (in);
+    *out = str_dup (in);
   }
   return rv;
 }
@@ -137,7 +130,7 @@ static int mbox_to_udomain (const char *mbx, char **user, char **domain)
     return -1;
   *user = safe_calloc ((p - mbx + 1), sizeof (mbx[0]));
   strfcpy (*user, mbx, (p - mbx + 1));
-  *domain = safe_strdup (p + 1);
+  *domain = str_dup (p + 1);
   return 0;
 }
 
@@ -159,10 +152,10 @@ int mutt_addrlist_to_idna (ADDRESS * a, char **err)
     if (mutt_local_to_idna (domain, &tmp) < 0) {
       e = 1;
       if (err)
-        *err = safe_strdup (domain);
+        *err = str_dup (domain);
     }
     else {
-      safe_realloc (&a->mailbox, mutt_strlen (user) + mutt_strlen (tmp) + 2);
+      safe_realloc (&a->mailbox, str_len (user) + str_len (tmp) + 2);
       sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp));       /* __SPRINTF_CHECKED__ */
     }
 
@@ -189,7 +182,7 @@ int mutt_addrlist_to_local (ADDRESS * a)
       continue;
 
     if (mutt_idna_to_local (domain, &tmp, 0) == 0) {
-      safe_realloc (&a->mailbox, mutt_strlen (user) + mutt_strlen (tmp) + 2);
+      safe_realloc (&a->mailbox, str_len (user) + str_len (tmp) + 2);
       sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp));       /* __SPRINTF_CHECKED__ */
     }
 
@@ -223,7 +216,7 @@ const char *mutt_addr_for_display (ADDRESS * a)
     return a->mailbox;
   }
 
-  safe_realloc (&buff, mutt_strlen (tmp) + mutt_strlen (user) + 2);
+  safe_realloc (&buff, str_len (tmp) + str_len (user) + 2);
   sprintf (buff, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
   FREE (&tmp);
   FREE (&user);