kimaniwamwangi / php-mime-mail-parser

Automatically exported from code.google.com/p/php-mime-mail-parser
0 stars 0 forks source link

Will not return email address when in format "name <user@domain>". #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Files are included to reproduce the error.

What is the expected output? What do you see instead?
I would expect the email address, or maybe an array with the name and email
address. Instead, it just returns the name.

What version of the product are you using? On what operating system?
Latest from trunk, (r15).

Please provide any additional information below.
None

Original issue reported on code.google.com by jbog91 on 31 Oct 2009 at 4:08

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
You must parse the address with mailparse_rfc822_parse_addresses.

public function getHeader($name) {
    if (isset($this->parts[1])) {
        $headers = $this->getPartHeaders($this->parts[1]);
        if (isset($headers[$name])) {
            if ($name == "from" || $name == "to") {
                //parse email address
                $part_email = mailparse_rfc822_parse_addresses($headers[$name]);
                $address = "";
                foreach ($part_email as $value)
                {
                    if ($address != "")
                        $address.=", ";

                    $address .= htmlspecialchars($value['display']." <".$value['address'].">");
                }
                return $address;
            }
            else
                return $headers[$name];
        }
    } else {
        throw new Exception('MimeMailParser::setPath() or MimeMailParser::setText() must be called before retrieving email headers.');
    }
    return false;
}

Original comment by palvoel...@gmail.com on 27 Aug 2010 at 5:30

GoogleCodeExporter commented 9 years ago
jbog91, I'm not able to reproduce the problem you're seeing. I've taken your 
two test files and run them and I get :

{{{
<pre>Array
(
    [to] => to@another-example.com
    [from] => Jay <from@example.com>
    [subject] => test
    [body] => testing testing do da do de do

)
</pre>
}}}

The "to and "from" values are captured correctly. I'm not seeing it "just 
return the name". I'm getting back "[from] => Jay <from@example.com>"

Palvoelgyi is correct that if you want to take the values returned and parse 
them into an array of their components, mailparse_rfc822_parse_addresses is the 
function to use.

I've done that in your test and it provides what you're looking for.

I think we probably shouldn't change the behavior within php-mime-mail-parser 
to provide an array of the email address components back instead of the string 
since it'll probably break existing installations.

I'll mark this as WontFix, but let me know if you're still having trouble.

Original comment by gene.wood.temp on 22 Oct 2010 at 4:51