Move wfQuotedPrintable() into UserMailer class
authorPlatonides <platonides@users.mediawiki.org>
Wed, 8 Dec 2010 23:09:29 +0000 (23:09 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Wed, 8 Dec 2010 23:09:29 +0000 (23:09 +0000)
includes/GlobalFunctions.php
includes/UserMailer.php

index c42a8a7..aad2da9 100644 (file)
@@ -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
index c15843d..1d0f99f 100644 (file)
@@ -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 );
+}
+/**@}*/