Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#1487742 closed Bugs (fixed)

IDNA support problem (ICANN e-mail test)

Reported by: arser Owned by:
Priority: 5 Milestone: 0.5.1
Component: Core functionality Version: 0.5
Severity: normal Keywords: idn idna


When I tried to send to "mailtest@пример.испытание" (ICANN e-mail test), I got an error "Please enter at least one recipient". Same error I got when trying to send to punicode notation "mailtest@xn--e1afmkfd.xn--80akhbyknj4f".
However, when I tried to write the address "mailtest@xn--e1afmkfd.xn--80akhbyknj4f" in the Copy field, the letter sent successfully.
Although when I tried to write the address "mailtest@пример.испытание" in the Copy field I got an error "Invalid e-mail address: xn--mailtest@-o0h6a0cxbod.xn--80akhbyknj4f".

In the last error address incorrectly encoded. When I view in roundcube sent letter, address "mailtest@xn--e1afmkfd.xn--80akhbyknj4f" also incorrectly decoded to "".

I think, "username@" is perceived as part of the domain name, resulting in a domain name is not correctly encoded/decoded, as well as username is corrupted.

RoundCube Forum thread

Change History (7)

comment:1 Changed 3 years ago by alec

  • Milestone changed from later to 0.5.1

comment:2 Changed 3 years ago by charly

i found some places on which we are mistaking the use of idna_to_ascii
if you see you will see that the function translates a domain to punycode, but only the domain and not the entire e-mail address.

this is a small fix i was working on, on one of the places i found idna_to_ascii to be used in the wrong way:

Index: trunk/roundcubemail/program/include/rcmail.php
--- trunk/roundcubemail/program/include/rcmail.php	(revisión: 4482)
+++ trunk/roundcubemail/program/include/rcmail.php	(copia de trabajo)
@@ -703,8 +703,10 @@
     if (strpos($username, '@')) {
       // lowercase domain name
       list($local, $domain) = explode('@', $username);
-      $username = $local . '@' . mb_strtolower($domain);
-      $username = idn_to_ascii($username);
+// idn_to_ascii process only the domain, not the user@ part of the email:
+      $username = $local . '@' . idn_to_ascii( mb_strtolower($domain) );
+// wrong:      $username = idn_to_ascii($username);

This is the list of files that need to be changed and the lines i found using 'grep':

      $username = idn_to_ascii($username);

        $smtp_user = idn_to_ascii($smtp_user);

  $from = idn_to_ascii(trim($_POST['_from']));
  $to   = idn_to_ascii(trim($_POST['_to']));
  $imap_host = idn_to_ascii($imap_host);
  $imap_user = idn_to_ascii($_POST['_user']);

                    if (check_email(idn_to_ascii($rec['email']))) {

                                    'email'         => idn_to_ascii($sql_arr[0]),
                                'reply-to'          => idn_to_ascii($sql_arr[3]),
                                    'bcc'                   => idn_to_ascii($sql_arr[4]),

                        $result[] = idn_to_ascii(trim(str_replace('\\@', '@', $arr[0])));

      $save_data['email'] = idn_to_ascii($save_data['email']);

                    $args['user_email'] = idn_to_ascii($results->records[0]['email']);

                    if (check_email(idn_to_ascii($rec['email']))) {
                                    'email'         => idn_to_ascii($sql_arr[0]),
                                'reply-to'          => idn_to_ascii($sql_arr[3]),
                                    'bcc'                   => idn_to_ascii($sql_arr[4]),

                        $result[] = idn_to_ascii(trim(str_replace('\\@', '@', $arr[0])));

      $save_data['email'] = idn_to_ascii($save_data['email']);

                    $args['user_email'] = idn_to_ascii($results->records[0]['email']);

i think this should help you on fixing this bug


comment:3 Changed 3 years ago by charly

may be a function should help on this, but i don't know were to declare it.

A small function like this can handle a full email and convert it to punycode:

function email_idna_to_ascii($email)
   $new_email = $user . '@' . $domain;
   return $new_email;

i know you will rework this on a better function, but you can get the idea on this

comment:4 Changed 3 years ago by alec

Right. It looks that we can't pass e-mail address to Intl/Idn?'s functions. PEAR::Net_IDNA2 supports this. We need to use wrapper functions.

comment:5 Changed 3 years ago by alec

  • Summary changed from IDNA support problem to IDNA support problem (ICANN e-mail test)

idn_* functions issue is fixed in [e8d5bdc8] and r4485/svn. We still need a fix for ICANN test e-mails.

comment:6 Changed 3 years ago by alec

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [e18d992e] and [47f55c0d].

comment:7 Changed 3 years ago by arser

Everything seems to work well now. Thank you!

Note: See TracTickets for help on using tickets.