From: Robert Kaiser Date: Sun, 30 Sep 2018 23:46:01 +0000 (+0200) Subject: add a workaround for when imap module is missing X-Git-Url: https://git-public.kairo.at/?a=commitdiff_plain;h=e86fbe321b15782d902d5492f2b2f6c78bd1d359;p=php-utility-classes.git add a workaround for when imap module is missing --- 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