cvs: pear /SOAP Client.php /SOAP/Server Email.php Email_Gateway.php /SOAP/Transport SMTP.php

From: Date: Mon, 13 May 2002 20:47:21 +0000
Subject: cvs: pear /SOAP Client.php /SOAP/Server Email.php Email_Gateway.php /SOAP/Transport SMTP.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3807@lists.php.net to get a copy of this message
shane Mon May 13 16:47:21 2002 EDT Modified files: /pear/SOAP Client.php /pear/SOAP/Server Email.php Email_Gateway.php /pear/SOAP/Transport SMTP.php Log: fix soap email handling

Index: pear/SOAP/Client.php diff -u pear/SOAP/Client.php:1.29 pear/SOAP/Client.php:1.30 --- pear/SOAP/Client.php:1.29 Mon May 13 02:47:09 2002 +++ pear/SOAP/Client.php Mon May 13 16:47:20 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Client.php,v 1.29 2002/05/13 06:47:09 shane Exp $ +// $Id: Client.php,v 1.30 2002/05/13 20:47:20 shane Exp $ // require_once 'SOAP/Value.php'; @@ -25,7 +25,7 @@ require_once 'SOAP/Transport.php'; require_once 'SOAP/WSDL.php'; require_once 'SOAP/Fault.php'; - +require_once 'SOAP/Parser.php'; /** * SOAP Client Class * this class is the main interface for making soap requests @@ -37,7 +37,7 @@ * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public -* @version $Id: Client.php,v 1.29 2002/05/13 06:47:09 shane Exp $ +* @version $Id: Client.php,v 1.30 2002/05/13 20:47:20 shane Exp $ * @package SOAP::Client * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates * @author Stig Bakken <ssb@fast.no> Conversion to PEAR Index: pear/SOAP/Server/Email.php diff -u pear/SOAP/Server/Email.php:1.2 pear/SOAP/Server/Email.php:1.3 --- pear/SOAP/Server/Email.php:1.2 Mon May 13 02:47:09 2002 +++ pear/SOAP/Server/Email.php Mon May 13 16:47:21 2002 @@ -16,7 +16,7 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more | // +----------------------------------------------------------------------+ // -// $Id: Email.php,v 1.2 2002/05/13 06:47:09 shane Exp $ +// $Id: Email.php,v 1.3 2002/05/13 20:47:21 shane Exp $ // require_once 'SOAP/Server.php'; @@ -36,7 +36,7 @@ * function call * * @access public -* @version $Id: Email.php,v 1.2 2002/05/13 06:47:09 shane Exp $ +* @version $Id: Email.php,v 1.3 2002/05/13 20:47:21 shane Exp $ * @package SOAP::Server * @author Shane Caraveo <shane@php.net> */ @@ -48,6 +48,49 @@ parent::SOAP_Server(); $this->send_response = $send_response; } + + /** + * remove http headers from response + * + * TODO: use PEAR email classes + * + * @return boolean + * @access private + */ + function _parseEmail(&$data) + { + if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match)) { + + if (preg_match_all('/^(.*?):\s+(.*)$/m', $match[1], $matches)) { + $hc = count($matches[0]); + for ($i = 0; $i < $hc; $i++) { + $this->headers[strtolower($matches[1][$i])] = trim($matches[2][$i]); + } + } + + if (!stristr($this->headers['content-type'],'text/xml')) { + $this->makeFault('Client','Invalid Content Type'); + return FALSE; + } + + if (strcasecmp($this->headers['content-transfer-encoding'],'base64')==0) { + // join lines back together + $enctext = preg_replace("/[\r|\n]/", '', $match[2]); + $data = base64_decode($enctext); + } else if (strcasecmp($this->headers['content-transfer-encoding'],'quoted-printable')==0) { + $data = $match[2]; + } else { + $this->makeFault('Client','Invalid Content-Transfer-Encoding'); + return FALSE; + } + + // if no content, return false + return strlen($this->request) > 0; + } + $this->makeFault('Client','Invalid Email Format'); + return FALSE; + } + function service(&$data, $endpoint = '', $send_response = TRUE, $dump = FALSE) { @@ -56,14 +99,17 @@ $headers = array(); # if neither matches, we'll just try it anyway - if (stristr($data,'Content-Type: application/dime')==0) { + if (stristr($data,'Content-Type: application/dime')) { $this->decodeDIMEMessage($data,$this->headers,$attachments); $useEncoding = 'DIME'; - } else if (stristr($data,'Content-Type: multipart/related')) { + } 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; + #$data = 'Content-Type: '.stripslashes($_SERVER['CONTENT_TYPE'])."\r\n\r\n".$data; $this->decodeMimeMessage($data,$this->headers,$attachments); $useEncoding = 'Mime'; + } else { + // the old fallback, but decodeMimeMessage handles things fine. + $this->_parseEmail($data); } // get the character encoding of the incoming request @@ -75,7 +121,9 @@ $response = $this->getFaultMessage(); } - if (!$this->soapfault) { + if ($this->soapfault) { + $response = $this->soapfault->message(); + } else { $soap_msg = $this->parseRequest($data,$attachments); // handle Mime or DIME encoding @@ -105,10 +153,8 @@ } if ($this->send_response) { - $payload = $response->serialize($this->response_encoding); - if ($dump) { - print $payload; + print $response; } else { $from = array_key_exists('reply-to',$this->headers) ? $this->headers['reply-to']:$this->headers['from']; # XXX what if no from????? @@ -117,7 +163,7 @@ $from = $this->endpoint ? $this->endpoint : $this->headers['to']; $headers['In-Reply-To']=$this->headers['message-id']; $options = array('from' => $from, 'subject'=> $this->headers['subject'], 'headers' => $headers); - $soap_transport->send($payload, $options); + $soap_transport->send($response, $options); } } } Index: pear/SOAP/Server/Email_Gateway.php diff -u pear/SOAP/Server/Email_Gateway.php:1.2 pear/SOAP/Server/Email_Gateway.php:1.3 --- pear/SOAP/Server/Email_Gateway.php:1.2 Mon May 13 02:47:09 2002 +++ pear/SOAP/Server/Email_Gateway.php Mon May 13 16:47:21 2002 @@ -16,7 +16,7 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more | // +----------------------------------------------------------------------+ // -// $Id: Email_Gateway.php,v 1.2 2002/05/13 06:47:09 shane Exp $ +// $Id: Email_Gateway.php,v 1.3 2002/05/13 20:47:21 shane Exp $ // require_once 'SOAP/Server/Email.php'; @@ -40,53 +40,11 @@ * email * * @access public -* @version $Id: Email_Gateway.php,v 1.2 2002/05/13 06:47:09 shane Exp $ +* @version $Id: Email_Gateway.php,v 1.3 2002/05/13 20:47:21 shane Exp $ * @package SOAP::Server * @author Shane Caraveo <shane@php.net> */ class SOAP_Server_Email_Gateway extends SOAP_Server_Email { - /** - * remove http headers from response - * - * TODO: use PEAR email classes - * - * @return boolean - * @access private - */ - function _parseEmail(&$data) - { - if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match)) { - - if (preg_match_all('/^(.*?):\s+(.*)$/m', $match[1], $matches)) { - $hc = count($matches[0]); - for ($i = 0; $i < $hc; $i++) { - $this->headers[strtolower($matches[1][$i])] = trim($matches[2][$i]); - } - } - - if (!stristr($this->headers['content-type'],'text/xml')) { - $this->makeFault('Client','Invalid Content Type'); - return FALSE; - } - - if (strcasecmp($this->headers['content-transfer-encoding'],'base64')==0) { - // join lines back together - $enctext = preg_replace("/[\r|\n]/", '', $match[2]); - $this->request = base64_decode($enctext); - } else if (strcasecmp($this->headers['content-transfer-encoding'],'quoted-printable')==0) { - $this->request = $match[2]; - } else { - $this->makeFault('Client','Invalid Content-Transfer-Encoding'); - return FALSE; - } - - // if no content, return false - return strlen($this->request) > 0; - } - $this->makeFault('Client','Invalid Email Format'); - return FALSE; - } - function service(&$data, $gateway, $endpoint = '', $send_response = TRUE, $dump = FALSE) { @@ -94,9 +52,9 @@ $response = ''; // we have a full set of headers, need to find the first blank line - if (!$this->_parseEmail($data)) { - $fault = $this->getFaultMessage(); - $response = $fault->serialize(); + $this->_parseEmail($data); + if ($this->soapfault) { + $response = $this->getFaultMessage(); } // get the character encoding of the incoming request // treat incoming data as UTF-8 if no encoding set @@ -104,31 +62,30 @@ $this->xml_encoding = SOAP_DEFAULT_ENCODING; // an encoding we don't understand, return a fault $this->makeFault('Server','Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8'); - $fault = $this->getFaultMessage(); - $response = $fault->serialize(); + $response = $this->getFaultMessage(); } # call the HTTP Server - $soap_transport = new SOAP_Transport($gateway, $this->xml_encoding); - if ($soap_transport->fault) { - $fault = $soap_transport->fault->message(); - $response = $fault->serialize(); + if (!$response) { + $soap_transport = new SOAP_Transport($gateway, $this->xml_encoding); + if ($soap_transport->fault) { + $response = $soap_transport->fault->message(); + } } // send the message if (!$response) { $options['soapaction'] = $this->headers['soapaction']; $options['headers']['Content-Type'] = $this->headers['content-type']; - $response = $soap_transport->send($this->request, $options); + $response = $soap_transport->send($data, $options); if ($soap_transport->fault) { - $fault = $soap_transport->fault->message(); - $response = $fault->serialize(); + $response = $soap_transport->fault->message(); } } if ($this->send_response) { if ($dump) { - print $payload; + print $response; } else { $from = array_key_exists('reply-to',$this->headers) ? $this->headers['reply-to']:$this->headers['from']; # XXX what if no from????? Index: pear/SOAP/Transport/SMTP.php diff -u pear/SOAP/Transport/SMTP.php:1.9 pear/SOAP/Transport/SMTP.php:1.10 --- pear/SOAP/Transport/SMTP.php:1.9 Mon May 13 02:47:10 2002 +++ pear/SOAP/Transport/SMTP.php Mon May 13 16:47:21 2002 @@ -16,7 +16,7 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.9 2002/05/13 06:47:10 shane Exp $ +// $Id: SMTP.php,v 1.10 2002/05/13 20:47:21 shane Exp $ // // Status: rough draft, untested // @@ -27,7 +27,6 @@ // ability to define smtp options (encoding, from, etc.) // -require_once 'SOAP/Message.php'; require_once 'SOAP/Base.php'; /** @@ -39,7 +38,7 @@ * TODO: use PEAR smtp and Mime classes * * @access public -* @version $Id: SMTP.php,v 1.9 2002/05/13 06:47:10 shane Exp $ +* @version $Id: SMTP.php,v 1.10 2002/05/13 20:47:21 shane Exp $ * @package SOAP::Transport::SMTP * @author Shane Caraveo <shane@php.net> */ @@ -107,28 +106,28 @@ $headers['Content-Type'] = "text/xml; charset=\"$this->encoding\""; if (array_key_exists('transfer-encoding', $options)) { if (strcasecmp($options['transfer-encoding'],'quoted-printable')==0) { - $headers .="Content-Transfer-Encoding: {$options['transfer-encoding']}\n"; + $headers['Content-Transfer-Encoding'] = $options['transfer-encoding']; $out = &$msg; } else if (strcasecmp($options['transfer-encoding'],'base64')==0) { - $headers .="Content-Transfer-Encoding: base64\n"; + $headers['Content-Transfer-Encoding'] = 'base64'; $out = chunk_split(base64_encode($msg)); } else { return $this->raiseSoapFault("Invalid Transfer Encoding: {$options['transfer-encoding']}"); } } else { // default to base64 - $headers .="Content-Transfer-Encoding: base64\n"; + $headers['Content-Transfer-Encoding'] = 'base64'; $out = chunk_split(base64_encode($msg)); } } foreach ($headers as $key => $value) { - $header_text .= "$key: $value\n"; + $header_text .= "$key: $value\r\n"; } $subject = array_key_exists('subject', $options) ? $options['subject'] : 'SOAP Message'; - $this->outgoing_payload = $header_text."\n\n".$this->outgoing_payload; + $this->outgoing_payload = $header_text."\r\n".$this->outgoing_payload; # we want to return a proper XML message $result = mail($this->urlparts['path'], $subject, $out, $header_text); @@ -141,9 +140,11 @@ )); } - $return_msg = new SOAP_Message(); - $return_msg->method('Response',array($val),'smtp'); - $this->incoming_payload = $return_msg->serialize(); + $mqname = new QName($method, $namespace); + $methodValue = new SOAP_Value('Response', 'Struct', array($val)); + $return_msg = $this->_makeEnvelope($methodValue, $this->headers, $this->encoding); + + $this->incoming_payload = $return_msg; return $this->incoming_payload; }
« previous php.pear.cvs (#3807) next »