Example #1
0
 /**
  * gets the HTTP body for the current request.
  *
  * @param string $soapmsg The SOAP payload
  * @return string The HTTP body, which includes the SOAP payload
  * @access private
  */
 function getHTTPBody($soapmsg)
 {
     if (count($this->requestAttachments) > 0) {
         $params['content_type'] = 'multipart/related; type="text/xml"';
         $mimeMessage = new Mail_mimePart('', $params);
         unset($params);
         $params['content_type'] = 'text/xml';
         $params['encoding'] = '8bit';
         $params['charset'] = $this->soap_defencoding;
         $mimeMessage->addSubpart($soapmsg, $params);
         foreach ($this->requestAttachments as $att) {
             unset($params);
             $params['content_type'] = $att['contenttype'];
             $params['encoding'] = 'base64';
             $params['disposition'] = 'attachment';
             $params['dfilename'] = $att['filename'];
             $params['cid'] = $att['cid'];
             if ($att['data'] == '' && $att['filename'] != '') {
                 if ($fd = fopen($att['filename'], 'rb')) {
                     $data = fread($fd, filesize($att['filename']));
                     fclose($fd);
                 } else {
                     $data = '';
                 }
                 $mimeMessage->addSubpart($data, $params);
             } else {
                 $mimeMessage->addSubpart($att['data'], $params);
             }
         }
         $output = $mimeMessage->encode();
         $mimeHeaders = $output['headers'];
         foreach ($mimeHeaders as $k => $v) {
             $this->debug("MIME header {$k}: {$v}");
             if (strtolower($k) == 'content-type') {
                 // PHP header() seems to strip leading whitespace starting
                 // the second line, so force everything to one line
                 $this->mimeContentType = str_replace("\r\n", " ", $v);
             }
         }
         return $output['body'];
     }
     return parent::getHTTPBody($soapmsg);
 }