From 5ec3fefc5fc0983d6fdc0efdaed2e78e0d09a868 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 5 Nov 2010 11:18:31 +0100 Subject: handle mailfrom replacements in a central place FS#2091 --- inc/mail.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index 38232d110..fb163585a 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -30,7 +30,39 @@ 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 + */ +function mail_setup(){ + global $conf; + global $INFO; + + $replace = array(); + + if(!empty($INFO['userinfo']['mail'])){ + $replace['@MAIL@'] = $INFO['userinfo']['mail']; + }else{ + $replace['@MAIL@'] = 'noreply@'.parse_url(DOKU_URL,PHP_URL_HOST); + } + if(!empty($_SERVER['REMOTE_USER'])){ + $replace['@USER@'] = $_SERVER['REMOTE_USER']; + }else{ + $replace['@USER@'] = 'noreply'; + } + + if(!empty($INFO['userinfo']['name'])){ + $replace['@NAME@'] = $INFO['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 -- cgit v1.2.3 From 609c41e4b585232192abba662698288798157297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 29 Nov 2010 20:59:50 +0200 Subject: Use $USERINFO in mail_setup, as $INFO['userinfo'] is not yet available. 20:51:05 what is the difference between $INFO['userinfo'] and $USERINFO? 20:52:17 none really 20:52:33 yet one works ($USERINFO) and the other doesn't in my setup 20:52:59 $INFO isn't available everywhere 20:53:27 or might not have been set yet (if you're fetching an early action hook) 20:53:27 yeah, mail headers setup failed for me --- inc/mail.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index fb163585a..604a0999a 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -37,12 +37,12 @@ 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); } @@ -53,8 +53,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@'] = ''; } -- cgit v1.2.3 From 204d9c533d983cce1a75f12ef218a92b01961d46 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 8 Dec 2010 23:55:54 +0100 Subject: surpress warning in mail setup when hostname can't be determined --- inc/mail.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index 604a0999a..e1f327cfe 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -44,7 +44,9 @@ function mail_setup(){ 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'])){ -- cgit v1.2.3 From 02700828f76adcfc63a9dafe75ffa941cdb9831b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 18 Dec 2010 10:33:31 +0100 Subject: Update EmailValidator to r10 and allow local email addresses FS#2118 --- inc/mail.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index e1f327cfe..aa9d195d1 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -227,6 +227,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); } -- cgit v1.2.3 From 1a6a1c042a16fc7ed8be4d870dbf32d60c05560b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 20:50:58 +0100 Subject: Revert "use CRLF in quoted printable encoding FS#1755" This research suggests that, the change does not help, but in fact breaks previoulsy working setups: https://bugs.dokuwiki.org/index.php?do=details&task_id=1755#comment3446 I'm still at loss on how to fix this bug. This reverts commit 2ae68f97446ff6bae5fbbe463eb00312598be840. --- inc/mail.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index aa9d195d1..c45a7c57e 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); /** @@ -290,11 +289,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); } -- cgit v1.2.3 From 7e8e923f9382c30776c2983fc4ae90eeadf0eb64 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 10 Feb 2011 14:16:44 +0100 Subject: Use Base64 encoding for long subjects FS#2169 Quoted-Printable specifies a maximum line length and some mail tools (Apple mail and Thunderbird) take this quite serious and will fail to decode subjects encoded with quoted-printable when the subject exceeds the length limit. The correct fix would be to wrap the header into multiple lines. But this seems not to be possible with mails() $subject variable. This patch switches to Base64 encoding for long subjects. A general decision if switching completely to Base64 is the best way to go is still open. (see bugreport) --- inc/mail.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index c45a7c57e..f991909d0 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -112,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 = ''; -- cgit v1.2.3 From 0667123fd26e32f9e914b6bb4a2bfcd6f894c076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 11 Feb 2011 11:10:53 +0100 Subject: correctly encode quoted email names --- inc/mail.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'inc/mail.php') diff --git a/inc/mail.php b/inc/mail.php index f991909d0..bd6c0db6a 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -203,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 = ''; -- cgit v1.2.3