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

Error while parsing non RFC 822 From Header #148

Closed
andrea-reda opened this issue Nov 10, 2020 · 4 comments
Closed

Error while parsing non RFC 822 From Header #148

andrea-reda opened this issue Nov 10, 2020 · 4 comments
Labels

Comments

@andrea-reda
Copy link

I have an mail with Friendly From Header escaped using single quote:

From: "Intuit E-Commerce Service" quickbooks@notification.intuit.com

I got an error when trying to retrieve the Person Name

`$parsed = $this->parseHeaders();

if (null === $fromHeader = $parsed->getHeader('from')) {
return null;
}
if (!$fromHeader instanceof AddressHeader) {
return null;
}

return $fromHeader->getPersonName() ?: null;`

Attempted to call an undefined method named "getName" of class "ZBateson\MailMimeParser\Header\Part\Token".

if (!empty($this->parts)) { return $this->parts[0]->getName(); }

This is the dump of the object $this->parts:

AddressHeader.php on line 124: array:2 [▼ 0 => Token {#488 ▼ #value: """ #charsetConverter: MbWrapper {#475 ▼ #mappedMbCharsets: array:3 [▼ "UTF8" => "UTF-8" "USASCII" => "US-ASCII" "ISO88591" => "ISO-8859-1" ] } } 1 => AddressPart {#501 ▼ #name: "Intuit E-Commerce Service"" #language: null #canIgnoreSpacesBefore: false #canIgnoreSpacesAfter: false #languages: array:1 [▼ 0 => array:2 [▼ "lang" => null "value" => "Intuit E-Commerce Service"" ] ] #value: "quickbooks@notification.intuit.com" #charsetConverter: MbWrapper {#475 ▶} } ]

I don't know if you can consider also the " as separator (I have tried to add it to the QuotedStringConsumer with no success), or simply manage the error returning an empty Person Name

@zbateson
Copy link
Owner

Hi @andrea-reda --

I think github isn't showing exactly what your headers are... clicking 'Edit' on your message, they look a little different. This would be a valid from header (and the double quotes would trigger the QuotedStringConsumer):

From: "Intuit E-Commerce Service" <quickbooks@notification.intuit.com>

and is very much supported, and is RFC compliant, etc...

On the other hand, this isn't:

From: \"Intuit E-Commerce Service\" <quickbooks@notification.intuit.com>

The backslash means the next character should be treated as-is (i.e. not the beginning of a quoted part). It looks to me like there's an issue with how I'm separating 'name' from 'email', and it should be done a little differently in case of a problem like this. What's happening is my processor takes the backslash and makes the next character it's own 'token' so it's not processed by any other processors, which is fine, but then that's the first part returned in the call to getPersonName (the " character).

@zbateson zbateson added the bug label Nov 10, 2020
@andrea-reda
Copy link
Author

HI @zbateson , first of all thank you for the reply.

Yes, it's exactly what I mean. With this kind of friendly from between "backslash-quote", the array of part have at position 0 the token " and at position 1 the object of type AddressHeader (or something similar, I don't remember now) with the name Intuit E-Commerce Service".

What I do as workaround was not call getPersonName, but "foreach" manually the array returned from the method getParts to retrieve the correct object.

I don't know if the best way is to parse this kind of header even if it's malformed, or simply do not return nothing with the getPersonName and leaving the possibility of still having the raw part with a separate method.

@zbateson
Copy link
Owner

I mean, it's not strictly correct, but yeah it shouldn't cause an error. I don't think it'll be a big deal to allow that to work, but I'll have to investigate a bit and see :)

@zbateson
Copy link
Owner

zbateson commented Dec 8, 2020

Released in 1.3.0

@zbateson zbateson closed this as completed Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants