ZF-8503: _formatAddress creates invalid format if Email and Name are both emailaddresses (different ones)

Description

If both arguments of _formatAddress are emailadresses, this function creates an invalid Header. Called like this: _formatAddress('jonas@email.de','jonas@email2.de') creates following return value: 'jonas@email2.de jonas@email.de' Using this value as a Headervalue like "From", the From-Field is displayed incorrect. In Outlook the header looks like 'From: "jonas@" <email2.de jonas@email.de>'

This is because the name should be quoted.

The easiest way to fix it is to change the function like this:


protected function _formatAddress($email, $name)
    {
        if ($name === '' || $name === null || $name === $email) {
            return $email;
        } else {
            $encodedName = $this->_encodeHeader($name);
            if ($encodedName === $name && (strpos($name, ',') !== false || strpos($name, '@') !== false)) {
                $format = '"%s" <%s>';
            } else {
                $format = '%s <%s>';
            }
            return sprintf($format, $encodedName, $email);
        }
    }

Greetings, Jonas

Comments

I think it may be Outlook problem. but I added some logic that you can handle name including at mark ;-)

SVN trunk r19608