Public Member Functions | Data Fields

ilBMFTransport_SMTP Class Reference

Inheritance diagram for ilBMFTransport_SMTP:
Collaboration diagram for ilBMFTransport_SMTP:

Public Member Functions

 ilBMFTransport_SMTP ($URL, $encoding='US-ASCII')
 ilBMFTransport_SMTP Constructor
 send (&$msg, $options=NULL)
 send and receive soap data
 setCredentials ($username, $password)
 set data for http authentication creates Authorization header
 _validateUrl ()
 validate url data passed to constructor

Data Fields

 $credentials = ''
 $timeout = 4
 $urlparts = NULL
 $url = ''
 $incoming_payload = ''
 $_userAgent = SOAP_LIBRARY_NAME
 $encoding = SOAP_DEFAULT_ENCODING
 $host = '127.0.0.1'
 $port = 25
 $auth = NULL

Detailed Description

Definition at line 46 of file class.ilBMFTransport_SMTP.php.


Member Function Documentation

ilBMFTransport_SMTP::_validateUrl (  ) 

validate url data passed to constructor

Returns:
boolean private

Definition at line 198 of file class.ilBMFTransport_SMTP.php.

References ilBMFBase::_raiseSoapFault().

Referenced by send().

    {
        if ( ! is_array($this->urlparts) ) {
            $this->_raiseSoapFault("Unable to parse URL $url");
            return FALSE;
        }
        if (!isset($this->urlparts['scheme']) ||
            strcasecmp($this->urlparts['scheme'], 'mailto') != 0) {
                $this->_raiseSoapFault("Unable to parse URL $url");
                return FALSE;
        }
        if (!isset($this->urlparts['path'])) {
            $this->_raiseSoapFault("Unable to parse URL $url");
            return FALSE;
        }
        return TRUE;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

ilBMFTransport_SMTP::ilBMFTransport_SMTP ( URL,
encoding = 'US-ASCII' 
)

ilBMFTransport_SMTP Constructor

Parameters:
string $URL mailto:address

public

Definition at line 65 of file class.ilBMFTransport_SMTP.php.

References $encoding, and ilBMFBase::ilBMFBase().

    {
        parent::ilBMFBase('SMTP');
        $this->encoding = $encoding;
        $this->urlparts = @parse_url($URL);
        $this->url = $URL;
    }

Here is the call graph for this function:

ilBMFTransport_SMTP::send ( &$  msg,
options = NULL 
)

send and receive soap data

Parameters:
string &$msg outgoing post data
string $action SOAP Action header data
int $timeout socket timeout, default 0 or off
Returns:
string &$response response data, minus http headers public

Definition at line 83 of file class.ilBMFTransport_SMTP.php.

References $key, $namespace, $result, ilBMFBase::_makeEnvelope(), ilBMFBase::_raiseSoapFault(), and _validateUrl().

    {
        $this->outgoing_payload = &$msg;
        if (!$this->_validateUrl()) {
            return $this->fault;
        }
        if (!$options || !array_key_exists('from',$options)) {
            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']}\"";
        }
        
        if (isset($options['headers']))
            $headers = array_merge($headers, $options['headers']);
        
        // if the content type is already set, we assume that Mime encoding
        // is already done
        if (isset($headers['Content-Type'])) {
            $out = $msg;
        } else {
            // do a simple inline Mime encoding
            $headers['Content-Disposition'] = 'inline';
            $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'];
                    $out = &$msg;
                } else if (strcasecmp($options['transfer-encoding'],'base64')==0) {
                    $headers['Content-Transfer-Encoding'] = 'base64';
                    $out = chunk_split(base64_encode($msg),76,"\n");
                } else {
                    return $this->_raiseSoapFault("Invalid Transfer Encoding: {$options['transfer-encoding']}");
                }
            } else {
                // default to base64
                $headers['Content-Transfer-Encoding'] = 'base64';
                $out = chunk_split(base64_encode($msg));
            }
        }
        
        $headers['Subject'] = array_key_exists('subject', $options) ? $options['subject'] : 'SOAP Message';
        
        foreach ($headers as $key => $value) {
            $header_text .= "$key: $value\n";
        }
        $this->outgoing_payload = $header_text."\r\n".$this->outgoing_payload;
        # we want to return a proper XML message
        
        $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 (!PEAR::isError($result)) {
            $val = new ilBMFValue('Message-ID','string',$headers['Message-ID']);
        } else {
            $val = new ilBMFValue('Fault','Struct',array(
                new ilBMFValue('faultcode','QName','SOAP-ENV:Client'),
                new ilBMFValue('faultstring','string',"couldn't send SMTP message to {$this->urlparts['path']}")
                ));
        }

        $mqname = new QName($method, $namespace);
        $methodValue = new ilBMFValue('Response', 'Struct', array($val));
        $return_msg = $this->_makeEnvelope($methodValue, $this->headers, $this->encoding);

        $this->incoming_payload = $return_msg;

        return $this->incoming_payload;
    }

Here is the call graph for this function:

ilBMFTransport_SMTP::setCredentials ( username,
password 
)

set data for http authentication creates Authorization header

Parameters:
string $username username
string $password response data, minus http headers
Returns:
none public

Definition at line 184 of file class.ilBMFTransport_SMTP.php.

    {
        $this->username = $username;
        $this->password = $password;
    }


Field Documentation

ilBMFTransport_SMTP::$_userAgent = SOAP_LIBRARY_NAME

Definition at line 53 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$auth = NULL

Definition at line 57 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$credentials = ''

Definition at line 48 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$encoding = SOAP_DEFAULT_ENCODING

Definition at line 54 of file class.ilBMFTransport_SMTP.php.

Referenced by ilBMFTransport_SMTP().

ilBMFTransport_SMTP::$host = '127.0.0.1'

Definition at line 55 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$incoming_payload = ''

Definition at line 52 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$port = 25

Definition at line 56 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$timeout = 4

Definition at line 49 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$url = ''

Definition at line 51 of file class.ilBMFTransport_SMTP.php.

ilBMFTransport_SMTP::$urlparts = NULL

Definition at line 50 of file class.ilBMFTransport_SMTP.php.


The documentation for this class was generated from the following file: