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


Messages In This Thread
invalid email From: header syntax per RFC 822 - by El Forum - 05-11-2009, 09:28 AM
invalid email From: header syntax per RFC 822 - by El Forum - 05-11-2009, 01:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB