]> granicus.if.org Git - neomutt/commitdiff
Add user reversibility check in intl_to_local.
authorKevin McCarthy <kevin@8t8.us>
Tue, 24 Nov 2015 23:49:31 +0000 (15:49 -0800)
committerKevin McCarthy <kevin@8t8.us>
Tue, 24 Nov 2015 23:49:31 +0000 (15:49 -0800)
This ensures we don't lose information by converting to the local charset.

mutt_idna.c

index 03b1dd828061d2b987767054d6f2b7dde179bb5e..8fc91fef2fa0eff545e2ff7f2a7773c1a01153ad 100644 (file)
@@ -92,6 +92,7 @@ static void set_intl_mailbox (ADDRESS *a, char *intl_mailbox)
 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
@@ -100,6 +101,7 @@ static char *intl_to_local (ADDRESS *a, int flags)
 
   if (mbox_to_udomain (a->mailbox, &user, &domain) == -1)
     goto cleanup;
+  orig_user = safe_strdup (user);
   orig_domain = safe_strdup (domain);
 
 #ifdef HAVE_LIBIDN
@@ -122,10 +124,27 @@ static char *intl_to_local (ADDRESS *a, int flags)
 
   /*
    * 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)
@@ -171,6 +190,8 @@ cleanup:
   FREE (&tmp);
   FREE (&orig_domain);
   FREE (&reversed_domain);
+  FREE (&orig_user);
+  FREE (&reversed_user);
 
   return mailbox;
 }