From 77c28206a14b5bee3f3091f10cffd531bce5649c Mon Sep 17 00:00:00 2001 From: yllar <yllar.pajus@gmail.com> Date: Sat, 16 Dec 2006 13:25:16 -0500 Subject: [PATCH] updated ja and fr translations --- program/lib/Mail/mime.php | 148 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 130 insertions(+), 18 deletions(-) diff --git a/program/lib/Mail/mime.php b/program/lib/Mail/mime.php index de2bba0..a9f798e 100644 --- a/program/lib/Mail/mime.php +++ b/program/lib/Mail/mime.php @@ -114,6 +114,7 @@ { $this->_setEOL($crlf); $this->_build_params = array( + 'head_encoding' => 'quoted-printable', 'text_encoding' => '7bit', 'html_encoding' => 'quoted-printable', '7bit_wrap' => 998, @@ -197,6 +198,16 @@ } /** + * returns the HTML body portion of the message + * @return string HTML body of the message + * @access public + */ + function getHTMLBody() + { + return $this->_htmlbody; + } + + /** * Adds an image to the list of embedded images. * * @param string $file The image file name OR image data itself @@ -205,11 +216,13 @@ * Only use if $file is the image data * @param bool $isfilename Whether $file is a filename or not * Defaults to true + * @param string $contentid Desired Content-ID of MIME part + * Defaults to generated unique ID * @return mixed true on success or PEAR_Error object * @access public */ function addHTMLImage($file, $c_type='application/octet-stream', - $name = '', $isfilename = true) + $name = '', $isfilename = true, $contentid = '') { $filedata = ($isfilename === true) ? $this->_file2str($file) : $file; @@ -221,11 +234,14 @@ if (PEAR::isError($filedata)) { return $filedata; } + if ($contentid == '') { + $contentid = md5(uniqid(time())); + } $this->_html_images[] = array( 'body' => $filedata, 'name' => $filename, 'c_type' => $c_type, - 'cid' => md5(uniqid(time())) + 'cid' => $contentid ); return true; } @@ -247,13 +263,15 @@ * @param string $disposition The content-disposition of this file * Defaults to attachment. * Possible values: attachment, inline. + * @param string $charset The character set used in the filename + * of this attachment. * @return mixed true on success or PEAR_Error object * @access public */ function addAttachment($file, $c_type = 'application/octet-stream', $name = '', $isfilename = true, $encoding = 'base64', - $disposition = 'attachment') + $disposition = 'attachment', $charset = '') { $filedata = ($isfilename === true) ? $this->_file2str($file) : $file; @@ -279,6 +297,7 @@ 'name' => $filename, 'c_type' => $c_type, 'encoding' => $encoding, + 'charset' => $charset, 'disposition' => $disposition ); return true; @@ -433,7 +452,7 @@ function &_addHtmlImagePart(&$obj, $value) { $params['content_type'] = $value['c_type'] . '; ' . - 'name="' . $params['dfilename'] . '"'; + 'name="' . $value['name'] . '"'; $params['encoding'] = 'base64'; $params['disposition'] = 'inline'; $params['dfilename'] = $value['name']; @@ -454,12 +473,20 @@ */ function &_addAttachmentPart(&$obj, $value) { + $params['dfilename'] = $value['name']; + $params['encoding'] = $value['encoding']; + if ($value['disposition'] != "inline") { + $fname = array("fname" => $value['name']); + $fname_enc = $this->_encodeHeaders($fname); + $params['dfilename'] = $fname_enc['fname']; + } + if ($value['charset']) { + $params['charset'] = $value['charset']; + } $params['content_type'] = $value['c_type'] . '; ' . 'name="' . $params['dfilename'] . '"'; - $params['encoding'] = $value['encoding']; $params['disposition'] = isset($value['disposition']) ? $value['disposition'] : 'attachment'; - $params['dfilename'] = $value['name']; $ret = $obj->addSubpart($value['body'], $params); return $ret; } @@ -500,9 +527,14 @@ * * @param array Build parameters that change the way the email * is built. Should be associative. Can contain: + * head_encoding - What encoding to use for the headers. + * Options: quoted-printable or base64 + * Default is quoted-printable * text_encoding - What encoding to use for plain text + * Options: 7bit, 8bit, base64, or quoted-printable * Default is 7bit * html_encoding - What encoding to use for html + * Options: 7bit, 8bit, base64, or quoted-printable * Default is quoted-printable * 7bit_wrap - Number of characters before text is * wrapped in 7bit encoding @@ -743,31 +775,110 @@ } /** + * Since the PHP send function requires you to specifiy + * recipients (To: header) separately from the other + * headers, the To: header is not properly encoded. + * To fix this, you can use this public method to + * encode your recipients before sending to the send + * function + * + * @param string $recipients A comma-delimited list of recipients + * @return string Encoded data + * @access public + */ + function encodeRecipients($recipients) + { + $input = array("To" => $recipients); + $retval = $this->_encodeHeaders($input); + return $retval["To"] ; + } + + /** * Encodes a header as per RFC2047 * - * @param string $input The header data to encode - * @return string Encoded data + * @param array $input The header data to encode + * @return array Encoded data * @access private */ function _encodeHeaders($input) { + $maxlen = 73; foreach ($input as $hdr_name => $hdr_value) { - preg_match_all('/(\w*[\x80-\xFF]+\w*)/', $hdr_value, $matches); - foreach ($matches[1] as $value) { - $replacement = preg_replace('/([\x80-\xFF])/e', - '"=" . - strtoupper(dechex(ord("\1")))', - $value); - $hdr_value = str_replace($value, '=?' . - $this->_build_params['head_charset'] . - '?Q?' . $replacement . '?=', - $hdr_value); + // if header contains e-mail addresses + if (preg_match('/\s<.+@[a-z0-9\-\.]+\.[a-z]+>/U', $hdr_value)) + $chunks = $this->_explode_quoted_string(',', $hdr_value); + else + $chunks = array($hdr_value); + + $hdr_value = ''; + $line_len = 0; + + foreach ($chunks as $i => $value) { + $value = trim($value); + + //This header contains non ASCII chars and should be encoded. + if (preg_match('#[\x80-\xFF]{1}#', $value)) { + $suffix = ''; + // Don't encode e-mail address + if (preg_match('/(.+)\s(<.+@[a-z0-9\-\.]+>)$/Ui', $value, $matches)) { + $value = $matches[1]; + $suffix = ' '.$matches[2]; + } + + switch ($this->_build_params['head_encoding']) { + case 'base64': + // Base64 encoding has been selected. + $mode = 'B'; + $encoded = base64_encode($value); + break; + + case 'quoted-printable': + default: + // quoted-printable encoding has been selected + $mode = 'Q'; + $encoded = preg_replace('/([\x20-\x25\x2C\x80-\xFF])/e', "'='.sprintf('%02X', ord('\\1'))", $value); + // replace spaces with _ + $encoded = str_replace('=20', '_', $encoded); + } + + $value = '=?' . $this->_build_params['head_charset'] . '?' . $mode . '?' . $encoded . '?=' . $suffix; + } + + // add chunk to output string by regarding the header maxlen + $len = strlen($value); + if ($line_len + $len < $maxlen) { + $hdr_value .= ($i>0?', ':'') . $value; + $line_len += $len + ($i>0?2:0); + } + else { + $hdr_value .= ($i>0?', ':'') . "\n " . $value; + $line_len = $len; + } } + $input[$hdr_name] = $hdr_value; } return $input; } + + + function _explode_quoted_string($delimiter, $string) + { + $quotes = explode("\"", $string); + foreach ($quotes as $key => $val) + if (($key % 2) == 1) + $quotes[$key] = str_replace($delimiter, "_!@!_", $quotes[$key]); + + $string = implode("\"", $quotes); + + $result = explode($delimiter, $string); + foreach ($result as $key => $val) + $result[$key] = str_replace("_!@!_", $delimiter, $result[$key]); + + return $result; + } + /** * Set the object's end-of-line and define the constant if applicable @@ -787,3 +898,4 @@ } // End of class ?> + -- Gitblit v1.9.1