Browse Source

Update PEAR Mail_MIME to 1.8.9

This is nusoap dependency and the unkown previous version
was GPL incompatible and used deprecated functions.
Raphaël Doursenaud 10 years ago
parent
commit
e8332cc724

+ 1 - 0
COPYRIGHT

@@ -18,6 +18,7 @@ CKEditor               4.3.3         LGPL-2.1+                   Yes
 FPDI                   1.5.2         Apache Software License 2.0 Yes             PDF templates management
 GeoIP                  1.4           LGPL-2.1+                   Yes             Sample code to make geoip convert (not into deb package)
 NuSoap                 0.9.5         LGPL 2.1+                   Yes             Library to develop SOAP Web services (not into rpm and deb package)
+PEAR Mail_MIME         1.8.9         BSD                         Yes             NuSoap dependency
 odtPHP                 1.0.1         GPL-2+  b                   Yes             Library to build/edit ODT files
 PHPExcel               1.8.0         LGPL-2.1+                   Yes             Read/Write XLS files, read ODS files
 php-iban               1.4.6         LGPL-3+                     Yes             Parse and validate IBAN (and IIBAN) bank account information in PHP

+ 0 - 1100
htdocs/includes/nusoap/lib/Mail/PEAR.php

@@ -1,1100 +0,0 @@
-<?php
-/**
- * PEAR, the PHP Extension and Application Repository
- *
- * PEAR class and PEAR_Error class
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category   pear
- * @package    PEAR
- * @author     Sterling Hughes <sterling@php.net>
- * @author     Stig Bakken <ssb@php.net>
- * @author     Tomas V.V.Cox <cox@idecnet.com>
- * @author     Greg Beaver <cellog@php.net>
- * @copyright  1997-2006 The PHP Group
- * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @link       http://pear.php.net/package/PEAR
- * @since      File available since Release 0.1
- */
-
-/**#@+
- * ERROR constants
- */
-define('PEAR_ERROR_RETURN',     1);
-define('PEAR_ERROR_PRINT',      2);
-define('PEAR_ERROR_TRIGGER',    4);
-define('PEAR_ERROR_DIE',        8);
-define('PEAR_ERROR_CALLBACK',  16);
-/**
- * WARNING: obsolete
- * @deprecated
- */
-define('PEAR_ERROR_EXCEPTION', 32);
-/**#@-*/
-define('PEAR_ZE2', (function_exists('version_compare') &&
-                    version_compare(zend_version(), "2-dev", "ge")));
-
-if (substr(PHP_OS, 0, 3) == 'WIN') {
-    define('OS_WINDOWS', true);
-    define('OS_UNIX',    false);
-    define('PEAR_OS',    'Windows');
-} else {
-    define('OS_WINDOWS', false);
-    define('OS_UNIX',    true);
-    define('PEAR_OS',    'Unix'); // blatant assumption
-}
-
-// instant backwards compatibility
-if (!defined('PATH_SEPARATOR')) {
-    if (OS_WINDOWS) {
-        define('PATH_SEPARATOR', ';');
-    } else {
-        define('PATH_SEPARATOR', ':');
-    }
-}
-
-$GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
-$GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
-$GLOBALS['_PEAR_destructor_object_list'] = array();
-$GLOBALS['_PEAR_shutdown_funcs']         = array();
-$GLOBALS['_PEAR_error_handler_stack']    = array();
-
-@ini_set('track_errors', true);
-
-/**
- * Base class for other PEAR classes.  Provides rudimentary
- * emulation of destructors.
- *
- * If you want a destructor in your class, inherit PEAR and make a
- * destructor method called _yourclassname (same name as the
- * constructor, but with a "_" prefix).  Also, in your constructor you
- * have to call the PEAR constructor: $this->PEAR();.
- * The destructor method will be called without parameters.  Note that
- * at in some SAPI implementations (such as Apache), any output during
- * the request shutdown (in which destructors are called) seems to be
- * discarded.  If you need to get any debug information from your
- * destructor, use error_log(), syslog() or something similar.
- *
- * IMPORTANT! To use the emulated destructors you need to create the
- * objects by reference: $obj =& new PEAR_child;
- *
- * @category   pear
- * @package    PEAR
- * @author     Stig Bakken <ssb@php.net>
- * @author     Tomas V.V. Cox <cox@idecnet.com>
- * @author     Greg Beaver <cellog@php.net>
- * @copyright  1997-2006 The PHP Group
- * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: 1.4.11
- * @link       http://pear.php.net/package/PEAR
- * @see        PEAR_Error
- * @since      Class available since PHP 4.0.2
- * @link        http://pear.php.net/manual/en/core.pear.php#core.pear.pear
- */
-class PEAR
-{
-    // {{{ properties
-
-    /**
-     * Whether to enable internal debug messages.
-     *
-     * @var     bool
-     * @access  private
-     */
-    var $_debug = false;
-
-    /**
-     * Default error mode for this object.
-     *
-     * @var     int
-     * @access  private
-     */
-    var $_default_error_mode = null;
-
-    /**
-     * Default error options used for this object when error mode
-     * is PEAR_ERROR_TRIGGER.
-     *
-     * @var     int
-     * @access  private
-     */
-    var $_default_error_options = null;
-
-    /**
-     * Default error handler (callback) for this object, if error mode is
-     * PEAR_ERROR_CALLBACK.
-     *
-     * @var     string
-     * @access  private
-     */
-    var $_default_error_handler = '';
-
-    /**
-     * Which class to use for error objects.
-     *
-     * @var     string
-     * @access  private
-     */
-    var $_error_class = 'PEAR_Error';
-
-    /**
-     * An array of expected errors.
-     *
-     * @var     array
-     * @access  private
-     */
-    var $_expected_errors = array();
-
-    // }}}
-
-    // {{{ constructor
-
-    /**
-     * Constructor.  Registers this object in
-     * $_PEAR_destructor_object_list for destructor emulation if a
-     * destructor object exists.
-     *
-     * @param string $error_class  (optional) which class to use for
-     *        error objects, defaults to PEAR_Error.
-     * @access public
-     * @return void
-     */
-    function PEAR($error_class = null)
-    {
-        $classname = strtolower(get_class($this));
-        if ($this->_debug) {
-            print "PEAR constructor called, class=$classname\n";
-        }
-        if ($error_class !== null) {
-            $this->_error_class = $error_class;
-        }
-        while ($classname && strcasecmp($classname, "pear")) {
-            $destructor = "_$classname";
-            if (method_exists($this, $destructor)) {
-                global $_PEAR_destructor_object_list;
-                $_PEAR_destructor_object_list[] = &$this;
-                if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
-                    register_shutdown_function("_PEAR_call_destructors");
-                    $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
-                }
-                break;
-            } else {
-                $classname = get_parent_class($classname);
-            }
-        }
-    }
-
-    // }}}
-    // {{{ destructor
-
-    /**
-     * Destructor (the emulated type of...).  Does nothing right now,
-     * but is included for forward compatibility, so subclass
-     * destructors should always call it.
-     *
-     * See the note in the class desciption about output from
-     * destructors.
-     *
-     * @access public
-     * @return void
-     */
-    function _PEAR() {
-        if ($this->_debug) {
-            printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
-        }
-    }
-
-    // }}}
-    // {{{ getStaticProperty()
-
-    /**
-    * If you have a class that's mostly/entirely static, and you need static
-    * properties, you can use this method to simulate them. Eg. in your method(s)
-    * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
-    * You MUST use a reference, or they will not persist!
-    *
-    * @access public
-    * @param  string $class  The calling classname, to prevent clashes
-    * @param  string $var    The variable to retrieve.
-    * @return mixed   A reference to the variable. If not set it will be
-    *                 auto initialised to NULL.
-    */
-    function &getStaticProperty($class, $var)
-    {
-        static $properties;
-        return $properties[$class][$var];
-    }
-
-    // }}}
-    // {{{ registerShutdownFunc()
-
-    /**
-    * Use this function to register a shutdown method for static
-    * classes.
-    *
-    * @access public
-    * @param  mixed $func  The function name (or array of class/method) to call
-    * @param  mixed $args  The arguments to pass to the function
-    * @return void
-    */
-    function registerShutdownFunc($func, $args = array())
-    {
-        // if we are called statically, there is a potential
-        // that no shutdown func is registered.  Bug #6445
-        if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
-            register_shutdown_function("_PEAR_call_destructors");
-            $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
-        }
-        $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
-    }
-
-    // }}}
-    // {{{ isError()
-
-    /**
-     * Tell whether a value is a PEAR error.
-     *
-     * @param   mixed $data   the value to test
-     * @param   int   $code   if $data is an error object, return true
-     *                        only if $code is a string and
-     *                        $obj->getMessage() == $code or
-     *                        $code is an integer and $obj->getCode() == $code
-     * @access  public
-     * @return  bool    true if parameter is an error
-     */
-    function isError($data, $code = null)
-    {
-        if (is_a($data, 'PEAR_Error')) {
-            if (is_null($code)) {
-                return true;
-            } elseif (is_string($code)) {
-                return $data->getMessage() == $code;
-            } else {
-                return $data->getCode() == $code;
-            }
-        }
-        return false;
-    }
-
-    // }}}
-    // {{{ setErrorHandling()
-
-    /**
-     * Sets how errors generated by this object should be handled.
-     * Can be invoked both in objects and statically.  If called
-     * statically, setErrorHandling sets the default behaviour for all
-     * PEAR objects.  If called in an object, setErrorHandling sets
-     * the default behaviour for that object.
-     *
-     * @param int $mode
-     *        One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
-     *        PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
-     *        PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
-     *
-     * @param mixed $options
-     *        When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
-     *        of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
-     *
-     *        When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
-     *        to be the callback function or method.  A callback
-     *        function is a string with the name of the function, a
-     *        callback method is an array of two elements: the element
-     *        at index 0 is the object, and the element at index 1 is
-     *        the name of the method to call in the object.
-     *
-     *        When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
-     *        a printf format string used when printing the error
-     *        message.
-     *
-     * @access public
-     * @return void
-     * @see PEAR_ERROR_RETURN
-     * @see PEAR_ERROR_PRINT
-     * @see PEAR_ERROR_TRIGGER
-     * @see PEAR_ERROR_DIE
-     * @see PEAR_ERROR_CALLBACK
-     * @see PEAR_ERROR_EXCEPTION
-     *
-     * @since PHP 4.0.5
-     */
-
-    function setErrorHandling($mode = null, $options = null)
-    {
-        if (isset($this) && is_a($this, 'PEAR')) {
-            $setmode     = &$this->_default_error_mode;
-            $setoptions  = &$this->_default_error_options;
-        } else {
-            $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
-            $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
-        }
-
-        switch ($mode) {
-            case PEAR_ERROR_EXCEPTION:
-            case PEAR_ERROR_RETURN:
-            case PEAR_ERROR_PRINT:
-            case PEAR_ERROR_TRIGGER:
-            case PEAR_ERROR_DIE:
-            case null:
-                $setmode = $mode;
-                $setoptions = $options;
-                break;
-
-            case PEAR_ERROR_CALLBACK:
-                $setmode = $mode;
-                // class/object method callback
-                if (is_callable($options)) {
-                    $setoptions = $options;
-                } else {
-                    trigger_error("invalid error callback", E_USER_WARNING);
-                }
-                break;
-
-            default:
-                trigger_error("invalid error mode", E_USER_WARNING);
-                break;
-        }
-    }
-
-    // }}}
-    // {{{ expectError()
-
-    /**
-     * This method is used to tell which errors you expect to get.
-     * Expected errors are always returned with error mode
-     * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
-     * and this method pushes a new element onto it.  The list of
-     * expected errors are in effect until they are popped off the
-     * stack with the popExpect() method.
-     *
-     * Note that this method can not be called statically
-     *
-     * @param mixed $code a single error code or an array of error codes to expect
-     *
-     * @return int     the new depth of the "expected errors" stack
-     * @access public
-     */
-    function expectError($code = '*')
-    {
-        if (is_array($code)) {
-            array_push($this->_expected_errors, $code);
-        } else {
-            array_push($this->_expected_errors, array($code));
-        }
-        return sizeof($this->_expected_errors);
-    }
-
-    // }}}
-    // {{{ popExpect()
-
-    /**
-     * This method pops one element off the expected error codes
-     * stack.
-     *
-     * @return array   the list of error codes that were popped
-     */
-    function popExpect()
-    {
-        return array_pop($this->_expected_errors);
-    }
-
-    // }}}
-    // {{{ _checkDelExpect()
-
-    /**
-     * This method checks unsets an error code if available
-     *
-     * @param mixed error code
-     * @return bool true if the error code was unset, false otherwise
-     * @access private
-     * @since PHP 4.3.0
-     */
-    function _checkDelExpect($error_code)
-    {
-        $deleted = false;
-
-        foreach ($this->_expected_errors AS $key => $error_array) {
-            if (in_array($error_code, $error_array)) {
-                unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
-                $deleted = true;
-            }
-
-            // clean up empty arrays
-            if (0 == count($this->_expected_errors[$key])) {
-                unset($this->_expected_errors[$key]);
-            }
-        }
-        return $deleted;
-    }
-
-    // }}}
-    // {{{ delExpect()
-
-    /**
-     * This method deletes all occurences of the specified element from
-     * the expected error codes stack.
-     *
-     * @param  mixed $error_code error code that should be deleted
-     * @return mixed list of error codes that were deleted or error
-     * @access public
-     * @since PHP 4.3.0
-     */
-    function delExpect($error_code)
-    {
-        $deleted = false;
-
-        if ((is_array($error_code) && (0 != count($error_code)))) {
-            // $error_code is a non-empty array here;
-            // we walk through it trying to unset all
-            // values
-            foreach($error_code as $key => $error) {
-                if ($this->_checkDelExpect($error)) {
-                    $deleted =  true;
-                } else {
-                    $deleted = false;
-                }
-            }
-            return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
-        } elseif (!empty($error_code)) {
-            // $error_code comes alone, trying to unset it
-            if ($this->_checkDelExpect($error_code)) {
-                return true;
-            } else {
-                return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
-            }
-        } else {
-            // $error_code is empty
-            return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
-        }
-    }
-
-    // }}}
-    // {{{ raiseError()
-
-    /**
-     * This method is a wrapper that returns an instance of the
-     * configured error class with this object's default error
-     * handling applied.  If the $mode and $options parameters are not
-     * specified, the object's defaults are used.
-     *
-     * @param mixed $message a text error message or a PEAR error object
-     *
-     * @param int $code      a numeric error code (it is up to your class
-     *                  to define these if you want to use codes)
-     *
-     * @param int $mode      One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
-     *                  PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
-     *                  PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
-     *
-     * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
-     *                  specifies the PHP-internal error level (one of
-     *                  E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
-     *                  If $mode is PEAR_ERROR_CALLBACK, this
-     *                  parameter specifies the callback function or
-     *                  method.  In other error modes this parameter
-     *                  is ignored.
-     *
-     * @param string $userinfo If you need to pass along for example debug
-     *                  information, this parameter is meant for that.
-     *
-     * @param string $error_class The returned error object will be
-     *                  instantiated from this class, if specified.
-     *
-     * @param bool $skipmsg If true, raiseError will only pass error codes,
-     *                  the error message parameter will be dropped.
-     *
-     * @access public
-     * @return object   a PEAR error object
-     * @see PEAR::setErrorHandling
-     * @since PHP 4.0.5
-     */
-    function &raiseError($message = null,
-                         $code = null,
-                         $mode = null,
-                         $options = null,
-                         $userinfo = null,
-                         $error_class = null,
-                         $skipmsg = false)
-    {
-        // The error is yet a PEAR error object
-        if (is_object($message)) {
-            $code        = $message->getCode();
-            $userinfo    = $message->getUserInfo();
-            $error_class = $message->getType();
-            $message->error_message_prefix = '';
-            $message     = $message->getMessage();
-        }
-
-        if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
-            if ($exp[0] == "*" ||
-                (is_int(reset($exp)) && in_array($code, $exp)) ||
-                (is_string(reset($exp)) && in_array($message, $exp))) {
-                $mode = PEAR_ERROR_RETURN;
-            }
-        }
-        // No mode given, try global ones
-        if ($mode === null) {
-            // Class error handler
-            if (isset($this) && isset($this->_default_error_mode)) {
-                $mode    = $this->_default_error_mode;
-                $options = $this->_default_error_options;
-            // Global error handler
-            } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
-                $mode    = $GLOBALS['_PEAR_default_error_mode'];
-                $options = $GLOBALS['_PEAR_default_error_options'];
-            }
-        }
-
-        if ($error_class !== null) {
-            $ec = $error_class;
-        } elseif (isset($this) && isset($this->_error_class)) {
-            $ec = $this->_error_class;
-        } else {
-            $ec = 'PEAR_Error';
-        }
-        if ($skipmsg) {
-            $a = new $ec($code, $mode, $options, $userinfo);
-            return $a;
-        } else {
-            $a = new $ec($message, $code, $mode, $options, $userinfo);
-            return $a;
-        }
-    }
-
-    // }}}
-    // {{{ throwError()
-
-    /**
-     * Simpler form of raiseError with fewer options.  In most cases
-     * message, code and userinfo are enough.
-     *
-     * @param string $message
-     *
-     */
-    function &throwError($message = null,
-                         $code = null,
-                         $userinfo = null)
-    {
-        if (isset($this) && is_a($this, 'PEAR')) {
-            $a = &$this->raiseError($message, $code, null, null, $userinfo);
-            return $a;
-        } else {
-            $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
-            return $a;
-        }
-    }
-
-    // }}}
-    function staticPushErrorHandling($mode, $options = null)
-    {
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
-        $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
-        $def_options = &$GLOBALS['_PEAR_default_error_options'];
-        $stack[] = array($def_mode, $def_options);
-        switch ($mode) {
-            case PEAR_ERROR_EXCEPTION:
-            case PEAR_ERROR_RETURN:
-            case PEAR_ERROR_PRINT:
-            case PEAR_ERROR_TRIGGER:
-            case PEAR_ERROR_DIE:
-            case null:
-                $def_mode = $mode;
-                $def_options = $options;
-                break;
-
-            case PEAR_ERROR_CALLBACK:
-                $def_mode = $mode;
-                // class/object method callback
-                if (is_callable($options)) {
-                    $def_options = $options;
-                } else {
-                    trigger_error("invalid error callback", E_USER_WARNING);
-                }
-                break;
-
-            default:
-                trigger_error("invalid error mode", E_USER_WARNING);
-                break;
-        }
-        $stack[] = array($mode, $options);
-        return true;
-    }
-
-    function staticPopErrorHandling()
-    {
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
-        $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
-        $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
-        array_pop($stack);
-        list($mode, $options) = $stack[sizeof($stack) - 1];
-        array_pop($stack);
-        switch ($mode) {
-            case PEAR_ERROR_EXCEPTION:
-            case PEAR_ERROR_RETURN:
-            case PEAR_ERROR_PRINT:
-            case PEAR_ERROR_TRIGGER:
-            case PEAR_ERROR_DIE:
-            case null:
-                $setmode = $mode;
-                $setoptions = $options;
-                break;
-
-            case PEAR_ERROR_CALLBACK:
-                $setmode = $mode;
-                // class/object method callback
-                if (is_callable($options)) {
-                    $setoptions = $options;
-                } else {
-                    trigger_error("invalid error callback", E_USER_WARNING);
-                }
-                break;
-
-            default:
-                trigger_error("invalid error mode", E_USER_WARNING);
-                break;
-        }
-        return true;
-    }
-
-    // {{{ pushErrorHandling()
-
-    /**
-     * Push a new error handler on top of the error handler options stack. With this
-     * you can easily override the actual error handler for some code and restore
-     * it later with popErrorHandling.
-     *
-     * @param mixed $mode (same as setErrorHandling)
-     * @param mixed $options (same as setErrorHandling)
-     *
-     * @return bool Always true
-     *
-     * @see PEAR::setErrorHandling
-     */
-    function pushErrorHandling($mode, $options = null)
-    {
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
-        if (isset($this) && is_a($this, 'PEAR')) {
-            $def_mode    = &$this->_default_error_mode;
-            $def_options = &$this->_default_error_options;
-        } else {
-            $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
-            $def_options = &$GLOBALS['_PEAR_default_error_options'];
-        }
-        $stack[] = array($def_mode, $def_options);
-
-        if (isset($this) && is_a($this, 'PEAR')) {
-            $this->setErrorHandling($mode, $options);
-        } else {
-            PEAR::setErrorHandling($mode, $options);
-        }
-        $stack[] = array($mode, $options);
-        return true;
-    }
-
-    // }}}
-    // {{{ popErrorHandling()
-
-    /**
-    * Pop the last error handler used
-    *
-    * @return bool Always true
-    *
-    * @see PEAR::pushErrorHandling
-    */
-    function popErrorHandling()
-    {
-        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
-        array_pop($stack);
-        list($mode, $options) = $stack[sizeof($stack) - 1];
-        array_pop($stack);
-        if (isset($this) && is_a($this, 'PEAR')) {
-            $this->setErrorHandling($mode, $options);
-        } else {
-            PEAR::setErrorHandling($mode, $options);
-        }
-        return true;
-    }
-
-    // }}}
-    // {{{ loadExtension()
-
-    /**
-    * OS independant PHP extension load. Remember to take care
-    * on the correct extension name for case sensitive OSes.
-    *
-    * @param string $ext The extension name
-    * @return bool Success or not on the dl() call
-    */
-    function loadExtension($ext)
-    {
-        if (!extension_loaded($ext)) {
-            // if either returns true dl() will produce a FATAL error, stop that
-            if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
-                return false;
-            }
-            if (OS_WINDOWS) {
-                $suffix = '.dll';
-            } elseif (PHP_OS == 'HP-UX') {
-                $suffix = '.sl';
-            } elseif (PHP_OS == 'AIX') {
-                $suffix = '.a';
-            } elseif (PHP_OS == 'OSX') {
-                $suffix = '.bundle';
-            } else {
-                $suffix = '.so';
-            }
-            return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
-        }
-        return true;
-    }
-
-    // }}}
-}
-
-// {{{ _PEAR_call_destructors()
-
-function _PEAR_call_destructors()
-{
-    global $_PEAR_destructor_object_list;
-    if (is_array($_PEAR_destructor_object_list) &&
-        sizeof($_PEAR_destructor_object_list))
-    {
-        reset($_PEAR_destructor_object_list);
-        if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) {
-            $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
-        }
-        while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
-            $classname = get_class($objref);
-            while ($classname) {
-                $destructor = "_$classname";
-                if (method_exists($objref, $destructor)) {
-                    $objref->$destructor();
-                    break;
-                } else {
-                    $classname = get_parent_class($classname);
-                }
-            }
-        }
-        // Empty the object list to ensure that destructors are
-        // not called more than once.
-        $_PEAR_destructor_object_list = array();
-    }
-
-    // Now call the shutdown functions
-    if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
-        foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
-            call_user_func_array($value[0], $value[1]);
-        }
-    }
-}
-
-// }}}
-/**
- * Standard PEAR error class for PHP 4
- *
- * This class is supserseded by {@link PEAR_Exception} in PHP 5
- *
- * @category   pear
- * @package    PEAR
- * @author     Stig Bakken <ssb@php.net>
- * @author     Tomas V.V. Cox <cox@idecnet.com>
- * @author     Gregory Beaver <cellog@php.net>
- * @copyright  1997-2006 The PHP Group
- * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: 1.4.11
- * @link       http://pear.php.net/manual/en/core.pear.pear-error.php
- * @see        PEAR::raiseError(), PEAR::throwError()
- * @since      Class available since PHP 4.0.2
- */
-class PEAR_Error
-{
-    // {{{ properties
-
-    var $error_message_prefix = '';
-    var $mode                 = PEAR_ERROR_RETURN;
-    var $level                = E_USER_NOTICE;
-    var $code                 = -1;
-    var $message              = '';
-    var $userinfo             = '';
-    var $backtrace            = null;
-
-    // }}}
-    // {{{ constructor
-
-    /**
-     * PEAR_Error constructor
-     *
-     * @param string $message  message
-     *
-     * @param int $code     (optional) error code
-     *
-     * @param int $mode     (optional) error mode, one of: PEAR_ERROR_RETURN,
-     * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
-     * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
-     *
-     * @param mixed $options   (optional) error level, _OR_ in the case of
-     * PEAR_ERROR_CALLBACK, the callback function or object/method
-     * tuple.
-     *
-     * @param string $userinfo (optional) additional user/debug info
-     *
-     * @access public
-     *
-     */
-    function PEAR_Error($message = 'unknown error', $code = null,
-                        $mode = null, $options = null, $userinfo = null)
-    {
-        if ($mode === null) {
-            $mode = PEAR_ERROR_RETURN;
-        }
-        $this->message   = $message;
-        $this->code      = $code;
-        $this->mode      = $mode;
-        $this->userinfo  = $userinfo;
-        if (function_exists("debug_backtrace")) {
-            if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
-                $this->backtrace = debug_backtrace();
-            }
-        }
-        if ($mode & PEAR_ERROR_CALLBACK) {
-            $this->level = E_USER_NOTICE;
-            $this->callback = $options;
-        } else {
-            if ($options === null) {
-                $options = E_USER_NOTICE;
-            }
-            $this->level = $options;
-            $this->callback = null;
-        }
-        if ($this->mode & PEAR_ERROR_PRINT) {
-            if (is_null($options) || is_int($options)) {
-                $format = "%s";
-            } else {
-                $format = $options;
-            }
-            printf($format, $this->getMessage());
-        }
-        if ($this->mode & PEAR_ERROR_TRIGGER) {
-            trigger_error($this->getMessage(), $this->level);
-        }
-        if ($this->mode & PEAR_ERROR_DIE) {
-            $msg = $this->getMessage();
-            if (is_null($options) || is_int($options)) {
-                $format = "%s";
-                if (substr($msg, -1) != "\n") {
-                    $msg .= "\n";
-                }
-            } else {
-                $format = $options;
-            }
-            die(sprintf($format, $msg));
-        }
-        if ($this->mode & PEAR_ERROR_CALLBACK) {
-            if (is_callable($this->callback)) {
-                call_user_func($this->callback, $this);
-            }
-        }
-        if ($this->mode & PEAR_ERROR_EXCEPTION) {
-            trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
-            eval('$e = new Exception($this->message, $this->code);throw($e);');
-        }
-    }
-
-    // }}}
-    // {{{ getMode()
-
-    /**
-     * Get the error mode from an error object.
-     *
-     * @return int error mode
-     * @access public
-     */
-    function getMode() {
-        return $this->mode;
-    }
-
-    // }}}
-    // {{{ getCallback()
-
-    /**
-     * Get the callback function/method from an error object.
-     *
-     * @return mixed callback function or object/method array
-     * @access public
-     */
-    function getCallback() {
-        return $this->callback;
-    }
-
-    // }}}
-    // {{{ getMessage()
-
-
-    /**
-     * Get the error message from an error object.
-     *
-     * @return  string  full error message
-     * @access public
-     */
-    function getMessage()
-    {
-        return ($this->error_message_prefix . $this->message);
-    }
-
-
-    // }}}
-    // {{{ getCode()
-
-    /**
-     * Get error code from an error object
-     *
-     * @return int error code
-     * @access public
-     */
-     function getCode()
-     {
-        return $this->code;
-     }
-
-    // }}}
-    // {{{ getType()
-
-    /**
-     * Get the name of this error/exception.
-     *
-     * @return string error/exception name (type)
-     * @access public
-     */
-    function getType()
-    {
-        return get_class($this);
-    }
-
-    // }}}
-    // {{{ getUserInfo()
-
-    /**
-     * Get additional user-supplied information.
-     *
-     * @return string user-supplied information
-     * @access public
-     */
-    function getUserInfo()
-    {
-        return $this->userinfo;
-    }
-
-    // }}}
-    // {{{ getDebugInfo()
-
-    /**
-     * Get additional debug information supplied by the application.
-     *
-     * @return string debug information
-     * @access public
-     */
-    function getDebugInfo()
-    {
-        return $this->getUserInfo();
-    }
-
-    // }}}
-    // {{{ getBacktrace()
-
-    /**
-     * Get the call backtrace from where the error was generated.
-     * Supported with PHP 4.3.0 or newer.
-     *
-     * @param int $frame (optional) what frame to fetch
-     * @return array Backtrace, or NULL if not available.
-     * @access public
-     */
-    function getBacktrace($frame = null)
-    {
-        if (defined('PEAR_IGNORE_BACKTRACE')) {
-            return null;
-        }
-        if ($frame === null) {
-            return $this->backtrace;
-        }
-        return $this->backtrace[$frame];
-    }
-
-    // }}}
-    // {{{ addUserInfo()
-
-    function addUserInfo($info)
-    {
-        if (empty($this->userinfo)) {
-            $this->userinfo = $info;
-        } else {
-            $this->userinfo .= " ** $info";
-        }
-    }
-
-    // }}}
-    // {{{ toString()
-
-    /**
-     * Make a string representation of this object.
-     *
-     * @return string a string with an object summary
-     * @access public
-     */
-    function toString() {
-        $modes = array();
-        $levels = array(E_USER_NOTICE  => 'notice',
-                        E_USER_WARNING => 'warning',
-                        E_USER_ERROR   => 'error');
-        if ($this->mode & PEAR_ERROR_CALLBACK) {
-            if (is_array($this->callback)) {
-                $callback = (is_object($this->callback[0]) ?
-                    strtolower(get_class($this->callback[0])) :
-                    $this->callback[0]) . '::' .
-                    $this->callback[1];
-            } else {
-                $callback = $this->callback;
-            }
-            return sprintf('[%s: message="%s" code=%d mode=callback '.
-                           'callback=%s prefix="%s" info="%s"]',
-                           strtolower(get_class($this)), $this->message, $this->code,
-                           $callback, $this->error_message_prefix,
-                           $this->userinfo);
-        }
-        if ($this->mode & PEAR_ERROR_PRINT) {
-            $modes[] = 'print';
-        }
-        if ($this->mode & PEAR_ERROR_TRIGGER) {
-            $modes[] = 'trigger';
-        }
-        if ($this->mode & PEAR_ERROR_DIE) {
-            $modes[] = 'die';
-        }
-        if ($this->mode & PEAR_ERROR_RETURN) {
-            $modes[] = 'return';
-        }
-        return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
-                       'prefix="%s" info="%s"]',
-                       strtolower(get_class($this)), $this->message, $this->code,
-                       implode("|", $modes), $levels[$this->level],
-                       $this->error_message_prefix,
-                       $this->userinfo);
-    }
-
-    // }}}
-}
-
-/*
- * Local Variables:
- * mode: php
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
-?>

+ 0 - 922
htdocs/includes/nusoap/lib/Mail/RFC822.php

@@ -1,922 +0,0 @@
-<?php
-// +-----------------------------------------------------------------------+
-// | Copyright (c) 2001-2002, Richard Heyes                                |
-// | All rights reserved.                                                  |
-// |                                                                       |
-// | Redistribution and use in source and binary forms, with or without    |
-// | modification, are permitted provided that the following conditions    |
-// | are met:                                                              |
-// |                                                                       |
-// | o Redistributions of source code must retain the above copyright      |
-// |   notice, this list of conditions and the following disclaimer.       |
-// | o Redistributions in binary form must reproduce the above copyright   |
-// |   notice, this list of conditions and the following disclaimer in the |
-// |   documentation and/or other materials provided with the distribution.|
-// | o The names of the authors may not be used to endorse or promote      |
-// |   products derived from this software without specific prior written  |
-// |   permission.                                                         |
-// |                                                                       |
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
-// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
-// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
-// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
-// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
-// | 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.  |
-// |                                                                       |
-// +-----------------------------------------------------------------------+
-// | Authors: Richard Heyes <richard@phpguru.org>                          |
-// |          Chuck Hagenbuch <chuck@horde.org>                            |
-// +-----------------------------------------------------------------------+
-
-/**
- * RFC 822 Email address list validation Utility
- *
- * What is it?
- *
- * This class will take an address string, and parse it into it's consituent
- * parts, be that either addresses, groups, or combinations. Nested groups
- * are not supported. The structure it returns is pretty straight forward,
- * and is similar to that provided by the imap_rfc822_parse_adrlist(). Use
- * print_r() to view the structure.
- *
- * How do I use it?
- *
- * $address_string = 'My Group: "Richard" <richard@localhost> (A comment), ted@example.com (Ted Bloggs), Barney;';
- * $structure = Mail_RFC822::parseAddressList($address_string, 'example.com', true)
- * print_r($structure);
- *
- * @author  Richard Heyes <richard@phpguru.org>
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @license BSD
- * @package Mail
- */
-class Mail_RFC822 {
-
-    /**
-     * The address being parsed by the RFC822 object.
-     * @var string $address
-     */
-    var $address = '';
-
-    /**
-     * The default domain to use for unqualified addresses.
-     * @var string $default_domain
-     */
-    var $default_domain = 'localhost';
-
-    /**
-     * Should we return a nested array showing groups, or flatten everything?
-     * @var boolean $nestGroups
-     */
-    var $nestGroups = true;
-
-    /**
-     * Whether or not to validate atoms for non-ascii characters.
-     * @var boolean $validate
-     */
-    var $validate = true;
-
-    /**
-     * The array of raw addresses built up as we parse.
-     * @var array $addresses
-     */
-    var $addresses = array();
-
-    /**
-     * The final array of parsed address information that we build up.
-     * @var array $structure
-     */
-    var $structure = array();
-
-    /**
-     * The current error message, if any.
-     * @var string $error
-     */
-    var $error = null;
-
-    /**
-     * An internal counter/pointer.
-     * @var integer $index
-     */
-    var $index = null;
-
-    /**
-     * The number of groups that have been found in the address list.
-     * @var integer $num_groups
-     * @access public
-     */
-    var $num_groups = 0;
-
-    /**
-     * A variable so that we can tell whether or not we're inside a
-     * Mail_RFC822 object.
-     * @var boolean $mailRFC822
-     */
-    var $mailRFC822 = true;
-
-    /**
-    * A limit after which processing stops
-    * @var int $limit
-    */
-    var $limit = null;
-
-    /**
-     * Sets up the object. The address must either be set here or when
-     * calling parseAddressList(). One or the other.
-     *
-     * @access public
-     * @param string  $address         The address(es) to validate.
-     * @param string  $default_domain  Default domain/host etc. If not supplied, will be set to localhost.
-     * @param boolean $nest_groups     Whether to return the structure with groups nested for easier viewing.
-     * @param boolean $validate        Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
-     *
-     * @return object Mail_RFC822 A new Mail_RFC822 object.
-     */
-    function Mail_RFC822($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
-    {
-        if (isset($address))        $this->address        = $address;
-        if (isset($default_domain)) $this->default_domain = $default_domain;
-        if (isset($nest_groups))    $this->nestGroups     = $nest_groups;
-        if (isset($validate))       $this->validate       = $validate;
-        if (isset($limit))          $this->limit          = $limit;
-    }
-
-    /**
-     * Starts the whole process. The address must either be set here
-     * or when creating the object. One or the other.
-     *
-     * @access public
-     * @param string  $address         The address(es) to validate.
-     * @param string  $default_domain  Default domain/host etc.
-     * @param boolean $nest_groups     Whether to return the structure with groups nested for easier viewing.
-     * @param boolean $validate        Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
-     *
-     * @return array A structured array of addresses.
-     */
-    function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
-    {
-        if (!isset($this) || !isset($this->mailRFC822)) {
-            $obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
-            return $obj->parseAddressList();
-        }
-
-        if (isset($address))        $this->address        = $address;
-        if (isset($default_domain)) $this->default_domain = $default_domain;
-        if (isset($nest_groups))    $this->nestGroups     = $nest_groups;
-        if (isset($validate))       $this->validate       = $validate;
-        if (isset($limit))          $this->limit          = $limit;
-
-        $this->structure  = array();
-        $this->addresses  = array();
-        $this->error      = null;
-        $this->index      = null;
-
-        // Unfold any long lines in $this->address.
-        $this->address = preg_replace('/\r?\n/', "\r\n", $this->address);
-        $this->address = preg_replace('/\r\n(\t| )+/', ' ', $this->address);
-
-        while ($this->address = $this->_splitAddresses($this->address));
-
-        if ($this->address === false || isset($this->error)) {
-            require_once 'PEAR.php';
-            return PEAR::raiseError($this->error);
-        }
-
-        // Validate each address individually.  If we encounter an invalid
-        // address, stop iterating and return an error immediately.
-        foreach ($this->addresses as $address) {
-            $valid = $this->_validateAddress($address);
-
-            if ($valid === false || isset($this->error)) {
-                require_once 'PEAR.php';
-                return PEAR::raiseError($this->error);
-            }
-
-            if (!$this->nestGroups) {
-                $this->structure = array_merge($this->structure, $valid);
-            } else {
-                $this->structure[] = $valid;
-            }
-        }
-
-        return $this->structure;
-    }
-
-    /**
-     * Splits an address into separate addresses.
-     *
-     * @access private
-     * @param string $address The addresses to split.
-     * @return boolean Success or failure.
-     */
-    function _splitAddresses($address)
-    {
-        if (!empty($this->limit) && count($this->addresses) == $this->limit) {
-            return '';
-        }
-
-        if ($this->_isGroup($address) && !isset($this->error)) {
-            $split_char = ';';
-            $is_group   = true;
-        } elseif (!isset($this->error)) {
-            $split_char = ',';
-            $is_group   = false;
-        } elseif (isset($this->error)) {
-            return false;
-        }
-
-        // Split the string based on the above ten or so lines.
-        $parts  = explode($split_char, $address);
-        $string = $this->_splitCheck($parts, $split_char);
-
-        // If a group...
-        if ($is_group) {
-            // If $string does not contain a colon outside of
-            // brackets/quotes etc then something's fubar.
-
-            // First check there's a colon at all:
-            if (strpos($string, ':') === false) {
-                $this->error = 'Invalid address: ' . $string;
-                return false;
-            }
-
-            // Now check it's outside of brackets/quotes:
-            if (!$this->_splitCheck(explode(':', $string), ':')) {
-                return false;
-            }
-
-            // We must have a group at this point, so increase the counter:
-            $this->num_groups++;
-        }
-
-        // $string now contains the first full address/group.
-        // Add to the addresses array.
-        $this->addresses[] = array(
-                                   'address' => trim($string),
-                                   'group'   => $is_group
-                                   );
-
-        // Remove the now stored address from the initial line, the +1
-        // is to account for the explode character.
-        $address = trim(substr($address, strlen($string) + 1));
-
-        // If the next char is a comma and this was a group, then
-        // there are more addresses, otherwise, if there are any more
-        // chars, then there is another address.
-        if ($is_group && substr($address, 0, 1) == ','){
-            $address = trim(substr($address, 1));
-            return $address;
-
-        } elseif (strlen($address) > 0) {
-            return $address;
-
-        } else {
-            return '';
-        }
-
-        // If you got here then something's off
-        return false;
-    }
-
-    /**
-     * Checks for a group at the start of the string.
-     *
-     * @access private
-     * @param string $address The address to check.
-     * @return boolean Whether or not there is a group at the start of the string.
-     */
-    function _isGroup($address)
-    {
-        // First comma not in quotes, angles or escaped:
-        $parts  = explode(',', $address);
-        $string = $this->_splitCheck($parts, ',');
-
-        // Now we have the first address, we can reliably check for a
-        // group by searching for a colon that's not escaped or in
-        // quotes or angle brackets.
-        if (count($parts = explode(':', $string)) > 1) {
-            $string2 = $this->_splitCheck($parts, ':');
-            return ($string2 !== $string);
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * A common function that will check an exploded string.
-     *
-     * @access private
-     * @param array $parts The exloded string.
-     * @param string $char  The char that was exploded on.
-     * @return mixed False if the string contains unclosed quotes/brackets, or the string on success.
-     */
-    function _splitCheck($parts, $char)
-    {
-        $string = $parts[0];
-
-        for ($i = 0; $i < count($parts); $i++) {
-            if ($this->_hasUnclosedQuotes($string)
-                || $this->_hasUnclosedBrackets($string, '<>')
-                || $this->_hasUnclosedBrackets($string, '[]')
-                || $this->_hasUnclosedBrackets($string, '()')
-                || substr($string, -1) == '\\') {
-                if (isset($parts[$i + 1])) {
-                    $string = $string . $char . $parts[$i + 1];
-                } else {
-                    $this->error = 'Invalid address spec. Unclosed bracket or quotes';
-                    return false;
-                }
-            } else {
-                $this->index = $i;
-                break;
-            }
-        }
-
-        return $string;
-    }
-
-    /**
-     * Checks if a string has an unclosed quotes or not.
-     *
-     * @access private
-     * @param string $string The string to check.
-     * @return boolean True if there are unclosed quotes inside the string, false otherwise.
-     */
-    function _hasUnclosedQuotes($string)
-    {
-        $string     = explode('"', $string);
-        $string_cnt = count($string);
-
-        for ($i = 0; $i < (count($string) - 1); $i++)
-            if (substr($string[$i], -1) == '\\')
-                $string_cnt--;
-
-        return ($string_cnt % 2 === 0);
-    }
-
-    /**
-     * Checks if a string has an unclosed brackets or not. IMPORTANT:
-     * This function handles both angle brackets and square brackets;
-     *
-     * @access private
-     * @param string $string The string to check.
-     * @param string $chars  The characters to check for.
-     * @return boolean True if there are unclosed brackets inside the string, false otherwise.
-     */
-    function _hasUnclosedBrackets($string, $chars)
-    {
-        $num_angle_start = substr_count($string, $chars[0]);
-        $num_angle_end   = substr_count($string, $chars[1]);
-
-        $this->_hasUnclosedBracketsSub($string, $num_angle_start, $chars[0]);
-        $this->_hasUnclosedBracketsSub($string, $num_angle_end, $chars[1]);
-
-        if ($num_angle_start < $num_angle_end) {
-            $this->error = 'Invalid address spec. Unmatched quote or bracket (' . $chars . ')';
-            return false;
-        } else {
-            return ($num_angle_start > $num_angle_end);
-        }
-    }
-
-    /**
-     * Sub function that is used only by hasUnclosedBrackets().
-     *
-     * @access private
-     * @param string $string The string to check.
-     * @param integer &$num    The number of occurences.
-     * @param string $char   The character to count.
-     * @return integer The number of occurences of $char in $string, adjusted for backslashes.
-     */
-    function _hasUnclosedBracketsSub($string, &$num, $char)
-    {
-        $parts = explode($char, $string);
-        for ($i = 0; $i < count($parts); $i++){
-            if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i]))
-                $num--;
-            if (isset($parts[$i + 1]))
-                $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
-        }
-
-        return $num;
-    }
-
-    /**
-     * Function to begin checking the address.
-     *
-     * @access private
-     * @param string $address The address to validate.
-     * @return mixed False on failure, or a structured array of address information on success.
-     */
-    function _validateAddress($address)
-    {
-        $is_group = false;
-        $addresses = array();
-
-        if ($address['group']) {
-            $is_group = true;
-
-            // Get the group part of the name
-            $parts     = explode(':', $address['address']);
-            $groupname = $this->_splitCheck($parts, ':');
-            $structure = array();
-
-            // And validate the group part of the name.
-            if (!$this->_validatePhrase($groupname)){
-                $this->error = 'Group name did not validate.';
-                return false;
-            } else {
-                // Don't include groups if we are not nesting
-                // them. This avoids returning invalid addresses.
-                if ($this->nestGroups) {
-                    $structure = new stdClass;
-                    $structure->groupname = $groupname;
-                }
-            }
-
-            $address['address'] = ltrim(substr($address['address'], strlen($groupname . ':')));
-        }
-
-        // If a group then split on comma and put into an array.
-        // Otherwise, Just put the whole address in an array.
-        if ($is_group) {
-            while (strlen($address['address']) > 0) {
-                $parts       = explode(',', $address['address']);
-                $addresses[] = $this->_splitCheck($parts, ',');
-                $address['address'] = trim(substr($address['address'], strlen(end($addresses) . ',')));
-            }
-        } else {
-            $addresses[] = $address['address'];
-        }
-
-        // Check that $addresses is set, if address like this:
-        // Groupname:;
-        // Then errors were appearing.
-        if (!count($addresses)){
-            $this->error = 'Empty group.';
-            return false;
-        }
-
-        // Trim the whitespace from all of the address strings.
-        array_map('trim', $addresses);
-
-        // Validate each mailbox.
-        // Format could be one of: name <geezer@domain.com>
-        //                         geezer@domain.com
-        //                         geezer
-        // ... or any other format valid by RFC 822.
-        for ($i = 0; $i < count($addresses); $i++) {
-            if (!$this->validateMailbox($addresses[$i])) {
-                if (empty($this->error)) {
-                    $this->error = 'Validation failed for: ' . $addresses[$i];
-                }
-                return false;
-            }
-        }
-
-        // Nested format
-        if ($this->nestGroups) {
-            if ($is_group) {
-                $structure->addresses = $addresses;
-            } else {
-                $structure = $addresses[0];
-            }
-
-        // Flat format
-        } else {
-            if ($is_group) {
-                $structure = array_merge($structure, $addresses);
-            } else {
-                $structure = $addresses;
-            }
-        }
-
-        return $structure;
-    }
-
-    /**
-     * Function to validate a phrase.
-     *
-     * @access private
-     * @param string $phrase The phrase to check.
-     * @return boolean Success or failure.
-     */
-    function _validatePhrase($phrase)
-    {
-        // Splits on one or more Tab or space.
-        $parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
-
-        $phrase_parts = array();
-        while (count($parts) > 0){
-            $phrase_parts[] = $this->_splitCheck($parts, ' ');
-            for ($i = 0; $i < $this->index + 1; $i++)
-                array_shift($parts);
-        }
-
-        foreach ($phrase_parts as $part) {
-            // If quoted string:
-            if (substr($part, 0, 1) == '"') {
-                if (!$this->_validateQuotedString($part)) {
-                    return false;
-                }
-                continue;
-            }
-
-            // Otherwise it's an atom:
-            if (!$this->_validateAtom($part)) return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * Function to validate an atom which from rfc822 is:
-     * atom = 1*<any CHAR except specials, SPACE and CTLs>
-     *
-     * If validation ($this->validate) has been turned off, then
-     * validateAtom() doesn't actually check anything. This is so that you
-     * can split a list of addresses up before encoding personal names
-     * (umlauts, etc.), for example.
-     *
-     * @access private
-     * @param string $atom The string to check.
-     * @return boolean Success or failure.
-     */
-    function _validateAtom($atom)
-    {
-        if (!$this->validate) {
-            // Validation has been turned off; assume the atom is okay.
-            return true;
-        }
-
-        // Check for any char from ASCII 0 - ASCII 127
-        if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) {
-            return false;
-        }
-
-        // Check for specials:
-        if (preg_match('/[][()<>@,;\\:". ]/', $atom)) {
-            return false;
-        }
-
-        // Check for control characters (ASCII 0-31):
-        if (preg_match('/[\\x00-\\x1F]+/', $atom)) {
-            return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * Function to validate quoted string, which is:
-     * quoted-string = <"> *(qtext/quoted-pair) <">
-     *
-     * @access private
-     * @param string $qstring The string to check
-     * @return boolean Success or failure.
-     */
-    function _validateQuotedString($qstring)
-    {
-        // Leading and trailing "
-        $qstring = substr($qstring, 1, -1);
-
-        // Perform check, removing quoted characters first.
-        return !preg_match('/[\x0D\\\\"]/', preg_replace('/\\\\./', '', $qstring));
-    }
-
-    /**
-     * Function to validate a mailbox, which is:
-     * mailbox =   addr-spec         ; simple address
-     *           / phrase route-addr ; name and route-addr
-     *
-     * @access public
-     * @param string &$mailbox The string to check.
-     * @return boolean Success or failure.
-     */
-    function validateMailbox(&$mailbox)
-    {
-        // A couple of defaults.
-        $phrase  = '';
-        $comment = '';
-        $comments = array();
-
-        // Catch any RFC822 comments and store them separately.
-        $_mailbox = $mailbox;
-        while (strlen(trim($_mailbox)) > 0) {
-            $parts = explode('(', $_mailbox);
-            $before_comment = $this->_splitCheck($parts, '(');
-            if ($before_comment != $_mailbox) {
-                // First char should be a (.
-                $comment    = substr(str_replace($before_comment, '', $_mailbox), 1);
-                $parts      = explode(')', $comment);
-                $comment    = $this->_splitCheck($parts, ')');
-                $comments[] = $comment;
-
-                // +1 is for the trailing )
-                $_mailbox   = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1);
-            } else {
-                break;
-            }
-        }
-
-        foreach ($comments as $comment) {
-            $mailbox = str_replace("($comment)", '', $mailbox);
-        }
-
-        $mailbox = trim($mailbox);
-
-        // Check for name + route-addr
-        if (substr($mailbox, -1) == '>' && substr($mailbox, 0, 1) != '<') {
-            $parts  = explode('<', $mailbox);
-            $name   = $this->_splitCheck($parts, '<');
-
-            $phrase     = trim($name);
-            $route_addr = trim(substr($mailbox, strlen($name.'<'), -1));
-
-            if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) {
-                return false;
-            }
-
-        // Only got addr-spec
-        } else {
-            // First snip angle brackets if present.
-            if (substr($mailbox, 0, 1) == '<' && substr($mailbox, -1) == '>') {
-                $addr_spec = substr($mailbox, 1, -1);
-            } else {
-                $addr_spec = $mailbox;
-            }
-
-            if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
-                return false;
-            }
-        }
-
-        // Construct the object that will be returned.
-        $mbox = new stdClass();
-
-        // Add the phrase (even if empty) and comments
-        $mbox->personal = $phrase;
-        $mbox->comment  = isset($comments) ? $comments : array();
-
-        if (isset($route_addr)) {
-            $mbox->mailbox = $route_addr['local_part'];
-            $mbox->host    = $route_addr['domain'];
-            $route_addr['adl'] !== '' ? $mbox->adl = $route_addr['adl'] : '';
-        } else {
-            $mbox->mailbox = $addr_spec['local_part'];
-            $mbox->host    = $addr_spec['domain'];
-        }
-
-        $mailbox = $mbox;
-        return true;
-    }
-
-    /**
-     * This function validates a route-addr which is:
-     * route-addr = "<" [route] addr-spec ">"
-     *
-     * Angle brackets have already been removed at the point of
-     * getting to this function.
-     *
-     * @access private
-     * @param string $route_addr The string to check.
-     * @return mixed False on failure, or an array containing validated address/route information on success.
-     */
-    function _validateRouteAddr($route_addr)
-    {
-        // Check for colon.
-        if (strpos($route_addr, ':') !== false) {
-            $parts = explode(':', $route_addr);
-            $route = $this->_splitCheck($parts, ':');
-        } else {
-            $route = $route_addr;
-        }
-
-        // If $route is same as $route_addr then the colon was in
-        // quotes or brackets or, of course, non existent.
-        if ($route === $route_addr){
-            unset($route);
-            $addr_spec = $route_addr;
-            if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
-                return false;
-            }
-        } else {
-            // Validate route part.
-            if (($route = $this->_validateRoute($route)) === false) {
-                return false;
-            }
-
-            $addr_spec = substr($route_addr, strlen($route . ':'));
-
-            // Validate addr-spec part.
-            if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
-                return false;
-            }
-        }
-
-        if (isset($route)) {
-            $return['adl'] = $route;
-        } else {
-            $return['adl'] = '';
-        }
-
-        $return = array_merge($return, $addr_spec);
-        return $return;
-    }
-
-    /**
-     * Function to validate a route, which is:
-     * route = 1#("@" domain) ":"
-     *
-     * @access private
-     * @param string $route The string to check.
-     * @return mixed False on failure, or the validated $route on success.
-     */
-    function _validateRoute($route)
-    {
-        // Split on comma.
-        $domains = explode(',', trim($route));
-
-        foreach ($domains as $domain) {
-            $domain = str_replace('@', '', trim($domain));
-            if (!$this->_validateDomain($domain)) return false;
-        }
-
-        return $route;
-    }
-
-    /**
-     * Function to validate a domain, though this is not quite what
-     * you expect of a strict internet domain.
-     *
-     * domain = sub-domain *("." sub-domain)
-     *
-     * @access private
-     * @param string $domain The string to check.
-     * @return mixed False on failure, or the validated domain on success.
-     */
-    function _validateDomain($domain)
-    {
-        // Note the different use of $subdomains and $sub_domains
-        $subdomains = explode('.', $domain);
-
-        while (count($subdomains) > 0) {
-            $sub_domains[] = $this->_splitCheck($subdomains, '.');
-            for ($i = 0; $i < $this->index + 1; $i++)
-                array_shift($subdomains);
-        }
-
-        foreach ($sub_domains as $sub_domain) {
-            if (!$this->_validateSubdomain(trim($sub_domain)))
-                return false;
-        }
-
-        // Managed to get here, so return input.
-        return $domain;
-    }
-
-    /**
-     * Function to validate a subdomain:
-     *   subdomain = domain-ref / domain-literal
-     *
-     * @access private
-     * @param string $subdomain The string to check.
-     * @return boolean Success or failure.
-     */
-    function _validateSubdomain($subdomain)
-    {
-        if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){
-            if (!$this->_validateDliteral($arr[1])) return false;
-        } else {
-            if (!$this->_validateAtom($subdomain)) return false;
-        }
-
-        // Got here, so return successful.
-        return true;
-    }
-
-    /**
-     * Function to validate a domain literal:
-     *   domain-literal =  "[" *(dtext / quoted-pair) "]"
-     *
-     * @access private
-     * @param string $dliteral The string to check.
-     * @return boolean Success or failure.
-     */
-    function _validateDliteral($dliteral)
-    {
-        return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\';
-    }
-
-    /**
-     * Function to validate an addr-spec.
-     *
-     * addr-spec = local-part "@" domain
-     *
-     * @access private
-     * @param string $addr_spec The string to check.
-     * @return mixed False on failure, or the validated addr-spec on success.
-     */
-    function _validateAddrSpec($addr_spec)
-    {
-        $addr_spec = trim($addr_spec);
-
-        // Split on @ sign if there is one.
-        if (strpos($addr_spec, '@') !== false) {
-            $parts      = explode('@', $addr_spec);
-            $local_part = $this->_splitCheck($parts, '@');
-            $domain     = substr($addr_spec, strlen($local_part . '@'));
-
-        // No @ sign so assume the default domain.
-        } else {
-            $local_part = $addr_spec;
-            $domain     = $this->default_domain;
-        }
-
-        if (($local_part = $this->_validateLocalPart($local_part)) === false) return false;
-        if (($domain     = $this->_validateDomain($domain)) === false) return false;
-
-        // Got here so return successful.
-        return array('local_part' => $local_part, 'domain' => $domain);
-    }
-
-    /**
-     * Function to validate the local part of an address:
-     *   local-part = word *("." word)
-     *
-     * @access private
-     * @param string $local_part
-     * @return mixed False on failure, or the validated local part on success.
-     */
-    function _validateLocalPart($local_part)
-    {
-        $parts = explode('.', $local_part);
-        $words = array();
-
-        // Split the local_part into words.
-        while (count($parts) > 0){
-            $words[] = $this->_splitCheck($parts, '.');
-            for ($i = 0; $i < $this->index + 1; $i++) {
-                array_shift($parts);
-            }
-        }
-
-        // Validate each word.
-        foreach ($words as $word) {
-            // If this word contains an unquoted space, it is invalid. (6.2.4)
-            if (strpos($word, ' ') && $word[0] !== '"')
-            {
-                return false;
-            }
-
-            if ($this->_validatePhrase(trim($word)) === false) return false;
-        }
-
-        // Managed to get here, so return the input.
-        return $local_part;
-    }
-
-    /**
-     * Returns an approximate count of how many addresses are in the
-     * given string. This is APPROXIMATE as it only splits based on a
-     * comma which has no preceding backslash. Could be useful as
-     * large amounts of addresses will end up producing *large*
-     * structures when used with parseAddressList().
-     *
-     * @param  string $data Addresses to count
-     * @return int          Approximate count
-     */
-    function approximateCount($data)
-    {
-        return count(preg_split('/(?<!\\\\),/', $data));
-    }
-
-    /**
-     * This is a email validating function separate to the rest of the
-     * class. It simply validates whether an email is of the common
-     * internet form: <user>@<domain>. This can be sufficient for most
-     * people. Optional stricter mode can be utilised which restricts
-     * mailbox characters allowed to alphanumeric, full stop, hyphen
-     * and underscore.
-     *
-     * @param  string  $data   Address to check
-     * @param  boolean $strict Optional stricter mode
-     * @return mixed           False if it fails, an indexed array
-     *                         username/domain if it matches
-     */
-    function isValidInetAddress($data, $strict = false)
-    {
-        $regex = $strict ? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
-        if (preg_match($regex, trim($data), $matches)) {
-            return array($matches[1], $matches[2]);
-        } else {
-            return false;
-        }
-    }
-
-}

+ 0 - 128
htdocs/includes/nusoap/lib/Mail/mail.php

@@ -1,128 +0,0 @@
-<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4                                                        |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2003 The PHP Group                                |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license,      |
-// | that is bundled with this package in the file LICENSE, and is        |
-// | available at through the world-wide-web at                           |
-// | http://www.php.net/license/2_02.txt.                                 |
-// | If you did not receive a copy of the PHP license and are unable to   |
-// | obtain it through the world-wide-web, please send a note to          |
-// | license@php.net so we can mail you a copy immediately.               |
-// +----------------------------------------------------------------------+
-// | Author: Chuck Hagenbuch <chuck@horde.org>                            |
-// +----------------------------------------------------------------------+
-//
-
-/**
- * internal PHP-mail() implementation of the PEAR Mail:: interface.
- * @package Mail
- */
-class Mail_mail extends Mail {
-
-    /**
-     * Any arguments to pass to the mail() function.
-     * @var string
-     */
-    var $_params = '';
-
-    /**
-     * Constructor.
-     *
-     * Instantiates a new Mail_mail:: object based on the parameters
-     * passed in.
-     *
-     * @param array $params Extra arguments for the mail() function.
-     */
-    function Mail_mail($params = null)
-    {
-        /* The other mail implementations accept parameters as arrays.
-         * In the interest of being consistent, explode an array into
-         * a string of parameter arguments. */
-        if (is_array($params)) {
-            $this->_params = join(' ', $params);
-        } else {
-            $this->_params = $params;
-        }
-
-        /* Because the mail() function may pass headers as command
-         * line arguments, we can't guarantee the use of the standard
-         * "\r\n" separator.  Instead, we use the system's native line
-         * separator. */
-        $this->sep = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n";
-    }
-
-	/**
-     * Implements Mail_mail::send() function using php's built-in mail()
-     * command.
-     *
-     * @param mixed $recipients Either a comma-seperated list of recipients
-     *              (RFC822 compliant), or an array of recipients,
-     *              each RFC822 valid. This may contain recipients not
-     *              specified in the headers, for Bcc:, resending
-     *              messages, etc.
-     *
-     * @param array $headers The array of headers to send with the mail, in an
-     *              associative array, where the array key is the
-     *              header name (ie, 'Subject'), and the array value
-     *              is the header value (ie, 'test'). The header
-     *              produced from those values would be 'Subject:
-     *              test'.
-     *
-     * @param string $body The full text of the message body, including any
-     *               Mime parts, etc.
-     *
-     * @return mixed Returns true on success, or a PEAR_Error
-     *               containing a descriptive error message on
-     *               failure.
-     *
-     * @access public
-     */
-    function send($recipients, $headers, $body)
-    {
-        // If we're passed an array of recipients, implode it.
-        if (is_array($recipients)) {
-            $recipients = implode(', ', $recipients);
-        }
-
-        // Get the Subject out of the headers array so that we can
-        // pass it as a seperate argument to mail().
-        $subject = '';
-        if (isset($headers['Subject'])) {
-            $subject = $headers['Subject'];
-            unset($headers['Subject']);
-        }
-
-        // Flatten the headers out.
-        $headerElements = $this->prepareHeaders($headers);
-        if (PEAR::isError($headerElements)) {
-            return $headerElements;
-        }
-        list(, $text_headers) = $headerElements;
-
-        /*
-         * We only use mail()'s optional fifth parameter if the additional
-         * parameters have been provided and we're not running in safe mode.
-         */
-        if (empty($this->_params) || ini_get('safe_mode')) {
-            $result = mail($recipients, $subject, $body, $text_headers);
-        } else {
-            $result = mail($recipients, $subject, $body, $text_headers,
-                           $this->_params);
-        }
-
-        /*
-         * If the mail() function returned failure, we need to create a
-         * PEAR_Error object and return it instead of the boolean result.
-         */
-        if ($result === false) {
-            $result = PEAR::raiseError('mail() returned failure');
-        }
-
-        return $result;
-    }
-
-}

File diff suppressed because it is too large
+ 638 - 233
htdocs/includes/nusoap/lib/Mail/mime.php


+ 0 - 836
htdocs/includes/nusoap/lib/Mail/mimeDecode.php

@@ -1,836 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-// +-----------------------------------------------------------------------+
-// | Copyright (c) 2002-2003  Richard Heyes                                |
-// | Copyright (c) 2003-2005  The PHP Group                                |
-// | All rights reserved.                                                  |
-// |                                                                       |
-// | Redistribution and use in source and binary forms, with or without    |
-// | modification, are permitted provided that the following conditions    |
-// | are met:                                                              |
-// |                                                                       |
-// | o Redistributions of source code must retain the above copyright      |
-// |   notice, this list of conditions and the following disclaimer.       |
-// | o Redistributions in binary form must reproduce the above copyright   |
-// |   notice, this list of conditions and the following disclaimer in the |
-// |   documentation and/or other materials provided with the distribution.|
-// | o The names of the authors may not be used to endorse or promote      |
-// |   products derived from this software without specific prior written  |
-// |   permission.                                                         |
-// |                                                                       |
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
-// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
-// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
-// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
-// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
-// | 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>                           |
-// +-----------------------------------------------------------------------+
-
-require_once 'PEAR.php';
-
-/**
-*  +----------------------------- IMPORTANT ------------------------------+
-*  | Usage of this class compared to native php extensions such as        |
-*  | mailparse or imap, is slow and may be feature deficient. If available|
-*  | you are STRONGLY recommended to use the php extensions.              |
-*  +----------------------------------------------------------------------+
-*
-* Mime Decoding class
-*
-* This class will parse a raw mime email and return
-* the structure. Returned structure is similar to
-* that returned by imap_fetchstructure().
-*
-* USAGE: (assume $input is your raw email)
-*
-* $decode = new Mail_mimeDecode($input, "\r\n");
-* $structure = $decode->decode();
-* print_r($structure);
-*
-* Or statically:
-*
-* $params['input'] = $input;
-* $structure = Mail_mimeDecode::decode($params);
-* print_r($structure);
-*
-* TODO:
-*  o Implement multipart/appledouble
-*  o UTF8: ???
-
-		> 4. We have also found a solution for decoding the UTF-8 
-		> headers. Therefore I made the following function:
-		> 
-		> function decode_utf8($txt) {
-		> $trans=array("�&#8216;"=>"õ","ű"=>"û","Ő"=>"�&#8226;","Ű"
-		=>"�&#8250;");
-		> $txt=strtr($txt,$trans);
-		> return(utf8_decode($txt));
-		> }
-		> 
-		> And I have inserted the following line to the class:
-		> 
-		> if (strtolower($charset)=="utf-8") $text=decode_utf8($text);
-		> 
-		> ... before the following one in the "_decodeHeader" function:
-		> 
-		> $input = str_replace($encoded, $text, $input);
-		> 
-		> This way from now on it can easily decode the UTF-8 headers too.
-
-*
-* @author  Richard Heyes <richard@phpguru.org>
-* @package Mail
-*/
-class Mail_mimeDecode extends PEAR
-{
-    /**
-     * The raw email to decode
-     * @var    string
-     */
-    var $_input;
-
-    /**
-     * The header part of the input
-     * @var    string
-     */
-    var $_header;
-
-    /**
-     * The body part of the input
-     * @var    string
-     */
-    var $_body;
-
-    /**
-     * If an error occurs, this is used to store the message
-     * @var    string
-     */
-    var $_error;
-
-    /**
-     * Flag to determine whether to include bodies in the
-     * returned object.
-     * @var    boolean
-     */
-    var $_include_bodies;
-
-    /**
-     * Flag to determine whether to decode bodies
-     * @var    boolean
-     */
-    var $_decode_bodies;
-
-    /**
-     * Flag to determine whether to decode headers
-     * @var    boolean
-     */
-    var $_decode_headers;
-
-    /**
-     * Constructor.
-     *
-     * Sets up the object, initialise the variables, and splits and
-     * stores the header and body of the input.
-     *
-     * @param string The input to decode
-     * @access public
-     */
-    function Mail_mimeDecode($input)
-    {
-        list($header, $body)   = $this->_splitBodyHeader($input);
-
-        $this->_input          = $input;
-        $this->_header         = $header;
-        $this->_body           = $body;
-        $this->_decode_bodies  = false;
-        $this->_include_bodies = true;
-    }
-
-    /**
-     * Begins the decoding process. If called statically
-     * it will create an object and call the decode() method
-     * of it.
-     *
-     * @param array An array of various parameters that determine
-     *              various things:
-     *              include_bodies - Whether to include the body in the returned
-     *                               object.
-     *              decode_bodies  - Whether to decode the bodies
-     *                               of the parts. (Transfer encoding)
-     *              decode_headers - Whether to decode headers
-     *              input          - If called statically, this will be treated
-     *                               as the input
-     * @return object Decoded results
-     * @access public
-     */
-    function decode($params = null)
-    {
-        // determine if this method has been called statically
-        $isStatic = !(isset($this) && get_class($this) == __CLASS__);
-
-        // Have we been called statically?
-	// If so, create an object and pass details to that.
-        if ($isStatic AND isset($params['input'])) {
-
-            $obj = new Mail_mimeDecode($params['input']);
-            $structure = $obj->decode($params);
-
-        // Called statically but no input
-        } elseif ($isStatic) {
-            return PEAR::raiseError('Called statically and no input given');
-
-        // Called via an object
-        } else {
-            $this->_include_bodies = isset($params['include_bodies']) ?
-	                             $params['include_bodies'] : false;
-            $this->_decode_bodies  = isset($params['decode_bodies']) ?
-	                             $params['decode_bodies']  : false;
-            $this->_decode_headers = isset($params['decode_headers']) ?
-	                             $params['decode_headers'] : false;
-
-            $structure = $this->_decode($this->_header, $this->_body);
-            if ($structure === false) {
-                $structure = $this->raiseError($this->_error);
-            }
-        }
-
-        return $structure;
-    }
-
-    /**
-     * Performs the decoding. Decodes the body string passed to it
-     * If it finds certain content-types it will call itself in a
-     * recursive fashion
-     *
-     * @param string Header section
-     * @param string Body section
-     * @return object Results of decoding process
-     * @access private
-     */
-    function _decode($headers, $body, $default_ctype = 'text/plain')
-    {
-        $return = new stdClass;
-        $return->headers = array();
-        $headers = $this->_parseHeaders($headers);
-
-        foreach ($headers as $value) {
-            if (isset($return->headers[strtolower($value['name'])]) AND !is_array($return->headers[strtolower($value['name'])])) {
-                $return->headers[strtolower($value['name'])]   = array($return->headers[strtolower($value['name'])]);
-                $return->headers[strtolower($value['name'])][] = $value['value'];
-
-            } elseif (isset($return->headers[strtolower($value['name'])])) {
-                $return->headers[strtolower($value['name'])][] = $value['value'];
-
-            } else {
-                $return->headers[strtolower($value['name'])] = $value['value'];
-            }
-        }
-
-        reset($headers);
-        while (list($key, $value) = each($headers)) {
-            $headers[$key]['name'] = strtolower($headers[$key]['name']);
-            switch ($headers[$key]['name']) {
-
-                case 'content-type':
-                    $content_type = $this->_parseHeaderValue($headers[$key]['value']);
-
-                    if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {
-                        $return->ctype_primary   = $regs[1];
-                        $return->ctype_secondary = $regs[2];
-                    }
-
-                    if (isset($content_type['other'])) {
-                        while (list($p_name, $p_value) = each($content_type['other'])) {
-                            $return->ctype_parameters[$p_name] = $p_value;
-                        }
-                    }
-                    break;
-
-                case 'content-disposition':
-                    $content_disposition = $this->_parseHeaderValue($headers[$key]['value']);
-                    $return->disposition   = $content_disposition['value'];
-                    if (isset($content_disposition['other'])) {
-                        while (list($p_name, $p_value) = each($content_disposition['other'])) {
-                            $return->d_parameters[$p_name] = $p_value;
-                        }
-                    }
-                    break;
-
-                case 'content-transfer-encoding':
-                    $content_transfer_encoding = $this->_parseHeaderValue($headers[$key]['value']);
-                    break;
-            }
-        }
-
-        if (isset($content_type)) {
-            switch (strtolower($content_type['value'])) {
-                case 'text/plain':
-                    $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
-                    $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
-                    break;
-
-                case 'text/html':
-                    $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
-                    $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
-                    break;
-
-                case 'multipart/parallel':
-                case 'multipart/report': // RFC1892
-                case 'multipart/signed': // PGP
-                case 'multipart/digest':
-                case 'multipart/alternative':
-                case 'multipart/related':
-                case 'multipart/mixed':
-                    if(!isset($content_type['other']['boundary'])){
-                        $this->_error = 'No boundary found for ' . $content_type['value'] . ' part';
-                        return false;
-                    }
-
-                    $default_ctype = (strtolower($content_type['value']) === 'multipart/digest') ? 'message/rfc822' : 'text/plain';
-
-                    $parts = $this->_boundarySplit($body, $content_type['other']['boundary']);
-                    for ($i = 0; $i < count($parts); $i++) {
-                        list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]);
-                        $part = $this->_decode($part_header, $part_body, $default_ctype);
-                        if($part === false)
-                            $part = $this->raiseError($this->_error);
-                        $return->parts[] = $part;
-                    }
-                    break;
-
-                case 'message/rfc822':
-                    $obj = new Mail_mimeDecode($body);
-                    $return->parts[] = $obj->decode(array('include_bodies' => $this->_include_bodies,
-					                                      'decode_bodies'  => $this->_decode_bodies,
-														  'decode_headers' => $this->_decode_headers));
-                    unset($obj);
-                    break;
-
-                default:
-                    if(!isset($content_transfer_encoding['value']))
-                        $content_transfer_encoding['value'] = '7bit';
-                    $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body) : null;
-                    break;
-            }
-
-        } else {
-            $ctype = explode('/', $default_ctype);
-            $return->ctype_primary   = $ctype[0];
-            $return->ctype_secondary = $ctype[1];
-            $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body) : $body) : null;
-        }
-
-        return $return;
-    }
-
-    /**
-     * Given the output of the above function, this will return an
-     * array of references to the parts, indexed by mime number.
-     *
-     * @param  object $structure   The structure to go through
-     * @param  string $mime_number Internal use only.
-     * @return array               Mime numbers
-     */
-    function &getMimeNumbers(&$structure, $no_refs = false, $mime_number = '', $prepend = '')
-    {
-        $return = array();
-        if (!empty($structure->parts)) {
-            if ($mime_number != '') {
-                $structure->mime_id = $prepend . $mime_number;
-                $return[$prepend . $mime_number] = &$structure;
-            }
-            for ($i = 0; $i < count($structure->parts); $i++) {
-
-            
-                if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') {
-                    $prepend      = $prepend . $mime_number . '.';
-                    $_mime_number = '';
-                } else {
-                    $_mime_number = ($mime_number == '' ? $i + 1 : sprintf('%s.%s', $mime_number, $i + 1));
-                }
-
-                $arr = &Mail_mimeDecode::getMimeNumbers($structure->parts[$i], $no_refs, $_mime_number, $prepend);
-                foreach ($arr as $key => $val) {
-                    $no_refs ? $return[$key] = '' : $return[$key] = &$arr[$key];
-                }
-            }
-        } else {
-            if ($mime_number == '') {
-                $mime_number = '1';
-            }
-            $structure->mime_id = $prepend . $mime_number;
-            $no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure;
-        }
-        
-        return $return;
-    }
-
-    /**
-     * Given a string containing a header and body
-     * section, this function will split them (at the first
-     * blank line) and return them.
-     *
-     * @param string Input to split apart
-     * @return array Contains header and body section
-     * @access private
-     */
-    function _splitBodyHeader($input)
-    {
-        if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {
-            return array($match[1], $match[2]);
-        }
-        $this->_error = 'Could not split header and body';
-        return false;
-    }
-
-    /**
-     * Parse headers given in $input and return
-     * as assoc array.
-     *
-     * @param string Headers to parse
-     * @return array Contains parsed headers
-     * @access private
-     */
-    function _parseHeaders($input)
-    {
-
-        if ($input !== '') {
-            // Unfold the input
-            $input   = preg_replace("/\r?\n/", "\r\n", $input);
-            $input   = preg_replace("/\r\n(\t| )+/", ' ', $input);
-            $headers = explode("\r\n", trim($input));
-
-            foreach ($headers as $value) {
-                $hdr_name = substr($value, 0, $pos = strpos($value, ':'));
-                $hdr_value = substr($value, $pos+1);
-                if($hdr_value[0] == ' ')
-                    $hdr_value = substr($hdr_value, 1);
-
-                $return[] = array(
-                                  'name'  => $hdr_name,
-                                  'value' => $this->_decode_headers ? $this->_decodeHeader($hdr_value) : $hdr_value
-                                 );
-            }
-        } else {
-            $return = array();
-        }
-
-        return $return;
-    }
-
-    /**
-     * Function to parse a header value,
-     * extract first part, and any secondary
-     * parts (after ;) This function is not as
-     * robust as it could be. Eg. header comments
-     * in the wrong place will probably break it.
-     *
-     * @param string Header value to parse
-     * @return array Contains parsed result
-     * @access private
-     */
-    function _parseHeaderValue($input)
-    {
-
-        if (($pos = strpos($input, ';')) !== false) {
-
-            $return['value'] = trim(substr($input, 0, $pos));
-            $input = trim(substr($input, $pos+1));
-
-            if (strlen($input) > 0) {
-
-                // This splits on a semi-colon, if there's no preceeding backslash
-                // Now works with quoted values; had to glue the \; breaks in PHP
-                // the regex is already bordering on incomprehensible
-                $splitRegex = '/([^;\'"]*[\'"]([^\'"]*([^\'"]*)*)[\'"][^;\'"]*|([^;]+))(;|$)/';
-                preg_match_all($splitRegex, $input, $matches);
-                $parameters = array();
-                for ($i=0; $i<count($matches[0]); $i++) {
-                    $param = $matches[0][$i];
-                    while (substr($param, -2) == '\;') {
-                        $param .= $matches[0][++$i];
-                    }
-                    $parameters[] = $param;
-                }
-
-                for ($i = 0; $i < count($parameters); $i++) {
-                    $param_name  = trim(substr($parameters[$i], 0, $pos = strpos($parameters[$i], '=')), "'\";\t\\ ");
-                    $param_value = trim(str_replace('\;', ';', substr($parameters[$i], $pos + 1)), "'\";\t\\ ");
-                    if ($param_value[0] == '"') {
-                        $param_value = substr($param_value, 1, -1);
-                    }
-                    $return['other'][$param_name] = $param_value;
-                    $return['other'][strtolower($param_name)] = $param_value;
-                }
-            }
-        } else {
-            $return['value'] = trim($input);
-        }
-
-        return $return;
-    }
-
-    /**
-     * This function splits the input based
-     * on the given boundary
-     *
-     * @param string Input to parse
-     * @return array Contains array of resulting mime parts
-     * @access private
-     */
-    function _boundarySplit($input, $boundary)
-    {
-        $parts = array();
-
-        $bs_possible = substr($boundary, 2, -2);
-        $bs_check = '\"' . $bs_possible . '\"';
-
-        if ($boundary == $bs_check) {
-            $boundary = $bs_possible;
-        }
-
-        $tmp = explode('--' . $boundary, $input);
-
-        for ($i = 1; $i < count($tmp) - 1; $i++) {
-            $parts[] = $tmp[$i];
-        }
-
-        return $parts;
-    }
-
-    /**
-     * Given a header, this function will decode it
-     * according to RFC2047. Probably not *exactly*
-     * conformant, but it does pass all the given
-     * examples (in RFC2047).
-     *
-     * @param string Input header value to decode
-     * @return string Decoded header value
-     * @access private
-     */
-    function _decodeHeader($input)
-    {
-        // Remove white space between encoded-words
-        $input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', $input);
-
-        // For each encoded-word...
-        while (preg_match('/(=\?([^?]+)\?(q|b)\?([^?]*)\?=)/i', $input, $matches)) {
-
-            $encoded  = $matches[1];
-            $charset  = $matches[2];
-            $encoding = $matches[3];
-            $text     = $matches[4];
-
-            switch (strtolower($encoding)) {
-                case 'b':
-                    $text = base64_decode($text);
-                    break;
-
-                case 'q':
-                    $text = str_replace('_', ' ', $text);
-                    preg_match_all('/=([a-f0-9]{2})/i', $text, $matches);
-                    foreach($matches[1] as $value)
-                        $text = str_replace('='.$value, chr(hexdec($value)), $text);
-                    break;
-            }
-
-            $input = str_replace($encoded, $text, $input);
-        }
-
-        return $input;
-    }
-
-    /**
-     * Given a body string and an encoding type,
-     * this function will decode and return it.
-     *
-     * @param  string Input body to decode
-     * @param  string Encoding type to use.
-     * @return string Decoded body
-     * @access private
-     */
-    function _decodeBody($input, $encoding = '7bit')
-    {
-        switch (strtolower($encoding)) {
-            case '7bit':
-                return $input;
-                break;
-
-            case 'quoted-printable':
-                return $this->_quotedPrintableDecode($input);
-                break;
-
-            case 'base64':
-                return base64_decode($input);
-                break;
-
-            default:
-                return $input;
-        }
-    }
-
-    /**
-     * Given a quoted-printable string, this
-     * function will decode and return it.
-     *
-     * @param  string Input body to decode
-     * @return string Decoded body
-     * @access private
-     */
-    function _quotedPrintableDecode($input)
-    {
-        // Remove soft line breaks
-        $input = preg_replace("/=\r?\n/", '', $input);
-
-        // Replace encoded characters
-		$input = preg_replace('/=([a-f0-9]{2})/ie', "chr(hexdec('\\1'))", $input);
-
-        return $input;
-    }
-
-    /**
-     * Checks the input for uuencoded files and returns
-     * an array of them. Can be called statically, eg:
-     *
-     * $files =& Mail_mimeDecode::uudecode($some_text);
-     *
-     * It will check for the begin 666 ... end syntax
-     * however and won't just blindly decode whatever you
-     * pass it.
-     *
-     * @param  string Input body to look for attahcments in
-     * @return array  Decoded bodies, filenames and permissions
-     * @access public
-     * @author Unknown
-     */
-    function &uudecode($input)
-    {
-        // Find all uuencoded sections
-        preg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches);
-
-        for ($j = 0; $j < count($matches[3]); $j++) {
-
-            $str      = $matches[3][$j];
-            $filename = $matches[2][$j];
-            $fileperm = $matches[1][$j];
-
-            $file = '';
-            $str = preg_split("/\r?\n/", trim($str));
-            $strlen = count($str);
-
-            for ($i = 0; $i < $strlen; $i++) {
-                $pos = 1;
-                $d = 0;
-                $len=(int)(((ord(substr($str[$i],0,1)) -32) - ' ') & 077);
-
-                while (($d + 3 <= $len) AND ($pos + 4 <= strlen($str[$i]))) {
-                    $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
-                    $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
-                    $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
-                    $c3 = (ord(substr($str[$i],$pos+3,1)) ^ 0x20);
-                    $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
-
-                    $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
-
-                    $file .= chr(((($c2 - ' ') & 077) << 6) |  (($c3 - ' ') & 077));
-
-                    $pos += 4;
-                    $d += 3;
-                }
-
-                if (($d + 2 <= $len) && ($pos + 3 <= strlen($str[$i]))) {
-                    $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
-                    $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
-                    $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
-                    $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
-
-                    $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
-
-                    $pos += 3;
-                    $d += 2;
-                }
-
-                if (($d + 1 <= $len) && ($pos + 2 <= strlen($str[$i]))) {
-                    $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
-                    $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
-                    $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
-
-                }
-            }
-            $files[] = array('filename' => $filename, 'fileperm' => $fileperm, 'filedata' => $file);
-        }
-
-        return $files;
-    }
-
-    /**
-     * getSendArray() returns the arguments required for Mail::send()
-     * used to build the arguments for a mail::send() call 
-     *
-     * Usage:
-     * $mailtext = Full email (for example generated by a template)
-     * $decoder = new Mail_mimeDecode($mailtext);
-     * $parts =  $decoder->getSendArray();
-     * if (!PEAR::isError($parts) {
-     *     list($recipents,$headers,$body) = $parts;
-     *     $mail = Mail::factory('smtp');
-     *     $mail->send($recipents,$headers,$body);
-     * } else {
-     *     echo $parts->message;
-     * }
-     * @return mixed   array of recipeint, headers,body or Pear_Error
-     * @access public
-     * @author Alan Knowles <alan@akbkhome.com>
-     */
-    function getSendArray()
-    {
-        // prevent warning if this is not set
-        $this->_decode_headers = FALSE;
-        $headerlist =$this->_parseHeaders($this->_header);
-        $to = "";
-        if (!$headerlist) {
-            return $this->raiseError("Message did not contain headers");
-        }
-        foreach($headerlist as $item) {
-            $header[$item['name']] = $item['value'];
-            switch (strtolower($item['name'])) {
-                case "to":
-                case "cc":
-                case "bcc":
-                    $to = ",".$item['value'];
-                default:
-                   break;
-            }
-        }
-        if ($to == "") {
-            return $this->raiseError("Message did not contain any recipents");
-        }
-        $to = substr($to,1);
-        return array($to,$header,$this->_body);
-    } 
-
-    /**
-     * Returns a xml copy of the output of
-     * Mail_mimeDecode::decode. Pass the output in as the
-     * argument. This function can be called statically. Eg:
-     *
-     * $output = $obj->decode();
-     * $xml    = Mail_mimeDecode::getXML($output);
-     *
-     * The DTD used for this should have been in the package. Or
-     * alternatively you can get it from cvs, or here:
-     * http://www.phpguru.org/xmail/xmail.dtd.
-     *
-     * @param  object Input to convert to xml. This should be the
-     *                output of the Mail_mimeDecode::decode function
-     * @return string XML version of input
-     * @access public
-     */
-    function getXML($input)
-    {
-        $crlf    =  "\r\n";
-        $output  = '<?xml version=\'1.0\'?>' . $crlf .
-                   '<!DOCTYPE email SYSTEM "http://www.phpguru.org/xmail/xmail.dtd">' . $crlf .
-                   '<email>' . $crlf .
-                   Mail_mimeDecode::_getXML($input) .
-                   '</email>';
-
-        return $output;
-    }
-
-    /**
-     * Function that does the actual conversion to xml. Does a single
-     * mimepart at a time.
-     *
-     * @param  object  Input to convert to xml. This is a mimepart object.
-     *                 It may or may not contain subparts.
-     * @param  integer Number of tabs to indent
-     * @return string  XML version of input
-     * @access private
-     */
-    function _getXML($input, $indent = 1)
-    {
-        $htab    =  "\t";
-        $crlf    =  "\r\n";
-        $output  =  '';
-        $headers = @(array)$input->headers;
-
-        foreach ($headers as $hdr_name => $hdr_value) {
-
-            // Multiple headers with this name
-            if (is_array($headers[$hdr_name])) {
-                for ($i = 0; $i < count($hdr_value); $i++) {
-                    $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value[$i], $indent);
-                }
-
-            // Only one header of this sort
-            } else {
-                $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value, $indent);
-            }
-        }
-
-        if (!empty($input->parts)) {
-            for ($i = 0; $i < count($input->parts); $i++) {
-                $output .= $crlf . str_repeat($htab, $indent) . '<mimepart>' . $crlf .
-                           Mail_mimeDecode::_getXML($input->parts[$i], $indent+1) .
-                           str_repeat($htab, $indent) . '</mimepart>' . $crlf;
-            }
-        } elseif (isset($input->body)) {
-            $output .= $crlf . str_repeat($htab, $indent) . '<body><![CDATA[' .
-                       $input->body . ']]></body>' . $crlf;
-        }
-
-        return $output;
-    }
-
-    /**
-     * Helper function to _getXML(). Returns xml of a header.
-     *
-     * @param  string  Name of header
-     * @param  string  Value of header
-     * @param  integer Number of tabs to indent
-     * @return string  XML version of input
-     * @access private
-     */
-    function _getXML_helper($hdr_name, $hdr_value, $indent)
-    {
-        $htab   = "\t";
-        $crlf   = "\r\n";
-        $return = '';
-
-        $new_hdr_value = ($hdr_name != 'received') ? Mail_mimeDecode::_parseHeaderValue($hdr_value) : array('value' => $hdr_value);
-        $new_hdr_name  = str_replace(' ', '-', ucwords(str_replace('-', ' ', $hdr_name)));
-
-        // Sort out any parameters
-        if (!empty($new_hdr_value['other'])) {
-            foreach ($new_hdr_value['other'] as $paramname => $paramvalue) {
-                $params[] = str_repeat($htab, $indent) . $htab . '<parameter>' . $crlf .
-                            str_repeat($htab, $indent) . $htab . $htab . '<paramname>' . htmlspecialchars($paramname) . '</paramname>' . $crlf .
-                            str_repeat($htab, $indent) . $htab . $htab . '<paramvalue>' . htmlspecialchars($paramvalue) . '</paramvalue>' . $crlf .
-                            str_repeat($htab, $indent) . $htab . '</parameter>' . $crlf;
-            }
-
-            $params = implode('', $params);
-        } else {
-            $params = '';
-        }
-
-        $return = str_repeat($htab, $indent) . '<header>' . $crlf .
-                  str_repeat($htab, $indent) . $htab . '<headername>' . htmlspecialchars($new_hdr_name) . '</headername>' . $crlf .
-                  str_repeat($htab, $indent) . $htab . '<headervalue>' . htmlspecialchars($new_hdr_value['value']) . '</headervalue>' . $crlf .
-                  $params .
-                  str_repeat($htab, $indent) . '</header>' . $crlf;
-
-        return $return;
-    }
-
-} // End of class
-?>

+ 1127 - 217
htdocs/includes/nusoap/lib/Mail/mimePart.php

@@ -1,196 +1,284 @@
 <?php
-// +-----------------------------------------------------------------------+
-// | Copyright (c) 2002-2003  Richard Heyes                                     |
-// | All rights reserved.                                                  |
-// |                                                                       |
-// | Redistribution and use in source and binary forms, with or without    |
-// | modification, are permitted provided that the following conditions    |
-// | are met:                                                              |
-// |                                                                       |
-// | o Redistributions of source code must retain the above copyright      |
-// |   notice, this list of conditions and the following disclaimer.       |
-// | o Redistributions in binary form must reproduce the above copyright   |
-// |   notice, this list of conditions and the following disclaimer in the |
-// |   documentation and/or other materials provided with the distribution.|
-// | o The names of the authors may not be used to endorse or promote      |
-// |   products derived from this software without specific prior written  |
-// |   permission.                                                         |
-// |                                                                       |
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
-// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
-// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
-// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
-// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
-// | 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>                           |
-// +-----------------------------------------------------------------------+
+/**
+ * The Mail_mimePart class is used to create MIME E-mail messages
+ *
+ * This class enables you to manipulate and build a mime email
+ * from the ground up. The Mail_Mime class is a userfriendly api
+ * to this class for people who aren't interested in the internals
+ * of mime mail.
+ * This class however allows full control over the email.
+ *
+ * Compatible with PHP versions 4 and 5
+ *
+ * LICENSE: This LICENSE is in the BSD license style.
+ * Copyright (c) 2002-2003, Richard Heyes <richard@phpguru.org>
+ * Copyright (c) 2003-2006, PEAR <pear-group@php.net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the authors, nor the names of its contributors 
+ *   may be used to endorse or promote products derived from this 
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY 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.
+ *
+ * @category  Mail
+ * @package   Mail_Mime
+ * @author    Richard Heyes  <richard@phpguru.org>
+ * @author    Cipriano Groenendal <cipri@php.net>
+ * @author    Sean Coates <sean@php.net>
+ * @author    Aleksander Machniak <alec@php.net>
+ * @copyright 2003-2006 PEAR <pear-group@php.net>
+ * @license   http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version   CVS: $Id$
+ * @link      http://pear.php.net/package/Mail_mime
+ */
+
 
 /**
-*
-*  Raw mime encoding class
-*
-* What is it?
-*   This class enables you to manipulate and build
-*   a mime email from the ground up.
-*
-* Why use this instead of mime.php?
-*   mime.php is a userfriendly api to this class for
-*   people who aren't interested in the internals of
-*   mime mail. This class however allows full control
-*   over the email.
-*
-* Eg.
-*
-* // Since multipart/mixed has no real body, (the body is
-* // the subpart), we set the body argument to blank.
-*
-* $params['content_type'] = 'multipart/mixed';
-* $email = new Mail_mimePart('', $params);
-*
-* // Here we add a text part to the multipart we have
-* // already. Assume $body contains plain text.
-*
-* $params['content_type'] = 'text/plain';
-* $params['encoding']     = '7bit';
-* $text = $email->addSubPart($body, $params);
-*
-* // Now add an attachment. Assume $attach is
-* the contents of the attachment
-*
-* $params['content_type'] = 'application/zip';
-* $params['encoding']     = 'base64';
-* $params['disposition']  = 'attachment';
-* $params['dfilename']    = 'example.zip';
-* $attach =& $email->addSubPart($body, $params);
-*
-* // Now build the email. Note that the encode
-* // function returns an associative array containing two
-* // elements, body and headers. You will need to add extra
-* // headers, (eg. Mime-Version) before sending.
-*
-* $email = $message->encode();
-* $email['headers'][] = 'Mime-Version: 1.0';
-*
-*
-* Further examples are available at http://www.phpguru.org
-*
-* TODO:
-*  - Set encode() to return the $obj->encoded if encode()
-*    has already been run. Unless a flag is passed to specifically
-*    re-build the message.
-*
-* @author  Richard Heyes <richard@phpguru.org>
-* @package Mail
-*/
-
-class Mail_mimePart {
-
-   /**
+ * The Mail_mimePart class is used to create MIME E-mail messages
+ *
+ * This class enables you to manipulate and build a mime email
+ * from the ground up. The Mail_Mime class is a userfriendly api
+ * to this class for people who aren't interested in the internals
+ * of mime mail.
+ * This class however allows full control over the email.
+ *
+ * @category  Mail
+ * @package   Mail_Mime
+ * @author    Richard Heyes  <richard@phpguru.org>
+ * @author    Cipriano Groenendal <cipri@php.net>
+ * @author    Sean Coates <sean@php.net>
+ * @author    Aleksander Machniak <alec@php.net>
+ * @copyright 2003-2006 PEAR <pear-group@php.net>
+ * @license   http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version   Release: @package_version@
+ * @link      http://pear.php.net/package/Mail_mime
+ */
+class Mail_mimePart
+{
+    /**
     * The encoding type of this part
+    *
     * @var string
+    * @access private
     */
     var $_encoding;
 
-   /**
+    /**
     * An array of subparts
+    *
     * @var array
+    * @access private
     */
     var $_subparts;
 
-   /**
+    /**
     * The output of this part after being built
+    *
     * @var string
+    * @access private
     */
     var $_encoded;
 
-   /**
+    /**
     * Headers for this part
+    *
     * @var array
+    * @access private
     */
     var $_headers;
 
-   /**
+    /**
     * The body of this part (not encoded)
+    *
     * @var string
+    * @access private
     */
     var $_body;
 
     /**
-     * Constructor.
-     *
-     * Sets up the object.
-     *
-     * @param $body   - The body of the mime part if any.
-     * @param $params - An associative array of parameters:
-     *                  content_type - The content type for this part eg multipart/mixed
-     *                  encoding     - The encoding to use, 7bit, 8bit, base64, or quoted-printable
-     *                  cid          - Content ID to apply
-     *                  disposition  - Content disposition, inline or attachment
-     *                  dfilename    - Optional filename parameter for content disposition
-     *                  description  - Content description
-     *                  charset      - Character set to use
-     * @access public
-     */
+    * The location of file with body of this part (not encoded)
+    *
+    * @var string
+    * @access private
+    */
+    var $_body_file;
+
+    /**
+    * The end-of-line sequence
+    *
+    * @var string
+    * @access private
+    */
+    var $_eol = "\r\n";
+
+
+    /**
+    * Constructor.
+    *
+    * Sets up the object.
+    *
+    * @param string $body   The body of the mime part if any.
+    * @param array  $params An associative array of optional parameters:
+    *     content_type      - The content type for this part eg multipart/mixed
+    *     encoding          - The encoding to use, 7bit, 8bit,
+    *                         base64, or quoted-printable
+    *     charset           - Content character set
+    *     cid               - Content ID to apply
+    *     disposition       - Content disposition, inline or attachment
+    *     filename          - Filename parameter for content disposition
+    *     description       - Content description
+    *     name_encoding     - Encoding of the attachment name (Content-Type)
+    *                         By default filenames are encoded using RFC2231
+    *                         Here you can set RFC2047 encoding (quoted-printable
+    *                         or base64) instead
+    *     filename_encoding - Encoding of the attachment filename (Content-Disposition)
+    *                         See 'name_encoding'
+    *     headers_charset   - Charset of the headers e.g. filename, description.
+    *                         If not set, 'charset' will be used
+    *     eol               - End of line sequence. Default: "\r\n"
+    *     headers           - Hash array with additional part headers. Array keys can be
+    *                         in form of <header_name>:<parameter_name>
+    *     body_file         - Location of file with part's body (instead of $body)
+    *
+    * @access public
+    */
     function Mail_mimePart($body = '', $params = array())
     {
-        if (!defined('MAIL_MIMEPART_CRLF')) {
-            define('MAIL_MIMEPART_CRLF', defined('MAIL_MIME_CRLF') ? MAIL_MIME_CRLF : "\r\n", TRUE);
+        if (!empty($params['eol'])) {
+            $this->_eol = $params['eol'];
+        } else if (defined('MAIL_MIMEPART_CRLF')) { // backward-copat.
+            $this->_eol = MAIL_MIMEPART_CRLF;
+        }
+
+        // Additional part headers
+        if (!empty($params['headers']) && is_array($params['headers'])) {
+            $headers = $params['headers'];
         }
 
         foreach ($params as $key => $value) {
             switch ($key) {
-                case 'content_type':
-                    $headers['Content-Type'] = $value . (isset($charset) ? '; charset="' . $charset . '"' : '');
-                    break;
-
-                case 'encoding':
-                    $this->_encoding = $value;
-                    $headers['Content-Transfer-Encoding'] = $value;
-                    break;
-
-                case 'cid':
-                    $headers['Content-ID'] = '<' . $value . '>';
-                    break;
-
-                case 'disposition':
-                    $headers['Content-Disposition'] = $value . (isset($dfilename) ? '; filename="' . $dfilename . '"' : '');
-                    break;
-
-                case 'dfilename':
-                    if (isset($headers['Content-Disposition'])) {
-                        $headers['Content-Disposition'] .= '; filename="' . $value . '"';
-                    } else {
-                        $dfilename = $value;
-                    }
-                    break;
+            case 'encoding':
+                $this->_encoding = $value;
+                $headers['Content-Transfer-Encoding'] = $value;
+                break;
 
-                case 'description':
-                    $headers['Content-Description'] = $value;
-                    break;
+            case 'cid':
+                $headers['Content-ID'] = '<' . $value . '>';
+                break;
 
-                case 'charset':
-                    if (isset($headers['Content-Type'])) {
-                        $headers['Content-Type'] .= '; charset="' . $value . '"';
-                    } else {
-                        $charset = $value;
-                    }
-                    break;
+            case 'location':
+                $headers['Content-Location'] = $value;
+                break;
+
+            case 'body_file':
+                $this->_body_file = $value;
+                break;
+
+            // for backward compatibility
+            case 'dfilename':
+                $params['filename'] = $value;
+                break;
             }
         }
 
         // Default content-type
-        if (!isset($headers['Content-Type'])) {
-            $headers['Content-Type'] = 'text/plain';
+        if (empty($params['content_type'])) {
+            $params['content_type'] = 'text/plain';
         }
 
-        //Default encoding
+        // Content-Type
+        $headers['Content-Type'] = $params['content_type'];
+        if (!empty($params['charset'])) {
+            $charset = "charset={$params['charset']}";
+            // place charset parameter in the same line, if possible
+            if ((strlen($headers['Content-Type']) + strlen($charset) + 16) <= 76) {
+                $headers['Content-Type'] .= '; ';
+            } else {
+                $headers['Content-Type'] .= ';' . $this->_eol . ' ';
+            }
+            $headers['Content-Type'] .= $charset;
+
+            // Default headers charset
+            if (!isset($params['headers_charset'])) {
+                $params['headers_charset'] = $params['charset'];
+            }
+        }
+
+        // header values encoding parameters
+        $h_charset  = !empty($params['headers_charset']) ? $params['headers_charset'] : 'US-ASCII';
+        $h_language = !empty($params['language']) ? $params['language'] : null;
+        $h_encoding = !empty($params['name_encoding']) ? $params['name_encoding'] : null;
+
+
+        if (!empty($params['filename'])) {
+            $headers['Content-Type'] .= ';' . $this->_eol;
+            $headers['Content-Type'] .= $this->_buildHeaderParam(
+                'name', $params['filename'], $h_charset, $h_language, $h_encoding
+            );
+        }
+
+        // Content-Disposition
+        if (!empty($params['disposition'])) {
+            $headers['Content-Disposition'] = $params['disposition'];
+            if (!empty($params['filename'])) {
+                $headers['Content-Disposition'] .= ';' . $this->_eol;
+                $headers['Content-Disposition'] .= $this->_buildHeaderParam(
+                    'filename', $params['filename'], $h_charset, $h_language,
+                    !empty($params['filename_encoding']) ? $params['filename_encoding'] : null
+                );
+            }
+
+            // add attachment size
+            $size = $this->_body_file ? filesize($this->_body_file) : strlen($body);
+            if ($size) {
+                $headers['Content-Disposition'] .= ';' . $this->_eol . ' size=' . $size;
+            }
+        }
+
+        if (!empty($params['description'])) {
+            $headers['Content-Description'] = $this->encodeHeader(
+                'Content-Description', $params['description'], $h_charset, $h_encoding,
+                $this->_eol
+            );
+        }
+
+        // Search and add existing headers' parameters
+        foreach ($headers as $key => $value) {
+            $items = explode(':', $key);
+            if (count($items) == 2) {
+                $header = $items[0];
+                $param  = $items[1];
+                if (isset($headers[$header])) {
+                    $headers[$header] .= ';' . $this->_eol;
+                }
+                $headers[$header] .= $this->_buildHeaderParam(
+                    $param, $value, $h_charset, $h_language, $h_encoding
+                );
+                unset($headers[$key]);
+            }
+        }
+
+        // Default encoding
         if (!isset($this->_encoding)) {
             $this->_encoding = '7bit';
         }
@@ -202,41 +290,60 @@ class Mail_mimePart {
     }
 
     /**
-     * encode()
-     *
      * Encodes and returns the email. Also stores
      * it in the encoded member variable
      *
+     * @param string $boundary Pre-defined boundary string
+     *
      * @return An associative array containing two elements,
      *         body and headers. The headers element is itself
-     *         an indexed array.
+     *         an indexed array. On error returns PEAR error object.
      * @access public
      */
-    function encode()
+    function encode($boundary=null)
     {
         $encoded =& $this->_encoded;
 
-        if (!empty($this->_subparts)) {
-            srand((double)microtime()*1000000);
-            $boundary = '=_' . md5(rand() . microtime());
-            $this->_headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF . "\t" . 'boundary="' . $boundary . '"';
+        if (count($this->_subparts)) {
+            $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
+            $eol = $this->_eol;
+
+            $this->_headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
+
+            $encoded['body'] = ''; 
 
-            // Add body parts to $subparts
             for ($i = 0; $i < count($this->_subparts); $i++) {
-                $headers = array();
+                $encoded['body'] .= '--' . $boundary . $eol;
                 $tmp = $this->_subparts[$i]->encode();
+                if ($this->_isError($tmp)) {
+                    return $tmp;
+                }
                 foreach ($tmp['headers'] as $key => $value) {
-                    $headers[] = $key . ': ' . $value;
+                    $encoded['body'] .= $key . ': ' . $value . $eol;
                 }
-                $subparts[] = implode(MAIL_MIMEPART_CRLF, $headers) . MAIL_MIMEPART_CRLF . MAIL_MIMEPART_CRLF . $tmp['body'];
+                $encoded['body'] .= $eol . $tmp['body'] . $eol;
             }
 
-            $encoded['body'] = '--' . $boundary . MAIL_MIMEPART_CRLF .
-                               implode('--' . $boundary . MAIL_MIMEPART_CRLF, $subparts) .
-                               '--' . $boundary.'--' . MAIL_MIMEPART_CRLF;
+            $encoded['body'] .= '--' . $boundary . '--' . $eol;
+
+        } else if ($this->_body) {
+            $encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding);
+        } else if ($this->_body_file) {
+            // Temporarily reset magic_quotes_runtime for file reads and writes
+            if ($magic_quote_setting = get_magic_quotes_runtime()) {
+                @ini_set('magic_quotes_runtime', 0);
+            }
+            $body = $this->_getEncodedDataFromFile($this->_body_file, $this->_encoding);
+            if ($magic_quote_setting) {
+                @ini_set('magic_quotes_runtime', $magic_quote_setting);
+            }
 
+            if ($this->_isError($body)) {
+                return $body;
+            }
+            $encoded['body'] = $body;
         } else {
-            $encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding) . MAIL_MIMEPART_CRLF;
+            $encoded['body'] = '';
         }
 
         // Add headers to $encoded
@@ -246,105 +353,908 @@ class Mail_mimePart {
     }
 
     /**
-     * &addSubPart()
+     * Encodes and saves the email into file. File must exist.
+     * Data will be appended to the file.
      *
+     * @param string  $filename  Output file location
+     * @param string  $boundary  Pre-defined boundary string
+     * @param boolean $skip_head True if you don't want to save headers
+     *
+     * @return array An associative array containing message headers
+     *               or PEAR error object
+     * @access public
+     * @since 1.6.0
+     */
+    function encodeToFile($filename, $boundary=null, $skip_head=false)
+    {
+        if (file_exists($filename) && !is_writable($filename)) {
+            $err = $this->_raiseError('File is not writeable: ' . $filename);
+            return $err;
+        }
+
+        if (!($fh = fopen($filename, 'ab'))) {
+            $err = $this->_raiseError('Unable to open file: ' . $filename);
+            return $err;
+        }
+
+        // Temporarily reset magic_quotes_runtime for file reads and writes
+        if ($magic_quote_setting = get_magic_quotes_runtime()) {
+            @ini_set('magic_quotes_runtime', 0);
+        }
+
+        $res = $this->_encodePartToFile($fh, $boundary, $skip_head);
+
+        fclose($fh);
+
+        if ($magic_quote_setting) {
+            @ini_set('magic_quotes_runtime', $magic_quote_setting);
+        }
+
+        return $this->_isError($res) ? $res : $this->_headers;
+    }
+
+    /**
+     * Encodes given email part into file
+     *
+     * @param string  $fh        Output file handle
+     * @param string  $boundary  Pre-defined boundary string
+     * @param boolean $skip_head True if you don't want to save headers
+     *
+     * @return array True on sucess or PEAR error object
+     * @access private
+     */
+    function _encodePartToFile($fh, $boundary=null, $skip_head=false)
+    {
+        $eol = $this->_eol;
+
+        if (count($this->_subparts)) {
+            $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
+            $this->_headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
+        }
+
+        if (!$skip_head) {
+            foreach ($this->_headers as $key => $value) {
+                fwrite($fh, $key . ': ' . $value . $eol);
+            }
+            $f_eol = $eol;
+        } else {
+            $f_eol = '';
+        }
+
+        if (count($this->_subparts)) {
+            for ($i = 0; $i < count($this->_subparts); $i++) {
+                fwrite($fh, $f_eol . '--' . $boundary . $eol);
+                $res = $this->_subparts[$i]->_encodePartToFile($fh);
+                if ($this->_isError($res)) {
+                    return $res;
+                }
+                $f_eol = $eol;
+            }
+
+            fwrite($fh, $eol . '--' . $boundary . '--' . $eol);
+
+        } else if ($this->_body) {
+            fwrite($fh, $f_eol . $this->_getEncodedData($this->_body, $this->_encoding));
+        } else if ($this->_body_file) {
+            fwrite($fh, $f_eol);
+            $res = $this->_getEncodedDataFromFile(
+                $this->_body_file, $this->_encoding, $fh
+            );
+            if ($this->_isError($res)) {
+                return $res;
+            }
+        }
+
+        return true;
+    }
+
+    /**
      * Adds a subpart to current mime part and returns
      * a reference to it
      *
-     * @param $body   The body of the subpart, if any.
-     * @param $params The parameters for the subpart, same
-     *                as the $params argument for constructor.
-     * @return A reference to the part you just added. It is
-     *         crucial if using multipart/* in your subparts that
-     *         you use =& in your script when calling this function,
-     *         otherwise you will not be able to add further subparts.
+     * @param string $body   The body of the subpart, if any.
+     * @param array  $params The parameters for the subpart, same
+     *                       as the $params argument for constructor.
+     *
+     * @return Mail_mimePart A reference to the part you just added. In PHP4, it is
+     *                       crucial if using multipart/* in your subparts that
+     *                       you use =& in your script when calling this function,
+     *                       otherwise you will not be able to add further subparts.
      * @access public
      */
-    function &addSubPart($body, $params)
+    function &addSubpart($body, $params)
     {
-        $this->_subparts[] = new Mail_mimePart($body, $params);
-        return $this->_subparts[count($this->_subparts) - 1];
+        $this->_subparts[] = $part = new Mail_mimePart($body, $params);
+        return $part;
     }
 
     /**
-     * _getEncodedData()
-     *
      * Returns encoded data based upon encoding passed to it
      *
-     * @param $data     The data to encode.
-     * @param $encoding The encoding type to use, 7bit, base64,
-     *                  or quoted-printable.
+     * @param string $data     The data to encode.
+     * @param string $encoding The encoding type to use, 7bit, base64,
+     *                         or quoted-printable.
+     *
+     * @return string
      * @access private
      */
     function _getEncodedData($data, $encoding)
     {
         switch ($encoding) {
-            case '8bit':
-            case '7bit':
-                return $data;
-                break;
-
-            case 'quoted-printable':
-                return $this->_quotedPrintableEncode($data);
-                break;
+        case 'quoted-printable':
+            return $this->_quotedPrintableEncode($data);
+            break;
 
-            case 'base64':
-                return rtrim(chunk_split(base64_encode($data), 76, MAIL_MIMEPART_CRLF));
-                break;
+        case 'base64':
+            return rtrim(chunk_split(base64_encode($data), 76, $this->_eol));
+            break;
 
-            default:
-                return $data;
+        case '8bit':
+        case '7bit':
+        default:
+            return $data;
         }
     }
 
     /**
-     * quoteadPrintableEncode()
+     * Returns encoded data based upon encoding passed to it
+     *
+     * @param string   $filename Data file location
+     * @param string   $encoding The encoding type to use, 7bit, base64,
+     *                           or quoted-printable.
+     * @param resource $fh       Output file handle. If set, data will be
+     *                           stored into it instead of returning it
      *
+     * @return string Encoded data or PEAR error object
+     * @access private
+     */
+    function _getEncodedDataFromFile($filename, $encoding, $fh=null)
+    {
+        if (!is_readable($filename)) {
+            $err = $this->_raiseError('Unable to read file: ' . $filename);
+            return $err;
+        }
+
+        if (!($fd = fopen($filename, 'rb'))) {
+            $err = $this->_raiseError('Could not open file: ' . $filename);
+            return $err;
+        }
+
+        $data = '';
+
+        switch ($encoding) {
+        case 'quoted-printable':
+            while (!feof($fd)) {
+                $buffer = $this->_quotedPrintableEncode(fgets($fd));
+                if ($fh) {
+                    fwrite($fh, $buffer);
+                } else {
+                    $data .= $buffer;
+                }
+            }
+            break;
+
+        case 'base64':
+            while (!feof($fd)) {
+                // Should read in a multiple of 57 bytes so that
+                // the output is 76 bytes per line. Don't use big chunks
+                // because base64 encoding is memory expensive
+                $buffer = fread($fd, 57 * 9198); // ca. 0.5 MB
+                $buffer = base64_encode($buffer);
+                $buffer = chunk_split($buffer, 76, $this->_eol);
+                if (feof($fd)) {
+                    $buffer = rtrim($buffer);
+                }
+
+                if ($fh) {
+                    fwrite($fh, $buffer);
+                } else {
+                    $data .= $buffer;
+                }
+            }
+            break;
+
+        case '8bit':
+        case '7bit':
+        default:
+            while (!feof($fd)) {
+                $buffer = fread($fd, 1048576); // 1 MB
+                if ($fh) {
+                    fwrite($fh, $buffer);
+                } else {
+                    $data .= $buffer;
+                }
+            }
+        }
+
+        fclose($fd);
+
+        if (!$fh) {
+            return $data;
+        }
+    }
+
+    /**
      * Encodes data to quoted-printable standard.
      *
-     * @param $input    The data to encode
-     * @param $line_max Optional max line length. Should
-     *                  not be more than 76 chars
+     * @param string $input    The data to encode
+     * @param int    $line_max Optional max line length. Should
+     *                         not be more than 76 chars
+     *
+     * @return string Encoded data
      *
      * @access private
      */
     function _quotedPrintableEncode($input , $line_max = 76)
     {
+        $eol = $this->_eol;
+        /*
+        // imap_8bit() is extremely fast, but doesn't handle properly some characters
+        if (function_exists('imap_8bit') && $line_max == 76) {
+            $input = preg_replace('/\r?\n/', "\r\n", $input);
+            $input = imap_8bit($input);
+            if ($eol != "\r\n") {
+                $input = str_replace("\r\n", $eol, $input);
+            }
+            return $input;
+        }
+        */
         $lines  = preg_split("/\r?\n/", $input);
-        $eol    = MAIL_MIMEPART_CRLF;
         $escape = '=';
         $output = '';
 
-        while(list(, $line) = each($lines)){
-
-            $linlen     = strlen($line);
+        while (list($idx, $line) = each($lines)) {
             $newline = '';
+            $i = 0;
 
-            for ($i = 0; $i < $linlen; $i++) {
-                $char = substr($line, $i, 1);
+            while (isset($line[$i])) {
+                $char = $line[$i];
                 $dec  = ord($char);
+                $i++;
 
-                if (($dec == 32) AND ($i == ($linlen - 1))){    // convert space at eol only
+                if (($dec == 32) && (!isset($line[$i]))) {
+                    // convert space at eol only
                     $char = '=20';
-
-                } elseif(($dec == 9) AND ($i == ($linlen - 1))) {  // convert tab at eol only
-                    $char = '=09';
-                } elseif($dec == 9) {
-                    ; // Do nothing if a tab.
-                } elseif(($dec == 61) OR ($dec < 32 ) OR ($dec > 126)) {
-                    $char = $escape . strtoupper(sprintf('%02s', dechex($dec)));
+                } elseif ($dec == 9 && isset($line[$i])) {
+                    ; // Do nothing if a TAB is not on eol
+                } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) {
+                    $char = $escape . sprintf('%02X', $dec);
+                } elseif (($dec == 46) && (($newline == '')
+                    || ((strlen($newline) + strlen("=2E")) >= $line_max))
+                ) {
+                    // Bug #9722: convert full-stop at bol,
+                    // some Windows servers need this, won't break anything (cipri)
+                    // Bug #11731: full-stop at bol also needs to be encoded
+                    // if this line would push us over the line_max limit.
+                    $char = '=2E';
                 }
 
-                if ((strlen($newline) + strlen($char)) >= $line_max) {        // MAIL_MIMEPART_CRLF is not counted
-                    $output  .= $newline . $escape . $eol;                    // soft line break; " =\r\n" is okay
+                // Note, when changing this line, also change the ($dec == 46)
+                // check line, as it mimics this line due to Bug #11731
+                // EOL is not counted
+                if ((strlen($newline) + strlen($char)) >= $line_max) {
+                    // soft line break; " =\r\n" is okay
+                    $output  .= $newline . $escape . $eol;
                     $newline  = '';
                 }
                 $newline .= $char;
             } // end of for
             $output .= $newline . $eol;
+            unset($lines[$idx]);
         }
-        $output = substr($output, 0, -1 * strlen($eol)); // Don't want last crlf
+        // Don't want last crlf
+        $output = substr($output, 0, -1 * strlen($eol));
         return $output;
     }
+
+    /**
+     * Encodes the parameter of a header.
+     *
+     * @param string $name      The name of the header-parameter
+     * @param string $value     The value of the paramter
+     * @param string $charset   The characterset of $value
+     * @param string $language  The language used in $value
+     * @param string $encoding  Parameter encoding. If not set, parameter value
+     *                          is encoded according to RFC2231
+     * @param int    $maxLength The maximum length of a line. Defauls to 75
+     *
+     * @return string
+     *
+     * @access private
+     */
+    function _buildHeaderParam($name, $value, $charset=null, $language=null,
+        $encoding=null, $maxLength=75
+    ) {
+        // RFC 2045:
+        // value needs encoding if contains non-ASCII chars or is longer than 78 chars
+        if (!preg_match('#[^\x20-\x7E]#', $value)) {
+            $token_regexp = '#([^\x21\x23-\x27\x2A\x2B\x2D'
+                . '\x2E\x30-\x39\x41-\x5A\x5E-\x7E])#';
+            if (!preg_match($token_regexp, $value)) {
+                // token
+                if (strlen($name) + strlen($value) + 3 <= $maxLength) {
+                    return " {$name}={$value}";
+                }
+            } else {
+                // quoted-string
+                $quoted = addcslashes($value, '\\"');
+                if (strlen($name) + strlen($quoted) + 5 <= $maxLength) {
+                    return " {$name}=\"{$quoted}\"";
+                }
+            }
+        }
+
+        // RFC2047: use quoted-printable/base64 encoding
+        if ($encoding == 'quoted-printable' || $encoding == 'base64') {
+            return $this->_buildRFC2047Param($name, $value, $charset, $encoding);
+        }
+
+        // RFC2231:
+        $encValue = preg_replace_callback(
+            '/([^\x21\x23\x24\x26\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7E])/',
+            array($this, '_encodeReplaceCallback'), $value
+        );
+        $value = "$charset'$language'$encValue";
+
+        $header = " {$name}*={$value}";
+        if (strlen($header) <= $maxLength) {
+            return $header;
+        }
+
+        $preLength = strlen(" {$name}*0*=");
+        $maxLength = max(16, $maxLength - $preLength - 3);
+        $maxLengthReg = "|(.{0,$maxLength}[^\%][^\%])|";
+
+        $headers = array();
+        $headCount = 0;
+        while ($value) {
+            $matches = array();
+            $found = preg_match($maxLengthReg, $value, $matches);
+            if ($found) {
+                $headers[] = " {$name}*{$headCount}*={$matches[0]}";
+                $value = substr($value, strlen($matches[0]));
+            } else {
+                $headers[] = " {$name}*{$headCount}*={$value}";
+                $value = '';
+            }
+            $headCount++;
+        }
+
+        $headers = implode(';' . $this->_eol, $headers);
+        return $headers;
+    }
+
+    /**
+     * Encodes header parameter as per RFC2047 if needed
+     *
+     * @param string $name      The parameter name
+     * @param string $value     The parameter value
+     * @param string $charset   The parameter charset
+     * @param string $encoding  Encoding type (quoted-printable or base64)
+     * @param int    $maxLength Encoded parameter max length. Default: 76
+     *
+     * @return string Parameter line
+     * @access private
+     */
+    function _buildRFC2047Param($name, $value, $charset,
+        $encoding='quoted-printable', $maxLength=76
+    ) {
+        // WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in
+        // parameter of a MIME Content-Type or Content-Disposition field",
+        // but... it's supported by many clients/servers
+        $quoted = '';
+
+        if ($encoding == 'base64') {
+            $value = base64_encode($value);
+            $prefix = '=?' . $charset . '?B?';
+            $suffix = '?=';
+
+            // 2 x SPACE, 2 x '"', '=', ';'
+            $add_len = strlen($prefix . $suffix) + strlen($name) + 6;
+            $len = $add_len + strlen($value);
+
+            while ($len > $maxLength) { 
+                // We can cut base64-encoded string every 4 characters
+                $real_len = floor(($maxLength - $add_len) / 4) * 4;
+                $_quote = substr($value, 0, $real_len);
+                $value = substr($value, $real_len);
+
+                $quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
+                $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
+                $len = strlen($value) + $add_len;
+            }
+            $quoted .= $prefix . $value . $suffix;
+
+        } else {
+            // quoted-printable
+            $value = $this->encodeQP($value);
+            $prefix = '=?' . $charset . '?Q?';
+            $suffix = '?=';
+
+            // 2 x SPACE, 2 x '"', '=', ';'
+            $add_len = strlen($prefix . $suffix) + strlen($name) + 6;
+            $len = $add_len + strlen($value);
+
+            while ($len > $maxLength) {
+                $length = $maxLength - $add_len;
+                // don't break any encoded letters
+                if (preg_match("/^(.{0,$length}[^\=][^\=])/", $value, $matches)) {
+                    $_quote = $matches[1];
+                }
+
+                $quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
+                $value = substr($value, strlen($_quote));
+                $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
+                $len = strlen($value) + $add_len;
+            }
+
+            $quoted .= $prefix . $value . $suffix;
+        }
+
+        return " {$name}=\"{$quoted}\"";
+    }
+
+    /**
+     * Encodes a header as per RFC2047
+     *
+     * @param string $name     The header name
+     * @param string $value    The header data to encode
+     * @param string $charset  Character set name
+     * @param string $encoding Encoding name (base64 or quoted-printable)
+     * @param string $eol      End-of-line sequence. Default: "\r\n"
+     *
+     * @return string          Encoded header data (without a name)
+     * @access public
+     * @since 1.6.1
+     */
+    function encodeHeader($name, $value, $charset='ISO-8859-1',
+        $encoding='quoted-printable', $eol="\r\n"
+    ) {
+        // Structured headers
+        $comma_headers = array(
+            'from', 'to', 'cc', 'bcc', 'sender', 'reply-to',
+            'resent-from', 'resent-to', 'resent-cc', 'resent-bcc',
+            'resent-sender', 'resent-reply-to',
+            'mail-reply-to', 'mail-followup-to',
+            'return-receipt-to', 'disposition-notification-to',
+        );
+        $other_headers = array(
+            'references', 'in-reply-to', 'message-id', 'resent-message-id',
+        );
+
+        $name = strtolower($name);
+
+        if (in_array($name, $comma_headers)) {
+            $separator = ',';
+        } else if (in_array($name, $other_headers)) {
+            $separator = ' ';
+        }
+
+        if (!$charset) {
+            $charset = 'ISO-8859-1';
+        }
+
+        // Structured header (make sure addr-spec inside is not encoded)
+        if (!empty($separator)) {
+            // Simple e-mail address regexp
+            $email_regexp = '([^\s<]+|("[^\r\n"]+"))@\S+';
+
+            $parts = Mail_mimePart::_explodeQuotedString("[\t$separator]", $value);
+            $value = '';
+
+            foreach ($parts as $part) {
+                $part = preg_replace('/\r?\n[\s\t]*/', $eol . ' ', $part);
+                $part = trim($part);
+
+                if (!$part) {
+                    continue;
+                }
+                if ($value) {
+                    $value .= $separator == ',' ? $separator . ' ' : ' ';
+                } else {
+                    $value = $name . ': ';
+                }
+
+                // let's find phrase (name) and/or addr-spec
+                if (preg_match('/^<' . $email_regexp . '>$/', $part)) {
+                    $value .= $part;
+                } else if (preg_match('/^' . $email_regexp . '$/', $part)) {
+                    // address without brackets and without name
+                    $value .= $part;
+                } else if (preg_match('/<*' . $email_regexp . '>*$/', $part, $matches)) {
+                    // address with name (handle name)
+                    $address = $matches[0];
+                    $word = str_replace($address, '', $part);
+                    $word = trim($word);
+                    // check if phrase requires quoting
+                    if ($word) {
+                        // non-ASCII: require encoding
+                        if (preg_match('#([^\s\x21-\x7E]){1}#', $word)) {
+                            if ($word[0] == '"' && $word[strlen($word)-1] == '"') {
+                                // de-quote quoted-string, encoding changes
+                                // string to atom
+                                $search = array("\\\"", "\\\\");
+                                $replace = array("\"", "\\");
+                                $word = str_replace($search, $replace, $word);
+                                $word = substr($word, 1, -1);
+                            }
+                            // find length of last line
+                            if (($pos = strrpos($value, $eol)) !== false) {
+                                $last_len = strlen($value) - $pos;
+                            } else {
+                                $last_len = strlen($value);
+                            }
+                            $word = Mail_mimePart::encodeHeaderValue(
+                                $word, $charset, $encoding, $last_len, $eol
+                            );
+                        } else if (($word[0] != '"' || $word[strlen($word)-1] != '"')
+                            && preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $word)
+                        ) {
+                            // ASCII: quote string if needed
+                            $word = '"'.addcslashes($word, '\\"').'"';
+                        }
+                    }
+                    $value .= $word.' '.$address;
+                } else {
+                    // addr-spec not found, don't encode (?)
+                    $value .= $part;
+                }
+
+                // RFC2822 recommends 78 characters limit, use 76 from RFC2047
+                $value = wordwrap($value, 76, $eol . ' ');
+            }
+
+            // remove header name prefix (there could be EOL too)
+            $value = preg_replace(
+                '/^'.$name.':('.preg_quote($eol, '/').')* /', '', $value
+            );
+        } else {
+            // Unstructured header
+            // non-ASCII: require encoding
+            if (preg_match('#([^\s\x21-\x7E]){1}#', $value)) {
+                if ($value[0] == '"' && $value[strlen($value)-1] == '"') {
+                    // de-quote quoted-string, encoding changes
+                    // string to atom
+                    $search = array("\\\"", "\\\\");
+                    $replace = array("\"", "\\");
+                    $value = str_replace($search, $replace, $value);
+                    $value = substr($value, 1, -1);
+                }
+                $value = Mail_mimePart::encodeHeaderValue(
+                    $value, $charset, $encoding, strlen($name) + 2, $eol
+                );
+            } else if (strlen($name.': '.$value) > 78) {
+                // ASCII: check if header line isn't too long and use folding
+                $value = preg_replace('/\r?\n[\s\t]*/', $eol . ' ', $value);
+                $tmp = wordwrap($name.': '.$value, 78, $eol . ' ');
+                $value = preg_replace('/^'.$name.':\s*/', '', $tmp);
+                // hard limit 998 (RFC2822)
+                $value = wordwrap($value, 998, $eol . ' ', true);
+            }
+        }
+
+        return $value;
+    }
+
+    /**
+     * Explode quoted string
+     *
+     * @param string $delimiter Delimiter expression string for preg_match()
+     * @param string $string    Input string
+     *
+     * @return array            String tokens array
+     * @access private
+     */
+    function _explodeQuotedString($delimiter, $string)
+    {
+        $result = array();
+        $strlen = strlen($string);
+
+        for ($q=$p=$i=0; $i < $strlen; $i++) {
+            if ($string[$i] == "\""
+                && (empty($string[$i-1]) || $string[$i-1] != "\\")
+            ) {
+                $q = $q ? false : true;
+            } else if (!$q && preg_match("/$delimiter/", $string[$i])) {
+                $result[] = substr($string, $p, $i - $p);
+                $p = $i + 1;
+            }
+        }
+
+        $result[] = substr($string, $p);
+        return $result;
+    }
+
+    /**
+     * Encodes a header value as per RFC2047
+     *
+     * @param string $value      The header data to encode
+     * @param string $charset    Character set name
+     * @param string $encoding   Encoding name (base64 or quoted-printable)
+     * @param int    $prefix_len Prefix length. Default: 0
+     * @param string $eol        End-of-line sequence. Default: "\r\n"
+     *
+     * @return string            Encoded header data
+     * @access public
+     * @since 1.6.1
+     */
+    function encodeHeaderValue($value, $charset, $encoding, $prefix_len=0, $eol="\r\n")
+    {
+        // #17311: Use multibyte aware method (requires mbstring extension)
+        if ($result = Mail_mimePart::encodeMB($value, $charset, $encoding, $prefix_len, $eol)) {
+            return $result;
+        }
+
+        // Generate the header using the specified params and dynamicly
+        // determine the maximum length of such strings.
+        // 75 is the value specified in the RFC.
+        $encoding = $encoding == 'base64' ? 'B' : 'Q';
+        $prefix = '=?' . $charset . '?' . $encoding .'?';
+        $suffix = '?=';
+        $maxLength = 75 - strlen($prefix . $suffix);
+        $maxLength1stLine = $maxLength - $prefix_len;
+
+        if ($encoding == 'B') {
+            // Base64 encode the entire string
+            $value = base64_encode($value);
+
+            // We can cut base64 every 4 characters, so the real max
+            // we can get must be rounded down.
+            $maxLength = $maxLength - ($maxLength % 4);
+            $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4);
+
+            $cutpoint = $maxLength1stLine;
+            $output = '';
+
+            while ($value) {
+                // Split translated string at every $maxLength
+                $part = substr($value, 0, $cutpoint);
+                $value = substr($value, $cutpoint);
+                $cutpoint = $maxLength;
+                // RFC 2047 specifies that any split header should
+                // be separated by a CRLF SPACE.
+                if ($output) {
+                    $output .= $eol . ' ';
+                }
+                $output .= $prefix . $part . $suffix;
+            }
+            $value = $output;
+        } else {
+            // quoted-printable encoding has been selected
+            $value = Mail_mimePart::encodeQP($value);
+
+            // This regexp will break QP-encoded text at every $maxLength
+            // but will not break any encoded letters.
+            $reg1st = "|(.{0,$maxLength1stLine}[^\=][^\=])|";
+            $reg2nd = "|(.{0,$maxLength}[^\=][^\=])|";
+
+            if (strlen($value) > $maxLength1stLine) {
+                // Begin with the regexp for the first line.
+                $reg = $reg1st;
+                $output = '';
+                while ($value) {
+                    // Split translated string at every $maxLength
+                    // But make sure not to break any translated chars.
+                    $found = preg_match($reg, $value, $matches);
+
+                    // After this first line, we need to use a different
+                    // regexp for the first line.
+                    $reg = $reg2nd;
+
+                    // Save the found part and encapsulate it in the
+                    // prefix & suffix. Then remove the part from the
+                    // $value_out variable.
+                    if ($found) {
+                        $part = $matches[0];
+                        $len = strlen($matches[0]);
+                        $value = substr($value, $len);
+                    } else {
+                        $part = $value;
+                        $value = '';
+                    }
+
+                    // RFC 2047 specifies that any split header should
+                    // be separated by a CRLF SPACE
+                    if ($output) {
+                        $output .= $eol . ' ';
+                    }
+                    $output .= $prefix . $part . $suffix;
+                }
+                $value = $output;
+            } else {
+                $value = $prefix . $value . $suffix;
+            }
+        }
+
+        return $value;
+    }
+
+    /**
+     * Encodes the given string using quoted-printable
+     *
+     * @param string $str String to encode
+     *
+     * @return string     Encoded string
+     * @access public
+     * @since 1.6.0
+     */
+    function encodeQP($str)
+    {
+        // Bug #17226 RFC 2047 restricts some characters
+        // if the word is inside a phrase, permitted chars are only:
+        // ASCII letters, decimal digits, "!", "*", "+", "-", "/", "=", and "_"
+
+        // "=",  "_",  "?" must be encoded
+        $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
+        $str = preg_replace_callback(
+            $regexp, array('Mail_mimePart', '_qpReplaceCallback'), $str
+        );
+
+        return str_replace(' ', '_', $str);
+    }
+
+    /**
+     * Encodes the given string using base64 or quoted-printable.
+     * This method makes sure that encoded-word represents an integral
+     * number of characters as per RFC2047.
+     *
+     * @param string $str        String to encode
+     * @param string $charset    Character set name
+     * @param string $encoding   Encoding name (base64 or quoted-printable)
+     * @param int    $prefix_len Prefix length. Default: 0
+     * @param string $eol        End-of-line sequence. Default: "\r\n"
+     *
+     * @return string     Encoded string
+     * @access public
+     * @since 1.8.0
+     */
+    function encodeMB($str, $charset, $encoding, $prefix_len=0, $eol="\r\n")
+    {
+        if (!function_exists('mb_substr') || !function_exists('mb_strlen')) {
+            return;
+        }
+
+        $encoding = $encoding == 'base64' ? 'B' : 'Q';
+        // 75 is the value specified in the RFC
+        $prefix = '=?' . $charset . '?'.$encoding.'?';
+        $suffix = '?=';
+        $maxLength = 75 - strlen($prefix . $suffix);
+
+        // A multi-octet character may not be split across adjacent encoded-words
+        // So, we'll loop over each character
+        // mb_stlen() with wrong charset will generate a warning here and return null
+        $length      = mb_strlen($str, $charset);
+        $result      = '';
+        $line_length = $prefix_len;
+
+        if ($encoding == 'B') {
+            // base64
+            $start = 0;
+            $prev  = '';
+
+            for ($i=1; $i<=$length; $i++) {
+                // See #17311
+                $chunk = mb_substr($str, $start, $i-$start, $charset);
+                $chunk = base64_encode($chunk);
+                $chunk_len = strlen($chunk);
+
+                if ($line_length + $chunk_len == $maxLength || $i == $length) {
+                    if ($result) {
+                        $result .= "\n";
+                    }
+                    $result .= $chunk;
+                    $line_length = 0;
+                    $start = $i;
+                } else if ($line_length + $chunk_len > $maxLength) {
+                    if ($result) {
+                        $result .= "\n";
+                    }
+                    if ($prev) {
+                        $result .= $prev;
+                    }
+                    $line_length = 0;
+                    $start = $i - 1;
+                } else {
+                    $prev = $chunk;
+                }
+            }
+        } else {
+            // quoted-printable
+            // see encodeQP()
+            $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
+
+            for ($i=0; $i<=$length; $i++) {
+                $char = mb_substr($str, $i, 1, $charset);
+                // RFC recommends underline (instead of =20) in place of the space
+                // that's one of the reasons why we're not using iconv_mime_encode()
+                if ($char == ' ') {
+                    $char = '_';
+                    $char_len = 1;
+                } else {
+                    $char = preg_replace_callback(
+                        $regexp, array('Mail_mimePart', '_qpReplaceCallback'), $char
+                    );
+                    $char_len = strlen($char);
+                }
+
+                if ($line_length + $char_len > $maxLength) {
+                    if ($result) {
+                        $result .= "\n";
+                    }
+                    $line_length = 0;
+                }
+
+                $result      .= $char;
+                $line_length += $char_len;
+            }
+        }
+
+        if ($result) {
+            $result = $prefix
+                .str_replace("\n", $suffix.$eol.' '.$prefix, $result).$suffix;
+        }
+
+        return $result;
+    }
+
+    /**
+     * Callback function to replace extended characters (\x80-xFF) with their
+     * ASCII values (RFC2047: quoted-printable)
+     *
+     * @param array $matches Preg_replace's matches array
+     *
+     * @return string        Encoded character string
+     * @access private
+     */
+    function _qpReplaceCallback($matches)
+    {
+        return sprintf('=%02X', ord($matches[1]));
+    }
+
+    /**
+     * Callback function to replace extended characters (\x80-xFF) with their
+     * ASCII values (RFC2231)
+     *
+     * @param array $matches Preg_replace's matches array
+     *
+     * @return string        Encoded character string
+     * @access private
+     */
+    function _encodeReplaceCallback($matches)
+    {
+        return sprintf('%%%02X', ord($matches[1]));
+    }
+
+    /**
+     * PEAR::isError implementation
+     *
+     * @param mixed $data Object
+     *
+     * @return bool True if object is an instance of PEAR_Error
+     * @access private
+     */
+    function _isError($data)
+    {
+        // PEAR::isError() is not PHP 5.4 compatible (see Bug #19473)
+        if (is_object($data) && is_a($data, 'PEAR_Error')) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * PEAR::raiseError implementation
+     *
+     * @param $message A text error message
+     *
+     * @return PEAR_Error Instance of PEAR_Error
+     * @access private
+     */
+    function _raiseError($message)
+    {
+        // PEAR::raiseError() is not PHP 5.4 compatible
+        return new PEAR_Error($message);
+    }
+
 } // End of class
-?>

+ 0 - 58
htdocs/includes/nusoap/lib/Mail/null.php

@@ -1,58 +0,0 @@
-<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4                                                        |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2003 The PHP Group                                |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license,      |
-// | that is bundled with this package in the file LICENSE, and is        |
-// | available at through the world-wide-web at                           |
-// | http://www.php.net/license/2_02.txt.                                 |
-// | If you did not receive a copy of the PHP license and are unable to   |
-// | obtain it through the world-wide-web, please send a note to          |
-// | license@php.net so we can mail you a copy immediately.               |
-// +----------------------------------------------------------------------+
-// | Author: Phil Kernick <philk@rotfl.com.au>                            |
-// +----------------------------------------------------------------------+
-//
-//
-
-/**
- * Null implementation of the PEAR Mail:: interface.
- * @access public
- * @package Mail
- */
-class Mail_null extends Mail {
-
-    /**
-     * Implements Mail_null::send() function. Silently discards all
-     * mail.
-     *
-     * @param mixed $recipients Either a comma-seperated list of recipients
-     *              (RFC822 compliant), or an array of recipients,
-     *              each RFC822 valid. This may contain recipients not
-     *              specified in the headers, for Bcc:, resending
-     *              messages, etc.
-     *
-     * @param array $headers The array of headers to send with the mail, in an
-     *              associative array, where the array key is the
-     *              header name (ie, 'Subject'), and the array value
-     *              is the header value (ie, 'test'). The header
-     *              produced from those values would be 'Subject:
-     *              test'.
-     *
-     * @param string $body The full text of the message body, including any
-     *               Mime parts, etc.
-     *
-     * @return mixed Returns true on success, or a PEAR_Error
-     *               containing a descriptive error message on
-     *               failure.
-     * @access public
-     */
-    function send($recipients, $headers, $body)
-    {
-        return true;
-    }
-
-}

+ 0 - 144
htdocs/includes/nusoap/lib/Mail/sendmail.php

@@ -1,144 +0,0 @@
-<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4                                                        |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2003 The PHP Group                                |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license,      |
-// | that is bundled with this package in the file LICENSE, and is        |
-// | available at through the world-wide-web at                           |
-// | http://www.php.net/license/2_02.txt.                                 |
-// | If you did not receive a copy of the PHP license and are unable to   |
-// | obtain it through the world-wide-web, please send a note to          |
-// | license@php.net so we can mail you a copy immediately.               |
-// +----------------------------------------------------------------------+
-// | Author: Chuck Hagenbuch <chuck@horde.org>                            |
-// +----------------------------------------------------------------------+
-
-/**
- * Sendmail implementation of the PEAR Mail:: interface.
- * @access public
- * @package Mail
- */
-class Mail_sendmail extends Mail {
-
-	/**
-     * The location of the sendmail or sendmail wrapper binary on the
-     * filesystem.
-     * @var string
-     */
-    var $sendmail_path = '/usr/sbin/sendmail';
-
-	/**
-     * Any extra command-line parameters to pass to the sendmail or
-     * sendmail wrapper binary.
-     * @var string
-     */
-    var $sendmail_args = '';
-
-	/**
-     * Constructor.
-     *
-     * Instantiates a new Mail_sendmail:: object based on the parameters
-     * passed in. It looks for the following parameters:
-     *     sendmail_path    The location of the sendmail binary on the
-     *                      filesystem. Defaults to '/usr/sbin/sendmail'.
-     *
-     *     sendmail_args    Any extra parameters to pass to the sendmail
-     *                      or sendmail wrapper binary.
-     *
-     * If a parameter is present in the $params array, it replaces the
-     * default.
-     *
-     * @param array $params Hash containing any parameters different from the
-     *              defaults.
-     * @access public
-     */
-    function Mail_sendmail($params)
-    {
-        if (isset($params['sendmail_path'])) $this->sendmail_path = $params['sendmail_path'];
-        if (isset($params['sendmail_args'])) $this->sendmail_args = $params['sendmail_args'];
-
-        /*
-         * Because we need to pass message headers to the sendmail program on
-         * the commandline, we can't guarantee the use of the standard "\r\n"
-         * separator.  Instead, we use the system's native line separator.
-         */
-        $this->sep = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n";
-    }
-
-	/**
-     * Implements Mail::send() function using the sendmail
-     * command-line binary.
-     *
-     * @param mixed $recipients Either a comma-seperated list of recipients
-     *              (RFC822 compliant), or an array of recipients,
-     *              each RFC822 valid. This may contain recipients not
-     *              specified in the headers, for Bcc:, resending
-     *              messages, etc.
-     *
-     * @param array $headers The array of headers to send with the mail, in an
-     *              associative array, where the array key is the
-     *              header name (ie, 'Subject'), and the array value
-     *              is the header value (ie, 'test'). The header
-     *              produced from those values would be 'Subject:
-     *              test'.
-     *
-     * @param string $body The full text of the message body, including any
-     *               Mime parts, etc.
-     *
-     * @return mixed Returns true on success, or a PEAR_Error
-     *               containing a descriptive error message on
-     *               failure.
-     * @access public
-     */
-    function send($recipients, $headers, $body)
-    {
-        $recipients = $this->parseRecipients($recipients);
-        if (PEAR::isError($recipients)) {
-            return $recipients;
-        }
-        $recipients = escapeShellCmd(implode(' ', $recipients));
-
-        $headerElements = $this->prepareHeaders($headers);
-        if (PEAR::isError($headerElements)) {
-            return $headerElements;
-        }
-        list($from, $text_headers) = $headerElements;
-
-        if (!isset($from)) {
-            return PEAR::raiseError('No from address given.');
-        } elseif (strstr($from, ' ') ||
-                  strstr($from, ';') ||
-                  strstr($from, '&') ||
-                  strstr($from, '`')) {
-            return PEAR::raiseError('From address specified with dangerous characters.');
-        }
-
-        $result = 0;
-        if (@is_file($this->sendmail_path)) {
-            $from = escapeShellCmd($from);
-            $mail = popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
-            fputs($mail, $text_headers);
-            fputs($mail, $this->sep);  // newline to end the headers section
-            fputs($mail, $body);
-            $result = pclose($mail);
-            if (version_compare(phpversion(), '4.2.3') == -1) {
-                // With older php versions, we need to shift the
-                // pclose result to get the exit code.
-                $result = $result >> 8 & 0xFF;
-            }
-        } else {
-            return PEAR::raiseError('sendmail [' . $this->sendmail_path . '] is not a valid file');
-        }
-
-        if ($result != 0) {
-            return PEAR::raiseError('sendmail returned error code ' . $result,
-                                    $result);
-        }
-
-        return true;
-    }
-
-}

+ 0 - 222
htdocs/includes/nusoap/lib/Mail/smtp.php

@@ -1,222 +0,0 @@
-<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4                                                        |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2003 The PHP Group                                |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license,      |
-// | that is bundled with this package in the file LICENSE, and is        |
-// | available at through the world-wide-web at                           |
-// | http://www.php.net/license/2_02.txt.                                 |
-// | If you did not receive a copy of the PHP license and are unable to   |
-// | obtain it through the world-wide-web, please send a note to          |
-// | license@php.net so we can mail you a copy immediately.               |
-// +----------------------------------------------------------------------+
-// | Authors: Chuck Hagenbuch <chuck@horde.org>                           |
-// |          Jon Parise <jon@php.net>                                    |
-// +----------------------------------------------------------------------+
-
-/**
- * SMTP implementation of the PEAR Mail:: interface. Requires the PEAR
- * Net_SMTP:: class.
- * @access public
- * @package Mail
- */
-class Mail_smtp extends Mail {
-
-    /**
-     * The SMTP host to connect to.
-     * @var string
-     */
-    var $host = 'localhost';
-
-    /**
-     * The port the SMTP server is on.
-     * @var integer
-     */
-    var $port = 25;
-
-    /**
-     * Should SMTP authentication be used?
-     *
-     * This value may be set to true, false or the name of a specific
-     * authentication method.
-     *
-     * If the value is set to true, the Net_SMTP package will attempt to use
-     * the best authentication method advertised by the remote SMTP server.
-     *
-     * @var mixed
-     */
-    var $auth = false;
-
-    /**
-     * The username to use if the SMTP server requires authentication.
-     * @var string
-     */
-    var $username = '';
-
-    /**
-     * The password to use if the SMTP server requires authentication.
-     * @var string
-     */
-    var $password = '';
-
-    /**
-     * Hostname or domain that will be sent to the remote SMTP server in the
-     * HELO / EHLO message.
-     *
-     * @var string
-     */
-    var $localhost = 'localhost';
-
-    /**
-     * SMTP connection timeout value.  NULL indicates no timeout.
-     *
-     * @var integer
-     */
-    var $timeout = null;
-
-    /**
-     * Whether to use VERP or not. If not a boolean, the string value
-     * will be used as the VERP separators.
-     *
-     * @var mixed boolean or string
-     */
-    var $verp = false;
-
-    /**
-     * Turn on Net_SMTP debugging?
-     *
-     * @var boolean $debug
-     */
-    var $debug = false;
-
-    /**
-     * Constructor.
-     *
-     * Instantiates a new Mail_smtp:: object based on the parameters
-     * passed in. It looks for the following parameters:
-     *     host        The server to connect to. Defaults to localhost.
-     *     port        The port to connect to. Defaults to 25.
-     *     auth        SMTP authentication.  Defaults to none.
-     *     username    The username to use for SMTP auth. No default.
-     *     password    The password to use for SMTP auth. No default.
-     *     localhost   The local hostname / domain. Defaults to localhost.
-     *     timeout     The SMTP connection timeout. Defaults to none.
-     *     verp        Whether to use VERP or not. Defaults to false.
-     *     debug       Activate SMTP debug mode? Defaults to false.
-     *
-     * If a parameter is present in the $params array, it replaces the
-     * default.
-     *
-     * @param array Hash containing any parameters different from the
-     *              defaults.
-     * @access public
-     */
-    function Mail_smtp($params)
-    {
-        if (isset($params['host'])) $this->host = $params['host'];
-        if (isset($params['port'])) $this->port = $params['port'];
-        if (isset($params['auth'])) $this->auth = $params['auth'];
-        if (isset($params['username'])) $this->username = $params['username'];
-        if (isset($params['password'])) $this->password = $params['password'];
-        if (isset($params['localhost'])) $this->localhost = $params['localhost'];
-        if (isset($params['timeout'])) $this->timeout = $params['timeout'];
-        if (isset($params['verp'])) $this->verp = $params['verp'];
-        if (isset($params['debug'])) $this->debug = (boolean)$params['debug'];
-    }
-
-    /**
-     * Implements Mail::send() function using SMTP.
-     *
-     * @param mixed $recipients Either a comma-seperated list of recipients
-     *              (RFC822 compliant), or an array of recipients,
-     *              each RFC822 valid. This may contain recipients not
-     *              specified in the headers, for Bcc:, resending
-     *              messages, etc.
-     *
-     * @param array $headers The array of headers to send with the mail, in an
-     *              associative array, where the array key is the
-     *              header name (e.g., 'Subject'), and the array value
-     *              is the header value (e.g., 'test'). The header
-     *              produced from those values would be 'Subject:
-     *              test'.
-     *
-     * @param string $body The full text of the message body, including any
-     *               Mime parts, etc.
-     *
-     * @return mixed Returns true on success, or a PEAR_Error
-     *               containing a descriptive error message on
-     *               failure.
-     * @access public
-     */
-    function send($recipients, $headers, $body)
-    {
-        include_once 'Net/SMTP.php';
-
-        if (!($smtp = &new Net_SMTP($this->host, $this->port, $this->localhost))) {
-            return PEAR::raiseError('unable to instantiate Net_SMTP object');
-        }
-
-        if ($this->debug) {
-            $smtp->setDebug(true);
-        }
-
-        if (PEAR::isError($smtp->connect($this->timeout))) {
-            return PEAR::raiseError('unable to connect to smtp server ' .
-                                    $this->host . ':' . $this->port);
-        }
-
-        if ($this->auth) {
-            $method = is_string($this->auth) ? $this->auth : '';
-
-            if (PEAR::isError($smtp->auth($this->username, $this->password,
-                              $method))) {
-                return PEAR::raiseError('unable to authenticate to smtp server');
-            }
-        }
-
-        $headerElements = $this->prepareHeaders($headers);
-        if (PEAR::isError($headerElements)) {
-            return $headerElements;
-        }
-        list($from, $text_headers) = $headerElements;
-
-        /* Since few MTAs are going to allow this header to be forged
-         * unless it's in the MAIL FROM: exchange, we'll use
-         * Return-Path instead of From: if it's set. */
-        if (!empty($headers['Return-Path'])) {
-            $from = $headers['Return-Path'];
-        }
-
-        if (!isset($from)) {
-            return PEAR::raiseError('No from address given');
-        }
-
-        $args['verp'] = $this->verp;
-        if (PEAR::isError($smtp->mailFrom($from, $args))) {
-            return PEAR::raiseError('unable to set sender to [' . $from . ']');
-        }
-
-        $recipients = $this->parseRecipients($recipients);
-        if (PEAR::isError($recipients)) {
-            return $recipients;
-        }
-
-        foreach ($recipients as $recipient) {
-            if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
-                return PEAR::raiseError('unable to add recipient [' .
-                                        $recipient . ']: ' . $res->getMessage());
-            }
-        }
-
-        if (PEAR::isError($smtp->data($text_headers . "\r\n" . $body))) {
-            return PEAR::raiseError('unable to send data');
-        }
-
-        $smtp->disconnect();
-        return true;
-    }
-
-}

+ 0 - 19
htdocs/includes/nusoap/lib/Mail/xmail.dtd

@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-
-<!ENTITY lt "&#38;#60;">
-<!ENTITY gt "&#62;">
-<!ENTITY amp "&#38;#38;">
-<!ENTITY apos "&#39;">
-<!ENTITY quot "&#34;">
-<!ENTITY crlf "&#13;&#10;">
-
-<!ELEMENT email (header+, (body | mimepart+))>
-<!ELEMENT mimepart (header+, (body | mimepart+))>
-<!ELEMENT body (#PCDATA)>
-<!ELEMENT header ((headername|headervalue|parameter)*)>
-<!ELEMENT headername (#PCDATA)>
-<!ELEMENT headervalue (#PCDATA)>
-<!ELEMENT parameter ((paramname|paramvalue)+)>
-<!ELEMENT paramvalue (#PCDATA)>
-<!ELEMENT paramname (#PCDATA)>
-

+ 0 - 70
htdocs/includes/nusoap/lib/Mail/xmail.xsl

@@ -1,70 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
-<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
-<xsl:preserve-space elements="headervalue paramvalue body"/>
-
-	<xsl:template name="mimepart">
-
-		<xsl:variable name="boundary">
-				<xsl:for-each select="./header">
-					<xsl:if test="string(./headername) = 'Content-Type'">
-						<xsl:for-each select="./parameter">
-							<xsl:if test="string(./paramname) = 'boundary'">
-								<xsl:value-of select="paramvalue"/>
-							</xsl:if>
-						</xsl:for-each>
-					</xsl:if>
-				</xsl:for-each>
-		</xsl:variable>
-
-		<xsl:for-each select="header">
-
-			<xsl:value-of select="headername"/>
-			<xsl:text>: </xsl:text>
-			<xsl:value-of select="headervalue"/>
-
-			<xsl:if test="count(./parameter) = 0">
-				<xsl:text>&#13;&#10;</xsl:text>
-			</xsl:if>
-
-			<xsl:for-each select="parameter">
-				<xsl:text>;&#13;&#10;&#09;</xsl:text>
-				<xsl:value-of select="paramname"/>
-				<xsl:text>="</xsl:text>
-				<xsl:value-of select="paramvalue"/>
-				<xsl:text>"</xsl:text>
-			</xsl:for-each>
-
-			<xsl:if test="count(./parameter) > 0">
-				<xsl:text>&#13;&#10;</xsl:text>
-			</xsl:if>
-
-		</xsl:for-each>
-
-		<xsl:text>&#13;&#10;</xsl:text>
-
-		<!-- Which to do, print a body or process subparts? -->
-		<xsl:choose>
-			<xsl:when test="count(./mimepart) = 0">
-				<xsl:value-of select="body"/>
-				<xsl:text>&#13;&#10;</xsl:text>
-			</xsl:when>
-
-			<xsl:otherwise>
-				<xsl:for-each select="mimepart">
-					<xsl:text>--</xsl:text><xsl:value-of select="$boundary"/><xsl:text>&#13;&#10;</xsl:text>
-					<xsl:call-template name="mimepart"/>
-				</xsl:for-each>
-
-				<xsl:text>--</xsl:text><xsl:value-of select="$boundary"/><xsl:text>--&#13;&#10;</xsl:text>
-
-			</xsl:otherwise>
-		</xsl:choose>
-	</xsl:template>
-
-<!-- This is where the stylesheet really starts, matching the top level email element -->
-	<xsl:template match="email">
-		<xsl:call-template name="mimepart"/>
-	</xsl:template>
-
-</xsl:stylesheet>

Some files were not shown because too many files changed in this diff