1

Topic: Email verification - error 451

Ok, firstly I'm aware this has been brought up before and supposidly "fixed" but the issue is still present in 1.2.7.

I've looked at the source and fixed it for myself but I'm wondering why it is you attempt to use different line breaks for different OS'? (lines 79-84 of include/email.php)

Firstly, the server PHP is running on in most cases will not be the same as the SMTP server, so they way it is determined could produce bad results. For example, if indeed it did matter that for instance mac MTA's only accepted "\r", and you were using a win php server for punbb but set it to use the mac as smtp server. You'd end up with "\r\n" being sent to the mac.

Secondly, any standards compliant MTA will allow "\r\n" breaks in headers over SMTP sessions (different story to it being piped through a CLI program, as with mail() on *nix), so I don't see why not just make all headers end with "\r\n" as done with the main message body.

-- Tx

P.S. The reason qmail rejects this is becasue it's fully standards compliant (painfully so according to some) and doesn't even bother to fix invalid input (it easily could) out of principal. Standards are here to be used, not ignored.... just an answer since you seem genuinly baffled as to why in previous posts

P.P.S. See section 3.1.2 of RFC822 if you need confirmation of header syntax.

Re: Email verification - error 451

Thanks for bringing this up again. I am aware that it isn't properly fixed and I was going to have a look at it. However, just putting CRLF line breaks everywhere won't work. The problem is that, most of the time, mail() isn't talking to an SMTP server, it's talking to a command line program running on the server. That command line program expects linebreaks that are native to the operating system on which it is running. Have a look at PHP Bug #15841.

The implementation we have now is in my opinion the most sensible. The only time mail() will be talking directly to an SMTP server is if we're running Windows and then we feed it proper CRLF's. If we aren't running Windows, we know mail() will be talking to a command line program and thus, we use the OS's native line breaks.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3 (edited by Tx 2005-09-17 21:23)

Re: Email verification - error 451

Rickard wrote:

Thanks for bringing this up again. I am aware that it isn't properly fixed and I was going to have a look at it. However, just putting CRLF line breaks everywhere won't work. The problem is that, most of the time, mail() isn't talking to an SMTP server, it's talking to a command line program running on the server. That command line program expects linebreaks that are native to the operating system on which it is running. Have a look at PHP Bug #15841.

Yes I've seen the bug but forgive me if I'm wrong but don't you use your own socket code to transmit emails if an smtp server is given? mail() should only be being used if that's blank, and yes, in that case it would be neccesary to alter the line breaks

edit: a ha, I see what's going on. you use a generic wrapper that then either calls mail() or smtp_mail(). prehaps the following...?

        // Detect what linebreak we should use for the headers
        if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
                $eol = "\r\n";
        else if (strtoupper(substr(PHP_OS, 0, 3) == 'MAC'))
                $eol = "\r";
        else
                $eol = "\n";

        $headers = 'From: '.$from.$eol.'Date: '.date('r').$eol.'MIME-Version: 1.0'.$eol.'Content-transfer-encoding: 8bit'.$eol.'Content-type: text/plain; c

        // Make sure all linebreaks are CRLF in message
        $message = str_replace("\n", "\r\n", pun_linebreaks($message));

        if ($pun_config['o_smtp_host'] != '')
                smtp_mail($to, $subject, $message, $headers);
        else
                mail($to, $subject, $message, $headers);

to

        $eol = "\r\n";
        $headers = 'From: '.$from.$eol.'Date: '.date('r').$eol.'MIME-Version: 1.0'.$eol.'Content-transfer-encoding: 8bit'.$eol.'Content-type: text/plain; c

        // Make sure all linebreaks are CRLF in message
        $message = str_replace("\n", "\r\n", pun_linebreaks($message));

        if ($pun_config['o_smtp_host'] != '')
                smtp_mail($to, $subject, $message, $headers);
        else {
                // Detect what linebreak we should use for the headers.
                if (strtoupper(substr(PHP_OS, 0, 3) == 'MAC'))
                        $eol = "\r";
                else if (strtoupper(substr(PHP_OS, 0, 3) != 'WIN'))
                        $eol = "\n";

                $headers = str_replace("\r\n", $eol, pun_linebreaks($headers));

                mail($to, $subject, $message, $headers);
        }

Re: Email verification - error 451

Ah, I forgot about my homegrown SMTP code. I don't think a lot of people use it though. It's only there as a last resort if the server's PHP environment, for some odd reason, does not support mail(). I will fix it for the next release.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

5

Re: Email verification - error 451

oh and oops, soory but see above edit

Re: Email verification - error 451

Yes, something like that looks good.

"Programming is like sex: one mistake and you have to support it for the rest of your life."