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
00053 class soapclientmime extends soap_client {
00054 var $requestAttachments = array();
00055 var $responseAttachments;
00056 var $mimeContentType;
00057
00073 function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
00074 if (! $cid) {
00075 $cid = md5(uniqid(time()));
00076 }
00077
00078 $info['data'] = $data;
00079 $info['filename'] = $filename;
00080 $info['contenttype'] = $contenttype;
00081 $info['cid'] = $cid;
00082
00083 $this->requestAttachments[] = $info;
00084
00085 return $cid;
00086 }
00087
00093 function clearAttachments() {
00094 $this->requestAttachments = array();
00095 }
00096
00107 function getAttachments() {
00108 return $this->responseAttachments;
00109 }
00110
00118 function getHTTPBody($soapmsg) {
00119 if (count($this->requestAttachments) > 0) {
00120 $params['content_type'] = 'multipart/related';
00121 $mimeMessage =& new Mail_mimePart('', $params);
00122 unset($params);
00123
00124 $params['content_type'] = 'text/xml';
00125 $params['encoding'] = '8bit';
00126 $params['charset'] = $this->soap_defencoding;
00127 $mimeMessage->addSubpart($soapmsg, $params);
00128
00129 foreach ($this->requestAttachments as $att) {
00130 unset($params);
00131
00132 $params['content_type'] = $att['contenttype'];
00133 $params['encoding'] = 'base64';
00134 $params['disposition'] = 'attachment';
00135 $params['dfilename'] = $att['filename'];
00136 $params['cid'] = $att['cid'];
00137
00138 if ($att['data'] == '' && $att['filename'] <> '') {
00139 if ($fd = fopen($att['filename'], 'rb')) {
00140 $data = fread($fd, filesize($att['filename']));
00141 fclose($fd);
00142 } else {
00143 $data = '';
00144 }
00145 $mimeMessage->addSubpart($data, $params);
00146 } else {
00147 $mimeMessage->addSubpart($att['data'], $params);
00148 }
00149 }
00150
00151 $output = $mimeMessage->encode();
00152 $mimeHeaders = $output['headers'];
00153
00154 foreach ($mimeHeaders as $k => $v) {
00155 $this->debug("MIME header $k: $v");
00156 if (strtolower($k) == 'content-type') {
00157
00158
00159 $this->mimeContentType = str_replace("\r\n", " ", $v);
00160 }
00161 }
00162
00163 return $output['body'];
00164 }
00165
00166 return parent::getHTTPBody($soapmsg);
00167 }
00168
00177 function getHTTPContentType() {
00178 if (count($this->requestAttachments) > 0) {
00179 return $this->mimeContentType;
00180 }
00181 return parent::getHTTPContentType();
00182 }
00183
00193 function getHTTPContentTypeCharset() {
00194 if (count($this->requestAttachments) > 0) {
00195 return false;
00196 }
00197 return parent::getHTTPContentTypeCharset();
00198 }
00199
00208 function parseResponse($headers, $data) {
00209 $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
00210 $this->responseAttachments = array();
00211 if (strstr($headers['content-type'], 'multipart/related')) {
00212 $this->debug('Decode multipart/related');
00213 $input = '';
00214 foreach ($headers as $k => $v) {
00215 $input .= "$k: $v\r\n";
00216 }
00217 $params['input'] = $input . "\r\n" . $data;
00218 $params['include_bodies'] = true;
00219 $params['decode_bodies'] = true;
00220 $params['decode_headers'] = true;
00221
00222 $structure = Mail_mimeDecode::decode($params);
00223
00224 foreach ($structure->parts as $part) {
00225 if (!isset($part->disposition)) {
00226 $this->debug('Have root part of type ' . $part->headers['content-type']);
00227 $return = parent::parseResponse($part->headers, $part->body);
00228 } else {
00229 $this->debug('Have an attachment of type ' . $part->headers['content-type']);
00230 $info['data'] = $part->body;
00231 $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
00232 $info['contenttype'] = $part->headers['content-type'];
00233 $info['cid'] = $part->headers['content-id'];
00234 $this->responseAttachments[] = $info;
00235 }
00236 }
00237
00238 if (isset($return)) {
00239 return $return;
00240 }
00241
00242 $this->setError('No root part found in multipart/related content');
00243 return;
00244 }
00245 $this->debug('Not multipart/related');
00246 return parent::parseResponse($headers, $data);
00247 }
00248 }
00249 ?>