36 require_once(
'Mail/mimeDecode.php');
37 require_once(
'Mail/mimePart.php');
84 $cid = md5(uniqid(time()));
87 $info[
'data'] =
$data;
89 $info[
'contenttype'] = $contenttype;
92 $this->requestAttachments[] = $info;
103 $this->requestAttachments = array();
128 if (count($this->requestAttachments) > 0) {
129 $params[
'content_type'] =
'multipart/related; type=text/xml';
130 $mimeMessage =&
new Mail_mimePart(
'',
$params);
133 $params[
'content_type'] =
'text/xml';
136 $mimeMessage->addSubpart($soapmsg,
$params);
138 foreach ($this->requestAttachments as $att) {
141 $params[
'content_type'] = $att[
'contenttype'];
142 $params[
'encoding'] =
'base64';
143 $params[
'disposition'] =
'attachment';
144 $params[
'dfilename'] = $att[
'filename'];
147 if ($att[
'data'] ==
'' && $att[
'filename'] <>
'') {
148 if ($fd = fopen($att[
'filename'],
'rb')) {
149 $data = fread($fd, filesize($att[
'filename']));
156 $mimeMessage->addSubpart($att[
'data'],
$params);
160 $output = $mimeMessage->encode();
161 $mimeHeaders = $output[
'headers'];
163 foreach ($mimeHeaders as $k => $v) {
164 $this->
debug(
"MIME header $k: $v");
165 if (strtolower($k) ==
'content-type') {
168 $this->mimeContentType = str_replace(
"\r\n",
" ", $v);
172 return $output[
'body'];
187 if (count($this->requestAttachments) > 0) {
203 if (count($this->requestAttachments) > 0) {
218 $this->
debug(
'Entering parseResponse() for payload of length ' . strlen(
$data) .
' and type of ' . $headers[
'content-type']);
219 $this->responseAttachments = array();
220 if (strstr($headers[
'content-type'],
'multipart/related')) {
221 $this->
debug(
'Decode multipart/related');
223 foreach ($headers as $k => $v) {
224 $input .=
"$k: $v\r\n";
227 $params[
'include_bodies'] =
true;
228 $params[
'decode_bodies'] =
true;
229 $params[
'decode_headers'] =
true;
231 $structure = Mail_mimeDecode::decode(
$params);
233 foreach ($structure->parts as $part) {
234 if (!isset($part->disposition)) {
235 $this->
debug(
'Have root part of type ' . $part->headers[
'content-type']);
238 $this->
debug(
'Have an attachment of type ' . $part->headers[
'content-type']);
239 $info[
'data'] = $part->body;
240 $info[
'filename'] = isset($part->d_parameters[
'filename']) ? $part->d_parameters[
'filename'] :
'';
241 $info[
'contenttype'] = $part->headers[
'content-type'];
242 $info[
'cid'] = $part->headers[
'content-id'];
243 $this->responseAttachments[] = $info;
247 if (isset($return)) {
251 $this->
setError(
'No root part found in multipart/related content');
254 $this->
debug(
'Not multipart/related');
304 $cid = md5(uniqid(time()));
307 $info[
'data'] =
$data;
309 $info[
'contenttype'] = $contenttype;
312 $this->responseAttachments[] = $info;
323 $this->responseAttachments = array();
348 if (count($this->responseAttachments) > 0) {
349 $params[
'content_type'] =
'multipart/related; type=text/xml';
350 $mimeMessage =&
new Mail_mimePart(
'',
$params);
353 $params[
'content_type'] =
'text/xml';
356 $mimeMessage->addSubpart($soapmsg,
$params);
358 foreach ($this->responseAttachments as $att) {
361 $params[
'content_type'] = $att[
'contenttype'];
362 $params[
'encoding'] =
'base64';
363 $params[
'disposition'] =
'attachment';
364 $params[
'dfilename'] = $att[
'filename'];
367 if ($att[
'data'] ==
'' && $att[
'filename'] <>
'') {
368 if ($fd = fopen($att[
'filename'],
'rb')) {
369 $data = fread($fd, filesize($att[
'filename']));
376 $mimeMessage->addSubpart($att[
'data'],
$params);
380 $output = $mimeMessage->encode();
381 $mimeHeaders = $output[
'headers'];
383 foreach ($mimeHeaders as $k => $v) {
384 $this->
debug(
"MIME header $k: $v");
385 if (strtolower($k) ==
'content-type') {
388 $this->mimeContentType = str_replace(
"\r\n",
" ", $v);
392 return $output[
'body'];
407 if (count($this->responseAttachments) > 0) {
423 if (count($this->responseAttachments) > 0) {
438 $this->
debug(
'Entering parseRequest() for payload of length ' . strlen(
$data) .
' and type of ' .
$headers[
'content-type']);
439 $this->requestAttachments = array();
440 if (strstr($headers[
'content-type'],
'multipart/related')) {
441 $this->
debug(
'Decode multipart/related');
443 foreach ($headers as $k => $v) {
444 $input .=
"$k: $v\r\n";
447 $params[
'include_bodies'] =
true;
448 $params[
'decode_bodies'] =
true;
449 $params[
'decode_headers'] =
true;
451 $structure = Mail_mimeDecode::decode(
$params);
453 foreach ($structure->parts as $part) {
454 if (!isset($part->disposition)) {
455 $this->
debug(
'Have root part of type ' . $part->headers[
'content-type']);
458 $this->
debug(
'Have an attachment of type ' . $part->headers[
'content-type']);
459 $info[
'data'] = $part->body;
460 $info[
'filename'] = isset($part->d_parameters[
'filename']) ? $part->d_parameters[
'filename'] :
'';
461 $info[
'contenttype'] = $part->headers[
'content-type'];
462 $info[
'cid'] = $part->headers[
'content-id'];
463 $this->requestAttachments[] = $info;
467 if (isset($return)) {
471 $this->
setError(
'No root part found in multipart/related content');
474 $this->
debug(
'Not multipart/related');