From a21b365848ce74a4f8d72ccf13eb733b1ba32f59 Mon Sep 17 00:00:00 2001 From: Platonides Date: Wed, 8 Dec 2010 23:09:29 +0000 Subject: [PATCH] Move wfQuotedPrintable() into UserMailer class --- includes/GlobalFunctions.php | 24 ----------------------- includes/UserMailer.php | 38 +++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index c42a8a7b71..aad2da906a 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1296,30 +1296,6 @@ function wfEscapeWikiText( $text ) { return $text; } -/** - * @todo document - */ -function wfQuotedPrintable( $string, $charset = '' ) { - # Probably incomplete; see RFC 2045 - if( empty( $charset ) ) { - global $wgInputEncoding; - $charset = $wgInputEncoding; - } - $charset = strtoupper( $charset ); - $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ? - - $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff='; - $replace = $illegal . '\t ?_'; - if( !preg_match( "/[$illegal]/", $string ) ) { - return $string; - } - $out = "=?$charset?Q?"; - $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string ); - $out .= '?='; - return $out; -} - - /** * @todo document * @return float diff --git a/includes/UserMailer.php b/includes/UserMailer.php index c15843d948..1d0f99f4ab 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -58,7 +58,7 @@ class MailAddress { if ( $this->name != '' && !wfIsWindows() ) { global $wgEnotifUseRealName; $name = ( $wgEnotifUseRealName && $this->realName ) ? $this->realName : $this->name; - $quoted = wfQuotedPrintable( $name ); + $quoted = UserMailer::quotedPrintable( $name ); if ( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) { $quoted = '"' . $quoted . '"'; } @@ -162,7 +162,7 @@ class UserMailer { if ( $replyto ) { $headers['Reply-To'] = $replyto->toString(); } - $headers['Subject'] = wfQuotedPrintable( $subject ); + $headers['Subject'] = self::quotedPrintable( $subject ); $headers['Date'] = date( 'r' ); $headers['MIME-Version'] = '1.0'; $headers['Content-type'] = ( is_null( $contentType ) ? @@ -225,10 +225,10 @@ class UserMailer { if ( is_array( $to ) ) { foreach ( $to as $recip ) { - $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); + $sent = mail( $recip->toString(), self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); } } else { - $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); + $sent = mail( $to->toString(), self::quotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams ); } restore_error_handler(); @@ -264,6 +264,29 @@ class UserMailer { $phrase = strtr( $phrase, array( "\r" => '', "\n" => '', '"' => '' ) ); return '"' . $phrase . '"'; } + + /** + * Converts a string into quoted-printable format + */ + public static function quotedPrintable( $string, $charset = '' ) { + # Probably incomplete; see RFC 2045 + if( empty( $charset ) ) { + global $wgInputEncoding; + $charset = $wgInputEncoding; + } + $charset = strtoupper( $charset ); + $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ? + + $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff='; + $replace = $illegal . '\t ?_'; + if( !preg_match( "/[$illegal]/", $string ) ) { + return $string; + } + $out = "=?$charset?Q?"; + $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string ); + $out .= '?='; + return $out; + } } /** @@ -642,4 +665,9 @@ function userMailer( $to, $from, $subject, $body, $replyto = null ) { wfDeprecated( __FUNCTION__ ); return UserMailer::send( $to, $from, $subject, $body, $replyto ); } -/**@}*/ \ No newline at end of file + +function wfQuotedPrintable( $string, $charset = '' ) { + wfDeprecated( __FUNCTION__ ); + return UserMailer::quotedPrintable( $string, $charset ); +} +/**@}*/ -- 2.20.1