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

Source for file Email_Gateway.php

Documentation is available at Email_Gateway.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_Gateway.php,v 1.9 2003/05/18 00:57:40 shane Exp $
  20. //
  21.  
  22. require_once 'SOAP/Server/Email.php';
  23. require_once 'SOAP/Transport.php';
  24.  
  25. /**
  26. *  SOAP_Server_Email
  27. * SOAP Server Class
  28. *
  29. * implements Email SOAP Server
  30. * http://www.pocketsoap.com/specs/smtpbinding/
  31. *
  32. * class overrides the default HTTP server, providing the ability
  33. * to parse an email message and execute soap calls.
  34. * this class DOES NOT pop the message, the message, complete
  35. * with headers, must be passed in as a parameter to the service
  36. * function call
  37. *
  38. * This class calls a provided HTTP SOAP server, forwarding
  39. * the email request, then sending the HTTP response out as an
  40. * email
  41. *
  42. @access   public
  43. @version  $Id: Email_Gateway.php,v 1.9 2003/05/18 00:57:40 shane Exp $
  44. @package  SOAP::Server
  45. @author   Shane Caraveo <shane@php.net>
  46. */
  47. {
  48.     var $gateway = NULL;
  49.     var $dump = FALSE;
  50.     
  51.     function SOAP_Server_Email_Gateway($gateway ''$send_response = TRUE$dump=FALSE)
  52.     {
  53.         parent::SOAP_Server();
  54.         $this->send_response $send_response;
  55.         $this->gateway = $gateway;
  56.         $this->dump = $dump;
  57.     }
  58.     
  59.     function service(&$data$gateway=''$endpoint ''$send_response = TRUE$dump = FALSE)
  60.     {
  61.         $this->endpoint = $endpoint;
  62.         $response '';
  63.         $useEncoding='Mime';
  64.         $options = array();
  65.         if (!$gateway$gateway $this->gateway;
  66.         
  67.         // we have a full set of headers, need to find the first blank line
  68.         $this->_parseEmail($data);
  69.         if ($this->fault{
  70.             $response $this->fault->message();
  71.         }
  72.         if ($this->headers['content-type']=='application/dime')
  73.             $useEncoding='DIME';
  74.         
  75.         # call the HTTP Server
  76.         if (!$response{
  77.             $soap_transport =SOAP_Transport::getTransport($gateway$this->xml_encoding);
  78.             if ($soap_transport->fault{
  79.                 $response $soap_transport->fault->message();
  80.             }
  81.         }
  82.         
  83.         // send the message
  84.         if (!$response{
  85.             $options['soapaction'$this->headers['soapaction'];
  86.             $options['headers']['Content-Type'$this->headers['content-type'];
  87.             
  88.             $response $soap_transport->send($data$options);
  89.             if (isset($this->headers['mime-version']))
  90.                 $options['headers']['MIME-Version'$this->headers['mime-version'];
  91.             
  92.             if ($soap_transport->fault{
  93.                 $response $soap_transport->fault->message();
  94.             else {
  95.                 foreach ($soap_transport->transport->attachments as $cid=>$body{
  96.                     $this->attachments[= array('body' => $body'cid' => $cid'encoding' => 'base64');
  97.                 }
  98.                 if (count($this->__attachments)) {
  99.                     if ($useEncoding == 'Mime'{
  100.                         $soap_msg $this->_makeMimeMessage($response);
  101.                         $options['headers']['MIME-Version''1.0';
  102.                     else {
  103.                         // default is dime
  104.                         $soap_msg $this->_makeDIMEMessage($response);
  105.                         $options['headers']['Content-Type''application/dime';
  106.                     }
  107.                     if (PEAR::isError($soap_msg)) {
  108.                         return $this->_raiseSoapFault($soap_msg);
  109.                     }
  110.                     if (is_array($soap_msg)) {
  111.                         $response $soap_msg['body'];
  112.                         if (count($soap_msg['headers'])) {
  113.                             if (isset($options['headers'])) {
  114.                                 $options['headers'array_merge($options['headers'],$soap_msg['headers']);
  115.                             else {
  116.                                 $options['headers'$soap_msg['headers'];
  117.                             }
  118.                         }
  119.                     }
  120.                 }
  121.             }
  122.         }
  123.         
  124.         if ($this->send_response{        
  125.             if ($this->dump || $dump{
  126.                 print $response;
  127.             else {
  128.                 $from array_key_exists('reply-to',$this->headers$this->headers['reply-to']:$this->headers['from'];
  129.                 # XXX what if no from?????
  130.                 
  131.                 $soap_transport =SOAP_Transport::getTransport('mailto:'.$from$this->response_encoding);
  132.                 $from $this->endpoint ? $this->endpoint : $this->headers['to'];
  133.                 $headers = array('In-Reply-To'=>$this->headers['message-id']);
  134.                 $options = array('from' => $from'subject'=> $this->headers['subject']'headers' => $headers);
  135.                 $soap_transport->send($response$options);
  136.             }
  137.         }
  138.     }    
  139. }
  140.  
  141. ?>

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