From e1906e6eda8098573a47fc7c78663348500920bd Mon Sep 17 00:00:00 2001 From: andi Date: Sun, 27 Feb 2005 10:41:02 +0100 Subject: better mailheader handling #168 darcs-hash:20050227094102-9977f-a481ce76ccdb40f8eaa762a332b93093de8f7a87.gz --- inc/mail.php | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'inc/mail.php') 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 ' - 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).'?='; -- cgit v1.2.3