コード例 #1
0
ファイル: DecodeTest.php プロジェクト: Tony133/zf-web
 public function testSplitHeaderFieldReturnsArrayWithFirstName()
 {
     $boundary = "----=_Alternative_1211565553483705f1280701.15526894A";
     $header = "Content-Type: multipart/alternative; " . "boundary=\"{$boundary}\"";
     $split = Zend_Mime_Decode::splitHeaderField($header, null, 'content-type');
     $this->assertEquals(2, count($split));
     $this->assertTrue(isset($split['content-type']), "'content-type' element is set");
     $this->assertEquals($boundary, $split['boundary']);
 }
コード例 #2
0
ファイル: Part.php プロジェクト: bartolomeu/estoque_gusella
 /**
  * Get a specific field from a header like content type or all fields as array
  *
  * If the header occurs more than once, only the value from the first header
  * is returned.
  *
  * Throws a Zend_Mail_Exception if the requested header does not exist. If
  * the specific header field does not exist, returns null.
  *
  * @param  string $name       name of header, like in getHeader()
  * @param  string $wantedPart the wanted part, default is first, if null an array with all parts is returned
  * @param  string $firstName  key name for the first part
  * @return string|array wanted part or all parts as array($firstName => firstPart, partname => value)
  * @throws Zend_Exception, Zend_Mail_Exception
  */
 public function getHeaderField($name, $wantedPart = 0, $firstName = 0)
 {
     return Zend_Mime_Decode::splitHeaderField(current($this->getHeader($name, 'array')), $wantedPart, $firstName);
 }
コード例 #3
0
 /**
  * get meta data (like contentype, charset, ...) from zmm and set it in zmp
  * 
  * @param Zend_Mail_Message $zmm
  * @param Zend_Mime_Part $zmp
  */
 protected static function _getMetaDataFromZMM(Zend_Mail_Message $zmm, Zend_Mime_Part $zmp)
 {
     if ($zmm->headerExists('content-transfer-encoding')) {
         $zmp->encoding = $zmm->getHeader('content-transfer-encoding');
     } else {
         $zmp->encoding = Zend_Mime::ENCODING_7BIT;
     }
     if ($zmm->headerExists('content-type')) {
         $contentTypeHeader = Zend_Mime_Decode::splitHeaderField($zmm->getHeader('content-type'));
         $zmp->type = $contentTypeHeader[0];
         if (isset($contentTypeHeader['boundary'])) {
             $zmp->boundary = $contentTypeHeader['boundary'];
         }
         if (isset($contentTypeHeader['charset'])) {
             $zmp->charset = $contentTypeHeader['charset'];
         }
     } else {
         $zmp->type = Zend_Mime::TYPE_TEXT;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Encoding: ' . $zmp->encoding . ' / type: ' . $zmp->type . ' / charset: ' . $zmp->charset);
     }
 }
コード例 #4
0
 public function testSplitInvalidHeader()
 {
     $header = '';
     try {
         Zend_Mime_Decode::splitHeaderField($header);
     } catch (Zend_Exception $e) {
         return;
         // ok
     }
     $this->fail('no exception raised while decoding invalid header field');
 }
コード例 #5
0
 public function testSpaceInFieldName()
 {
     $header = 'test; foo =bar; baz      =42';
     $this->assertEquals(Zend_Mime_Decode::splitHeaderField($header, 'foo'), 'bar');
     $this->assertEquals(Zend_Mime_Decode::splitHeaderField($header, 'baz'), 42);
 }
コード例 #6
0
 public function testCaseInsensitiveField()
 {
     $header = 'test; fOO="this is a test"';
     $this->assertEquals(Zend_Mime_Decode::splitHeaderField($header, 'Foo'), 'this is a test');
     $this->assertEquals(Zend_Mime_Decode::splitHeaderField($header, 'bar'), null);
 }
コード例 #7
0
 /**
  * create Tinebase_Mail from Zend_Mail_Message
  * 
  * @param  Zend_Mail_Message  $_zmm
  * @param  string             $_replyBody
  * @return Tinebase_Mail
  */
 public static function createFromZMM(Zend_Mail_Message $_zmm, $_replyBody = null)
 {
     $contentStream = fopen("php://temp", 'r+');
     if (preg_match('/application\\/(x\\-){0,1}pkcs7-mime/i', $_zmm->getHeader('content-type')) > 0) {
         $mp = new Zend_Mime_Part($_zmm->getContent());
     } else {
         fputs($contentStream, $_zmm->getContent());
         rewind($contentStream);
         $mp = new Zend_Mime_Part($contentStream);
     }
     if ($_zmm->headerExists('content-transfer-encoding')) {
         $mp->encoding = $_zmm->getHeader('content-transfer-encoding');
         $mp->decodeContent();
     } else {
         $mp->encoding = Zend_Mime::ENCODING_7BIT;
     }
     // append old body when no multipart/mixed
     if ($_replyBody !== null && $_zmm->headerExists('content-transfer-encoding')) {
         $mp = self::_appendReplyBody($mp, $_replyBody);
         $mp->encoding = $_zmm->getHeader('content-transfer-encoding');
     }
     if ($_zmm->headerExists('content-type')) {
         $contentTypeHeader = Zend_Mime_Decode::splitHeaderField($_zmm->getHeader('content-type'));
         if ($mp->type = strtolower($contentTypeHeader[0]) === 'application/pkcs7-mime') {
             $mp->type = $_zmm->getHeader('content-type');
         } else {
             $mp->type = $contentTypeHeader[0];
         }
         if (isset($contentTypeHeader['boundary'])) {
             $mp->boundary = $contentTypeHeader['boundary'];
         }
         if (isset($contentTypeHeader['charset'])) {
             $mp->charset = $contentTypeHeader['charset'];
         }
     } else {
         $mp->type = Zend_Mime::TYPE_TEXT;
     }
     $result = new Expressomail_Mail('utf-8');
     $result->setBodyText($mp);
     foreach ($_zmm->getHeaders() as $header => $values) {
         foreach ((array) $values as $value) {
             switch ($header) {
                 case 'content-transfer-encoding':
                     // these are implicitly set by Zend_Mail_Transport_Abstract::_getHeaders()
                 // these are implicitly set by Zend_Mail_Transport_Abstract::_getHeaders()
                 case 'content-type':
                 case 'mime-version':
                     // do nothing
                     break;
                 case 'bcc':
                     $addresses = Expressomail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->addBcc($address['address'], $address['name']);
                     }
                     break;
                 case 'cc':
                     $addresses = Expressomail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->addCc($address['address'], $address['name']);
                     }
                     break;
                 case 'date':
                     try {
                         $result->setDate($value);
                     } catch (Zend_Mail_Exception $zme) {
                         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Could not set date: " . $value);
                         }
                         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " " . $zme);
                         }
                         $result->setDate();
                     }
                     break;
                 case 'from':
                     $addresses = Expressomail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->setFrom($address['address'], $address['name']);
                     }
                     break;
                 case 'message-id':
                     $result->setMessageId($value);
                     break;
                 case 'return-path':
                     $result->setReturnPath($value);
                     break;
                 case 'subject':
                     $result->setSubject($value);
                     break;
                 case 'to':
                     $addresses = Expressomail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->addTo($address['address'], $address['name']);
                     }
                     break;
                 default:
                     $result->addHeader($header, $value);
                     break;
             }
         }
     }
     return $result;
 }