cvs: pear /SOAP Client.php /SOAP/Server Email.php Email_Gateway.php /SOAP/Transport SMTP.php /SOAP/example email_client.php email_pop_gateway.php
email_pop_server.php /SOAP/interop client_round2_run.php

From: Date: Tue, 14 May 2002 23:02:50 +0000
Subject: cvs: pear /SOAP Client.php /SOAP/Server Email.php Email_Gateway.php /SOAP/Transport SMTP.php /SOAP/example email_client.php email_pop_gateway.php
email_pop_server.php /SOAP/interop client_round2_run.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3825@lists.php.net to get a copy of this message
shane Tue May 14 19:02:50 2002 EDT Added files: /pear/SOAP/example email_client.php email_pop_gateway.php email_pop_server.php Modified files: /pear/SOAP Client.php /pear/SOAP/Server Email.php Email_Gateway.php /pear/SOAP/Transport SMTP.php /pear/SOAP/interop client_round2_run.php Log: change smtp server to use PEAR smtp mail class return Message-ID when sending SOAP over SMTP additional examples of using soap with email

Index: pear/SOAP/Client.php diff -u pear/SOAP/Client.php:1.30 pear/SOAP/Client.php:1.31 --- pear/SOAP/Client.php:1.30 Mon May 13 16:47:20 2002 +++ pear/SOAP/Client.php Tue May 14 19:02:47 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: Client.php,v 1.30 2002/05/13 20:47:20 shane Exp $ +// $Id: Client.php,v 1.31 2002/05/14 23:02:47 shane Exp $ // require_once 'SOAP/Value.php'; @@ -37,7 +37,7 @@ * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public -* @version $Id: Client.php,v 1.30 2002/05/13 20:47:20 shane Exp $ +* @version $Id: Client.php,v 1.31 2002/05/14 23:02:47 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 @@ -326,7 +326,7 @@ } // send the message - $this->response = $soap_transport->send($soap_data, $options); + $response = $soap_transport->send($soap_data, $options); // save the wire information for debugging $this->wire = "OUTGOING:\n\n". @@ -337,11 +337,15 @@ $this->xml = $soap_transport->transport->incoming_payload; if ($soap_transport->fault) { - return $this->raiseSoapFault($this->response); + return $this->raiseSoapFault($response); } - + return $this->parseResponse($response, $soap_transport->result_encoding,$soap_transport->transport->attachments); + } + + function parseResponse($response, $encoding, $attachments) + { // parse the response - $this->response = new SOAP_Parser($this->response, $soap_transport->result_encoding,$soap_transport->transport->attachments); + $this->response = new SOAP_Parser($response, $encoding, $attachments); if ($this->response->fault) { return $this->raiseSoapFault($this->response->fault); } Index: pear/SOAP/Server/Email.php diff -u pear/SOAP/Server/Email.php:1.4 pear/SOAP/Server/Email.php:1.5 --- pear/SOAP/Server/Email.php:1.4 Mon May 13 18:05:43 2002 +++ pear/SOAP/Server/Email.php Tue May 14 19:02:49 2002 @@ -16,10 +16,11 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more | // +----------------------------------------------------------------------+ // -// $Id: Email.php,v 1.4 2002/05/13 22:05:43 shane Exp $ +// $Id: Email.php,v 1.5 2002/05/14 23:02:49 shane Exp $ // require_once 'SOAP/Server.php'; +require_once 'SOAP/Client.php'; require_once 'SOAP/Transport.php'; require_once 'Mail/mimeDecode.php'; /** @@ -36,7 +37,7 @@ * function call * * @access public -* @version $Id: Email.php,v 1.4 2002/05/13 22:05:43 shane Exp $ +* @version $Id: Email.php,v 1.5 2002/05/14 23:02:49 shane Exp $ * @package SOAP::Server * @author Shane Caraveo <shane@php.net> */ @@ -94,6 +95,38 @@ return FALSE; } + function client(&$data) + { + $attachments = array(); + + # if neither matches, we'll just try it anyway + if (stristr($data,'Content-Type: application/dime')) { + $this->decodeDIMEMessage($data,$this->headers,$attachments); + $useEncoding = 'DIME'; + } 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); + $useEncoding = 'Mime'; + } else { + // 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'])) { + $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'); + } + + if ($this->soapfault) { + return $this->soapfault->getFault(); + } + $client = new SOAP_Client(NULL); + return $client->parseResponse($data, $this->xml_encoding, $this->attachments); + } function service(&$data, $endpoint = '', $send_response = TRUE, $dump = FALSE) { Index: pear/SOAP/Server/Email_Gateway.php diff -u pear/SOAP/Server/Email_Gateway.php:1.4 pear/SOAP/Server/Email_Gateway.php:1.5 --- pear/SOAP/Server/Email_Gateway.php:1.4 Mon May 13 18:05:45 2002 +++ pear/SOAP/Server/Email_Gateway.php Tue May 14 19:02:49 2002 @@ -16,7 +16,7 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more | // +----------------------------------------------------------------------+ // -// $Id: Email_Gateway.php,v 1.4 2002/05/13 22:05:45 shane Exp $ +// $Id: Email_Gateway.php,v 1.5 2002/05/14 23:02:49 shane Exp $ // require_once 'SOAP/Server/Email.php'; @@ -40,17 +40,30 @@ * email * * @access public -* @version $Id: Email_Gateway.php,v 1.4 2002/05/13 22:05:45 shane Exp $ +* @version $Id: Email_Gateway.php,v 1.5 2002/05/14 23:02:49 shane Exp $ * @package SOAP::Server * @author Shane Caraveo <shane@php.net> */ -class SOAP_Server_Email_Gateway extends SOAP_Server_Email { - - function service(&$data, $gateway, $endpoint = '', $send_response = TRUE, $dump = FALSE) +class SOAP_Server_Email_Gateway extends SOAP_Server_Email +{ + var $gateway = NULL; + var $dump = FALSE; + + function SOAP_Server_Email_Gateway($gateway = '', $send_response = TRUE, $dump=FALSE) + { + parent::SOAP_Server(); + $this->send_response = $send_response; + $this->gateway = $gateway; + $this->dump = $dump; + } + + function service(&$data, $gateway='', $endpoint = '', $send_response = TRUE, $dump = FALSE) { $this->endpoint = $endpoint; $response = ''; $useEncoding='Mime'; + $options = array(); + if (!$gateway) $gateway = $this->gateway; // we have a full set of headers, need to find the first blank line $this->_parseEmail($data); @@ -72,7 +85,11 @@ if (!$response) { $options['soapaction'] = $this->headers['soapaction']; $options['headers']['Content-Type'] = $this->headers['content-type']; + $response = $soap_transport->send($data, $options); + if (isset($this->headers['mime-version'])) + $options['headers']['MIME-Version'] = $this->headers['mime-version']; + if ($soap_transport->fault) { $response = $soap_transport->fault->message(); } else { @@ -82,10 +99,11 @@ if (count($this->attachments)) { if ($useEncoding == 'Mime') { $soap_msg = $this->_makeMimeMessage($response); + $options['headers']['MIME-Version'] = '1.0'; } else { // default is dime $soap_msg = $this->_makeDIMEMessage($response); - $header['Content-Type'] = 'application/dime'; + $options['headers']['Content-Type'] = 'application/dime'; } if (PEAR::isError($soap_msg)) { return $this->raiseSoapFault($soap_msg); @@ -105,7 +123,7 @@ } if ($this->send_response) { - if ($dump) { + if ($this->dump || $dump) { print $response; } else { $from = array_key_exists('reply-to',$this->headers) ? $this->headers['reply-to']:$this->headers['from']; Index: pear/SOAP/Transport/SMTP.php diff -u pear/SOAP/Transport/SMTP.php:1.12 pear/SOAP/Transport/SMTP.php:1.13 --- pear/SOAP/Transport/SMTP.php:1.12 Mon May 13 20:55:03 2002 +++ pear/SOAP/Transport/SMTP.php Tue May 14 19:02:49 2002 @@ -16,7 +16,7 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.12 2002/05/14 00:55:03 shane Exp $ +// $Id: SMTP.php,v 1.13 2002/05/14 23:02:49 shane Exp $ // // Status: rough draft, untested // @@ -28,6 +28,7 @@ // require_once 'SOAP/Base.php'; +require_once 'Mail/smtp.php'; /** * SMTP Transport for SOAP @@ -38,7 +39,7 @@ * TODO: use PEAR smtp and Mime classes * * @access public -* @version $Id: SMTP.php,v 1.12 2002/05/14 00:55:03 shane Exp $ +* @version $Id: SMTP.php,v 1.13 2002/05/14 23:02:49 shane Exp $ * @package SOAP::Transport::SMTP * @author Shane Caraveo <shane@php.net> */ @@ -51,7 +52,9 @@ var $incoming_payload = ''; var $_userAgent = SOAP_LIBRARY_NAME; var $encoding = SOAP_DEFAULT_ENCODING; - + var $host = '127.0.0.1'; + var $port = 25; + var $auth = NULL; /** * SOAP_Transport_SMTP Constructor * @@ -87,10 +90,18 @@ return $this->raiseSoapFault("No FROM address to send message with"); } + if (isset($options['host'])) $this->host = $options['host']; + if (isset($options['port'])) $this->port = $options['port']; + if (isset($options['auth'])) $this->auth = $options['auth']; + if (isset($options['username'])) $this->username = $options['username']; + if (isset($options['password'])) $this->password = $options['password']; + $headers = array(); $headers['From'] = $options['from']; $headers['X-Mailer'] = $this->_userAgent; $headers['MIME-Version'] = '1.0'; + $headers['Message-ID'] = md5(time()).'.soap@'.$this->host; + $headers['To'] = $this->urlparts['path']; if (array_key_exists('soapaction', $options)) { $headers['Soapaction'] = "\"{$options['soapaction']}\""; } @@ -123,22 +134,31 @@ } } + $headers['Subject'] = array_key_exists('subject', $options) ? $options['subject'] : 'SOAP Message'; + foreach ($headers as $key => $value) { $header_text .= "$key: $value\n"; } - - $subject = array_key_exists('subject', $options) ? $options['subject'] : 'SOAP Message'; - $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); + + $mailer_params = array( + 'host' => $this->host, + 'port' => $this->port, + 'username' => $this->username, + 'password' => $this->password, + 'auth' => $this->auth + ); + $mailer = new Mail_smtp($mailer_params); + $result = $mailer->send($this->urlparts['path'], $headers, $out); + #$result = mail($this->urlparts['path'], $headers['Subject'], $out, $header_text); - if ($result) { - $val = new SOAP_Value('return','boolean',TRUE); + if (!PEAR::isError($result)) { + $val = new SOAP_Value('Message-ID','string',$headers['Message-ID']); } else { $val = new SOAP_Value('Fault','Struct',array( new SOAP_Value('faultcode','QName','SOAP-ENV:Client'), - new SOAP_Value('faultstring','string',"couldn't send SMTP message to $action") + new SOAP_Value('faultstring','string',"couldn't send SMTP message to {$this->urlparts['path']}") )); } Index: pear/SOAP/interop/client_round2_run.php diff -u pear/SOAP/interop/client_round2_run.php:1.2 pear/SOAP/interop/client_round2_run.php:1.3 --- pear/SOAP/interop/client_round2_run.php:1.2 Mon May 13 02:47:10 2002 +++ pear/SOAP/interop/client_round2_run.php Tue May 14 19:02:50 2002 @@ -17,7 +17,7 @@ // | Authors: Shane Caraveo <Shane@Caraveo.com> | // +----------------------------------------------------------------------+ // -// $Id: client_round2_run.php,v 1.2 2002/05/13 06:47:10 shane Exp $ +// $Id: client_round2_run.php,v 1.3 2002/05/14 23:02:50 shane Exp $ // set_time_limit(0); require_once 'SOAP/interop/client_round2_interop.php'; @@ -37,7 +37,7 @@ $this->nosave = 0; // 1= disable saving results to database // debug output $iop->show = 1; -$iop->debug = 1; +$iop->debug = 0; $iop->showFaults = 0; // used in result table output #$iop->doTest(); // run a single set of tests using above options Index: pear/SOAP/example/email_client.php +++ pear/SOAP/example/email_client.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 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_client.php,v 1.1 2002/05/14 23:02:49 shane Exp $ // /* This reads a message from stdin, and calls the soap server defined You can use this from qmail by creating a .qmail-soaptest file with: | /usr/bin/php /path/to/email_server.php */ # include the email server class require_once 'SOAP/Server/Email.php'; $server = new SOAP_Server_Email; # read stdin $fin = fopen('php://stdin','rb'); if (!$fin) exit(0); $email = ''; while (!feof($fin) && $data = fread($fin, 8096)) { $email .= $data; } fclose($fin); $response = $server->client($email); print_r($response); ?> Index: pear/SOAP/example/email_pop_gateway.php +++ pear/SOAP/example/email_pop_gateway.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 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_pop_gateway.php,v 1.1 2002/05/14 23:02:49 shane Exp $ // /* include the Email server class, which knows how to parse a standard email as a soap message */ require_once 'SOAP/Server/Email_Gateway.php'; /* include a class to access POP3 */ require_once 'Net/POP3.php'; /* create the SOAP Server object */ $server = new SOAP_Server_Email_Gateway('http://localhost/soap_interop/server_round2.php'); /* bind some classes to the server, so it can actually do something. These classes are part of the PEAR::SOAP library, and are based on the SOAPBuilder Interoperability tests. */ require_once 'SOAP/interop/server_round2_base.php'; require_once 'SOAP/interop/server_round2_groupB.php'; require_once 'SOAP/interop/server_round2_groupC.php'; /* Connect to a POP3 server and read the messages */ $pop3 =& new Net_POP3(); if ($pop3->connect('caraveo.com', 110)) { if ($pop3->login('caraveo-soap', 'roap')) { $listing = $pop3->getListing(); /* now loop through each message, and call the SOAP server with that message */ foreach ($listing as $msg) { $email = $pop3->getMsg($msg['msg_id']); /* this is where we actually handle the SOAP response. The SOAP::Server::Email class we are using will send the SOAP response to the sender via email. */ if ($email) $server->service($email); #$pop3->deleteMsg($msg['msg_id']); } } $pop3->disconnect(); } ?> Index: pear/SOAP/example/email_pop_server.php +++ pear/SOAP/example/email_pop_server.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 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_pop_server.php,v 1.1 2002/05/14 23:02:49 shane Exp $ // /* include the Email server class, which knows how to parse a standard email as a soap message */ require_once 'SOAP/Server/Email.php'; /* include a class to access POP3 */ require_once 'Net/POP3.php'; /* create the SOAP Server object */ $server = new SOAP_Server_Email; /* bind some classes to the server, so it can actually do something. These classes are part of the PEAR::SOAP library, and are based on the SOAPBuilder Interoperability tests. */ require_once 'SOAP/interop/server_round2_base.php'; require_once 'SOAP/interop/server_round2_groupB.php'; require_once 'SOAP/interop/server_round2_groupC.php'; /* Connect to a POP3 server and read the messages */ $pop3 =& new Net_POP3(); if ($pop3->connect('localhost', 110)) { if ($pop3->login('soap', 'password')) { $listing = $pop3->getListing(); /* now loop through each message, and call the SOAP server with that message */ foreach ($listing as $msg) { $email = $pop3->getMsg($msg['msg_id']); /* this is where we actually handle the SOAP response. The SOAP::Server::Email class we are using will send the SOAP response to the sender via email. */ if ($email) { $server->client($email); $pop3->deleteMsg($msg['msg_id']); } } } $pop3->disconnect(); } ?>
« previous php.pear.cvs (#3825) next »