Address list with comment before address parses incorrectly if no space after comma
HermanHiddema opened this issue · comments
Given the following five examples:
Mail::AddressList.new("name1@example.com,name2@example.com")
Mail::AddressList.new("(comment) name1@example.com,name2@example.com")
Mail::AddressList.new("name1@example.com,(comment) name2@example.com")
Mail::AddressList.new("name1@example.com, (comment) name2@example.com")
Mail::AddressList.new("name1@example.com,(comment) name2@example.com,name3@example.com")
If I run these, I get weird results on case 3 and case 5:
[1] pry(main)> require 'mail';
[2] pry(main)> Mail::AddressList.new("name1@example.com,name2@example.com")
=> #<Mail::AddressList:0x000055ca6eb5a638
@addresses=
[#<Mail::Address:940 Address: |name1@example.com| >,
#<Mail::Address:960 Address: |name2@example.com| >],
@group_names=[]>
[3] pry(main)> Mail::AddressList.new("(comment) name1@example.com,name2@example.com")
=> #<Mail::AddressList:0x000055ca6ea2e6d8
@addresses=
[#<Mail::Address:980 Address: |"(comment)" <name1@example.com> (comment)| >,
#<Mail::Address:1000 Address: |name2@example.com| >],
@group_names=[]>
[4] pry(main)> Mail::AddressList.new("name1@example.com,(comment) name2@example.com")
=> #<Mail::AddressList:0x000055ca6e976970
@addresses=[#<Mail::Address:1020 Address: |name1@example.com| >],
@group_names=[]>
[5] pry(main)> Mail::AddressList.new("name1@example.com, (comment) name2@example.com")
=> #<Mail::AddressList:0x000055ca6e86dd08
@addresses=
[#<Mail::Address:1040 Address: |name1@example.com| >,
#<Mail::Address:1060 Address: |"(comment)" <name2@example.com> (comment)| >],
@group_names=[]>
[6] pry(main)> Mail::AddressList.new("name1@example.com,(comment) name2@example.com,name3@example.com")
=> #<Mail::AddressList:0x000055ca6e799ee0
@addresses=
[#<Mail::Address:1080 Address: |name1@example.com| >,
#<Mail::Address:1100 Address: |"(comment)" <name3@example.com> (comment)| >],
@group_names=[]>
Cases 2 and 3 are identical, except that the addresses have been swapped, so I'd expect it to work.
The fact that case 4 is correct, means that the parser is sensitive to the white space behind the comma after the first address.
Case 5 really shows that the parser gets confused, it adds the comment from the second address to the third one.