Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Un-deprecate quoted printable encoding, but move to separate class
Built-in quoted_printable_encode() method does not allow for specifying EOL or line-length. So keep a utility method around that wraps around the PHP Q-P stream filter that does handle these paramters.
- Loading branch information
Showing
4 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Copyright 2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Mime | ||
*/ | ||
|
||
/** | ||
* Quoted-printable utility methods. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package Mime | ||
* @since 2.5.0 | ||
*/ | ||
class Horde_Mime_QuotedPrintable | ||
{ | ||
/** | ||
* Decodes quoted-printable data. | ||
* | ||
* @param string $data The Q-P data to decode. | ||
* | ||
* @return string The decoded text. | ||
*/ | ||
static public function decode($data) | ||
{ | ||
return quoted_printable_decode($data); | ||
} | ||
|
||
/** | ||
* Encodes text via quoted-printable encoding. | ||
* | ||
* @param string $text The text to encode (UTF-8). | ||
* @param string $eol The EOL sequence to use. | ||
* @param integer $wrap Wrap a line at this many characters. | ||
* | ||
* @return string The quoted-printable encoded string. | ||
*/ | ||
static public function encode($text, $eol = "\n", $wrap = 76) | ||
{ | ||
$fp = fopen('php://temp', 'r+'); | ||
stream_filter_append( | ||
$fp, | ||
'convert.quoted-printable-encode', | ||
STREAM_FILTER_WRITE, | ||
array( | ||
'line-break-chars' => $eol, | ||
'line-length' => $wrap | ||
) | ||
); | ||
fwrite($fp, $text); | ||
rewind($fp); | ||
$out = stream_get_contents($fp); | ||
fclose($fp); | ||
|
||
return $out; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters