Check to make sure the user as well as the domain are reversible when
converting to local.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
http://www.8t8.us/configs/gpg-key-transition-statement.txt
# HG changeset patch
# User Kevin McCarthy <[email protected]>
# Date 1447791392 28800
#      Tue Nov 17 12:16:32 2015 -0800
# Node ID e2c44b1605f9062cb1b66bb4ae54d2886957df0d
# Parent  33a294afd7d66776fcf0b9c79c49ac361747e638
Add user reversibility check in intl_to_local.

This ensures we don't lose information by converting to the local charset.

diff --git a/mutt_idna.c b/mutt_idna.c
--- a/mutt_idna.c
+++ b/mutt_idna.c
@@ -87,24 +87,26 @@
   a->mailbox = intl_mailbox;
   a->intl_checked = 1;
   a->is_intl = 1;
 }
 
 static char *intl_to_local (ADDRESS *a, int flags)
 {
   char *user = NULL, *domain = NULL, *mailbox = NULL;
+  char *orig_user = NULL, *reversed_user = NULL;
   char *orig_domain = NULL, *reversed_domain = NULL;
   char *tmp = NULL;
 #ifdef HAVE_LIBIDN
   int is_idn_encoded = 0;
 #endif /* HAVE_LIBIDN */
 
   if (mbox_to_udomain (a->mailbox, &user, &domain) == -1)
     goto cleanup;
+  orig_user = safe_strdup (user);
   orig_domain = safe_strdup (domain);
 
 #ifdef HAVE_LIBIDN
   is_idn_encoded = check_idn (domain);
   if (is_idn_encoded && option (OPTIDNDECODE))
   {
     if (idna_to_unicode_8z8z (domain, &tmp, IDNA_ALLOW_UNASSIGNED) != 
IDNA_SUCCESS)
       goto cleanup;
@@ -117,20 +119,37 @@
   if (mutt_convert_string (&user, "utf-8", Charset, 0) == -1)
     goto cleanup;
 
   if (mutt_convert_string (&domain, "utf-8", Charset, 0) == -1)
     goto cleanup;
 
   /*
    * make sure that we can convert back and come out with the same
-   * domain name.
+   * user and domain name.
    */
   if ((flags & MI_MAY_BE_IRREVERSIBLE) == 0)
   {
+    reversed_user = safe_strdup (user);
+
+    if (mutt_convert_string (&reversed_user, Charset, "utf-8", 0) == -1)
+    {
+      dprint (1, (debugfile,
+                  "intl_to_local: Not reversible. Charset conv to utf-8 failed 
for user = '%s'.\n",
+                  reversed_user));
+      goto cleanup;
+    }
+
+    if (ascii_strcasecmp (orig_user, reversed_user))
+    {
+      dprint (1, (debugfile, "intl_to_local: Not reversible. orig = '%s', 
reversed = '%s'.\n",
+                  orig_user, reversed_user));
+      goto cleanup;
+    }
+
     reversed_domain = safe_strdup (domain);
 
     if (mutt_convert_string (&reversed_domain, Charset, "utf-8", 0) == -1)
     {
       dprint (1, (debugfile,
                   "intl_to_local: Not reversible. Charset conv to utf-8 failed 
for domain = '%s'.\n",
                   reversed_domain));
       goto cleanup;
@@ -166,16 +185,18 @@
   sprintf (mailbox, "%s@%s", NONULL(user), NONULL(domain)); /* 
__SPRINTF_CHECKED__ */
 
 cleanup:
   FREE (&user);
   FREE (&domain);
   FREE (&tmp);
   FREE (&orig_domain);
   FREE (&reversed_domain);
+  FREE (&orig_user);
+  FREE (&reversed_user);
 
   return mailbox;
 }
 
 static char *local_to_intl (ADDRESS *a)
 {
   char *user = NULL, *domain = NULL, *mailbox = NULL;
   char *tmp = NULL;

Attachment: signature.asc
Description: PGP signature

Reply via email to