summaryrefslogtreecommitdiffstats
path: root/mutt_idna.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2008-09-17 22:27:43 +0200
committerThomas Roessler <roessler@does-not-exist.org>2008-09-17 22:27:43 +0200
commit4af1c6d6e20ec5e803ba760760a3dec46bec04c7 (patch)
tree7c620fed5048c91bf2e33e945eece8c9e7259a84 /mutt_idna.c
parent3d8a7dcf1851c4e310cfcb37a081dea12ac6aa43 (diff)
sorting efficiency
Diffstat (limited to 'mutt_idna.c')
-rw-r--r--mutt_idna.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/mutt_idna.c b/mutt_idna.c
index 721bf4f0..47839e1c 100644
--- a/mutt_idna.c
+++ b/mutt_idna.c
@@ -42,6 +42,29 @@ int mutt_local_to_idna (const char *in, char **out)
#else
+/* check whether an address is an IDN */
+
+static int check_idn (ADDRESS *ap)
+{
+ char *p = 0;
+
+ if (!ap || !ap->mailbox)
+ return 0;
+
+ if (!ap->idn_checked)
+ {
+ ap->idn_checked = 1;
+ for (p = strchr (ap->mailbox, '@'); p && *p; p = strchr (p, '.'))
+ if (ascii_strncasecmp (++p, "xn--", 4) == 0)
+ {
+ ap->is_idn = 1;
+ break;
+ }
+ }
+
+ return ap->is_idn;
+}
+
int mutt_idna_to_local (const char *in, char **out, int flags)
{
*out = NULL;
@@ -51,7 +74,7 @@ int mutt_idna_to_local (const char *in, char **out, int flags)
if (!in)
goto notrans;
-
+
/* Is this the right function? Interesting effects with some bad identifiers! */
if (idna_to_unicode_8z8z (in, out, 1) != IDNA_SUCCESS)
goto notrans;
@@ -132,16 +155,17 @@ int mutt_local_to_idna (const char *in, char **out)
static int mbox_to_udomain (const char *mbx, char **user, char **domain)
{
+ static char *buff = NULL;
char *p;
- *user = NULL;
- *domain = NULL;
- p = strchr (mbx, '@');
+ mutt_str_replace (&buff, mbx);
+
+ p = strchr (buff, '@');
if (!p || !p[1])
return -1;
- *user = safe_calloc((p - mbx + 1), sizeof(mbx[0]));
- strfcpy (*user, mbx, (p - mbx + 1));
- *domain = safe_strdup(p + 1);
+ *p = '\0';
+ *user = buff;
+ *domain = p + 1;
return 0;
}
@@ -171,10 +195,9 @@ int mutt_addrlist_to_idna (ADDRESS *a, char **err)
{
safe_realloc (&a->mailbox, mutt_strlen (user) + mutt_strlen (tmp) + 2);
sprintf (a->mailbox, "%s@%s", NONULL(user), NONULL(tmp)); /* __SPRINTF_CHECKED__ */
+ a->idn_checked = 0;
}
- FREE (&domain);
- FREE (&user);
FREE (&tmp);
if (e)
@@ -193,17 +216,17 @@ int mutt_addrlist_to_local (ADDRESS *a)
{
if (!a->mailbox)
continue;
+ if (!check_idn (a))
+ continue;
if (mbox_to_udomain (a->mailbox, &user, &domain) == -1)
continue;
-
if (mutt_idna_to_local (domain, &tmp, 0) == 0)
{
safe_realloc (&a->mailbox, mutt_strlen (user) + mutt_strlen (tmp) + 2);
sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
+ a->idn_checked = 0;
}
- FREE (&domain);
- FREE (&user);
FREE (&tmp);
}
@@ -221,13 +244,13 @@ const char *mutt_addr_for_display (ADDRESS *a)
char *user = NULL;
FREE (&buff);
-
+
+ if (!check_idn (a))
+ return a->mailbox;
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);
return a->mailbox;
}
@@ -235,8 +258,6 @@ const char *mutt_addr_for_display (ADDRESS *a)
safe_realloc (&buff, mutt_strlen (tmp) + mutt_strlen (user) + 2);
sprintf (buff, "%s@%s", NONULL(user), NONULL(tmp)); /* __SPRINTF_CHECKED__ */
FREE (&tmp);
- FREE (&user);
- FREE (&domain);
return buff;
}