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

Documentation generated on Mon, 11 Mar 2019 14:20:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.