From e86fbe321b15782d902d5492f2b2f6c78bd1d359 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Mon, 1 Oct 2018 01:46:01 +0200 Subject: [PATCH 1/1] add a workaround for when imap module is missing --- classes/email.php-class | 83 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/classes/email.php-class b/classes/email.php-class index 9853ba4..4f35aa2 100644 --- a/classes/email.php-class +++ b/classes/email.php-class @@ -315,7 +315,12 @@ class email { } private function mimeencode($fieldtext, $stringescape = false) { - $mText = imap_8bit($fieldtext); + if (function_exists('imap_8bit')) { + $mText = imap_8bit($fieldtext); + } + else { + $mText = quoted_printable_encode($fieldtext); + } $is_qpformat = ($mText != $fieldtext); if ($stringescape && preg_match('/[^\w !#$%&\'*+\/=?^`{|}~-]/', $mText)) { // if needed, make this a quoted-string instead of an atom (to speak in RFC2822 language) @@ -327,5 +332,81 @@ class email { } return $mText; } + + private function quoted_printable_encode($sText, $bEmulate_imap_8bit=true) { + /* by ...deed.ztinmehc-ut.zrh@umuumu@hrz.tu-chemnitz.deed... + from https://secure.php.net/manual/en/function.imap-8bit.php#61216 + + I use the following function instead of imap_8bit + when using PHP without the IMAP module, + which is based on code found in + http://www.php.net/quoted_printable_decode, + and giving (supposedly) exactly the same results as imap_8bit, + (tested on thousands of random strings containing lots + of spaces, tabs, crlf, lfcr, lf, cr and so on, + no counterexample found SO FAR:) + + AND you can force a trailing space to be encoded, + as opposed to what imap_8bit does, + which I consider is a violation of RFC2045, + (see http://bugs.php.net/bug.php?id=35290) + by commenting that one central line. + */ + // split text into lines + $aLines=explode(chr(13).chr(10),$sText); + + for ($i=0;$i -- 2.35.3