Skip to content

Mail::Parser::AddressListsParser removes intentional escaping from address display names #1656

@MattSNZ

Description

@MattSNZ

There is a long-standing issue with Microsoft email servers (Outlook.com and enterprise) causing DKIM checks to fail by adding double-quotes to email address fields with display names: to: "Joe Bloggs <joe.bloggs@example.com>" becomes to: "Joe Bloggs"<joe.bloggs@example.com>, for example.

Due to this my org is trying to double-quote all display names when sending emails to prevent the header change causing the DKIM check to fail. We've updated our mailers so that the relevant addresses are passed with escaped double-quotes into the relevant address fields on the mail method. On Mail::Field.unparsed_value it's showing with the double-quotes however they're still being parsed without the double quotes on the Mail::Address object. I've tracked the change down to the AddressListsParser, but that's where I get stuck.

Expected behavior

The AddressListsParser parser should leave escaped strings escaped.

parsed_address = Mail::Parsers::AddressListsParser.parse("\"Foo Bar\" <foo.bar@example.com>")
parsed_address.addresses.first.display_name
=>"\"Foo Bar\" <foo.bar@example.com>"

Actual behavior

The parser removes the escaped quotes if there are no special characters.

parsed_address = Mail::Parsers::AddressListsParser.parse("\"Foo Bar\" <foo.bar@example.com>")
parsed_address.addresses.first.display_name
=>"Foo Bar <foo.bar@example.com>"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions