From 7e3069ed54acaed49a1ea33a4773454e06167941 Mon Sep 17 00:00:00 2001 From: sakamocchi Date: Sat, 18 Feb 2012 16:10:10 +0900 Subject: [PATCH] =?utf8?q?CHANGE:=20NOTIFICATION=E3=82=AF=E3=83=A9?= =?utf8?q?=E3=82=B9=E3=81=AE=E6=95=B4=E5=82=99=E3=80=82i18n=E3=81=AE?= =?utf8?q?=E3=83=A1=E3=83=BC=E3=83=AB=E9=80=81=E4=BF=A1=E3=83=A1=E3=82=BD?= =?utf8?q?=E3=83=83=E3=83=89=E3=82=92=E7=A7=BB=E6=A4=8D=20CHANGE:=20rearra?= =?utf8?q?nge=20NOTIFICATION=20class=20and=20migrate=20mail-related=20func?= =?utf8?q?tions=20from=20i18n?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- nucleus/libs/ACTION.php | 36 ++-- nucleus/libs/ADMIN.php | 28 ++- nucleus/libs/BLOG.php | 24 ++- nucleus/libs/COMMENTACTIONS.php | 10 +- nucleus/libs/COMMENTS.php | 30 ++-- nucleus/libs/MEMBER.php | 12 +- nucleus/libs/NOTIFICATION.php | 375 ++++++++++++++++++++++++++++++++++++--- nucleus/libs/globalfunctions.php | 66 ++----- nucleus/libs/i18n.php | 268 ---------------------------- 9 files changed, 433 insertions(+), 416 deletions(-) diff --git a/nucleus/libs/ACTION.php b/nucleus/libs/ACTION.php index 24a1e05..5809bbd 100644 --- a/nucleus/libs/ACTION.php +++ b/nucleus/libs/ACTION.php @@ -174,10 +174,10 @@ class ACTION . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n" . _MMAIL_MAIL . " \n\n" . postVar('message'); - $message .= getMailFooter(); + $message .= NOTIFICATION::get_mail_footer(); $title = _MMAIL_TITLE . ' ' . $fromName; - i18n::mail($tomem->getEmail(), $title, $message, $fromMail); + NOTIFICATION::mail($tomem->getEmail(), $title, $message, $fromMail, i18n::get_current_charset()); if ( postVar('url') ) { @@ -224,7 +224,7 @@ class ACTION return _ERROR_DISALLOWED; } - if ( !$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail') ) ) ) + if ( !$member->isLoggedIn() && !NOTIFICATION::address_validation(postVar('frommail')) ) { return _ERROR_BADMAILADDRESS; } @@ -384,20 +384,12 @@ class ACTION break; } -// $blogid = getBlogIDFromItemID($itemid); $blog =& $manager->getBlog($blogid); // send email to notification address, if any if ( $blog->getNotifyAddress() && $blog->notifyOnVote() ) { - - $mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n"; -// if ($CONF['URLMode'] == 'pathinfo') { -// $itemLink = createItemLink(intval($itemid)); -// } else { -// $itemLink = $CONF['IndexURL'] . createItemLink(intval($itemid)); -// } -// $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n"; + $message = _NOTIFY_KV_MSG . ' ' . $itemid . "\n"; $itemLink = createItemLink(intval($itemid) ); $temp = parse_url($itemLink); @@ -406,24 +398,23 @@ class ACTION $itemLink = $CONF['IndexURL'] . $itemLink; } - $mailto_msg .= $itemLink . "\n\n"; + $message .= $itemLink . "\n\n"; if ( $member->isLoggedIn() ) { - $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n"; + $message .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n"; } - $mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n"; - $mailto_msg .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n"; - $mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n"; - $mailto_msg .= getMailFooter(); + $message .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n"; + $message .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n"; + $message .= _NOTIFY_VOTE . "\n " . $type . "\n"; + $message .= NOTIFICATION::get_mail_footer(); - $mailto_title = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')'; + $subject = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')'; - $frommail = $member->getNotifyFromMailAddress(); + $from = $member->getNotifyFromMailAddress(); - $notify = new NOTIFICATION($blog->getNotifyAddress() ); - $notify->notify($mailto_title, $mailto_msg, $frommail); + NOTIFICATION::mail($blog->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset()); } $refererUrl = serverVar('HTTP_REFERER'); @@ -434,7 +425,6 @@ class ACTION } else { -// $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid; $url = $itemLink; } diff --git a/nucleus/libs/ADMIN.php b/nucleus/libs/ADMIN.php index c6c8c52..6d03b53 100644 --- a/nucleus/libs/ADMIN.php +++ b/nucleus/libs/ADMIN.php @@ -1993,7 +1993,7 @@ class ADMIN } } - if ( !isValidMailAddress($email) ) + if ( !NOTIFICATION::address_validation($email) ) { $this->error(_ERROR_BADMAILADDRESS); } @@ -3009,7 +3009,7 @@ class ADMIN $blog =& $manager->getBlog($blogid); - $notify = trim(postVar('notify')); + $notify_address = trim(postVar('notify')); $shortname = trim(postVar('shortname')); $updatefile = trim(postVar('update')); @@ -3017,47 +3017,43 @@ class ADMIN $notifyVote = intPostVar('notifyVote'); $notifyNewItem = intPostVar('notifyNewItem'); - if ($notifyComment == 0) + if ( $notifyComment == 0 ) { $notifyComment = 1; } - if ($notifyVote == 0) + if ( $notifyVote == 0 ) { $notifyVote = 1; } - if ($notifyNewItem == 0) + if ( $notifyNewItem == 0 ) { $notifyNewItem = 1; } $notifyType = $notifyComment * $notifyVote * $notifyNewItem; - if ($notify) + if ( $notify_address && !NOTIFICATION::address_validation($notify_address) ) { - $not = new NOTIFICATION($notify); - if (!$not->validAddresses()) - { - $this->error(_ERROR_BADNOTIFY); - } + $this->error(_ERROR_BADNOTIFY); } - if (!isValidShortName($shortname)) + if ( !isValidShortName($shortname) ) { $this->error(_ERROR_BADSHORTBLOGNAME); } - if (($blog->getShortName() != $shortname) && $manager->existsBlog($shortname)) + if ( ($blog->getShortName() != $shortname) && $manager->existsBlog($shortname) ) { $this->error(_ERROR_DUPSHORTBLOGNAME); } // check if update file is writable - if ($updatefile && !is_writeable($updatefile)) + if ( $updatefile && !is_writeable($updatefile) ) { $this->error(_ERROR_UPDATEFILE); } $blog->setName(trim(postVar('name'))); $blog->setShortName($shortname); - $blog->setNotifyAddress($notify); + $blog->setNotifyAddress($notify_address); $blog->setNotifyType($notifyType); $blog->setMaxComments(postVar('maxcomments')); $blog->setCommentsEnabled(postVar('comments')); @@ -5075,7 +5071,7 @@ selector(); $member->isAdmin() or $this->disallow(); // check if email address for admin is valid - if ( !isValidMailAddress(postVar('AdminEmail')) ) + if ( !NOTIFICATION::address_validation(postVar('AdminEmail')) ) { $this->error(_ERROR_BADMAILADDRESS); } diff --git a/nucleus/libs/BLOG.php b/nucleus/libs/BLOG.php index a3bb092..ff06c9c 100644 --- a/nucleus/libs/BLOG.php +++ b/nucleus/libs/BLOG.php @@ -313,38 +313,36 @@ class BLOG { { global $CONF, $member; - // create text version of html post + // FIXME: create text version of html post. this seems to be needless... $ascii = toAscii($body); - $mailto_msg = _NOTIFY_NI_MSG . " \n"; -// $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n"; + $message = _NOTIFY_NI_MSG . " \n"; $temp = parse_url($CONF['Self']); if ( $temp['scheme'] ) { - $mailto_msg .= createItemLink($itemid) . "\n\n"; + $message .= createItemLink($itemid) . "\n\n"; } else { $tempurl = $this->getURL(); if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' ) { - $mailto_msg .= $tempurl . '?itemid=' . $itemid . "\n\n"; + $message .= $tempurl . '?itemid=' . $itemid . "\n\n"; } else { - $mailto_msg .= $tempurl . '/?itemid=' . $itemid . "\n\n"; + $message .= $tempurl . '/?itemid=' . $itemid . "\n\n"; } } - $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n"; - $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n"; - $mailto_msg .= getMailFooter(); + $message .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n"; + $message .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n"; + $message .= NOTIFICATION::get_mail_footer(); - $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE; + $subject = $this->getName() . ': ' . _NOTIFY_NI_TITLE; - $frommail = $member->getNotifyFromMailAddress(); + $from = $member->getNotifyFromMailAddress(); - $notify = new NOTIFICATION($this->getNotifyAddress()); - $notify->notify($mailto_title, $mailto_msg , $frommail); + NOTIFICATION::mail($this->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset()); return; } diff --git a/nucleus/libs/COMMENTACTIONS.php b/nucleus/libs/COMMENTACTIONS.php index 2a52a6e..838dac1 100644 --- a/nucleus/libs/COMMENTACTIONS.php +++ b/nucleus/libs/COMMENTACTIONS.php @@ -104,7 +104,7 @@ class COMMENTACTIONS extends BaseActions { { global $manager; - if ( $comment['memberid'] != 0) + if ( $comment['memberid'] != 0 ) { $comment['authtext'] = $template['COMMENTS_AUTH']; $mem =& $manager->getMember($comment['memberid']); @@ -142,11 +142,11 @@ class COMMENTACTIONS extends BaseActions { $comment['userlinkraw'] = 'http://' . $comment['userid']; } } - else if ( isValidMailAddress($comment['email']) ) + else if ( NOTIFICATION::address_validation($comment['email']) ) { $comment['userlinkraw'] = 'mailto:' . $comment['email']; } - else if ( isValidMailAddress($comment['userid']) ) + else if ( NOTIFICATION::address_validation($comment['userid']) ) { $comment['userlinkraw'] = 'mailto:' . $comment['userid']; } @@ -394,11 +394,11 @@ class COMMENTACTIONS extends BaseActions { } else { - if ( isValidMailAddress($this->currentComment['email']) ) + if ( NOTIFICATION::address_validation($this->currentComment['email']) ) { echo $this->currentComment['email']; } - elseif ( isValidMailAddress($this->currentComment['userid']) ) + elseif ( NOTIFICATION::address_validation($this->currentComment['userid']) ) { echo $this->currentComment['userid']; } diff --git a/nucleus/libs/COMMENTS.php b/nucleus/libs/COMMENTS.php index daacb4b..e3db729 100644 --- a/nucleus/libs/COMMENTS.php +++ b/nucleus/libs/COMMENTS.php @@ -274,12 +274,13 @@ class COMMENTS { // begin if: send email to notification address if ( $settings->getNotifyAddress() && $settings->notifyOnComment() ) { - $mailto_msg = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n"; + + $message = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n"; $temp = parse_url($CONF['Self']); if ( $temp['scheme'] ) { - $mailto_msg .= createItemLink($this->itemid) . "\n\n"; + $message .= createItemLink($this->itemid) . "\n\n"; } else { @@ -287,35 +288,34 @@ class COMMENTS { if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' ) { - $mailto_msg .= $tempurl . '?itemid=' . $this->itemid . "\n\n"; + $message .= $tempurl . '?itemid=' . $this->itemid . "\n\n"; } else { - $mailto_msg .= $tempurl . '/?itemid=' . $this->itemid . "\n\n"; + $message .= $tempurl . '/?itemid=' . $this->itemid . "\n\n"; } } if ( $comment['memberid'] == 0 ) { - $mailto_msg .= _NOTIFY_USER . ' ' . $comment['user'] . "\n"; - $mailto_msg .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n"; + $message .= _NOTIFY_USER . ' ' . $comment['user'] . "\n"; + $message .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n"; } else { - $mailto_msg .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n"; + $message .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n"; } - $mailto_msg .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n"; - $mailto_msg .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n"; - $mailto_msg .= getMailFooter(); + $message .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n"; + $message .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n"; + $message .= NOTIFICATION::get_mail_footer(); $item =& $manager->getItem($this->itemid, 0, 0); - $mailto_title = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')'; + $subject = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')'; - $frommail = $member->getNotifyFromMailAddress($comment['email']); + $from = $member->getNotifyFromMailAddress($comment['email']); - $notify = new NOTIFICATION($settings->getNotifyAddress() ); - $notify->notify($mailto_title, $mailto_msg , $frommail); + NOTIFICATION::mail($settings->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset()); } $comment = COMMENT::prepare($comment); @@ -409,7 +409,7 @@ class COMMENTS { return _ERROR_COMMENT_NOUSERNAME; } - if ( (i18n::strlen($comment['email']) != 0) && !isValidMailAddress(trim($comment['email'])) ) + if ( (i18n::strlen($comment['email']) != 0) && !NOTIFICATION::address_validation(trim($comment['email'])) ) { return _ERROR_BADMAILADDRESS; } diff --git a/nucleus/libs/MEMBER.php b/nucleus/libs/MEMBER.php index 114d1ee..b08bc76 100644 --- a/nucleus/libs/MEMBER.php +++ b/nucleus/libs/MEMBER.php @@ -422,15 +422,15 @@ class MEMBER { { case 'register': $message = _ACTIVATE_REGISTER_MAIL; - $title = _ACTIVATE_REGISTER_MAILTITLE; + $subject = _ACTIVATE_REGISTER_MAILTITLE; break; case 'forgot': $message = _ACTIVATE_FORGOT_MAIL; - $title = _ACTIVATE_FORGOT_MAILTITLE; + $subject = _ACTIVATE_FORGOT_MAILTITLE; break; case 'addresschange': $message = _ACTIVATE_CHANGE_MAIL; - $title = _ACTIVATE_CHANGE_MAILTITLE; + $subject = _ACTIVATE_CHANGE_MAILTITLE; break; default; } @@ -445,10 +445,10 @@ class MEMBER { ); $message = TEMPLATE::fill($message, $aVars); - $title = TEMPLATE::fill($title, $aVars); + $subject = TEMPLATE::fill($subject, $aVars); // send mail - i18n::mail($this->getEmail(), $title ,$message, $CONF['AdminEmail']); + NOTIFICATION::mail($this->getEmail(), $subject ,$message, $CONF['AdminEmail'], i18n::get_current_charset()); ACTIONLOG::add(INFO, _ACTIONLOG_ACTIVATIONLINK . ' (' . $this->getDisplayName() . ' / type: ' . $type . ')'); return; @@ -525,7 +525,7 @@ class MEMBER { { return $this->getDisplayName() . " <" . $this->getEmail() . ">"; } - else if ( isValidMailAddress($suggest) ) + else if ( NOTIFICATION::address_validation($suggest) ) { return $suggest; } diff --git a/nucleus/libs/NOTIFICATION.php b/nucleus/libs/NOTIFICATION.php index 52dac90..ad13cfc 100644 --- a/nucleus/libs/NOTIFICATION.php +++ b/nucleus/libs/NOTIFICATION.php @@ -17,34 +17,368 @@ * @copyright Copyright (C) 2002-2009 The Nucleus Group * @version $Id: NOTIFICATION.php 1534 2011-06-22 06:13:23Z sakamocchi $ */ -class NOTIFICATION { - - // array of addresses that need to get a notification - var $addresses = array(); - +class NOTIFICATION +{ + static private $charset; + static private $scheme = 'B'; + /** - * takes one string as argument, containing multiple e-mail addresses - * separated by semicolons - * eg: site@demuynck.org;nucleus@demuynck.org;foo@bar.com - */ - function NOTIFICATION($addresses) { + * NOTIFICATION::address_validation() + * Validating the string as address + * + * FIXME: this is just migrated from globalfunctions.php + * we should confirm this regular expression refering to RFC 5322 + * + * @link http://www.ietf.org/rfc/rfc5322.txt + * @see 3.4. Address Specification + * + * @static + * @param String $address Address + * @return Boolean valid or not + */ + static public function address_validation($address) + { + return (boolean) preg_match('#^(?!\\.)(?:\\.?[-a-zA-Z0-9!\\#$%&\'*+/=?^_`{|}~]+)+@(?!\\.)(?:\\.?(?!-)[-a-zA-Z0-9]+(?$#", $mailbox, $match) ) + { + $display_name = self::seven_bit_characters_encoder(trim($match[1])); + $local_part = trim($match[2]); + $domain = trim($match[3]); + $encoded_mailboxes[] = "{$display_name} <{$local_part}@{$domain}>"; + } + else if ( preg_match("#([^,]+)?@([^,]+)?#", $mailbox) ) + { + $encoded_mailboxes[] = $mailbox; + } + else + { + continue; + } + } + if ( $encoded_mailboxes == array() ) + { + return FALSE; + } + return implode(',', $encoded_mailboxes); + } + + /** + * NOTIFICATION::seven_bit_characters_encoder + * Encoder into 7bit ASCII expression for Non-ASCII Text based on RFC 2047. + * + * @link http://www.ietf.org/rfc/rfc2047.txt + * @see 2. Syntax of encoded-words + * + * NOTE: RFC 2047 has a ambiguousity for dealing with 'linear-white-space'. + * This causes a trouble related to line breaking between single byte and multi-byte strings. + * To avoid this, single byte string is encoded as well as multi byte string here. + * + * NOTE: RFC 2231 also defines the way to use non-ASCII characters in MIME header. + * http://www.ietf.org/rfc/rfc2231.txt + * + * NOTE: iconv extension give the same functions as this in PHP5 + * iconv_mime_encode(): + * http://www.php.net/manual/en/function.iconv-mime-encode.php + * + * @static + * @param string $charset Character set encoding + * @param string $type type of 7 bit encoding, should be 'B' or 'Q' + * @param string $string Target string with header field + * @return string encoded string + * + */ + static private function seven_bit_characters_encoder($string) + { + $header = chr(13) . chr(10) . chr(32) . '=?' . self::$charset . '?' . self::$scheme . '?'; + $footer = "?="; + $restriction = 78 - strlen($header) - strlen($footer) ; + + $encoded_words = array(); + for ( $i = 0; $i < self::strlen($string); $i++ ) + { + if ( self::$scheme == 'B' ) + { + if ( $i == 0 ) + { + $letters = ''; + } + + $letter = self::substr($string, $i, 1); + $expected_length = strlen($letters) + strlen($letter) * 4 / 3; + + if ( $expected_length > $restriction ) + { + $encoded_text = self::b_encoder($letters); + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + $letters = ''; + } + + $letters .= $letter; + + if ( $i == self::strlen($string) - 1 ) + { + $encoded_text = self::b_encoder($letters); + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + break; + } + continue; + } + else + { + if ( $i == 0 ) + { + $encoded_text = ''; + } + + $encoded_letter = self::q_encoder(self::substr($string, $i, 1)); + $expected_length = strlen($encoded_text) + strlen($encoded_letter); + + if ( $expected_length > $restriction ) + { + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + $letters = ''; + } + + $encoded_text .= $encoded_letter; + + if ( $i == self::strlen($string) - 1 ) + { + $encoded_words[] = "{$header}{$encoded_text}{$footer}"; + break; + } + continue; + } + } + + return implode('', $encoded_words); + } + + /** + * NOTIFICATION::b_encoder() + * + * B encoder according to RFC 2047. + * The "B" encoding is identical to the "BASE64" encoding defined by RFC 4648. + * + * @link http://www.ietf.org/rfc/rfc4648.txt + * @see 6.8. Base64 Content-Transfer-Encoding + * + * NOTE: According to RFC 4648 + * (1) The final quantum of encoding input is an integral multiple of 24 bits; + * here, the final unit of encoded output will be an integral multiple + * of 4 characters with no "=" padding. + * (2) The final quantum of encoding input is exactly 8 bits; here, + * the final unit of encoded output will be two characters followed + * by two "=" padding characters. + * (3) The final quantum of encoding input is exactly 16 bits; here, + * the final unit of encoded output will be three characters followed + * by one "=" padding character. + * + * @static + * @param string $target targetted string + * @return string encoded string + */ + static private function b_encoder($target) + { + return base64_encode($target); + } + + /** + * NOTIFICATION::q_encoder() + * + * Q encoder according to RFC 2047. + * The "Q" encoding is similar to "Quoted-Printable" content-transfer-encoding defined in RFC 2045, + * but the "Q" encoding and the "Quoted-Printable" are different a bit. + * + * @link http://www.ietf.org/rfc/rfc2047.txt + * @see 4.2. The "Q" encoding + * + * NOTE: According to RFC 2047 + * (1) Any 8-bit value may be represented by a "=" followed by two hexadecimal digits. + * For example, if the character set in use were ISO-8859-1, + * the "=" character would thus be encoded as "=3D", and a SPACE by "=20". + * (Upper case should be used for hexadecimal digits "A" through "F".) + * (2) The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be + * represented as "_" (underscore, ASCII 95.). + * (This character may not pass through some internetwork mail gateways, + * but its use will greatly enhance readability of "Q" encoded data + * with mail readers that do not support this encoding.) + * Note that the "_" always represents hexadecimal 20, + * even if the SPACE character occupies a different code position + * in the character set in use. + * (3) 8-bit values which correspond to printable ASCII characters + * other than "=", "?", and "_" (underscore), MAY be represented as those characters. + * (But see section 5 for restrictions.) + * In particular, SPACE and TAB MUST NOT be represented as themselves within encoded words. + * + * @static + * @param string $target targetted string + * @return string encoded string + */ + static private function q_encoder($target) + { + $string = ''; + + for ( $i = 0; $i < strlen($target); $i++ ) + { + $letter = substr ($target, $i, 1); + $order = ord($letter); + + // Printable ASCII characters without "=", "?", "_" + if ((33 <= $order && $order <= 60) + || (62 == $order) + || (64 <= $order && $order <= 94) + || (96 <= $order && $order <= 126)) + { + $string .= strtoupper(dechex($order)); + } + // Space shuold be encoded as the same strings as "_" + else if ($order == 32) + { + $string .= '_'; + } + // Other characters + else + { + $string .= '=' . strtoupper(dechex($order)); + } + } + + return $string; + } + + /** + * NOTICE: Deprecated + * NOTIFICATION::$addresses + * + * @deprecated + */ + private $addresses = array(); + + /** + * NOTICE: Deprecated + * takes one string as argument, containing multiple e-mail addresses + * separated by semicolons + * eg: site@demuynck.org;nucleus@demuynck.org;foo@bar.com + * + * @deprecated + */ + function __construct($addresses) + { $this->addresses = i18n::explode(';' , $addresses); } - + /** - * returns true if all addresses are valid - */ - function validAddresses() { - foreach ( $this->addresses as $address ) { - if (!isValidMailAddress(trim($address))) + * NOTICE: Deprecated + * NOTIFICATION::validAddresses() + * + * returns true if all addresses are valid + * + * @deprecated + * @param Void + * @return Boolean + */ + function validAddresses() + { + foreach ( $this->addresses as $address ) + { + if ( !self::address_validation(trim($address)) ) + { return 0; + } } return 1; } - + /** - * Sends email messages to all the email addresses - */ + * NOTICE: Deprecated + * NOTIFICATION::notify() + * + * Sends email messages to all the email addresses + * + * @deprecated + * @param String $title + * @param String $message + * @param String $from + * @return Void + */ function notify($title, $message, $from) { global $member; @@ -59,8 +393,7 @@ class NOTIFICATION { $addresses[] = $address; } - i18n::mail(implode(',', $addresses), $title, $message , $from); + self::mail(implode(',', $addresses), $title, $message , $from); return; } } - diff --git a/nucleus/libs/globalfunctions.php b/nucleus/libs/globalfunctions.php index be79ae1..8a1b832 100644 --- a/nucleus/libs/globalfunctions.php +++ b/nucleus/libs/globalfunctions.php @@ -1040,27 +1040,6 @@ $manager->notify( } } - - /** - * This function checks if an email address is valid - * @param string $address - * @return int - */ - function isValidMailAddress($address) - { - // enhancement made in 3.6x based on code by Quandary. - if ( preg_match('/^(?!\\.)(?:\\.?[-a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~]+)+@(?!\\.)(?:\\.?(?!-)[-a-zA-Z0-9]+(?'; } -function getMailFooter() { - $message = "\n\n-----------------------------"; - $message .= "\n Powered by Nucleus CMS"; - $message .= "\n(http://www.nucleuscms.org/)"; - return $message; +/** + * Deprecated since 4.0: + * Please use functions in MAIL class instead + */ +function getMailFooter() +{ + NOTIFICATION::get_mail_footer(); +} +function isValidMailAddress($address) +{ + return NOTIFICATION::address_validation($address); } /* @@ -2395,43 +2380,26 @@ function stringStripTags ($string) { } /** + * NOTE: Deprecated since 4.0, use i18n::hen() + * * Make a string containing HTML safe for use in a HTML attribute * Tags are stripped and entities are normalized */ function stringToAttribute ($string) { - $string = stringStripTags($string); - $string = entity::named_to_numeric($string); - $string = entity::normalize_numeric($string); - - if ( i18n::get_current_charset() == 'UTF-8' ) - { - $string = entity::numeric_to_utf8($string); - } - - $string = entity::specialchars($string, 'html'); - $string = entity::numeric_to_named($string); - return $string; + return i18n::hsc($string); } /** + * NOTE: Deprecated since 4.0, use i18n::hsc() + * * Make a string containing HTML safe for use in a XML document * Tags are stripped, entities are normalized and named entities are * converted to numeric entities. */ function stringToXML ($string) { - $string = stringStripTags($string); - $string = entity::named_to_numeric($string); - $string = entity::normalize_numeric($string); - - if ( i18n::get_current_charset() == 'UTF-8' ) - { - $string = entity::numeric_to_utf8($string); - } - - $string = entity::specialchars($string, 'xml'); - return $string; + return i18n::hen($string); } // START: functions from the end of file BLOG.php diff --git a/nucleus/libs/i18n.php b/nucleus/libs/i18n.php index e9c0ef7..05c257f 100644 --- a/nucleus/libs/i18n.php +++ b/nucleus/libs/i18n.php @@ -477,274 +477,6 @@ class i18n } /** - * i18n::mail - * Send mails with headers including 7bit-encoded multibyte string - * - * @static - * @access public - * @param string $to receivers including singlebyte and multibyte strings, based on RFC 5322 - * @param string $subject subject including singlebyte and multibyte strings - * @param string $message message including singlebyte and multibyte strings - * @param string $from senders including singlebyte and multibyte strings, based on RFC 5322 - * @param string(B/Q) $scheme 7bit-encoder scheme based on RFC 2047 - * @return boolean accepted delivery or not - */ - static public function mail($to, $subject, $message, $from, $scheme='B') - { - - $to = self::mailbox_list_encoder($to, $scheme); - $subject = self::seven_bit_characters_encoder($subject, $scheme); - $from = 'From: ' . self::mailbox_list_encoder($from, $scheme); - - /* - * All of 7bit character encoding derives from ISO/IEC 646 - * So we can decide the body's encoding bit count by this regular expression. - * - */ - $bitcount = '8bit'; - if ( preg_match('#\A[\x00-\x7f]*\z#', $message) ) - { - $bitcount = '7bit'; - } - - $headers = 'Content-Type: text/html; charset=' . self::$charset . "; format=flowed; delsp=yes\n" - . "Content-Transfer-Encoding: {$bitcount}\n" - . "X-Mailer: Nucleus CMS i18n class\n"; - - return mail($to, $subject, $message, "{$from}\n{$headers}"); - } - - /** - * i18n::mailbox_list_encoder - * Encode multi byte strings included in mailbox. - * The format of mailbox is based on RFC 5322, which obsoletes RFC 2822 - * - * @link http://www.ietf.org/rfc/rfc5322.txt - * @see 3.4. Address Specification - * - * @static - * @access private - * @param string $mailbox_list mailbox list - * @return string encoded string - * - */ - static private function mailbox_list_encoder ($mailbox_list, $scheme='B') - { - $encoded_mailboxes = array(); - $mailboxes = preg_split('#,#', $mailbox_list); - foreach ( $mailboxes as $mailbox ) - { - if ( preg_match("#^([^,]+)?<([^,]+)?@([^,]+)?>$#", $mailbox, $match) ) - { - $display_name = self::seven_bit_characters_encoder(trim($match[1]), $scheme); - $local_part = trim($match[2]); - $domain = trim($match[3]); - $encoded_mailboxes[] = "{$name} <{$local_part}@{$domain}>"; - } - else if ( preg_match("#([^,]+)?@([^,]+)?#", $mailbox) ) - { - $encoded_mailboxes[] = $mailbox; - } - else - { - continue; - } - } - if ( $encoded_mailboxes == array() ) - { - return FALSE; - } - return implode(',', $encoded_mailboxes); - } - - /** - * i18n::seven_bit_characters_encoder - * Encoder into 7bit ASCII expression for Non-ASCII Text based on RFC 2047. - * - * @link http://www.ietf.org/rfc/rfc2047.txt - * @see 2. Syntax of encoded-words - * - * NOTE: RFC 2047 has a ambiguousity for dealing with 'linear-white-space'. - * This causes a trouble related to line breaking between single byte and multi-byte strings. - * To avoid this, single byte string is encoded as well as multi byte string here. - * - * NOTE: RFC 2231 also defines the way to use non-ASCII characters in MIME header. - * http://www.ietf.org/rfc/rfc2231.txt - * - * NOTE: iconv extension give the same functions as this in PHP5 - * iconv_mime_encode(): - * http://www.php.net/manual/en/function.iconv-mime-encode.php - * - * @static - * @access private - * @param string $charset Character set encoding - * @param string $type type of 7 bit encoding, should be 'B' or 'Q' - * @param string $string Target string with header field - * @return string encoded string - * - */ - static private function seven_bit_characters_encoder($string, $scheme='B') - { - if ( $scheme != 'Q' ) - { - $scheme = 'B'; - } - $header = chr(13) . chr(10) . chr(32) . '=?' . self::$charset . "?{$scheme}?"; - $footer = "?="; - $restriction = 78 - strlen($header) - strlen($footer) ; - - $encoded_words = array(); - for ( $i = 0; $i < self::strlen($string); $i++ ) - { - if ( $scheme == 'B' ) - { - if ( $i == 0 ) - { - $letters = ''; - } - - $letter = self::substr($string, $i, 1); - $expected_length = strlen($letters) + strlen($letter) * 4 / 3; - - if ( $expected_length > $restriction ) - { - $encoded_text = self::b_encoder($letters); - $encoded_words[] = "{$header}{$encoded_text}{$footer}"; - $letters = ''; - } - - $letters .= $letter; - - if ( $i == self::strlen($string) - 1 ) - { - $encoded_text = self::b_encoder($letters); - $encoded_words[] = "{$header}{$encoded_text}{$footer}"; - break; - } - continue; - } - else - { - if ( $i == 0 ) - { - $encoded_text = ''; - } - - $encoded_letter = self::q_encoder(self::substr($string, $i, 1)); - $expected_length = strlen($encoded_text) + strlen($encoded_letter); - - if ( $expected_length > $restriction ) - { - $encoded_words[] = "{$header}{$encoded_text}{$footer}"; - $letters = ''; - } - - $encoded_text .= $encoded_letter; - - if ( $i == self::strlen($string) - 1 ) - { - $encoded_words[] = "{$header}{$encoded_text}{$footer}"; - break; - } - continue; - } - } - - return implode('', $encoded_words); - } - - /** - * B encoder according to RFC 2047. - * The "B" encoding is identical to the "BASE64" encoding defined by RFC 4648. - * - * @link http://www.ietf.org/rfc/rfc4648.txt - * @see 6.8. Base64 Content-Transfer-Encoding - * - * NOTE: According to RFC 4648 - * (1) The final quantum of encoding input is an integral multiple of 24 bits; - * here, the final unit of encoded output will be an integral multiple - * of 4 characters with no "=" padding. - * (2) The final quantum of encoding input is exactly 8 bits; here, - * the final unit of encoded output will be two characters followed - * by two "=" padding characters. - * (3) The final quantum of encoding input is exactly 16 bits; here, - * the final unit of encoded output will be three characters followed - * by one "=" padding character. - * - * @static - * @access private - * @param string $target targetted string - * @return string encoded string - */ - static private function b_encoder($target) - { - return base64_encode($target); - } - - /** - * Q encoder according to RFC 2047. - * The "Q" encoding is similar to "Quoted-Printable" content-transfer-encoding defined in RFC 2045, - * but the "Q" encoding and the "Quoted-Printable" are different a bit. - * - * @link http://www.ietf.org/rfc/rfc2047.txt - * @see 4.2. The "Q" encoding - * - * NOTE: According to RFC 2047 - * (1) Any 8-bit value may be represented by a "=" followed by two hexadecimal digits. - * For example, if the character set in use were ISO-8859-1, - * the "=" character would thus be encoded as "=3D", and a SPACE by "=20". - * (Upper case should be used for hexadecimal digits "A" through "F".) - * (2) The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be - * represented as "_" (underscore, ASCII 95.). - * (This character may not pass through some internetwork mail gateways, - * but its use will greatly enhance readability of "Q" encoded data - * with mail readers that do not support this encoding.) - * Note that the "_" always represents hexadecimal 20, - * even if the SPACE character occupies a different code position - * in the character set in use. - * (3) 8-bit values which correspond to printable ASCII characters - * other than "=", "?", and "_" (underscore), MAY be represented as those characters. - * (But see section 5 for restrictions.) - * In particular, SPACE and TAB MUST NOT be represented as themselves within encoded words. - * - * @static - * @access private - * @param string $target targetted string - * @return string encoded string - */ - static private function q_encoder($target) - { - $string = ''; - - for ( $i = 0; $i < strlen($target); $i++ ) - { - $letter = substr ($target, $i, 1); - $order = ord($letter); - - // Printable ASCII characters without "=", "?", "_" - if ((33 <= $order && $order <= 60) - || (62 == $order) - || (64 <= $order && $order <= 94) - || (96 <= $order && $order <= 126)) - { - $string .= strtoupper(dechex($order)); - } - // Space shuold be encoded as the same strings as "_" - else if ($order == 32) - { - $string .= '_'; - } - // Other characters - else - { - $string .= '=' . strtoupper(dechex($order)); - } - } - - return $string; - } - - /** * i18n::convert_locale_to_old_language_file_name() * NOTE: this should be obsoleted near future. * -- 2.11.0