| version 1.1, 2005/06/05 12:14:29 |
version 1.2, 2005/11/07 20:37:49 |
|
|
| <?php
|
<?php |
| // +-----------------------------------------------------------------------+
|
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
| // | Copyright (c) 2002 Richard Heyes |
|
// +-----------------------------------------------------------------------+ |
| // | All rights reserved. |
|
// | Copyright (c) 2002-2003 Richard Heyes | |
| // | |
|
// | Copyright (c) 2003-2005 The PHP Group | |
| // | Redistribution and use in source and binary forms, with or without |
|
// | All rights reserved. | |
| // | modification, are permitted provided that the following conditions |
|
// | | |
| // | are met: |
|
// | Redistribution and use in source and binary forms, with or without | |
| // | |
|
// | modification, are permitted provided that the following conditions | |
| // | o Redistributions of source code must retain the above copyright |
|
// | are met: | |
| // | notice, this list of conditions and the following disclaimer. |
|
// | | |
| // | o Redistributions in binary form must reproduce the above copyright |
|
// | o Redistributions of source code must retain the above copyright | |
| // | notice, this list of conditions and the following disclaimer in the |
|
// | notice, this list of conditions and the following disclaimer. | |
| // | documentation and/or other materials provided with the distribution.|
|
// | o Redistributions in binary form must reproduce the above copyright | |
| // | o The names of the authors may not be used to endorse or promote |
|
// | notice, this list of conditions and the following disclaimer in the | |
| // | products derived from this software without specific prior written |
|
// | documentation and/or other materials provided with the distribution.| |
| // | permission. |
|
// | o The names of the authors may not be used to endorse or promote | |
| // | |
|
// | products derived from this software without specific prior written | |
| // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
// | permission. | |
| // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
// | | |
| // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| // | |
|
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| // +-----------------------------------------------------------------------+
|
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| // | Author: Richard Heyes <richard@phpguru.org> |
|
// | | |
| // | Tomas V.V.Cox <cox@idecnet.com> (port to PEAR) |
|
// +-----------------------------------------------------------------------+ |
| // +-----------------------------------------------------------------------+
|
// | Author: Richard Heyes <richard@phpguru.org> | |
| //
|
// | Tomas V.V.Cox <cox@idecnet.com> (port to PEAR) | |
| // $Id$
|
// +-----------------------------------------------------------------------+ |
|
|
// |
| require_once 'PEAR.php';
|
// $Id$ |
| require_once 'Mail/mimePart.php';
|
|
|
|
require_once('PEAR.php'); |
| /**
|
require_once('Mail/mimePart.php'); |
| * Mime mail composer class. Can handle: text and html bodies, embedded html
|
|
| * images and attachments.
|
/** |
| * Documentation and examples of this class are avaible here:
|
* Mime mail composer class. Can handle: text and html bodies, embedded html |
| * http://pear.php.net/manual/
|
* images and attachments. |
| *
|
* Documentation and examples of this class are avaible here: |
| * @notes This class is based on HTML Mime Mail class from
|
* http://pear.php.net/manual/ |
| * Richard Heyes <richard@phpguru.org> which was based also
|
* |
| * in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it> and
|
* @notes This class is based on HTML Mime Mail class from |
| * Sascha Schumann <sascha@schumann.cx>.
|
* Richard Heyes <richard@phpguru.org> which was based also |
| *
|
* in the mime_mail.class by Tobias Ratschiller <tobias@dnet.it> and |
| * @author Richard Heyes <richard.heyes@heyes-computing.net>
|
* Sascha Schumann <sascha@schumann.cx> |
| * @author Tomas V.V.Cox <cox@idecnet.com>
|
* |
| * @package Mail
|
* @author Richard Heyes <richard.heyes@heyes-computing.net> |
| * @access public
|
* @author Tomas V.V.Cox <cox@idecnet.com> |
| */
|
* @package Mail |
| class Mail_mime
|
* @access public |
| {
|
*/ |
| /**
|
class Mail_mime |
| * Contains the plain text part of the email
|
{ |
| * @var string
|
/** |
| */
|
* Contains the plain text part of the email |
| var $_txtbody;
|
* @var string |
| /**
|
*/ |
| * Contains the html part of the email
|
var $_txtbody; |
| * @var string
|
/** |
| */
|
* Contains the html part of the email |
| var $_htmlbody;
|
* @var string |
| /**
|
*/ |
| * contains the mime encoded text
|
var $_htmlbody; |
| * @var string
|
/** |
| */
|
* contains the mime encoded text |
| var $_mime;
|
* @var string |
| /**
|
*/ |
| * contains the multipart content
|
var $_mime; |
| * @var string
|
/** |
| */
|
* contains the multipart content |
| var $_multipart;
|
* @var string |
| /**
|
*/ |
| * list of the attached images
|
var $_multipart; |
| * @var array
|
/** |
| */
|
* list of the attached images |
| var $_html_images = array();
|
* @var array |
| /**
|
*/ |
| * list of the attachements
|
var $_html_images = array(); |
| * @var array
|
/** |
| */
|
* list of the attachements |
| var $_parts = array();
|
* @var array |
| /**
|
*/ |
| * Build parameters
|
var $_parts = array(); |
| * @var array
|
/** |
| */
|
* Build parameters |
| var $_build_params = array();
|
* @var array |
| /**
|
*/ |
| * Headers for the mail
|
var $_build_params = array(); |
| * @var array
|
/** |
| */
|
* Headers for the mail |
| var $_headers = array();
|
* @var array |
|
|
*/ |
|
|
var $_headers = array(); |
| /*
|
/** |
| * Constructor function
|
* End Of Line sequence (for serialize) |
| *
|
* @var string |
| * @access public
|
*/ |
| */
|
var $_eol; |
| function Mail_mime($crlf = "\r\n")
|
|
| {
|
|
| if (!defined('MAIL_MIME_CRLF')) {
|
/** |
| define('MAIL_MIME_CRLF', $crlf, true);
|
* Constructor function |
| }
|
* |
|
|
* @access public |
| $this->_boundary = '=_' . md5(uniqid(time()));
|
*/ |
|
|
function Mail_mime($crlf = "\r\n") |
| $this->_build_params = array(
|
{ |
| 'text_encoding' => '7bit',
|
$this->_setEOL($crlf); |
| 'html_encoding' => 'quoted-printable',
|
$this->_build_params = array( |
| '7bit_wrap' => 998,
|
'text_encoding' => '7bit', |
| 'html_charset' => 'ISO-8859-1',
|
'html_encoding' => 'quoted-printable', |
| 'text_charset' => 'ISO-8859-1',
|
'7bit_wrap' => 998, |
| 'head_charset' => 'ISO-8859-1'
|
'html_charset' => 'ISO-8859-1', |
| );
|
'text_charset' => 'ISO-8859-1', |
| }
|
'head_charset' => 'ISO-8859-1' |
|
|
); |
| /*
|
} |
| * Accessor function to set the body text. Body text is used if
|
|
| * it's not an html mail being sent or else is used to fill the
|
/** |
| * text/plain part that emails clients who don't support
|
* Wakeup (unserialize) - re-sets EOL constant |
| * html should show.
|
* |
| *
|
* @access private |
| * @param string $data Either a string or the file name with the
|
*/ |
| * contents
|
function __wakeup() |
| * @param bool $isfile If true the first param should be trated
|
{ |
| * as a file name, else as a string (default)
|
$this->_setEOL($this->_eol); |
| * @param bool If true the text or file is appended to the
|
} |
| * existing body, else the old body is overwritten
|
|
| * @return mixed true on success or PEAR_Error object
|
/** |
| * @access public
|
* Accessor function to set the body text. Body text is used if |
| */
|
* it's not an html mail being sent or else is used to fill the |
| function setTXTBody($data, $isfile = false, $append = false)
|
* text/plain part that emails clients who don't support |
| {
|
* html should show. |
| if (!$isfile) {
|
* |
| if (!$append) {
|
* @param string $data Either a string or |
| $this->_txtbody = $data;
|
* the file name with the contents |
| } else {
|
* @param bool $isfile If true the first param should be treated |
| $this->_txtbody .= $data;
|
* as a file name, else as a string (default) |
| }
|
* @param bool $append If true the text or file is appended to |
| } else {
|
* the existing body, else the old body is |
| $cont = $this->_file2str($data);
|
* overwritten |
| if (PEAR::isError($cont)) {
|
* @return mixed true on success or PEAR_Error object |
| return $cont;
|
* @access public |
| }
|
*/ |
| if (!$append) {
|
function setTXTBody($data, $isfile = false, $append = false) |
| $this->_txtbody = $cont;
|
{ |
| } else {
|
if (!$isfile) { |
| $this->_txtbody .= $cont;
|
if (!$append) { |
| }
|
$this->_txtbody = $data; |
| }
|
} else { |
| return true;
|
$this->_txtbody .= $data; |
| }
|
} |
|
|
} else { |
| /*
|
$cont = $this->_file2str($data); |
| * Adds a html part to the mail
|
if (PEAR::isError($cont)) { |
| *
|
return $cont; |
| * @param string $data Either a string or the file name with the
|
} |
| * contents
|
if (!$append) { |
| * @param bool $isfile If true the first param should be trated
|
$this->_txtbody = $cont; |
| * as a file name, else as a string (default)
|
} else { |
| * @return mixed true on success or PEAR_Error object
|
$this->_txtbody .= $cont; |
| * @access public
|
} |
| */
|
} |
| function setHTMLBody($data, $isfile = false)
|
return true; |
| {
|
} |
| if (!$isfile) {
|
|
| $this->_htmlbody = $data;
|
/** |
| } else {
|
* Adds a html part to the mail |
| $cont = $this->_file2str($data);
|
* |
| if (PEAR::isError($cont)) {
|
* @param string $data Either a string or the file name with the |
| return $cont;
|
* contents |
| }
|
* @param bool $isfile If true the first param should be treated |
| $this->_htmlbody = $cont;
|
* as a file name, else as a string (default) |
| }
|
* @return mixed true on success or PEAR_Error object |
|
|
* @access public |
| return true;
|
*/ |
| }
|
function setHTMLBody($data, $isfile = false) |
|
|
{ |
| /*
|
if (!$isfile) { |
| * Adds an image to the list of embedded images.
|
$this->_htmlbody = $data; |
| *
|
} else { |
| * @param string $file The image file name OR image data itself
|
$cont = $this->_file2str($data); |
| * @param string $c_type The content type
|
if (PEAR::isError($cont)) { |
| * @param string $name The filename of the image. Only use if $file is the image data
|
return $cont; |
| * @param bool $isfilename Whether $file is a filename or not. Defaults to true
|
} |
| * @return mixed true on success or PEAR_Error object
|
$this->_htmlbody = $cont; |
| * @access public
|
} |
| */
|
|
| function addHTMLImage($file, $c_type='application/octet-stream', $name = '', $isfilename = true)
|
return true; |
| {
|
} |
| $filedata = ($isfilename === true) ? $this->_file2str($file) : $file;
|
|
| $filename = ($isfilename === true) ? basename($file) : basename($name);
|
/** |
| if (PEAR::isError($filedata)) {
|
* Adds an image to the list of embedded images. |
| return $filedata;
|
* |
| }
|
* @param string $file The image file name OR image data itself |
| $this->_html_images[] = array(
|
* @param string $c_type The content type |
| 'body' => $filedata,
|
* @param string $name The filename of the image. |
| 'name' => $filename,
|
* Only use if $file is the image data |
| 'c_type' => $c_type,
|
* @param bool $isfilename Whether $file is a filename or not |
| 'cid' => md5(uniqid(time()))
|
* Defaults to true |
| );
|
* @return mixed true on success or PEAR_Error object |
| return true;
|
* @access public |
| }
|
*/ |
|
|
function addHTMLImage($file, $c_type='application/octet-stream', |
| /*
|
$name = '', $isfilename = true) |
| * Adds a file to the list of attachments.
|
{ |
| *
|
$filedata = ($isfilename === true) ? $this->_file2str($file) |
| * @param string $file The file name of the file to attach OR the file data itself
|
: $file; |
| * @param string $c_type The content type
|
if ($isfilename === true) { |
| * @param string $name The filename of the attachment. Only use if $file is the file data
|
$filename = ($name == '' ? basename($file) : basename($name)); |
| * @param bool $isFilename Whether $file is a filename or not. Defaults to true
|
} else { |
| * @return mixed true on success or PEAR_Error object
|
$filename = basename($name); |
| * @access public
|
} |
| */
|
if (PEAR::isError($filedata)) { |
| function addAttachment($file, $c_type='application/octet-stream', $name = '', $isfilename = true, $encoding = 'base64')
|
return $filedata; |
| {
|
} |
| $filedata = ($isfilename === true) ? $this->_file2str($file) : $file;
|
$this->_html_images[] = array( |
| if ($isfilename === true) {
|
'body' => $filedata, |
| // Force the name the user supplied, otherwise use $file
|
'name' => $filename, |
| $filename = (!empty($name)) ? $name : $file;
|
'c_type' => $c_type, |
| } else {
|
'cid' => md5(uniqid(time())) |
| $filename = $name;
|
); |
| }
|
return true; |
| if (empty($filename)) {
|
} |
| return PEAR::raiseError('The supplied filename for the attachment can\'t be empty');
|
|
| }
|
/** |
| $filename = basename($filename);
|
* Adds a file to the list of attachments. |
| if (PEAR::isError($filedata)) {
|
* |
| return $filedata;
|
* @param string $file The file name of the file to attach |
| }
|
* OR the file data itself |
|
|
* @param string $c_type The content type |
| $this->_parts[] = array(
|
* @param string $name The filename of the attachment |
| 'body' => $filedata,
|
* Only use if $file is the file data |
| 'name' => $filename,
|
* @param bool $isFilename Whether $file is a filename or not |
| 'c_type' => $c_type,
|
* Defaults to true |
| 'encoding' => $encoding
|
* @return mixed true on success or PEAR_Error object |
| );
|
* @access public |
| return true;
|
*/ |
| }
|
function addAttachment($file, $c_type = 'application/octet-stream', |
|
|
$name = '', $isfilename = true, |
| /*
|
$encoding = 'base64') |
| * Returns the contents of the given file name as string
|
{ |
| * @param string $file_name
|
$filedata = ($isfilename === true) ? $this->_file2str($file) |
| * @return string
|
: $file; |
| * @acces private
|
if ($isfilename === true) { |
| */
|
// Force the name the user supplied, otherwise use $file |
| function & _file2str($file_name)
|
$filename = (!empty($name)) ? $name : $file; |
| {
|
} else { |
| if (!is_readable($file_name)) {
|
$filename = $name; |
| return PEAR::raiseError('File is not readable ' . $file_name);
|
} |
| }
|
if (empty($filename)) { |
| if (!$fd = fopen($file_name, 'rb')) {
|
return PEAR::raiseError( |
| return PEAR::raiseError('Could not open ' . $file_name);
|
'The supplied filename for the attachment can\'t be empty' |
| }
|
); |
| $cont = fread($fd, filesize($file_name));
|
} |
| fclose($fd);
|
$filename = basename($filename); |
| return $cont;
|
if (PEAR::isError($filedata)) { |
| }
|
return $filedata; |
|
|
} |
| /*
|
|
| * Adds a text subpart to the mimePart object and
|
$this->_parts[] = array( |
| * returns it during the build process.
|
'body' => $filedata, |
| *
|
'name' => $filename, |
| * @param mixed The object to add the part to, or
|
'c_type' => $c_type, |
| * null if a new object is to be created.
|
'encoding' => $encoding |
| * @param string The text to add.
|
); |
| * @return object The text mimePart object
|
return true; |
| * @access private
|
} |
| */
|
|
| function &_addTextPart(&$obj, $text){
|
/** |
|
|
* Get the contents of the given file name as string |
| $params['content_type'] = 'text/plain';
|
* |
| $params['encoding'] = $this->_build_params['text_encoding'];
|
* @param string $file_name path of file to process |
| $params['charset'] = $this->_build_params['text_charset'];
|
* @return string contents of $file_name |
| if (is_object($obj)) {
|
* @access private |
| return $obj->addSubpart($text, $params);
|
*/ |
| } else {
|
function &_file2str($file_name) |
| return new Mail_mimePart($text, $params);
|
{ |
| }
|
if (!is_readable($file_name)) { |
| }
|
return PEAR::raiseError('File is not readable ' . $file_name); |
|
|
} |
| /*
|
if (!$fd = fopen($file_name, 'rb')) { |
| * Adds a html subpart to the mimePart object and
|
return PEAR::raiseError('Could not open ' . $file_name); |
| * returns it during the build process.
|
} |
| *
|
$filesize = filesize($file_name); |
| * @param mixed The object to add the part to, or
|
if ($filesize == 0){ |
| * null if a new object is to be created.
|
$cont = ""; |
| * @return object The html mimePart object
|
}else{ |
| * @access private
|
$cont = fread($fd, $filesize); |
| */
|
} |
| function &_addHtmlPart(&$obj){
|
fclose($fd); |
|
|
return $cont; |
| $params['content_type'] = 'text/html';
|
} |
| $params['encoding'] = $this->_build_params['html_encoding'];
|
|
| $params['charset'] = $this->_build_params['html_charset'];
|
/** |
| if (is_object($obj)) {
|
* Adds a text subpart to the mimePart object and |
| return $obj->addSubpart($this->_htmlbody, $params);
|
* returns it during the build process. |
| } else {
|
* |
| return new Mail_mimePart($this->_htmlbody, $params);
|
* @param mixed The object to add the part to, or |
| }
|
* null if a new object is to be created. |
| }
|
* @param string The text to add. |
|
|
* @return object The text mimePart object |
| /*
|
* @access private |
| * Creates a new mimePart object, using multipart/mixed as
|
*/ |
| * the initial content-type and returns it during the
|
function &_addTextPart(&$obj, $text) |
| * build process.
|
{ |
| *
|
$params['content_type'] = 'text/plain'; |
| * @return object The multipart/mixed mimePart object
|
$params['encoding'] = $this->_build_params['text_encoding']; |
| * @access private
|
$params['charset'] = $this->_build_params['text_charset']; |
| */
|
if (is_object($obj)) { |
| function &_addMixedPart(){
|
return $obj->addSubpart($text, $params); |
|
|
} else { |
| $params['content_type'] = 'multipart/mixed';
|
return new Mail_mimePart($text, $params); |
| return new Mail_mimePart('', $params);
|
} |
| }
|
} |
|
|
|
| /*
|
/** |
| * Adds a multipart/alternative part to a mimePart
|
* Adds a html subpart to the mimePart object and |
| * object, (or creates one), and returns it during
|
* returns it during the build process. |
| * the build process.
|
* |
| *
|
* @param mixed The object to add the part to, or |
| * @param mixed The object to add the part to, or
|
* null if a new object is to be created. |
| * null if a new object is to be created.
|
* @return object The html mimePart object |
| * @return object The multipart/mixed mimePart object
|
* @access private |
| * @access private
|
*/ |
| */
|
function &_addHtmlPart(&$obj) |
| function &_addAlternativePart(&$obj){
|
{ |
|
|
$params['content_type'] = 'text/html'; |
| $params['content_type'] = 'multipart/alternative';
|
$params['encoding'] = $this->_build_params['html_encoding']; |
| if (is_object($obj)) {
|
$params['charset'] = $this->_build_params['html_charset']; |
| return $obj->addSubpart('', $params);
|
if (is_object($obj)) { |
| } else {
|
return $obj->addSubpart($this->_htmlbody, $params); |
| return new Mail_mimePart('', $params);
|
} else { |
| }
|
return new Mail_mimePart($this->_htmlbody, $params); |
| }
|
} |
|
|
} |
| /*
|
|
| * Adds a multipart/related part to a mimePart
|
/** |
| * object, (or creates one), and returns it during
|
* Creates a new mimePart object, using multipart/mixed as |
| * the build process.
|
* the initial content-type and returns it during the |
| *
|
* build process. |
| * @param mixed The object to add the part to, or
|
* |
| * null if a new object is to be created.
|
* @return object The multipart/mixed mimePart object |
| * @return object The multipart/mixed mimePart object
|
* @access private |
| * @access private
|
*/ |
| */
|
function &_addMixedPart() |
| function &_addRelatedPart(&$obj){
|
{ |
|
|
$params['content_type'] = 'multipart/mixed'; |
| $params['content_type'] = 'multipart/related';
|
return new Mail_mimePart('', $params); |
| if (is_object($obj)) {
|
} |
| return $obj->addSubpart('', $params);
|
|
| } else {
|
/** |
| return new Mail_mimePart('', $params);
|
* Adds a multipart/alternative part to a mimePart |
| }
|
* object (or creates one), and returns it during |
| }
|
* the build process. |
|
|
* |
| /*
|
* @param mixed The object to add the part to, or |
| * Adds an html image subpart to a mimePart object
|
* null if a new object is to be created. |
| * and returns it during the build process.
|
* @return object The multipart/mixed mimePart object |
| *
|
* @access private |
| * @param object The mimePart to add the image to
|
*/ |
| * @param array The image information
|
function &_addAlternativePart(&$obj) |
| * @return object The image mimePart object
|
{ |
| * @access private
|
$params['content_type'] = 'multipart/alternative'; |
| */
|
if (is_object($obj)) { |
| function &_addHtmlImagePart(&$obj, $value){
|
return $obj->addSubpart('', $params); |
|
|
} else { |
| $params['content_type'] = $value['c_type'];
|
return new Mail_mimePart('', $params); |
| $params['encoding'] = 'base64';
|
} |
| $params['disposition'] = 'inline';
|
} |
| $params['dfilename'] = $value['name'];
|
|
| $params['cid'] = $value['cid'];
|
/** |
| $obj->addSubpart($value['body'], $params);
|
* Adds a multipart/related part to a mimePart |
| }
|
* object (or creates one), and returns it during |
|
|
* the build process. |
| /*
|
* |
| * Adds an attachment subpart to a mimePart object
|
* @param mixed The object to add the part to, or |
| * and returns it during the build process.
|
* null if a new object is to be created |
| *
|
* @return object The multipart/mixed mimePart object |
| * @param object The mimePart to add the image to
|
* @access private |
| * @param array The attachment information
|
*/ |
| * @return object The image mimePart object
|
function &_addRelatedPart(&$obj) |
| * @access private
|
{ |
| */
|
$params['content_type'] = 'multipart/related'; |
| function &_addAttachmentPart(&$obj, $value){
|
if (is_object($obj)) { |
|
|
return $obj->addSubpart('', $params); |
| $params['content_type'] = $value['c_type'];
|
} else { |
| $params['encoding'] = $value['encoding'];
|
return new Mail_mimePart('', $params); |
| $params['disposition'] = 'attachment';
|
} |
| $params['dfilename'] = $value['name'];
|
} |
| $obj->addSubpart($value['body'], $params);
|
|
| }
|
/** |
|
|
* Adds an html image subpart to a mimePart object |
| /*
|
* and returns it during the build process. |
| * Builds the multipart message from the list ($this->_parts) and
|
* |
| * returns the mime content.
|
* @param object The mimePart to add the image to |
| *
|
* @param array The image information |
| * @param array Build parameters that change the way the email
|
* @return object The image mimePart object |
| * is built. Should be associative. Can contain:
|
* @access private |
| * text_encoding - What encoding to use for plain text
|
*/ |
| * Default is 7bit
|
function &_addHtmlImagePart(&$obj, $value) |
| * html_encoding - What encoding to use for html
|
{ |
| * Default is quoted-printable
|
$params['content_type'] = $value['c_type']; |
| * 7bit_wrap - Number of characters before text is
|
$params['encoding'] = 'base64'; |
| * wrapped in 7bit encoding
|
$params['disposition'] = 'inline'; |
| * Default is 998
|
$params['dfilename'] = $value['name']; |
| * html_charset - The character set to use for html.
|
$params['cid'] = $value['cid']; |
| * Default is iso-8859-1
|
$obj->addSubpart($value['body'], $params); |
| * text_charset - The character set to use for text.
|
} |
| * Default is iso-8859-1
|
|
| * head_charset - The character set to use for headers.
|
/** |
| * Default is iso-8859-1
|
* Adds an attachment subpart to a mimePart object |
| * @return string The mime content
|
* and returns it during the build process. |
| * @access public
|
* |
| */
|
* @param object The mimePart to add the image to |
| function &get($build_params = null)
|
* @param array The attachment information |
| {
|
* @return object The image mimePart object |
| if (isset($build_params)) {
|
* @access private |
| while (list($key, $value) = each($build_params)) {
|
*/ |
| $this->_build_params[$key] = $value;
|
function &_addAttachmentPart(&$obj, $value) |
| }
|
{ |
| }
|
$params['content_type'] = $value['c_type']; |
|
|
$params['encoding'] = $value['encoding']; |
| if (!empty($this->_html_images) AND isset($this->_htmlbody)) {
|
$params['disposition'] = 'attachment'; |
| foreach ($this->_html_images as $value) {
|
$params['dfilename'] = $value['name']; |
| $this->_htmlbody = str_replace($value['name'], 'cid:'.$value['cid'], $this->_htmlbody);
|
$obj->addSubpart($value['body'], $params); |
| }
|
} |
| }
|
|
|
|
/** |
| $null = null;
|
* Builds the multipart message from the list ($this->_parts) and |
| $attachments = !empty($this->_parts) ? TRUE : FALSE;
|
* returns the mime content. |
| $html_images = !empty($this->_html_images) ? TRUE : FALSE;
|
* |
| $html = !empty($this->_htmlbody) ? TRUE : FALSE;
|
* @param array Build parameters that change the way the email |
| $text = (!$html AND !empty($this->_txtbody)) ? TRUE : FALSE;
|
* is built. Should be associative. Can contain: |
|
|
* text_encoding - What encoding to use for plain text |
| switch (TRUE) {
|
* Default is 7bit |
| case $text AND !$attachments:
|
* html_encoding - What encoding to use for html |
| $message =& $this->_addTextPart($null, $this->_txtbody);
|
* Default is quoted-printable |
| break;
|
* 7bit_wrap - Number of characters before text is |
|
|
* wrapped in 7bit encoding |
| case !$text AND !$html AND $attachments:
|
* Default is 998 |
| $message =& $this->_addMixedPart();
|
* html_charset - The character set to use for html. |
|
|
* Default is iso-8859-1 |
| for ($i = 0; $i < count($this->_parts); $i++) {
|
* text_charset - The character set to use for text. |
| $this->_addAttachmentPart($message, $this->_parts[$i]);
|
* Default is iso-8859-1 |
| }
|
* head_charset - The character set to use for headers. |
| break;
|
* Default is iso-8859-1 |
|
|
* @return string The mime content |
| case $text AND $attachments:
|
* @access public |
| $message =& $this->_addMixedPart();
|
*/ |
| $this->_addTextPart($message, $this->_txtbody);
|
function &get($build_params = null) |
|
|
{ |
| for ($i = 0; $i < count($this->_parts); $i++) {
|
if (isset($build_params)) { |
| $this->_addAttachmentPart($message, $this->_parts[$i]);
|
while (list($key, $value) = each($build_params)) { |
| }
|
$this->_build_params[$key] = $value; |
| break;
|
} |
|
|
} |
| case $html AND !$attachments AND !$html_images:
|
|
| if (isset($this->_txtbody)) {
|
if (!empty($this->_html_images) AND isset($this->_htmlbody)) { |
| $message =& $this->_addAlternativePart($null);
|
foreach ($this->_html_images as $value) { |
| $this->_addTextPart($message, $this->_txtbody);
|
$regex = '#(\s)((?i)src|background|href(?-i))\s*=\s*(["\']?)' . preg_quote($value['name'], '#') . |
| $this->_addHtmlPart($message);
|
'\3#'; |
|
|
$rep = '\1\2=\3cid:' . $value['cid'] .'\3'; |
| } else {
|
$this->_htmlbody = preg_replace($regex, $rep, |
| $message =& $this->_addHtmlPart($null);
|
$this->_htmlbody |
| }
|
); |
| break;
|
} |
|
|
} |
| case $html AND !$attachments AND $html_images:
|
|
| if (isset($this->_txtbody)) {
|
$null = null; |
| $message =& $this->_addAlternativePart($null);
|
$attachments = !empty($this->_parts) ? true : false; |
| $this->_addTextPart($message, $this->_txtbody);
|
$html_images = !empty($this->_html_images) ? true : false; |
| $related =& $this->_addRelatedPart($message);
|
$html = !empty($this->_htmlbody) ? true : false; |
| } else {
|
$text = (!$html AND !empty($this->_txtbody)) ? true : false; |
| $message =& $this->_addRelatedPart($null);
|
|
| $related =& $message;
|
switch (true) { |
| }
|
case $text AND !$attachments: |
| $this->_addHtmlPart($related);
|
$message =& $this->_addTextPart($null, $this->_txtbody); |
| for ($i = 0; $i < count($this->_html_images); $i++) {
|
break; |
| $this->_addHtmlImagePart($related, $this->_html_images[$i]);
|
|
| }
|
case !$text AND !$html AND $attachments: |
| break;
|
$message =& $this->_addMixedPart(); |
|
|
for ($i = 0; $i < count($this->_parts); $i++) { |
| case $html AND $attachments AND !$html_images:
|
$this->_addAttachmentPart($message, $this->_parts[$i]); |
| $message =& $this->_addMixedPart();
|
} |
| if (isset($this->_txtbody)) {
|
break; |
| $alt =& $this->_addAlternativePart($message);
|
|
| $this->_addTextPart($alt, $this->_txtbody);
|
case $text AND $attachments: |
| $this->_addHtmlPart($alt);
|
$message =& $this->_addMixedPart(); |
| } else {
|
$this->_addTextPart($message, $this->_txtbody); |
| $this->_addHtmlPart($message);
|
for ($i = 0; $i < count($this->_parts); $i++) { |
| }
|
$this->_addAttachmentPart($message, $this->_parts[$i]); |
| for ($i = 0; $i < count($this->_parts); $i++) {
|
} |
| $this->_addAttachmentPart($message, $this->_parts[$i]);
|
break; |
| }
|
|
| break;
|
case $html AND !$attachments AND !$html_images: |
|
|
if (isset($this->_txtbody)) { |
| case $html AND $attachments AND $html_images:
|
$message =& $this->_addAlternativePart($null); |
| $message =& $this->_addMixedPart();
|
$this->_addTextPart($message, $this->_txtbody); |
| if (isset($this->_txtbody)) {
|
$this->_addHtmlPart($message); |
| $alt =& $this->_addAlternativePart($message);
|
} else { |
| $this->_addTextPart($alt, $this->_txtbody);
|
$message =& $this->_addHtmlPart($null); |
| $rel =& $this->_addRelatedPart($alt);
|
} |
| } else {
|
break; |
| $rel =& $this->_addRelatedPart($message);
|
|
| }
|
case $html AND !$attachments AND $html_images: |
| $this->_addHtmlPart($rel);
|
if (isset($this->_txtbody)) { |
| for ($i = 0; $i < count($this->_html_images); $i++) {
|
$message =& $this->_addAlternativePart($null); |
| $this->_addHtmlImagePart($rel, $this->_html_images[$i]);
|
$this->_addTextPart($message, $this->_txtbody); |
| }
|
$related =& $this->_addRelatedPart($message); |
| for ($i = 0; $i < count($this->_parts); $i++) {
|
} else { |
| $this->_addAttachmentPart($message, $this->_parts[$i]);
|
$message =& $this->_addRelatedPart($null); |
| }
|
$related =& $message; |
| break;
|
} |
|
|
$this->_addHtmlPart($related); |
| }
|
for ($i = 0; $i < count($this->_html_images); $i++) { |
|
|
$this->_addHtmlImagePart($related, $this->_html_images[$i]); |
| if (isset($message)) {
|
} |
| $output = $message->encode();
|
break; |
| $this->_headers = array_merge($this->_headers, $output['headers']);
|
|
|
|
case $html AND $attachments AND !$html_images: |
| return $output['body'];
|
$message =& $this->_addMixedPart(); |
|
|
if (isset($this->_txtbody)) { |
| } else {
|
$alt =& $this->_addAlternativePart($message); |
| return FALSE;
|
$this->_addTextPart($alt, $this->_txtbody); |
| }
|
$this->_addHtmlPart($alt); |
| }
|
} else { |
|
|
$this->_addHtmlPart($message); |
| /*
|
} |
| * Returns an array with the headers needed to prepend to the email
|
for ($i = 0; $i < count($this->_parts); $i++) { |
| * (MIME-Version and Content-Type). Format of argument is:
|
$this->_addAttachmentPart($message, $this->_parts[$i]); |
| * $array['header-name'] = 'header-value';
|
} |
| *
|
break; |
| * @param array $xtra_headers Assoc array with any extra headers. Optional.
|
|
| * @return array Assoc array with the mime headers
|
case $html AND $attachments AND $html_images: |
| * @access public
|
$message =& $this->_addMixedPart(); |
| */
|
if (isset($this->_txtbody)) { |
| function &headers($xtra_headers = null)
|
$alt =& $this->_addAlternativePart($message); |
| {
|
$this->_addTextPart($alt, $this->_txtbody); |
| // Content-Type header should already be present,
|
$rel =& $this->_addRelatedPart($alt); |
| // So just add mime version header
|
} else { |
| $headers['MIME-Version'] = '1.0';
|
$rel =& $this->_addRelatedPart($message); |
| if (isset($xtra_headers)) {
|
} |
| $headers = array_merge($headers, $xtra_headers);
|
$this->_addHtmlPart($rel); |
| }
|
for ($i = 0; $i < count($this->_html_images); $i++) { |
| $this->_headers = array_merge($headers, $this->_headers);
|
$this->_addHtmlImagePart($rel, $this->_html_images[$i]); |
|
|
} |
| return $this->_encodeHeaders($this->_headers);
|
for ($i = 0; $i < count($this->_parts); $i++) { |
| }
|
$this->_addAttachmentPart($message, $this->_parts[$i]); |
|
|
} |
| /**
|
break; |
| * Get the text version of the headers
|
|
| * (usefull if you want to use the PHP mail() function)
|
} |
| *
|
|
| * @param array $xtra_headers Assoc array with any extra headers. Optional.
|
if (isset($message)) { |
| * @return string Plain text headers
|
$output = $message->encode(); |
| * @access public
|
$this->_headers = array_merge($this->_headers, |
| */
|
$output['headers']); |
| function txtHeaders($xtra_headers = null)
|
return $output['body']; |
| {
|
|
| $headers = $this->headers($xtra_headers);
|
} else { |
| $ret = '';
|
return false; |
| foreach ($headers as $key => $val) {
|
} |
| $ret .= "$key: $val" . MAIL_MIME_CRLF;
|
} |
| }
|
|
| return $ret;
|
/** |
| }
|
* Returns an array with the headers needed to prepend to the email |
|
|
* (MIME-Version and Content-Type). Format of argument is: |
| /**
|
* $array['header-name'] = 'header-value'; |
| * Sets the Subject header
|
* |
| *
|
* @param array $xtra_headers Assoc array with any extra headers. |
| * @param string $subject String to set the subject to
|
* Optional. |
| * access public
|
* @return array Assoc array with the mime headers |
| */
|
* @access public |
| function setSubject($subject)
|
*/ |
| {
|
function &headers($xtra_headers = null) |
| $this->_headers['Subject'] = $subject;
|
{ |
| }
|
// Content-Type header should already be present, |
|
|
// So just add mime version header |
| /**
|
$headers['MIME-Version'] = '1.0'; |
| * Set an email to the From (the sender) header
|
if (isset($xtra_headers)) { |
| *
|
$headers = array_merge($headers, $xtra_headers); |
| * @param string $email The email direction to add
|
} |
| * @access public
|
$this->_headers = array_merge($headers, $this->_headers); |
| */
|
|
| function setFrom($email)
|
return $this->_encodeHeaders($this->_headers); |
| {
|
} |
| $this->_headers['From'] = $email;
|
|
| }
|
/** |
|
|
* Get the text version of the headers |
| /**
|
* (usefull if you want to use the PHP mail() function) |
| * Add an email to the Cc (carbon copy) header
|
* |
| * (multiple calls to this method is allowed)
|
* @param array $xtra_headers Assoc array with any extra headers. |
| *
|
* Optional. |
| * @param string $email The email direction to add
|
* @return string Plain text headers |
| * @access public
|
* @access public |
| */
|
*/ |
| function addCc($email)
|
function txtHeaders($xtra_headers = null) |
| {
|
{ |
| if (isset($this->_headers['Cc'])) {
|
$headers = $this->headers($xtra_headers); |
| $this->_headers['Cc'] .= ", $email";
|
$ret = ''; |
| } else {
|
foreach ($headers as $key => $val) { |
| $this->_headers['Cc'] = $email;
|
$ret .= "$key: $val" . MAIL_MIME_CRLF; |
| }
|
} |
| }
|
return $ret; |
|
|
} |
| /**
|
|
| * Add an email to the Bcc (blank carbon copy) header
|
/** |
| * (multiple calls to this method is allowed)
|
* Sets the Subject header |
| *
|
* |
| * @param string $email The email direction to add
|
* @param string $subject String to set the subject to |
| * @access public
|
* access public |
| */
|
*/ |
| function addBcc($email)
|
function setSubject($subject) |
| {
|
{ |
| if (isset($this->_headers['Bcc'])) {
|
$this->_headers['Subject'] = $subject; |
| $this->_headers['Bcc'] .= ", $email";
|
} |
| } else {
|
|
| $this->_headers['Bcc'] = $email;
|
/** |
| }
|
* Set an email to the From (the sender) header |
| }
|
* |
|
|
* @param string $email The email direction to add |
| /**
|
* @access public |
| * Encodes a header as per RFC2047
|
*/ |
| *
|
function setFrom($email) |
| * @param string $input The header data to encode
|
{ |
| * @return string Encoded data
|
$this->_headers['From'] = $email; |
| * @access private
|
} |
| */
|
|
| function _encodeHeaders($input)
|
/** |
| {
|
* Add an email to the Cc (carbon copy) header |
| foreach ($input as $hdr_name => $hdr_value) {
|
* (multiple calls to this method are allowed) |
| preg_match_all('/(\w*[\x80-\xFF]+\w*)/', $hdr_value, $matches);
|
* |
| foreach ($matches[1] as $value) {
|
* @param string $email The email direction to add |
| $replacement = preg_replace('/([\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
|
* @access public |
| $hdr_value = str_replace($value, '=?' . $this->_build_params['head_charset'] . '?Q?' . $replacement . '?=', $hdr_value);
|
*/ |
| }
|
function addCc($email) |
| $input[$hdr_name] = $hdr_value;
|
{ |
| }
|
if (isset($this->_headers['Cc'])) { |
|
|
$this->_headers['Cc'] .= ", $email"; |
| return $input;
|
} else { |
| }
|
$this->_headers['Cc'] = $email; |
|
|
} |
| } // End of class
|
} |
| ?>
|
|
| |
/** |
| |
* Add an email to the Bcc (blank carbon copy) header |
| |
* (multiple calls to this method are allowed) |
| |
* |
| |
* @param string $email The email direction to add |
| |
* @access public |
| |
*/ |
| |
function addBcc($email) |
| |
{ |
| |
if (isset($this->_headers['Bcc'])) { |
| |
$this->_headers['Bcc'] .= ", $email"; |
| |
} else { |
| |
$this->_headers['Bcc'] = $email; |
| |
} |
| |
} |
| |
|
| |
/** |
| |
* Encodes a header as per RFC2047 |
| |
* |
| |
* @param string $input The header data to encode |
| |
* @return string Encoded data |
| |
* @access private |
| |
*/ |
| |
function _encodeHeaders($input) |
| |
{ |
| |
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); |
| |
} |
| |
$input[$hdr_name] = $hdr_value; |
| |
} |
| |
|
| |
return $input; |
| |
} |
| |
|
| |
/** |
| |
* Set the object's end-of-line and define the constant if applicable |
| |
* |
| |
* @param string $eol End Of Line sequence |
| |
* @access private |
| |
*/ |
| |
function _setEOL($eol) |
| |
{ |
| |
$this->_eol = $eol; |
| |
if (!defined('MAIL_MIME_CRLF')) { |
| |
define('MAIL_MIME_CRLF', $this->_eol, true); |
| |
} |
| |
} |
| |
|
| |
|
| |
|
| |
} // End of class |
| |
?> |