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
Comments
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):
and is very much supported, and is RFC compliant, etc... On the other hand, this isn't:
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). |
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 What I do as workaround was not call getPersonName, but "foreach" manually the array returned from the method 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. |
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 :) |
Released in 1.3.0 |
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
The text was updated successfully, but these errors were encountered: