Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address list with comment before address parses incorrectly if no space after comma #1578

Open
HermanHiddema opened this issue May 9, 2023 · 0 comments

Comments

@HermanHiddema
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant