# HG changeset patch # User wolfgang.scherer@gmx.de # Date 2012-03-30 18:20:52 # Node ID fad285782be80dfff3dc150027b9472560efa1bb # Parent 80ff2ac9be1c2f0fe9fc51c690978bfc71c5eca4 lib/util.php: poor man's quoted_printable_encode for PHP < 5.30. diff --git a/lib/util.php b/lib/util.php --- a/lib/util.php +++ b/lib/util.php @@ -248,6 +248,37 @@ function error_msg($message) // |||:sec:||| vaccation(1) message // -------------------------------------------------- +if (!function_exists("quoted_printable_encode")) { + // only available with PHP >= 5.3.0 + if (function_exists("imap_8bit")) { + function quoted_printable_encode($string) { + return imap_8bit($string); + } + } else { + /** + * Process a string to fit the requirements of RFC2045 section 6.7. Note that + * this works, but replaces more characters than the minimum set. For readability + * the spaces and CRLF pairs aren't encoded though. + */ + function quoted_printable_encode($string) { + $string = str_replace(array('%20', '%0D%0A', '%'), array(' ', "\r\n", '='), rawurlencode($string)); + $string = preg_replace('/[^\r\n]{73}[^=\r\n]{2}/', "$0=\r\n", $string); + return $string; + } + } +} + +// there should be no need ... quoted_printable_decode is around since PHP4 +if (!function_exists("quoted_printable_decode")) { + if (function_exists("imap_qprint")) { + echo "imap_qprint"; + function quoted_printable_decode($string) { + return imap_qprint($string); + } + } else { + } +} + function vacation_split($message, $decode) { $lines = explode("\n", $message);