Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 require_once('Mail/mimeDecode.php');
00037 require_once('Mail/mimePart.php');
00038
00049 class soapclientmime extends soap_client {
00050 var $requestAttachments = array();
00051 var $responseAttachments;
00052 var $mimeContentType;
00053
00069 function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
00070 if (! $cid) {
00071 $cid = md5(uniqid(time()));
00072 }
00073
00074 $info['data'] = $data;
00075 $info['filename'] = $filename;
00076 $info['contenttype'] = $contenttype;
00077 $info['cid'] = $cid;
00078
00079 $this->requestAttachments[] = $info;
00080
00081 return $cid;
00082 }
00083
00089 function clearAttachments() {
00090 $this->requestAttachments = array();
00091 }
00092
00103 function getAttachments() {
00104 return $this->responseAttachments;
00105 }
00106
00114 function getHTTPBody($soapmsg) {
00115 if (count($this->requestAttachments) > 0) {
00116 $params['content_type'] = 'multipart/related';
00117 $mimeMessage =& new Mail_mimePart('', $params);
00118 unset($params);
00119
00120 $params['content_type'] = 'text/xml';
00121 $params['encoding'] = '8bit';
00122 $params['charset'] = $this->soap_defencoding;
00123 $mimeMessage->addSubpart($soapmsg, $params);
00124
00125 foreach ($this->requestAttachments as $att) {
00126 unset($params);
00127
00128 $params['content_type'] = $att['contenttype'];
00129 $params['encoding'] = 'base64';
00130 $params['disposition'] = 'attachment';
00131 $params['dfilename'] = $att['filename'];
00132 $params['cid'] = $att['cid'];
00133
00134 if ($att['data'] == '' && $att['filename'] <> '') {
00135 if ($fd = fopen($att['filename'], 'rb')) {
00136 $data = fread($fd, filesize($att['filename']));
00137 fclose($fd);
00138 } else {
00139 $data = '';
00140 }
00141 $mimeMessage->addSubpart($data, $params);
00142 } else {
00143 $mimeMessage->addSubpart($att['data'], $params);
00144 }
00145 }
00146
00147 $output = $mimeMessage->encode();
00148 $mimeHeaders = $output['headers'];
00149
00150 foreach ($mimeHeaders as $k => $v) {
00151 $this->debug("MIME header $k: $v");
00152 if (strtolower($k) == 'content-type') {
00153
00154
00155 $this->mimeContentType = str_replace("\r\n", " ", $v);
00156 }
00157 }
00158
00159 return $output['body'];
00160 }
00161
00162 return parent::getHTTPBody($soapmsg);
00163 }
00164
00173 function getHTTPContentType() {
00174 if (count($this->requestAttachments) > 0) {
00175 return $this->mimeContentType;
00176 }
00177 return parent::getHTTPContentType();
00178 }
00179
00189 function getHTTPContentTypeCharset() {
00190 if (count($this->requestAttachments) > 0) {
00191 return false;
00192 }
00193 return parent::getHTTPContentTypeCharset();
00194 }
00195
00204 function parseResponse($headers, $data) {
00205 $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
00206 $this->responseAttachments = array();
00207 if (strstr($headers['content-type'], 'multipart/related')) {
00208 $this->debug('Decode multipart/related');
00209 $input = '';
00210 foreach ($headers as $k => $v) {
00211 $input .= "$k: $v\r\n";
00212 }
00213 $params['input'] = $input . "\r\n" . $data;
00214 $params['include_bodies'] = true;
00215 $params['decode_bodies'] = true;
00216 $params['decode_headers'] = true;
00217
00218 $structure = Mail_mimeDecode::decode($params);
00219
00220 foreach ($structure->parts as $part) {
00221 if (!isset($part->disposition)) {
00222 $this->debug('Have root part of type ' . $part->headers['content-type']);
00223 $return = parent::parseResponse($part->headers, $part->body);
00224 } else {
00225 $this->debug('Have an attachment of type ' . $part->headers['content-type']);
00226 $info['data'] = $part->body;
00227 $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
00228 $info['contenttype'] = $part->headers['content-type'];
00229 $info['cid'] = $part->headers['content-id'];
00230 $this->responseAttachments[] = $info;
00231 }
00232 }
00233
00234 if (isset($return)) {
00235 return $return;
00236 }
00237
00238 $this->setError('No root part found in multipart/related content');
00239 return;
00240 }
00241 $this->debug('Not multipart/related');
00242 return parent::parseResponse($headers, $data);
00243 }
00244 }
00245 ?>