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

Mail::AddressList cannot parse CC header value #1591

Open
carlhauck opened this issue Nov 1, 2023 · 0 comments
Open

Mail::AddressList cannot parse CC header value #1591

carlhauck opened this issue Nov 1, 2023 · 0 comments

Comments

@carlhauck
Copy link

Here's how we're retrieving email objects from AWS S3 and then using the mail gem to parse them:

s3_object = Aws::S3::Client.new.get_object(bucket: bucket_name, key: s3_object_key)
mail = Mail.read_from_string(s3_object.body.read)

Here's an anonymized copy of a CC mail header we encountered this week:

#<Mail::Field 0x441b0 @name="Cc" @unparsed_value="Umi Anon <umi_anon@somecompany.com>, Allison Who\r\n\t<allison_who@somecompany.com>, \"gabby.where@other.com.\"\r\n\t<gabby.where@other.com.>" @charset="UTF-8" @field=#<Mail::UnstructuredField:0x00007f029fbbda48 @errors=[["Cc", "Umi Anon <umi_anon@somecompany.com>, Allison Who\r\n\t<allison_who@somecompany.com>, \"gabby.where@other.com.\"\r\n\t<gabby.where@other.com.>", #<Mail::Field::IncompleteParseError: Mail::AddressList can not parse |Umi Anon <umi_anon@somecompany.com>, Allison Who	<allison_who@somecompany.com>, "gabby.where@other.com."	<gabby.where@other.com.>|: Only able to parse up to "Umi Anon <umi_anon@somecompany.com>, Allison Who\t<allison_who@somecompany.com>, \"gabby.where@other.com.\"\t<gabby.where@other.com.">]], @name="Cc", @element=nil, @value="Umi Anon <umi_anon@somecompany.com>, Allison Who\r\n\t<allison_who@somecompany.com>, \"gabby.where@other.com.\"\r\n\t<gabby.where@other.com.>", @charset=#<Encoding:UTF-8>> @field_order_id=14>

As you can see, there's a Mail::Field::IncompleteParseError in the header itself, and we're ultimately receiving a string value from @mail.cc instead of an array of strings.

We were able to reproduce the error by mimicking some of the mail gem code:

class_name = Mail.const_get('CcField')
unfolded_anon = "Umi Anon <umi_anon@somecompany.com>, Allison Who\r\n\t<allison_who@somecompany.com>,
 \"gabby.where@other.com.\"\r\n\t<gabby.where@other.com.>".gsub(UNFOLD_WS, '\1')

class_name.parse(unfolded_anon, 'utf-8')
/usr/local/bundle/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:33233:in `parse': Mail::AddressList can not parse |Umi Anon <umi_anon@somecompany.com>, Allison Who	<allison_who@somecompany.com>, "gabby.where@other.com."	<gabby.where@other.com.>|: Only able to parse up to "Umi Anon <umi_anon@somecompany.com>, Allison Who\t<allison_who@somecompany.com>, \"gabby.where@other.com.\"\t<gabby.where@other.com." (Mail::Field::IncompleteParseError)
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