+
+ /**
+ * Converts a string into quoted-printable format
+ * @since 1.17
+ */
+ public static function quotedPrintable( $string, $charset = '' ) {
+ # Probably incomplete; see RFC 2045
+ if( empty( $charset ) ) {
+ $charset = 'UTF-8';
+ }
+ $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_callback( "/([$replace])/",
+ array( __CLASS__, 'quotedPrintableCallback' ), $string );
+ $out .= '?=';
+ return $out;
+ }
+
+ protected static function quotedPrintableCallback( $matches ) {
+ return sprintf( "=%02X", ord( $matches[1] ) );
+ }