SOAP--Server
[ class tree: SOAP--Server ] [ index: SOAP--Server ] [ all elements ]

Source for file Email.php

Documentation is available at Email.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more   |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Email.php,v 1.10 2003/05/18 00:57:40 shane Exp $
  20. //
  21.  
  22. require_once 'SOAP/Server.php';
  23. require_once 'SOAP/Client.php';
  24. require_once 'SOAP/Transport.php';
  25. require_once 'Mail/mimeDecode.php';
  26. /**
  27. *  SOAP_Server_Email
  28. * SOAP Server Class
  29. *
  30. * implements Email SOAP Server
  31. * http://www.pocketsoap.com/specs/smtpbinding/
  32. *
  33. * class overrides the default HTTP server, providing the ability
  34. * to parse an email message and execute soap calls.
  35. * this class DOES NOT pop the message, the message, complete
  36. * with headers, must be passed in as a parameter to the service
  37. * function call
  38. *
  39. @access   public
  40. @version  $Id: Email.php,v 1.10 2003/05/18 00:57:40 shane Exp $
  41. @package  SOAP::Server
  42. @author   Shane Caraveo <shane@php.net>
  43. */
  44. class SOAP_Server_Email extends SOAP_Server {
  45.     var $headers = array();
  46.     
  47.     function SOAP_Server_Email($send_response = TRUE)
  48.     {
  49.         parent::SOAP_Server();
  50.         $this->send_response $send_response;
  51.     }
  52.  
  53.     /**
  54.     * remove http headers from response
  55.     *
  56.     * TODO: use PEAR email classes
  57.     *
  58.     * @return boolean 
  59.     * @access private
  60.     */
  61.     function _parseEmail(&$data)
  62.     {
  63.         if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s"$data$match)) {
  64.             
  65.             if (preg_match_all('/^(.*?):\s+(.*)$/m'$match[1]$matches)) {
  66.                 $hc count($matches[0]);
  67.                 for ($i = 0; $i $hc$i++{
  68.                     $this->headers[strtolower($matches[1][$i])trim($matches[2][$i]);
  69.                 }
  70.             }
  71.  
  72.             if (!stristr($this->headers['content-type'],'text/xml')) {
  73.                     $this->_raiseSoapFault('Invalid Content Type','','','Client');
  74.                     return FALSE;
  75.             }
  76.             
  77.             if (strcasecmp($this->headers['content-transfer-encoding'],'base64')==0{
  78.                 // join lines back together
  79.                 $enctext preg_replace("/[\r|\n]/"''$match[2]);
  80.                 $data base64_decode($enctext);
  81.             #} else if (strcasecmp($this->headers['content-transfer-encoding'],'quoted-printable')==0) {
  82.             #    $data = $match[2];
  83.             #} else {
  84.             #    $this->_raiseSoapFault('Invalid Content-Transfer-Encoding','','','Client');
  85.             #    return FALSE;
  86.             #}
  87.             else {
  88.                 $data $match[2];
  89.             }
  90.             
  91.             // if no content, return false
  92.             return strlen($this->request> 0;
  93.         }
  94.         $this->_raiseSoapFault('Invalid Email Format','','','Client');
  95.         return FALSE;
  96.     }
  97.  
  98.     function client(&$data)
  99.     {
  100.         $attachments = array();
  101.  
  102.         # if neither matches, we'll just try it anyway
  103.         if (stristr($data,'Content-Type: application/dime')) {
  104.             $this->_decodeDIMEMessage($data,$this->headers,$attachments);
  105.             $useEncoding 'DIME';
  106.         else if (stristr($data,'MIME-Version:')) {
  107.             // this is a mime message, lets decode it.
  108.             #$data = 'Content-Type: '.stripslashes($_SERVER['CONTENT_TYPE'])."\r\n\r\n".$data;
  109.             $this->_decodeMimeMessage($data,$this->headers,$attachments);
  110.             $useEncoding 'Mime';
  111.         else {
  112.             // the old fallback, but decodeMimeMessage handles things fine.
  113.             $this->_parseEmail($data);
  114.         }
  115.         
  116.         // get the character encoding of the incoming request
  117.         // treat incoming data as UTF-8 if no encoding set
  118.         if (!$this->soapfault && !$this->_getContentEncoding($this->headers['content-type'])) {
  119.             $this->xml_encoding = SOAP_DEFAULT_ENCODING;
  120.             // an encoding we don't understand, return a fault
  121.             $this->_raiseSoapFault('Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8','','','Server');
  122.         }
  123.         
  124.         if ($this->soapfault{
  125.             return $this->soapfault->getFault();
  126.         }
  127.         $client =new SOAP_Client(NULL);
  128.         return $client->__parse($data$this->xml_encoding$this->attachments);
  129.     }
  130.     
  131.     function service(&$data$endpoint ''$send_response = TRUE$dump = FALSE)
  132.     {
  133.         $this->endpoint = $endpoint;
  134.         $attachments = array();
  135.         $headers = array();
  136.  
  137.         # if neither matches, we'll just try it anyway
  138.         if (stristr($data,'Content-Type: application/dime')) {
  139.             $this->_decodeDIMEMessage($data,$this->headers,$attachments);
  140.             $useEncoding 'DIME';
  141.         else if (stristr($data,'MIME-Version:')) {
  142.             // this is a mime message, lets decode it.
  143.             #$data = 'Content-Type: '.stripslashes($_SERVER['CONTENT_TYPE'])."\r\n\r\n".$data;
  144.             $this->_decodeMimeMessage($data,$this->headers,$attachments);
  145.             $useEncoding 'Mime';
  146.         else {
  147.             // the old fallback, but decodeMimeMessage handles things fine.
  148.             $this->_parseEmail($data);
  149.         }
  150.         
  151.         // get the character encoding of the incoming request
  152.         // treat incoming data as UTF-8 if no encoding set
  153.         if (!$response && !$this->_getContentEncoding($this->headers['content-type'])) {
  154.             $this->xml_encoding = SOAP_DEFAULT_ENCODING;
  155.             // an encoding we don't understand, return a fault
  156.             $this->_raiseSoapFault('Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8','','','Server');
  157.             $response $this->getFaultMessage();                
  158.         }
  159.         
  160.         if ($this->soapfault{
  161.             $response $this->soapfault->message();
  162.         else {
  163.             $soap_msg $this->parseRequest($data,$attachments);
  164.             
  165.             // handle Mime or DIME encoding
  166.             // XXX DIME Encoding should move to the transport, do it here for now
  167.             // and for ease of getting it done
  168.             if (count($this->__attachments)) {
  169.                 if ($useEncoding == 'Mime'{
  170.                     $soap_msg $this->_makeMimeMessage($soap_msg);
  171.                 else {
  172.                     // default is dime
  173.                     $soap_msg $this->_makeDIMEMessage($soap_msg);
  174.                     $header['Content-Type''application/dime';
  175.                 }
  176.                 if (PEAR::isError($soap_msg)) {
  177.                     return $this->raiseSoapFault($soap_msg);
  178.                 }
  179.             }
  180.             
  181.             if (is_array($soap_msg)) {
  182.                 $response $soap_msg['body'];
  183.                 if (count($soap_msg['headers'])) {
  184.                     $headers $soap_msg['headers'];
  185.                 }
  186.             else {
  187.                 $response $soap_msg;
  188.             }
  189.         }
  190.  
  191.         if ($this->send_response{        
  192.             if ($dump{
  193.                 print $response;
  194.             else {
  195.                 $from array_key_exists('reply-to',$this->headers$this->headers['reply-to']:$this->headers['from'];
  196.                 # XXX what if no from?????
  197.                 
  198.                 $soap_transport =SOAP_Transport::getTransport('mailto:'.$from$this->response_encoding);
  199.                 $from $this->endpoint ? $this->endpoint : $this->headers['to'];
  200.                 $headers['In-Reply-To']=$this->headers['message-id'];
  201.                 $options = array('from' => $from'subject'=> $this->headers['subject']'headers' => $headers);
  202.                 $soap_transport->send($response$options);
  203.             }
  204.         }
  205.     }    
  206. }
  207.  
  208. ?>

Documentation generated on Mon, 11 Mar 2019 13:59:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.