Changeset 6d0ada3 in github


Ignore:
Timestamp:
Aug 9, 2011 5:46:54 AM (22 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
2185899
Parents:
efc24a5
Message:
  • Fix handling of email addresses with quoted local part (#1487939)
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r359e19a r6d0ada3  
    22=========================== 
    33 
     4- Fix handling of email addresses with quoted local part (#1487939) 
    45- Fix EOL character in vCard exports (#1487873) 
    56- Added optional "multithreading" autocomplete feature 
  • program/include/rcube_imap.php

    r1cd3626 r6d0ada3  
    47614761        $result = array(); 
    47624762 
     4763        // simplified regexp, supporting quoted local part 
     4764        $email_rx = '(\S+|("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+"))@\S+'; 
     4765 
    47634766        foreach ($str as $key => $val) { 
    47644767            $name    = ''; 
     
    47664769            $val     = trim($val); 
    47674770 
    4768             if (preg_match('/(.*)<(\S+@\S+)>$/', $val, $m)) { 
     4771            if (preg_match('/(.*)<('.$email_rx.')>$/', $val, $m)) { 
    47694772                $address = $m[2]; 
    47704773                $name    = trim($m[1]); 
     
    47804783            // dequote and/or decode name 
    47814784            if ($name) { 
    4782                 if ($name[0] == '"') { 
     4785                if ($name[0] == '"' && $name[strlen($name)-1] == '"') { 
    47834786                    $name = substr($name, 1, -1); 
    47844787                    $name = stripslashes($name); 
  • program/include/rcube_smtp.php

    r462de2d r6d0ada3  
    440440    if (is_array($recipients)) 
    441441      $recipients = implode(', ', $recipients); 
    442      
     442 
    443443    $addresses = array(); 
    444444    $recipients = rcube_explode_quoted_string(',', $recipients); 
     
    447447    while (list($k, $recipient) = each($recipients)) 
    448448    { 
    449       $a = explode(" ", $recipient); 
     449      $a = rcube_explode_quoted_string(' ', $recipient); 
    450450      while (list($k2, $word) = each($a)) 
    451451      { 
     
    458458      } 
    459459    } 
     460 
    460461    return $addresses; 
    461462  } 
  • program/lib/Mail/mimePart.php

    r53604a0 r6d0ada3  
    132132    var $_eol = "\r\n"; 
    133133 
     134 
    134135    /** 
    135136    * Constructor. 
     
    801802        // Structured header (make sure addr-spec inside is not encoded) 
    802803        if (!empty($separator)) { 
     804            // Simple e-mail address regexp 
     805            $email_regexp = '(\S+|("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+"))@\S+'; 
     806 
    803807            $parts = Mail_mimePart::_explodeQuotedString($separator, $value); 
    804808            $value = ''; 
     
    818822 
    819823                // let's find phrase (name) and/or addr-spec 
    820                 if (preg_match('/^<\S+@\S+>$/', $part)) { 
     824                if (preg_match('/^<' . $email_regexp . '>$/', $part)) { 
    821825                    $value .= $part; 
    822                 } else if (preg_match('/^\S+@\S+$/', $part)) { 
     826                } else if (preg_match('/^' . $email_regexp . '$/', $part)) { 
    823827                    // address without brackets and without name 
    824828                    $value .= $part; 
    825                 } else if (preg_match('/<*\S+@\S+>*$/', $part, $matches)) { 
     829                } else if (preg_match('/<*' . $email_regexp . '>*$/', $part, $matches)) { 
    826830                    // address with name (handle name) 
    827831                    $address = $matches[0]; 
  • program/steps/mail/sendmail.inc

    r340546c r6d0ada3  
    144144  global $EMAIL_FORMAT_ERROR, $RECIPIENT_COUNT; 
    145145 
    146   $regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<\S+@\S+>)/U'); 
     146  // simplified email regexp, supporting quoted local part 
     147  $email_regexp = '(\S+|("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+"))@\S+'; 
     148 
     149  $regexp  = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<'.$email_regexp.'>)/U'); 
    147150  $replace = array(', ', ', ', '', ',', '\\1 \\2'); 
    148151 
     
    156159    $item = trim($item); 
    157160    // address in brackets without name (do nothing) 
    158     if (preg_match('/^<\S+@\S+>$/', $item)) { 
     161    if (preg_match('/^<'.$email_regexp.'>$/', $item)) { 
    159162      $item = rcube_idn_to_ascii($item); 
    160163      $result[] = $item; 
    161164    // address without brackets and without name (add brackets) 
    162     } else if (preg_match('/^\S+@\S+$/', $item)) { 
     165    } else if (preg_match('/^'.$email_regexp.'$/', $item)) { 
    163166      $item = rcube_idn_to_ascii($item); 
    164167      $result[] = '<'.$item.'>'; 
    165168    // address with name (handle name) 
    166     } else if (preg_match('/\S+@\S+>*$/', $item, $matches)) { 
     169    } else if (preg_match('/'.$email_regexp.'>*$/', $item, $matches)) { 
    167170      $address = $matches[0]; 
    168171      $name = str_replace($address, '', $item); 
     
    173176      } 
    174177      $address = rcube_idn_to_ascii($address); 
    175       if (!preg_match('/^<\S+@\S+>$/', $address)) 
     178      if (!preg_match('/^<'.$email_regexp.'>$/', $address)) 
    176179        $address = '<'.$address.'>'; 
    177180 
  • tests/maildecode.php

    r6c68cbd r6d0ada3  
    4545        17 => 'test@domain.tld (comment)', 
    4646        18 => '"Test,Test" <test@domain.tld>', 
     47        // 1487939 
     48        19 => 'Test <"test test"@domain.tld>', 
    4749    ); 
    4850 
     
    6769        17 => array(1, '', 'test@domain.tld'), 
    6870        18 => array(1, 'Test,Test', 'test@domain.tld'), 
     71        19 => array(1, 'Test', '"test test"@domain.tld'), 
    6972    ); 
    7073 
     
    7477      $this->assertEqual($results[$idx][0], count($res), "Rows number in result for header: " . $header); 
    7578      $this->assertEqual($results[$idx][1], $res[1]['name'], "Name part decoding for header: " . $header); 
    76       $this->assertEqual($results[$idx][2], $res[1]['mailto'], "Name part decoding for header: " . $header); 
     79      $this->assertEqual($results[$idx][2], $res[1]['mailto'], "Email part decoding for header: " . $header); 
    7780    } 
    7881  } 
Note: See TracChangeset for help on using the changeset viewer.