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

EmailAddress::__toString() fails if there the sender/recipient name contains a colon #96

Closed
vmattila opened this issue Oct 19, 2015 · 4 comments
Milestone

Comments

@vmattila
Copy link

Consider following From: header of a message From: Something: Somewhere <[email protected]>. When this kind of message is read, PHP Catchable fatal error: Method Ddeboer\Imap\Message\EmailAddress::__toString() must return a string value is thrown.

It seems that PHP's native imap_headerinfo() parses this kind of address line incorrectly. When putting print_r($value) to the header parsing script vendor/ddeboer/imap/src/Message/Headers.php the output is:

Array
(
    [0] => stdClass Object
        (
            [mailbox] => Something
        )

    [1] => stdClass Object
        (
            [personal] => Somewhere
            [mailbox] => example
            [host] => example.com
        )

    [2] => stdClass Object
        (
        )

)
@ddeboer
Copy link
Owner

ddeboer commented Dec 14, 2015

Thanks for the bug report. Are such From: headers valid? If so, would you like to open a PR to fix this?

@Slamdunk
Copy link
Collaborator

Yes such From header is valid, but the spaces should be escaped.

@vmattila can you provide the original raw message headers?

@vmattila
Copy link
Author

I think I do not have the original message anymore to copy-paste the raw headers here.

As it has been a while since last update, I searched through the codebase and could not find imap_headerinfo() call anywhere. Before anybody gets confused as I was, must clarify that https://github.com/ddeboer/imap/blob/master/src/Message.php#L184 imap_header() is alias to imap_headerinfo() . ;)

Slamdunk added a commit that referenced this issue Sep 28, 2017
Parse all email type headers
Closes #96 #135
@Slamdunk Slamdunk added this to the 1.0 milestone Sep 28, 2017
@Slamdunk
Copy link
Collaborator

In #199 we've put into test a standard complex email address:

Cc: "This one: is \"right\"" <[email protected]>, No-address

The format without the double-quotes is not valid and we can't do anything to fix it (except complex parsing of raw headers or throwing away the imap extension).
We have removed the __toString() function: use the getAddress() from now so at least you can catch handle graceful the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants