[bbDev] [1043] trunk/bb-includes/pluggable.php: Fixes for bb_mail()

Michael D Adams mikea at turbonet.com
Fri Jan 18 18:46:48 GMT 2008


Has this been a problem or did you just notice the error in the code?

We should watch this.  While \r\n is technically correct, I can recall  
anecdotal evidence that most MTAs correct for it on the fly and that  
some actually break when given these correct line endings.

See note: http://us3.php.net/manual/en/function.mail.php
And bug: http://bugs.php.net/bug.php?id=15841 which claims that the  
issue is not related to RFCs but rather to interfacing with unix  
commands that expect native line endings.


On Jan 18, 2008, at 3:17 AM, m at wordpress.org wrote:

> Revision
> 1043
> Author
> sambauers
> Date
> 2008-01-18 11:17:48 +0000 (Fri, 18 Jan 2008)
> Log Message
>
> Fixes for bb_mail()
>
> Delimiter between header fields should be \r\n
>
> Calling old $bb->domain variable
> Modified Paths
>
> trunk/bb-includes/pluggable.php
> Diff
>
> Modified: trunk/bb-includes/pluggable.php (1042 => 1043)
> --- trunk/bb-includes/pluggable.php	2008-01-17 18:21:48 UTC (rev 1042)
> +++ trunk/bb-includes/pluggable.php	2008-01-18 11:17:48 UTC (rev 1043)
> @@ -510,23 +510,21 @@
>
>  if ( !function_exists( 'bb_mail' ) ) :
>  function bb_mail( $to, $subject, $message, $headers = '' ) {
> -	$headers = trim($headers);
> -
> -	if ( !preg_match( '/^from:\s/im', $headers ) ) {
> -		$from = parse_url( bb_get_option( 'domain' ) );
> -		if ( !$from || !$from['host'] ) {
> -			$from = '';
> -		} else {
> -			$from_host = $from['host'];
> -		        if ( substr( $from_host, 0, 4 ) == 'www.' )
> -		                $from_host = substr( $from_host, 4 );
> -			$from = 'From: "' . bb_get_option( 'name' ) . '" <bbpress@' .  
> $from_host . '>';
> -		}
> -		$headers .= "\n$from";
> +	if (!is_array($headers)) {
>  		$headers = trim($headers);
> +		$headers = preg_split('@\r(?:\n{0,1})|\n@', $headers);
>  	}
> -
> -	return @mail( $to, $subject, $message, $headers );
> +	
> +	if (!count($headers) || !count(preg_grep('/^from:\s/im',  
> $headers))) {
> +		$from = parse_url(bb_get_option('uri'));
> +		if ($from && $from['host']) {
> +			$from = trim(preg_replace('/^www./i', '', $from['host']));
> +			$headers[] = 'From: "' . bb_get_option('name') . '" <bbpress@' .  
> $from . '>';
> +		}
> +	}
> +	$headers = trim(join("\r\n", $headers));
> +	
> +	return @mail($to, $subject, $message, $headers);
>  }
>  endif;
>
> _______________________________________________
> bbDev mailing list
> bbDev at lists.bbpress.org
> http://lists.bbpress.org/mailman/listinfo/bbdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://comox.textdrive.com/pipermail/bbdev/attachments/20080118/ad9e2ff4/attachment.htm


More information about the bbDev mailing list