Skip to content

Commit

Permalink
Un-deprecate quoted printable encoding, but move to separate class
Browse files Browse the repository at this point in the history
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
slusarz committed Oct 1, 2014
1 parent 213b8b7 commit 064ede6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 22 deletions.
4 changes: 3 additions & 1 deletion framework/Mime/doc/Horde/Mime/UPGRADING
Expand Up @@ -45,7 +45,8 @@ Upgrading to 2.5
- quotedPrintableEncode()

This method is deprecated. Use PHP's quoted_printable_encode() method
instead.
instead (or, if you need to control EOL and/or wrapping length, use
Horde_Mime_QuotedPrintable::encode()).

- uudecode()

Expand All @@ -60,6 +61,7 @@ Upgrading to 2.5
- Horde_Mime_ContentParam
- Horde_Mime_ContentParam_Decode
- Horde_Mime_Id
- Horde_Mime_QuotedPrintable
- Horde_Mime_Uudecode

These classes were added.
Expand Down
19 changes: 2 additions & 17 deletions framework/Mime/lib/Horde/Mime.php
Expand Up @@ -372,27 +372,12 @@ static public function isChild($base, $id)
}

/**
* @deprecated Use quoted_printable_encode() instead.
* @deprecated Use Horde_Mime_QuotedPrintable instead.
*/
static public function quotedPrintableEncode($text, $eol = self::EOL,
$wrap = 76)
{
$fp = fopen('php://temp', 'r+');
stream_filter_append(
$fp,
'convert.quoted-printable-encode',
STREAM_FILTER_WRITE,
array(
'line-break-chars' => self::EOL,
'line-length' => $wrap
)
);
fwrite($fp, $text);
rewind($fp);
$out = stream_get_contents($fp);
fclose($fp);

return $out;
return strval(new Horde_Mime_QuotedPrintable($text, $eol, $wrap));
}

}
67 changes: 67 additions & 0 deletions framework/Mime/lib/Horde/Mime/QuotedPrintable.php
@@ -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;
}

}
10 changes: 6 additions & 4 deletions framework/Mime/package.xml
Expand Up @@ -17,7 +17,7 @@
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
<date>2014-09-25</date>
<date>2014-09-30</date>
<version>
<release>2.5.0</release>
<api>2.5.0</api>
Expand All @@ -29,7 +29,7 @@
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Improved MIME encoding.
* [mms] Horde_Mime::quotedPrintableEncode() is deprecated.
* [mms] Deprecated Horde_Mime::quotedPrintableEncode() and move to Horde_Mime_QuotedPrintable.
* [mms] Moved MIME ID manipulation/query methods out of Horde_Mime and into Horde_Mime_Id.
* [mms] Use string-based ABNF-based parser for scanning MIME content parameters instead of a regular expression (Bug #13587).
* [mms] Moved content parameter handling methods out of Horde_Mime and into Horde_Mime_ContentParam.
Expand Down Expand Up @@ -62,6 +62,7 @@
<file name="Mdn.php" role="php" />
<file name="mime.mapping.php" role="php" />
<file name="Part.php" role="php" />
<file name="QuotedPrintable.php" role="php" />
<file name="Related.php" role="php" />
<file name="Translation.php" role="php">
<tasks:replace from="@data_dir@" to="data_dir" type="pear-config" />
Expand Down Expand Up @@ -493,6 +494,7 @@
<install as="Horde/Mime/Mdn.php" name="lib/Horde/Mime/Mdn.php" />
<install as="Horde/Mime/mime.mapping.php" name="lib/Horde/Mime/mime.mapping.php" />
<install as="Horde/Mime/Part.php" name="lib/Horde/Mime/Part.php" />
<install as="Horde/Mime/QuotedPrintable.php" name="lib/Horde/Mime/QuotedPrintable.php" />
<install as="Horde/Mime/Related.php" name="lib/Horde/Mime/Related.php" />
<install as="Horde/Mime/Translation.php" name="lib/Horde/Mime/Translation.php" />
<install as="Horde/Mime/Uudecode.php" name="lib/Horde/Mime/Uudecode.php" />
Expand Down Expand Up @@ -1454,11 +1456,11 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2014-09-25</date>
<date>2014-09-30</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Improved MIME encoding.
* [mms] Horde_Mime::quotedPrintableEncode() is deprecated.
* [mms] Deprecated Horde_Mime::quotedPrintableEncode() and move to Horde_Mime_QuotedPrintable.
* [mms] Moved MIME ID manipulation/query methods out of Horde_Mime and into Horde_Mime_Id.
* [mms] Use string-based ABNF-based parser for scanning MIME content parameters instead of a regular expression (Bug #13587).
* [mms] Moved content parameter handling methods out of Horde_Mime and into Horde_Mime_ContentParam.
Expand Down

0 comments on commit 064ede6

Please sign in to comment.