summaryrefslogtreecommitdiff
path: root/inc/mail.php
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-02-27 10:41:02 +0100
committerandi <andi@splitbrain.org>2005-02-27 10:41:02 +0100
commite1906e6eda8098573a47fc7c78663348500920bd (patch)
tree9a048b9260ed7bb44fea63733d572e5a52c582c6 /inc/mail.php
parent074cf26b87d427287e6179f51b9e64c2b1e88ac2 (diff)
downloadrpg-e1906e6eda8098573a47fc7c78663348500920bd.tar.gz
rpg-e1906e6eda8098573a47fc7c78663348500920bd.tar.bz2
better mailheader handling #168
darcs-hash:20050227094102-9977f-a481ce76ccdb40f8eaa762a332b93093de8f7a87.gz
Diffstat (limited to 'inc/mail.php')
-rw-r--r--inc/mail.php35
1 files changed, 28 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).'?=';