From 1a6a1c042a16fc7ed8be4d870dbf32d60c05560b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 20:50:58 +0100 Subject: Revert "use CRLF in quoted printable encoding FS#1755" This research suggests that, the change does not help, but in fact breaks previoulsy working setups: https://bugs.dokuwiki.org/index.php?do=details&task_id=1755#comment3446 I'm still at loss on how to fix this bug. This reverts commit 2ae68f97446ff6bae5fbbe463eb00312598be840. --- inc/mail.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index aa9d195d1..c45a7c57e 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -11,7 +11,6 @@ if(!defined('DOKU_INC')) die('meh.'); // end of line for mail lines - RFC822 says CRLF but postfix (and other MTAs?) // think different if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n"); -if(!defined('QUOTEDPRINTABLE_EOL')) define('QUOTEDPRINTABLE_EOL',"\015\012"); #define('MAILHEADER_ASCIIONLY',1); /** @@ -290,11 +289,11 @@ function mail_quotedprintable_encode($sText,$maxlen=74,$bEmulate_imap_8bit=true) // but this wouldn't be caught by such an easy RegExp if($maxlen){ preg_match_all( '/.{1,'.($maxlen - 2).'}([^=]{0,2})?/', $sLine, $aMatch ); - $sLine = implode( '=' . QUOTEDPRINTABLE_EOL, $aMatch[0] ); // add soft crlf's + $sLine = implode( '=' . MAILHEADER_EOL, $aMatch[0] ); // add soft crlf's } } // join lines into text - return implode(QUOTEDPRINTABLE_EOL,$aLines); + return implode(MAILHEADER_EOL,$aLines); } -- cgit v1.2.3 From 7e8e923f9382c30776c2983fc4ae90eeadf0eb64 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 10 Feb 2011 14:16:44 +0100 Subject: Use Base64 encoding for long subjects FS#2169 Quoted-Printable specifies a maximum line length and some mail tools (Apple mail and Thunderbird) take this quite serious and will fail to decode subjects encoded with quoted-printable when the subject exceeds the length limit. The correct fix would be to wrap the header into multiple lines. But this seems not to be possible with mails() $subject variable. This patch switches to Base64 encoding for long subjects. A general decision if switching completely to Base64 is the best way to go is still open. (see bugreport) --- inc/mail.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index c45a7c57e..f991909d0 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -112,9 +112,16 @@ function _mail_send_action($data) { } if(!utf8_isASCII($subject)) { - $subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject,0).'?='; + $enc_subj = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject,0).'?='; // Spaces must be encoded according to rfc2047. Use the "_" shorthand - $subject = preg_replace('/ /', '_', $subject); + $enc_sub = preg_replace('/ /', '_', $enc_sub); + + // quoted printable has length restriction, use base64 if needed + if(strlen($subject) > 74){ + $enc_subj = '=?UTF-8?B?'.base64_encode($subject).'?='; + } + + $subject = $enc_subj; } $header = ''; -- cgit v1.2.3 From 0667123fd26e32f9e914b6bb4a2bfcd6f894c076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 11 Feb 2011 11:10:53 +0100 Subject: correctly encode quoted email names --- inc/mail.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index f991909d0..bd6c0db6a 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -203,7 +203,16 @@ function mail_encode_address($string,$header='',$names=true){ } if(!utf8_isASCII($text)){ - $text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text,0).'?='; + // put the quotes outside as in =?UTF-8?Q?"Elan Ruusam=C3=A4e"?= vs "=?UTF-8?Q?Elan Ruusam=C3=A4e?=" + if (preg_match('/^"(.+)"$/', $text, $matches)) { + $text = '"=?UTF-8?Q?'.mail_quotedprintable_encode($matches[1], 0).'?="'; + } else { + $text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text, 0).'?='; + } + // additionally the space character should be encoded as =20 (or each + // word QP encoded separately). + // however this is needed only in mail headers, not globally in mail_quotedprintable_encode(). + $text = str_replace(" ", "=20", $text); } }else{ $text = ''; -- cgit v1.2.3