mikel / mail

A Really Ruby Mail Library
MIT License
3.62k stars 938 forks source link

Mail::Address parser breaks on domains which begin with a comment #1244

Open ticky opened 6 years ago

ticky commented 6 years ago

For user input formatted like Mail::Address.new("someone@(comment)net") or Mail::Address.new("someone@(comment).net"), Mail::Address will emit an ArgumentError (bad value for range):

> Mail::Address.new("someone@(comment)net")
Traceback (most recent call last):
        7: from /Users/ticky/.rbenv/versions/2.5.0/bin/irb:11:in `<main>'
        6: from (irb):16
        5: from (irb):16:in `new'
        4: from /Users/ticky/.rbenv/gems/2.5.0/gems/mail-2.7.0/lib/mail/elements/address.rb:30:in `initialize'
        3: from /Users/ticky/.rbenv/gems/2.5.0/gems/mail-2.7.0/lib/mail/elements/address.rb:192:in `parse'
        2: from /Users/ticky/.rbenv/gems/2.5.0/gems/mail-2.7.0/lib/mail/parsers/address_lists_parser.rb:32930:in `parse'
        1: from /Users/ticky/.rbenv/gems/2.5.0/gems/mail-2.7.0/lib/mail/parser_tools.rb:9:in `chars'
ArgumentError (bad value for range)

This appears to be because it tries to find the string indexes of the domain part, and fails to do so. This should probably emit a more useful Mail-specific error.

Tested on Ruby 2.5.0 with mail 2.7.0

stefanwork commented 3 years ago

This appears to work properly with Ruby 2.7.