X-Git-Url: http://git.osdn.net/view?p=nucleus-jp%2Fnucleus-next.git;a=blobdiff_plain;f=nucleus%2Flibs%2FNOTIFICATION.php;h=1d708d10ba841cc823578c01d78773c8bf18eaad;hp=e756712a567d3fbd614a7bf909952feabf095256;hb=0f2bcd518e8d035a5e25317d7900a9eb23d80e80;hpb=b767b4e8351829b6af6852b13d572e7cc28ca8d3 diff --git a/nucleus/libs/NOTIFICATION.php b/nucleus/libs/NOTIFICATION.php index e756712..1d708d1 100644 --- a/nucleus/libs/NOTIFICATION.php +++ b/nucleus/libs/NOTIFICATION.php @@ -1,399 +1,399 @@ -$#", $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 < i18n::strlen($string); $i++ ) - { - if ( self::$scheme == 'B' ) - { - if ( $i == 0 ) - { - $letters = ''; - } - - $letter = i18n::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 == i18n::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 == i18n::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 = preg_split('#;#' , $addresses); - } - - /** - * 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; - } - - /** - * 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; - $addresses = array(); - - foreach ($this->addresses as $address) - { - if ( $member->isLoggedIn() && ($member->getEmail() == $address) ) - { - continue; - } - $addresses[] = $address; - } - - self::mail(implode(',', $addresses), $title, $message , $from); - return; - } -} +$#", $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 < i18n::strlen($string); $i++ ) + { + if ( self::$scheme == 'B' ) + { + if ( $i == 0 ) + { + $letters = ''; + } + + $letter = i18n::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 == i18n::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(i18n::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 == i18n::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 = preg_split('#;#' , $addresses); + } + + /** + * 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; + } + + /** + * 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; + $addresses = array(); + + foreach ($this->addresses as $address) + { + if ( $member->isLoggedIn() && ($member->getEmail() == $address) ) + { + continue; + } + $addresses[] = $address; + } + + self::mail(implode(',', $addresses), $title, $message , $from); + return; + } +}