*/ if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/'); require_once(DOKU_INC.'inc/utf8.php'); // end of line for mail lines - RFC822 says CRLF but postfix (and other MTAs?) // think different if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n"); #define('MAILHEADER_ASCIIONLY',1); /** * UTF-8 autoencoding replacement for PHPs mail function * * Email address fields (To, From, Cc, Bcc can contain a textpart and an address * like this: 'Andreas Gohr ' - the text part is encoded * automatically. You can seperate receivers by commas. * * @param string $to Receiver of the mail (multiple seperated by commas) * @param string $subject Mailsubject * @param string $body Messagebody * @param string $from Sender address * @param string $cc CarbonCopy receiver (multiple seperated by commas) * @param string $bcc BlindCarbonCopy receiver (multiple seperated by commas) * @param string $headers Additional Headers (seperated by MAILHEADER_EOL * @param string $params Additonal Sendmail params (passed to mail()) * * @author Andreas Gohr * @see mail() */ function mail_send($to, $subject, $body, $from='', $cc='', $bcc='', $headers=null, $params=null){ $message = compact('to','subject','body','from','cc','bcc','headers','params'); return trigger_event('MAIL_MESSAGE_SEND',$message,'_mail_send_action'); } function _mail_send_action($data) { // retrieve parameters from event data, $to, $subject, $body, $from, $cc, $bcc, $headers, $params $to = $data['to']; $subject = $data['subject']; $body = $data['body']; // add robustness in case plugin removes any of these optional values $from = isset($data['from']) ? $data['from'] : ''; $cc = isset($data['cc']) ? $data['cc'] : ''; $bcc = isset($data['bcc']) ? $data['bcc'] : ''; $headers = isset($data['headers']) ? $data['headers'] : null; $params = isset($data['params']) ? $data['params'] : null; // end additional code to support event ... original mail_send() code from here if(defined('MAILHEADER_ASCIIONLY')){ $subject = utf8_deaccent($subject); $subject = utf8_strip($subject); } if(!utf8_isASCII($subject)) { $subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject,0).'?='; // Spaces must be encoded according to rfc2047. Use the "_" shorthand $subject = preg_replace('/ /', '_', $subject); } $header = ''; // No named recipients for To: in Windows (see FS#652) $usenames = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true; $to = mail_encode_address($to,'',$usenames); $header .= mail_encode_address($from,'From'); $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; $header = trim($header); $body = mail_quotedprintable_encode($body); if($params == null){ return @mail($to,$subject,$body,$header); }else{ return @mail($to,$subject,$body,$header,$params); } } /** * Encodes an email address header * * Unicode characters will be deaccented and encoded * quoted_printable for headers. * Addresses may not contain Non-ASCII data! * * Example: * mail_encode_address("föö , me@somewhere.com","TBcc"); * * @param string $string Multiple adresses separated by commas * @param string $header Name of the header (To,Bcc,Cc,...) * @param boolean $names Allow named Recipients? */ function mail_encode_address($string,$header='',$names=true){ $headers = ''; $parts = split(',',$string); foreach ($parts as $part){ $part = trim($part); // parse address if(preg_match('#(.*?)<(.*?)>#',$part,$matches)){ $text = trim($matches[1]); $addr = $matches[2]; }else{ $addr = $part; } // skip empty ones if(empty($addr)){ continue; } // FIXME: is there a way to encode the localpart of a emailaddress? if(!utf8_isASCII($addr)){ msg(htmlspecialchars("E-Mail address <$addr> is not ASCII"),-1); continue; } if(!mail_isvalid($addr)){ msg(htmlspecialchars("E-Mail address <$addr> is not valid"),-1); continue; } // text was given if(!empty($text) && $names){ // add address quotes $addr = "<$addr>"; if(defined('MAILHEADER_ASCIIONLY')){ $text = utf8_deaccent($text); $text = utf8_strip($text); } if(!utf8_isASCII($text)){ $text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text,0).'?='; } }else{ $text = ''; } // add to header comma seperated and in new line to avoid too long headers if($headers != '') $headers .= ','.MAILHEADER_EOL.' '; $headers .= $text.' '.$addr; } if(empty($headers)) return null; //if headername was given add it and close correctly if($header) $headers = $header.': '.$headers.MAILHEADER_EOL; return $headers; } /** * Uses a regular expresion to check if a given mail address is valid * * May not be completly RFC conform! * @link http://www.faqs.org/rfcs/rfc2822.html (paras 3.4.1 & 3.2.4) * * @author Chris Smith * * @param string $email the address to check * @return bool true if address is valid */ // patterns for use in email detection and validation // NOTE: there is an unquoted '/' in RFC2822_ATEXT, it must remain unquoted to be used in the parser // the pattern uses non-capturing groups as captured groups aren't allowed in the parser // select pattern delimiters with care! if (!defined('RFC2822_ATEXT')) define('RFC2822_ATEXT',"0-9a-z!#$%&'*+/=?^_`{|}~-"); if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['.RFC2822_ATEXT.']+(?:\.['.RFC2822_ATEXT.']+)*@(?:[0-9a-z][0-9a-z-]*\.)+(?:[a-z]{2,4}|museum|travel)'); function mail_isvalid($email){ return preg_match('<^'.PREG_PATTERN_VALID_EMAIL.'$>i', $email); } /** * Quoted printable encoding * * @author umu * @link http://www.php.net/manual/en/function.imap-8bit.php#61216 */ function mail_quotedprintable_encode($sText,$maxlen=74,$bEmulate_imap_8bit=true) { // split text into lines $aLines= preg_split("/(?:\r\n|\r|\n)/", $sText); for ($i=0;$i