This is patch 1 of 4 implementing support for SMTPUTF8 (RFC 6531).
Change mutt_idna.c to be always compiled. Remove the stub functions in
mutt_idna.h. Instead, put #ifdefs around the idna function calls. The
conversion functions will be fixed up in the next patch.
Rename the conversion functions to mutt_addrlist_to_intl() and
mutt_env_to_intl(). Rename the ADDRESS idna status bits to "intl"
status bits.
rfc822.c rfc1524.c rfc2047.c rfc2231.c rfc3676.c \
score.c send.c sendlib.c signal.c sort.c \
status.c system.c thread.c charset.c history.c lib.c \
- muttlib.c editmsg.c mbyte.c \
+ muttlib.c editmsg.c mbyte.c mutt_idna.c \
url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c
nodist_mutt_SOURCES = $(BUILT_SOURCES)
EXTRA_mutt_SOURCES = account.c bcache.c crypt-gpgme.c crypt-mod-pgp-classic.c \
crypt-mod-pgp-gpgme.c crypt-mod-smime-classic.c \
crypt-mod-smime-gpgme.c dotlock.c gnupgparse.c hcache.c md5.c \
- mutt_idna.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \
+ mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \
mutt_tunnel.c pgp.c pgpinvoke.c pgpkey.c pgplib.c pgpmicalg.c \
pgppacket.c pop.c pop_auth.c pop_lib.c remailer.c resize.c sha1.c \
smime.c smtp.c utf8.c wcwidth.c \
else
buf[0] = 0;
- mutt_addrlist_to_idna (adr, NULL);
+ mutt_addrlist_to_intl (adr, NULL);
do
{
if((new->addr = rfc822_parse_adrlist (new->addr, buf)) == NULL)
BEEP ();
- if (mutt_addrlist_to_idna (new->addr, &err))
+ if (mutt_addrlist_to_intl (new->addr, &err))
{
mutt_error (_("Error: '%s' is a bad IDN."), err);
mutt_sleep (2);
adr = mutt_expand_aliases (adr);
- if (mutt_addrlist_to_idna (adr, &err) < 0)
+ if (mutt_addrlist_to_intl (adr, &err) < 0)
{
mutt_error (_("Bad IDN: '%s'"), err);
FREE (&err);
return (REDRAW_FULL);
}
- if (mutt_addrlist_to_idna (*addr, &err) != 0)
+ if (mutt_addrlist_to_intl (*addr, &err) != 0)
{
mutt_error (_("Warning: '%s' is a bad IDN."), err);
mutt_refresh();
mutt_env_to_local (msg->env);
mutt_edit_headers (NONULL (Editor), msg->content->filename, msg,
fcc, fcclen);
- if (mutt_env_to_idna (msg->env, &tag, &err))
+ if (mutt_env_to_intl (msg->env, &tag, &err))
{
mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
FREE (&err);
AC_SEARCH_LIBS([stringprep_check_version], [idn], [
AC_DEFINE([HAVE_LIBIDN], 1, [Define to 1 if you have the GNU idn library])
- MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS mutt_idna.o"
MUTTLIBS="$MUTTLIBS $LIBS"
LIBS="$LIBS $LIBICONV"
rfc822_free_address (&e->to);
e->to = mutt_parse_adrlist (e->to, tmp);
e->to = mutt_expand_aliases (e->to);
- mutt_addrlist_to_idna (e->to, NULL); /* XXX - IDNA error reporting? */
+ mutt_addrlist_to_intl (e->to, NULL); /* XXX - IDNA error reporting? */
tmp[0] = 0;
rfc822_write_address (tmp, sizeof (tmp), e->to, 1);
mvaddstr (LINES - 1, 4, tmp);
}
else
{
- mutt_addrlist_to_idna (e->to, NULL); /* XXX - IDNA error reporting? */
+ mutt_addrlist_to_intl (e->to, NULL); /* XXX - IDNA error reporting? */
addstr (tmp);
}
addch ('\n');
e->cc = mutt_parse_adrlist (e->cc, tmp);
e->cc = mutt_expand_aliases (e->cc);
tmp[0] = 0;
- mutt_addrlist_to_idna (e->cc, NULL);
+ mutt_addrlist_to_intl (e->cc, NULL);
rfc822_write_address (tmp, sizeof (tmp), e->cc, 1);
mvaddstr (LINES - 1, 4, tmp);
}
else
- mutt_addrlist_to_idna (e->cc, NULL);
+ mutt_addrlist_to_intl (e->cc, NULL);
addch ('\n');
}
rfc822_free_address (&e->bcc);
e->bcc = mutt_parse_adrlist (e->bcc, tmp);
e->bcc = mutt_expand_aliases (e->bcc);
- mutt_addrlist_to_idna (e->bcc, NULL);
+ mutt_addrlist_to_intl (e->bcc, NULL);
tmp[0] = 0;
rfc822_write_address (tmp, sizeof (tmp), e->bcc, 1);
mvaddstr (LINES - 1, 5, tmp);
}
else
- mutt_addrlist_to_idna (e->bcc, NULL);
+ mutt_addrlist_to_intl (e->bcc, NULL);
addch ('\n');
}
}
{
mutt_env_to_local (msg->env);
mutt_edit_headers (NONULL(Visual), path, msg, NULL, 0);
- if (mutt_env_to_idna (msg->env, &tag, &err))
+ if (mutt_env_to_intl (msg->env, &tag, &err))
printw (_("Bad IDN in %s: '%s'\n"), tag, err);
}
else
case ADDR:
if ((addr = mutt_parse_adrlist (NULL, buf->data)) == NULL)
goto bail;
- if (mutt_addrlist_to_idna (addr, &estr))
+ if (mutt_addrlist_to_intl (addr, &estr))
{
snprintf (err->data, err->dsize, _("%sgroup: warning: bad IDN '%s'.\n"),
data == 1 ? "un" : "", estr);
last->next = tmp;
else
Aliases = tmp;
- if (mutt_addrlist_to_idna (tmp->addr, &estr))
+ if (mutt_addrlist_to_intl (tmp->addr, &estr))
{
snprintf (err->data, err->dsize, _("Warning: Bad IDN '%s' in alias '%s'.\n"),
estr, tmp->name);
if ((a = mutt_lookup_alias (alias_queries->data)))
{
/* output in machine-readable form */
- mutt_addrlist_to_idna (a, NULL);
+ mutt_addrlist_to_intl (a, NULL);
mutt_write_address_list (a, stdout, 0, 0);
}
else
#include "charset.h"
#include "mutt_idna.h"
-/* The low-level interface we use. */
-#ifdef HAVE_LIBIDN
/* check whether an address is an IDN */
if (!ap || !ap->mailbox)
return 0;
- if (!ap->idn_checked)
+ if (!ap->intl_checked)
{
- ap->idn_checked = 1;
+ ap->intl_checked = 1;
for (p = strchr (ap->mailbox, '@'); p && *p; p = strchr (p, '.'))
if (ascii_strncasecmp (++p, "xn--", 4) == 0)
{
- ap->is_idn = 1;
+ ap->is_intl = 1;
break;
}
}
- return ap->is_idn;
+ return ap->is_intl;
}
-static int mutt_idna_to_local (const char *in, char **out, int flags)
+static int intl_to_local (const char *in, char **out, int flags)
{
*out = NULL;
goto notrans;
/* Is this the right function? Interesting effects with some bad identifiers! */
+#ifdef HAVE_LIBIDN
if (idna_to_unicode_8z8z (in, out, IDNA_ALLOW_UNASSIGNED) != IDNA_SUCCESS)
goto notrans;
+#endif /* HAVE_LIBIDN */
/* we don't want charset-hook effects, so we set flags to 0 */
if (mutt_convert_string (out, "utf-8", Charset, 0) == -1)
/* we don't want charset-hook effects, so we set flags to 0 */
if (mutt_convert_string (&tmp, Charset, "utf-8", 0) == -1)
irrev = 1;
+#ifdef HAVE_LIBIDN
if (!irrev && idna_to_ascii_8z (tmp, &t2, IDNA_ALLOW_UNASSIGNED) != IDNA_SUCCESS)
irrev = 1;
+#endif /* HAVE_LIBIDN */
if (!irrev && ascii_strcasecmp (t2, in))
{
- dprint (1, (debugfile, "mutt_idna_to_local: Not reversible. in = '%s', t2 = '%s'.\n",
+ dprint (1, (debugfile, "intl_to_local: Not reversible. in = '%s', t2 = '%s'.\n",
in, t2));
irrev = 1;
}
return 1;
}
-static int mutt_local_to_idna (const char *in, char **out)
+static int local_to_intl (const char *in, char **out)
{
int rv = 0;
char *tmp = safe_strdup (in);
/* we don't want charset-hook effects, so we set flags to 0 */
if (mutt_convert_string (&tmp, Charset, "utf-8", 0) == -1)
rv = -1;
+
+#ifdef HAVE_LIBIDN
if (!rv && idna_to_ascii_8z (tmp, out, IDNA_ALLOW_UNASSIGNED) != IDNA_SUCCESS)
rv = -2;
+#endif /* HAVE_LIBIDN */
FREE (&tmp);
if (rv < 0)
return 0;
}
-int mutt_addrlist_to_idna (ADDRESS *a, char **err)
+int mutt_addrlist_to_intl (ADDRESS *a, char **err)
{
char *user = NULL, *domain = NULL;
char *tmp = NULL;
if (mbox_to_udomain (a->mailbox, &user, &domain) == -1)
continue;
- if (mutt_local_to_idna (domain, &tmp) < 0)
+ if (local_to_intl (domain, &tmp) < 0)
{
e = 1;
if (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;
+ a->intl_checked = 0;
}
FREE (&tmp);
continue;
if (mbox_to_udomain (a->mailbox, &user, &domain) == -1)
continue;
- if (mutt_idna_to_local (domain, &tmp, 0) == 0)
+ if (intl_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;
+ a->intl_checked = 0;
}
FREE (&tmp);
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)
+ if (intl_to_local (domain, &tmp, MI_MAY_BE_IRREVERSIBLE) != 0)
{
FREE (&tmp);
return a->mailbox;
* "real" name of an `env' compound member. Real name will be substituted
* by preprocessor at the macro-expansion time.
*/
-#define H_TO_IDNA(a) \
- if (mutt_addrlist_to_idna (env->a, err) && !e) \
+#define H_TO_INTL(a) \
+ if (mutt_addrlist_to_intl (env->a, err) && !e) \
{ \
if (tag) *tag = #a; e = 1; err = NULL; \
}
-int mutt_env_to_idna (ENVELOPE *env, char **tag, char **err)
+int mutt_env_to_intl (ENVELOPE *env, char **tag, char **err)
{
int e = 0;
- H_TO_IDNA(return_path);
- H_TO_IDNA(from);
- H_TO_IDNA(to);
- H_TO_IDNA(cc);
- H_TO_IDNA(bcc);
- H_TO_IDNA(reply_to);
- H_TO_IDNA(mail_followup_to);
+ H_TO_INTL(return_path);
+ H_TO_INTL(from);
+ H_TO_INTL(to);
+ H_TO_INTL(cc);
+ H_TO_INTL(bcc);
+ H_TO_INTL(reply_to);
+ H_TO_INTL(mail_followup_to);
return e;
}
-#undef H_TO_IDNA
-
-#endif /* HAVE_LIBIDN */
+#undef H_TO_INTL
/* Work around incompatibilities in the libidn API */
#ifdef HAVE_LIBIDN
-int mutt_addrlist_to_idna (ADDRESS *, char **);
-int mutt_addrlist_to_local (ADDRESS *);
-
-void mutt_env_to_local (ENVELOPE *);
-int mutt_env_to_idna (ENVELOPE *, char **, char **);
-
-const char *mutt_addr_for_display (ADDRESS *a);
-
# if (!defined(HAVE_IDNA_TO_ASCII_8Z) && defined(HAVE_IDNA_TO_ASCII_FROM_UTF8))
# define idna_to_ascii_8z(a,b,c) idna_to_ascii_from_utf8(a,b,(c)&1,((c)&2)?1:0)
# endif
# if (!defined(HAVE_IDNA_TO_UNICODE_8Z8Z) && defined(HAVE_IDNA_TO_UNICODE_UTF8_FROM_UTF8))
# define idna_to_unicode_8z8z(a,b,c) idna_to_unicode_utf8_from_utf8(a,b,(c)&1,((c)&2)?1:0)
# endif
-#else
-
-static inline int mutt_addrlist_to_idna (ADDRESS *addr, char **err)
-{
- return 0;
-}
+#endif /* HAVE_LIBIDN */
-static inline int mutt_addrlist_to_local (ADDRESS *addr)
-{
- return 0;
-}
-static inline void mutt_env_to_local (ENVELOPE *env)
-{
- return;
-}
+int mutt_addrlist_to_intl (ADDRESS *, char **);
+int mutt_addrlist_to_local (ADDRESS *);
-static inline int mutt_env_to_idna (ENVELOPE *env, char **tag, char **err)
-{
- return 0;
-}
+void mutt_env_to_local (ENVELOPE *);
+int mutt_env_to_intl (ENVELOPE *, char **, char **);
-static inline const char *mutt_addr_for_display (ADDRESS *a)
-{
- return a->mailbox;
-}
+const char *mutt_addr_for_display (ADDRESS *a);
-#endif /* HAVE_LIBIDN */
#endif
if(!tmp->next && !tmp->personal)
tmp->personal = safe_strdup (r->name);
- mutt_addrlist_to_idna (tmp, NULL);
+ mutt_addrlist_to_intl (tmp, NULL);
return tmp;
}
adr = mutt_expand_aliases (adr);
- if (mutt_addrlist_to_idna (adr, &err) < 0)
+ if (mutt_addrlist_to_intl (adr, &err) < 0)
{
mutt_error (_("Bad IDN: '%s'"), err);
FREE (&err);
p->personal = safe_strdup (addr->personal);
p->mailbox = safe_strdup (addr->mailbox);
p->group = addr->group;
- p->is_idn = addr->is_idn;
- p->idn_checked = addr->idn_checked;
+ p->is_intl = addr->is_intl;
+ p->intl_checked = addr->intl_checked;
return p;
}
char *mailbox; /* mailbox and host address */
int group; /* group mailbox? */
struct address_t *next;
- unsigned is_idn : 1;
- unsigned idn_checked : 1;
+ unsigned is_intl : 1;
+ unsigned intl_checked : 1;
}
ADDRESS;
return (-1);
rfc822_free_address (a);
*a = mutt_expand_aliases (mutt_parse_adrlist (NULL, buf));
- if ((idna_ok = mutt_addrlist_to_idna (*a, &err)) != 0)
+ if ((idna_ok = mutt_addrlist_to_intl (*a, &err)) != 0)
{
mutt_error (_("Error: '%s' is a bad IDN."), err);
mutt_refresh ();
{
mutt_env_to_local (msg->env);
mutt_edit_headers (Editor, msg->content->filename, msg, fcc, sizeof (fcc));
- mutt_env_to_idna (msg->env, NULL, NULL);
+ mutt_env_to_intl (msg->env, NULL, NULL);
}
else
{
encode_descriptions (msg->content, 1);
mutt_prepare_envelope (msg->env, 0);
- mutt_env_to_idna (msg->env, NULL, NULL); /* Handle bad IDNAs the next time. */
+ mutt_env_to_intl (msg->env, NULL, NULL); /* Handle bad IDNAs the next time. */
if (!Postponed || mutt_write_fcc (NONULL (Postponed), msg, (cur && (flags & SENDREPLY)) ? cur->env->message_id : NULL, 1, fcc) < 0)
{
}
}
- if (mutt_env_to_idna (msg->env, &tag, &err))
+ if (mutt_env_to_intl (msg->env, &tag, &err))
{
mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
FREE (&err);
rfc822_qualify (from, fqdn);
rfc2047_encode_adrlist (from, "Resent-From");
- if (mutt_addrlist_to_idna (from, &err))
+ if (mutt_addrlist_to_intl (from, &err))
{
mutt_error (_("Bad IDN %s while preparing resent-from."),
err);