diff options
author | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-03-23 10:39:45 +0100 |
---|---|---|
committer | Michal Rezler <rezlemic@fel.cvut.cz> | 2011-03-23 10:39:45 +0100 |
commit | 35838d22a57707952f630eaf9f9e9ab4c6c3cfb0 (patch) | |
tree | 3603e2e56314af40a4b7922e14e52c0bc06f6f9d /inc/mail.php | |
parent | c4bb7947fcb2d4a5e5f8a15d9e3bbec333e44e13 (diff) | |
parent | ee1214abb2c14cf0f86ff6d9a5b49536c6b01e18 (diff) | |
download | rpg-35838d22a57707952f630eaf9f9e9ab4c6c3cfb0.tar.gz rpg-35838d22a57707952f630eaf9f9e9ab4c6c3cfb0.tar.bz2 |
jQuery rewrite branch merged into master branch of whole project
Diffstat (limited to 'inc/mail.php')
-rw-r--r-- | inc/mail.php | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/inc/mail.php b/inc/mail.php index 38232d110..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); /** @@ -30,7 +29,41 @@ if(!defined('QUOTEDPRINTABLE_EOL')) define('QUOTEDPRINTABLE_EOL',"\015\012"); if (!defined('RFC2822_ATEXT')) define('RFC2822_ATEXT',"0-9a-zA-Z!#$%&'*+/=?^_`{|}~-"); if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['.RFC2822_ATEXT.']+(?:\.['.RFC2822_ATEXT.']+)*@(?i:[0-9a-z][0-9a-z-]*\.)+(?i:[a-z]{2,4}|museum|travel)'); +/** + * Prepare mailfrom replacement patterns + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function mail_setup(){ + global $conf; + global $USERINFO; + + $replace = array(); + if(!empty($USERINFO['mail'])){ + $replace['@MAIL@'] = $USERINFO['mail']; + }else{ + $host = @parse_url(DOKU_URL,PHP_URL_HOST); + if(!$host) $host = 'example.com'; + $replace['@MAIL@'] = 'noreply@'.$host; + } + + if(!empty($_SERVER['REMOTE_USER'])){ + $replace['@USER@'] = $_SERVER['REMOTE_USER']; + }else{ + $replace['@USER@'] = 'noreply'; + } + + if(!empty($USERINFO['name'])){ + $replace['@NAME@'] = $USERINFO['name']; + }else{ + $replace['@NAME@'] = ''; + } + + $conf['mailfrom'] = str_replace(array_keys($replace), + array_values($replace), + $conf['mailfrom']); +} /** * UTF-8 autoencoding replacement for PHPs mail function @@ -79,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 = ''; @@ -163,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 = ''; @@ -193,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); } @@ -255,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); } |