@@ -197,7 +197,7 @@ class Email
197197 *
198198 * @see http://www.ietf.org/rfc/rfc822.txt
199199 *
200- * @var "\r\ n"|"\n"
200+ * @var "\n"|"\r \n"
201201 */
202202 public $ CRLF = "\r\n" ;
203203
@@ -1335,14 +1335,22 @@ protected function appendAttachments(&$body, $boundary, $multipart = null)
13351335 */
13361336 protected function prepQuotedPrintable ($ str )
13371337 {
1338+ // We are intentionally wrapping so mail servers will encode characters
1339+ // properly and MUAs will behave, so {unwrap} must go!
13381340 $ str = str_replace (['{unwrap} ' , '{/unwrap} ' ], '' , $ str );
13391341
1342+ // RFC 2045 specifies CRLF as "\r\n".
1343+ // However, many developers choose to override that and violate
1344+ // the RFC rules due to (apparently) a bug in MS Exchange,
1345+ // which only works with "\n".
13401346 if ($ this ->CRLF === "\r\n" ) {
13411347 return quoted_printable_encode ($ str );
13421348 }
13431349
1350+ // Reduce multiple spaces & remove nulls
13441351 $ str = preg_replace (['| +| ' , '/\x00+/ ' ], [' ' , '' ], $ str );
13451352
1353+ // Standardize newlines
13461354 if (str_contains ($ str , "\r" )) {
13471355 $ str = str_replace (["\r\n" , "\r" ], "\n" , $ str );
13481356 }
@@ -1361,34 +1369,48 @@ protected function prepQuotedPrintable($str)
13611369 $ temp = '' ;
13621370 $ tempLen = 0 ;
13631371
1372+ // Loop through each character in the line to add soft-wrap
1373+ // characters at the end of a line " =\r\n" and add the newly
1374+ // processed line(s) to the output (see comment on $crlf class property)
13641375 for ($ i = 0 ; $ i < $ length ; $ i ++) {
13651376 $ char = $ line [$ i ];
13661377 $ ascii = ord ($ char );
13671378 $ charLen = 1 ;
13681379
1380+ // Convert spaces and tabs but only if it's the end of the line
13691381 if ($ ascii === 32 || $ ascii === 9 ) {
13701382 if ($ i === ($ length - 1 )) {
13711383 $ char = sprintf ('=%02X ' , $ ascii );
13721384 $ charLen = 3 ;
13731385 }
1374- } elseif ($ ascii === 61 || ! isset ($ asciiSafeChars [$ ascii ])) {
1386+ }
1387+ // DO NOT move this below the $ascii_safe_chars line!
1388+ //
1389+ // = (equals) signs are allowed by RFC2049, but must be encoded
1390+ // as they are the encoding delimiter!
1391+ elseif ($ ascii === 61 || ! isset ($ asciiSafeChars [$ ascii ])) {
13751392 $ char = sprintf ('=%02X ' , $ ascii );
13761393 $ charLen = 3 ;
13771394 }
13781395
1396+ // If we're at the character limit, add the line to the output,
1397+ // reset our temp variable, and keep on chuggin'
13791398 if (($ tempLen + $ charLen ) >= 76 ) {
13801399 $ output .= $ temp . '= ' . $ this ->CRLF ;
13811400 $ temp = '' ;
13821401 $ tempLen = 0 ;
13831402 }
13841403
1404+ // Add the character to our temporary line
13851405 $ temp .= $ char ;
13861406 $ tempLen += $ charLen ;
13871407 }
13881408
1409+ // Add our completed line to the output
13891410 $ output .= $ temp . $ this ->CRLF ;
13901411 }
13911412
1413+ // get rid of extra CRLF tacked onto the end
13921414 return static ::substr ($ output , 0 , static ::strlen ($ this ->CRLF ) * -1 );
13931415 }
13941416
0 commit comments