diff options
-rw-r--r-- | inc/mail.php | 35 | ||||
-rw-r--r-- | inc/utf8.php | 17 |
2 files changed, 45 insertions, 7 deletions
diff --git a/inc/mail.php b/inc/mail.php index 451fa6cb6..c7b4eb40b 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -10,6 +10,7 @@ require_once(DOKU_INC.'inc/utf8.php'); define('MAILHEADER_EOL',"\n"); //end of line for mail headers + #define('MAILHEADER_ASCIIONLY',1); /** * UTF-8 autoencoding replacement for PHPs mail function @@ -18,8 +19,6 @@ * like this: 'Andreas Gohr <andi@splitbrain.org>' - the text part is encoded * automatically. You can seperate receivers by commas. * - * @todo currently an empty To: header is added - * * @param string $to Receiver of the mail (multiple seperated by commas) * @param string $subject Mailsubject * @param string $body Messagebody @@ -33,28 +32,44 @@ * @see mail() */ function mail_send($to, $subject, $body, $from='', $cc='', $bcc='', $headers=null, $params=null){ - if(!utf8_isASCII($subject)) $subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject).'?='; + if(defined('MAILHEADER_ASCIIONLY')){ + $subject = utf8_deaccent($subject); + $subject = utf8_strip($subject); + } + + if(!utf8_isASCII($subject)) + $subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject).'?='; $header = ''; + + // use PHP mail's to field if pure ASCII-7 is available + $to = mail_encode_address($to,'To'); + if(preg_match('#=?UTF-8?=#',$to)){ + $header .= $to; + $to = null; + }else{ + $to = preg_replace('#^To: #','',$to); + } + $header .= mail_encode_address($from,'From'); - $header .= mail_encode_address($to,'To'); $header .= mail_encode_address($cc,'Cc'); $header .= mail_encode_address($bcc,'Bcc'); $header .= 'MIME-Version: 1.0'.MAILHEADER_EOL; $header .= 'Content-Type: text/plain; charset=UTF-8'.MAILHEADER_EOL; $header .= 'Content-Transfer-Encoding: quoted-printable'.MAILHEADER_EOL; $header .= $headers; - $heade = trim($header); + $header = trim($header); $body = mail_quotedprintable_encode($body); - return @mail(null,$subject,$body,$header,$params); + return @mail($to,$subject,$body,$header,$params); } /** * Encodes an email address header * - * Unicode chracters will be encoded quoted_printable for headers like + * Unicode characters will be deaccented and encoded + * quoted_printable for headers. * Addresses may not contain Non-ASCII data! * * Example: @@ -98,6 +113,12 @@ function mail_encode_address($string,$header='To'){ continue; } + if(defined('MAILHEADER_ASCIIONLY')){ + $text = utf8_deaccent($text); + $text = utf8_strip($text); + } + + // FIME: can make problems with long headers? if(!utf8_isASCII($text)){ $text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text).'?='; diff --git a/inc/utf8.php b/inc/utf8.php index 4fee844d6..9fc99820e 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -54,6 +54,23 @@ function utf8_isASCII($str){ } /** + * Strips all highbyte chars + * + * Returns a pure ASCII7 string + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function utf8_strip($str){ + $ascii = ''; + for($i=0; $i<strlen($str); $i++){ + if(ord($str{$i}) <128){ + $ascii .= $str{$i}; + } + } + return $ascii; +} + +/** * Tries to detect if a string is in Unicode encoding * * @author <bmorel@ssi.fr> |