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

Trim surrounding single quotes in emails to support Outlook-style single-quotes around To: header weirdness #183

Merged
merged 6 commits into from
Feb 23, 2022

Conversation

CapnFelix
Copy link

@CapnFelix CapnFelix commented Feb 22, 2022

Outlook does add single quotes to emails sometimes which is not valid

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

We're seeing emails generated by outlook which do have surrounding single quote like this:
To: <'user@example.com'>
The fix does just trim those.

Issue on microsoft.com: https://answers.microsoft.com/en-us/outlook_com/forum/all/single-quote-marks-around-email-addresses-in/37122680-0ea2-46ed-bfeb-8f67d3441e5f

This is my first PR, so please let me know if did something wrong :)

Signed-off-by: Felix Krueger <felix.krueger@gressus.de>
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests strictly required to validate such a change: IMO not valid to accept a string within quotes as a valid Address anyway, as such kind of cleanup should occur wherever you input data into the system that uses Address::fromString()

src/Address.php Show resolved Hide resolved
@CapnFelix
Copy link
Author

Thanks for the quick feedback.
I agree that stripping it in ::fromString is not perfect, even though when looking at the caller stack, I'm not quite sure where to put this instead.

Message is loaded from IMAP in
Laminas\Mail\Storage\Imap->getMessage()
which is then calling \Laminas\Mail\Storage\Message
and then finally using \Laminas\Mail\Header\AbstractAddressList::fromString to generate the AddressList.
I think it would be possible to do the trimming here, but I would need to use the same reg ex to unpack the email address.
What do you think?

@Ocramius
Copy link
Member

Aha, the fact that it is loaded via IMAP is new info.

I wonder if it is possible to get one of the loaded raw messages as part of data provider entries for our test suite? That would make it clear that we're talking about a real-world IMAP use-case, and prevent future regressions.

Felix Krueger added 2 commits February 23, 2022 12:15
Signed-off-by: Felix Krueger <felix.krueger@gressus.de>
Signed-off-by: Felix Krueger <felix.krueger@gressus.de>
@CapnFelix
Copy link
Author

I am sorry, I should have provided this info in the initial description.
I've added a regression test to verify the change + added an example mail to the files folder.
Does this make sense?

Felix Krueger added 2 commits February 23, 2022 12:56
Signed-off-by: Felix Krueger <felix.krueger@gressus.de>
Signed-off-by: Felix Krueger <felix.krueger@gressus.de>
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests make sense to me, although the type errors reported by psalm should really be checked (see them on the diff).

As for the trim() call, I'm thinking that it should be moved into Message, rather than in Address. Rationale: Address::fromString() is used outside the context of Message too, while it looks like this Outlook IMAP oddity is only applicable when parsing messages in Outlook.

@CapnFelix
Copy link
Author

Maybe there is a small misunderstanding: We're looking at a message sent from an outlook client to a Gmail inbox. We're actually downloading this message via IMAP from Gmail in this case.
So I guess this is more a general problem not related to the storage since it is the email that is "wrong" no matter which protocol I'm using to download it.
But I can look into a way to do that fix in Message...

@CapnFelix
Copy link
Author

CapnFelix commented Feb 23, 2022

Some thoughts looking at it a little more in depths:
what the Address::fromString really does is extracting name and email from an address header value string. So I think it would make sense to enhance the extracting to be able to deal with the single quotes either by adjusting the preg_match or by doing the trimming.
When looking at the Message class I don't really have a good idea how to fix it there.
Let me know what you think!
Thanks!

@Ocramius
Copy link
Member

Reasoning seems fine: are you able to bring CI to green, so that somebody else can throw in a more informed review on whether putting this responsibility in Address is acceptable?

@Ocramius Ocramius added this to the 2.16.0 milestone Feb 23, 2022
@Ocramius Ocramius requested a review from a team February 23, 2022 14:24
@Slamdunk
Copy link
Contributor

Issue on microsoft.com: https://answers.microsoft.com/en-us/outlook_com/forum/all/single-quote-marks-around-email-addresses-in/37122680-0ea2-46ed-bfeb-8f67d3441e5f

I've read https://datatracker.ietf.org/doc/html/rfc5322 twice, and nowhere it allows <'foo@example.com'> as valid syntax 🤦

But as maintainer of ddeboer/imap it's no surprise to me

@Ocramius
Copy link
Member

Ok, so let's get it green, then merged

Signed-off-by: Felix Krueger <felix.krueger@gressus.de>
@CapnFelix
Copy link
Author

Awesome!
I am not familiar with psalm yet, but I think I got it to work :D

@CapnFelix CapnFelix removed their assignment Feb 23, 2022
@Ocramius Ocramius self-assigned this Feb 23, 2022
@Ocramius Ocramius changed the title trim surrounding single quotes in emails Trim surrounding single quotes in emails to support Outlook-style single-quotes around To: header weirdness Feb 23, 2022
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🚢

Thanks @CapnFelix! Releasing nao.

@Ocramius Ocramius merged commit 1ee1a38 into laminas:2.16.x Feb 23, 2022
@CapnFelix
Copy link
Author

Thank you so much! 🌊

artemii-karkusha pushed a commit to artemii-karkusha/laminas-mail that referenced this pull request May 24, 2023
…e-quotes

Trim surrounding single quotes in emails to support Outlook-style single-quotes around `To:` header weirdness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants