Source for file Email.php
Documentation is available at Email.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | 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: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
// +----------------------------------------------------------------------+
// $Id: Email.php,v 1.10 2003/05/18 00:57:40 shane Exp $
require_once 'SOAP/Server.php';
require_once 'SOAP/Client.php';
require_once 'SOAP/Transport.php';
require_once 'Mail/mimeDecode.php';
* implements Email SOAP Server
* http://www.pocketsoap.com/specs/smtpbinding/
* class overrides the default HTTP server, providing the ability
* to parse an email message and execute soap calls.
* this class DOES NOT pop the message, the message, complete
* with headers, must be passed in as a parameter to the service
* @version $Id: Email.php,v 1.10 2003/05/18 00:57:40 shane Exp $
* @author Shane Caraveo <shane@php.net>
$this->send_response = $send_response;
* remove http headers from response
* TODO: use PEAR email classes
function _parseEmail (&$data)
if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match)) {
$hc = count($matches[0 ]);
for ($i = 0; $i < $hc; $i++ ) {
$this->_raiseSoapFault ('Invalid Content Type','','','Client');
// join lines back together
#} else if (strcasecmp($this->headers['content-transfer-encoding'],'quoted-printable')==0) {
# $this->_raiseSoapFault('Invalid Content-Transfer-Encoding','','','Client');
// if no content, return false
$this->_raiseSoapFault ('Invalid Email Format','','','Client');
# if neither matches, we'll just try it anyway
if (stristr($data,'Content-Type: application/dime')) {
$this->_decodeDIMEMessage ($data,$this->headers,$attachments);
} else if (stristr($data,'MIME-Version:')) {
// this is a mime message, lets decode it.
#$data = 'Content-Type: '.stripslashes($_SERVER['CONTENT_TYPE'])."\r\n\r\n".$data;
$this->_decodeMimeMessage ($data,$this->headers,$attachments);
// the old fallback, but decodeMimeMessage handles things fine.
$this->_parseEmail ($data);
// get the character encoding of the incoming request
// treat incoming data as UTF-8 if no encoding set
if (!$this->soapfault && !$this->_getContentEncoding ($this->headers['content-type'])) {
// an encoding we don't understand, return a fault
$this->_raiseSoapFault ('Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8','','','Server');
return $this->soapfault->getFault ();
return $client->__parse ($data, $this->xml_encoding, $this->attachments);
function service(&$data, $endpoint = '', $send_response = TRUE , $dump = FALSE )
# if neither matches, we'll just try it anyway
if (stristr($data,'Content-Type: application/dime')) {
$this->_decodeDIMEMessage ($data,$this->headers,$attachments);
} else if (stristr($data,'MIME-Version:')) {
// this is a mime message, lets decode it.
#$data = 'Content-Type: '.stripslashes($_SERVER['CONTENT_TYPE'])."\r\n\r\n".$data;
$this->_decodeMimeMessage ($data,$this->headers,$attachments);
// the old fallback, but decodeMimeMessage handles things fine.
$this->_parseEmail ($data);
// get the character encoding of the incoming request
// treat incoming data as UTF-8 if no encoding set
if (!$response && !$this->_getContentEncoding ($this->headers['content-type'])) {
// an encoding we don't understand, return a fault
$this->_raiseSoapFault ('Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8','','','Server');
$response = $this->getFaultMessage ();
$response = $this->soapfault->message ();
// handle Mime or DIME encoding
// XXX DIME Encoding should move to the transport, do it here for now
// and for ease of getting it done
if (count($this->__attachments)) {
if ($useEncoding == 'Mime') {
$soap_msg = $this->_makeMimeMessage ($soap_msg);
$soap_msg = $this->_makeDIMEMessage ($soap_msg);
$header['Content-Type'] = 'application/dime';
if (PEAR ::isError ($soap_msg)) {
return $this->raiseSoapFault ($soap_msg);
$response = $soap_msg['body'];
if (count($soap_msg['headers'])) {
$headers = $soap_msg['headers'];
if ($this->send_response) {
# XXX what if no from?????
$headers['In-Reply-To']= $this->headers['message-id'];
$options = array ('from' => $from, 'subject'=> $this->headers['subject'], 'headers' => $headers);
$soap_transport->send ($response, $options);
Documentation generated on Mon, 11 Mar 2019 13:59:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|