X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mutt_idna.c;h=78fe7bee3a403366a1618330a4bc65dfdebd6127;hp=b8bf8fdccf47451a54a011a356a772fd712cabcc;hb=13b3b36c8f696aea26b7c60444f2baa4858b004d;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/mutt_idna.c b/mutt_idna.c index b8bf8fd..78fe7be 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -1,19 +1,10 @@ /* + * Copyright notice from original mutt: * Copyright (C) 2003 Thomas Roessler - * - * 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 @@ -21,22 +12,28 @@ #endif #include "mutt.h" +#include "ascii.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,22 +63,19 @@ 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; } - FREE (&t2); - FREE (&tmp); + mem_free (&t2); + mem_free (&tmp); if (irrev) goto notrans; @@ -90,15 +84,15 @@ int mutt_idna_to_local (const char *in, char **out, int flags) return 0; notrans: - FREE (out); - *out = safe_strdup (in); + mem_free (out); + *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; @@ -112,10 +106,10 @@ int mutt_local_to_idna (const char *in, char **out) if (!rv && idna_to_ascii_8z (tmp, out, 1) != IDNA_SUCCESS) rv = -2; - FREE (&tmp); + mem_free (&tmp); if (rv < 0) { - FREE (out); - *out = safe_strdup (in); + mem_free (out); + *out = str_dup (in); } return rv; } @@ -133,11 +127,11 @@ static int mbox_to_udomain (const char *mbx, char **user, char **domain) *domain = NULL; p = strchr (mbx, '@'); - if (!p) + if (!p || !p[1]) return -1; - *user = safe_calloc ((p - mbx + 1), sizeof (mbx[0])); + *user = mem_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,16 +153,16 @@ 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); + mem_realloc (&a->mailbox, str_len (user) + str_len (tmp) + 2); sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */ } - FREE (&domain); - FREE (&user); - FREE (&tmp); + mem_free (&domain); + mem_free (&user); + mem_free (&tmp); if (e) return -1; @@ -189,13 +183,13 @@ 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); + mem_realloc (&a->mailbox, str_len (user) + str_len (tmp) + 2); sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */ } - FREE (&domain); - FREE (&user); - FREE (&tmp); + mem_free (&domain); + mem_free (&user); + mem_free (&tmp); } return 0; @@ -212,22 +206,22 @@ const char *mutt_addr_for_display (ADDRESS * a) char *domain = NULL; char *user = NULL; - FREE (&buff); + mem_free (&buff); if (mbox_to_udomain (a->mailbox, &user, &domain) != 0) return a->mailbox; if (mutt_idna_to_local (domain, &tmp, MI_MAY_BE_IRREVERSIBLE) != 0) { - FREE (&user); - FREE (&domain); - FREE (&tmp); + mem_free (&user); + mem_free (&domain); + mem_free (&tmp); return a->mailbox; } - safe_realloc (&buff, mutt_strlen (tmp) + mutt_strlen (user) + 2); + mem_realloc (&buff, str_len (tmp) + str_len (user) + 2); sprintf (buff, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */ - FREE (&tmp); - FREE (&user); - FREE (&domain); + mem_free (&tmp); + mem_free (&user); + mem_free (&domain); return buff; }