Welcome Guest, Not a member yet? Register   Sign In
invalid email From: header syntax per RFC 822
#1

[eluser]Moobies[/eluser]
Hey,

I think I've stumbled upon a bug with the Email library of CI, latest version 1.7.

I am using Mercury as a localhost SMTP server as part of XAMPP and it throws 501 Bad recipient address syntax errors at me.

I have dug a little deeper and found that CI is sending what appears to be a bad From: header syntax.

The correct syntax for From headers as far as I can make out from the RFC is

From: [email protected]
From: Code Igniter <[email protected]>
From: [email protected], john@Smith.com

If I use CI->email->send("[email protected]") then CI sends

From: <[email protected]>

And CI->email->send("[email protected]", "Code Igniter") sends

From: "Code Igniter" <[email protected]>

Both of which are syntactically wrong, or if not wrong they do not match the syntax I have found from the RFC and the mail server I am sending to does not like it either.

If I modify the CI source for the from function to account for the syntax.

Code:
function from($from, $name = '')
    {
        if (preg_match( '/\<(.*)\>/', $from, $match))
        {
            $from = $match['1'];
        }
        
        $return_path = $from;

        if ($this->validate)
        {
            $this->validate_email($this->_str_to_array($from));
        }

        // prepare the display name
        if ($name != '')
        {
            // only use Q encoding if there are characters that would require it
            if ( ! preg_match('/[\200-\377]/', $name))
            {
                // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
                $name = addcslashes($name, "\0..\37\177'\"\\");
            }
            else
            {
                $name = $this->_prep_q_encoding($name, TRUE);
            }
            
            $from = ' <'.$from.'>';
        }

        $this->_set_header('From', $name.$from);
        $this->_set_header('Return-Path', '<'.$return_path.'>');
    }

This produces

[From] => [email protected]
[Return-Path] => <[email protected]>

Which works when not using a name in the from() call.

The above function, when using a name to the from() function will produce as per the syntax

[From] => Code Ingiter <[email protected]>
[Return-Path] => <[email protected]>

However, this still breaks the mail server and I get the 501 error again despite this matching the correct syntax.

So not too sure about what is happening when using a from name.

Any ideas/suggestions? Am I wrong about the syntax here or is there an issue going on?

Cheers
#2

[eluser]Michael Wales[/eluser]
RFC 2822 made RFC 822 obsolete and introduced the patterns you are seeing in CodeIgniter's output (RFC 2822 is obsolete as well, RFC 5322 is the latest).

The patterns <[email protected]> and "A User" <[email protected]> are both valid according to the addr-spec (Example A.1.2 features both of these formats in addition to others).

I'm leaning to Mercury being misconfigured (or maybe an older version of Mercury, but I doubt that RFC 2822 was released in April 2001).




Theme © iAndrew 2016 - Forum software by © MyBB