mail icon indicating copy to clipboard operation
mail copied to clipboard

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

Open ticky opened this issue 7 years ago • 1 comments

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

ticky avatar Jun 26 '18 01:06 ticky

This appears to work properly with Ruby 2.7.

stefanwork avatar Dec 31 '20 00:12 stefanwork