diff options
Diffstat (limited to 'inc/mail.php')
-rw-r--r-- | inc/mail.php | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/inc/mail.php b/inc/mail.php index fb163585a..bd6c0db6a 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); /** @@ -37,14 +36,16 @@ if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '[' */ function mail_setup(){ global $conf; - global $INFO; + global $USERINFO; $replace = array(); - if(!empty($INFO['userinfo']['mail'])){ - $replace['@MAIL@'] = $INFO['userinfo']['mail']; + if(!empty($USERINFO['mail'])){ + $replace['@MAIL@'] = $USERINFO['mail']; }else{ - $replace['@MAIL@'] = 'noreply@'.parse_url(DOKU_URL,PHP_URL_HOST); + $host = @parse_url(DOKU_URL,PHP_URL_HOST); + if(!$host) $host = 'example.com'; + $replace['@MAIL@'] = 'noreply@'.$host; } if(!empty($_SERVER['REMOTE_USER'])){ @@ -53,8 +54,8 @@ function mail_setup(){ $replace['@USER@'] = 'noreply'; } - if(!empty($INFO['userinfo']['name'])){ - $replace['@NAME@'] = $INFO['userinfo']['name']; + if(!empty($USERINFO['name'])){ + $replace['@NAME@'] = $USERINFO['name']; }else{ $replace['@NAME@'] = ''; } @@ -111,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 = ''; @@ -195,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 = ''; @@ -225,6 +242,7 @@ function mail_encode_address($string,$header='',$names=true){ */ function mail_isvalid($email){ $validator = new EmailAddressValidator; + $validator->allowLocalAddresses = true; return $validator->check_email_address($email); } @@ -287,11 +305,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); } |