mail: Address fails to parse email addresses with extended characters

For example, “josé.cuervo@cactus.com”

AddressListsParser can not parse |josé.cuervo@cactus.com|
Reason was: Expected one of !, #, $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, }, ~, 
, (, ", ., :, <, @, , at line 1, column 4 (byte 4) after 
/opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/mail-2.1.3/lib/mail/elements/address_list.rb:29:in `initialize'

Judging by our data, these are becoming quite common.

About this issue

  • Original URL
  • State: closed
  • Created 14 years ago
  • Comments: 36 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for working on this. It is greatly appreciated. I tested with 2.7.0.rc1 but it doesn’t seem to be happy with umlauts: Here’s an example:

>> puts Gem.loaded_specs["mail"].version
2.7.0.rc1
nil
>> Mail::Address.new('über <uber@mail.com>')
Mail::Field::ParseError: Mail::AddressList can not parse |über <uber@mail.com>|
Reason was: Only able to parse up to ü
	from /Users/beders/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mail-2.7.0.rc1/lib/mail/parsers/address_lists_parser.rb:15336:in `parse'
	from /Users/beders/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mail-2.7.0.rc1/lib/mail/elements/address.rb:191:in `parse'
	from /Users/beders/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mail-2.7.0.rc1/lib/mail/elements/address.rb:31:in `initialize'
	from (irb):9:in `new'
	from (irb):9

Since we are still on Ruby 1.8.7 and could not use the proposed patch to the treetop grammar by @tessi, as a workaround, we used the stringex gem, which adds a to_ascii method to String.

> m = Mail::Address.new('"Stéphane Guillou" <985389@bugs.launchpad.net>'.to_ascii)
=> ...
> m.name
=> "Stephane Guillou"
> m.address
=> "985389@bugs.launchpad.net"

That at least gets around the parse error and will convert special characters to their closest ascii equivalent.