/** * Decodes a MIME encoded string and returns a Zend_Mime_Message object with * all the MIME parts set according to the given string * * @param string $message * @param string $boundary * @param string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND} * @throws Exception\RuntimeException * @return \Zend\Mime\Message */ public static function createFromMessage($message, $boundary, $EOL = Mime::LINEEND) { $parts = Decode::splitMessageStruct($message, $boundary, $EOL); $res = new static(); foreach ($parts as $part) { // now we build a new MimePart for the current Message Part: $newPart = new Part($part['body']); foreach ($part['header'] as $header) { /** @var \Zend\Mail\Header\HeaderInterface $header */ /** * @todo check for characterset and filename */ $fieldName = $header->getFieldName(); $fieldValue = $header->getFieldValue(); switch (strtolower($fieldName)) { case 'content-type': $newPart->type = $fieldValue; break; case 'content-transfer-encoding': $newPart->encoding = $fieldValue; break; case 'content-id': $newPart->id = trim($fieldValue, '<>'); break; case 'content-disposition': $newPart->disposition = $fieldValue; break; case 'content-description': $newPart->description = $fieldValue; break; case 'content-location': $newPart->location = $fieldValue; break; case 'content-language': $newPart->language = $fieldValue; break; default: throw new Exception\RuntimeException('Unknown header ignored for MimePart:' . $fieldName); } } $res->addPart($newPart); } return $res; }
/** * Decodes a MIME encoded string and returns a Zend\Mime\Message object with * all the MIME parts set according to the given string * * @param string $message * @param string $boundary * @param string $EOL EOL string; defaults to {@link Zend\Mime\Mime::LINEEND} * @throws Exception\RuntimeException * @return \Zend\Mime\Message */ public static function createFromMessage($message, $boundary, $EOL = Mime::LINEEND) { $parts = Decode::splitMessageStruct($message, $boundary, $EOL); $res = new static(); foreach ($parts as $part) { // now we build a new MimePart for the current Message Part: $properties = array(); foreach ($part['header'] as $header) { /** @var \Zend\Mail\Header\HeaderInterface $header */ /** * @todo check for characterset and filename */ $fieldName = $header->getFieldName(); $fieldValue = $header->getFieldValue(); switch (strtolower($fieldName)) { case 'content-type': $properties['type'] = $fieldValue; break; case 'content-transfer-encoding': $properties['encoding'] = $fieldValue; break; case 'content-id': $properties['id'] = trim($fieldValue, '<>'); break; case 'content-disposition': $properties['disposition'] = $fieldValue; break; case 'content-description': $properties['description'] = $fieldValue; break; case 'content-location': $properties['location'] = $fieldValue; break; case 'content-language': $properties['language'] = $fieldValue; break; default: // Ignore unknown header break; } } $body = $part['body']; if (isset($properties['encoding'])) { switch ($properties['encoding']) { case 'quoted-printable': $body = quoted_printable_decode($body); break; case 'base64': $body = base64_decode($body); break; } } $newPart = new Part($body); foreach ($properties as $key => $value) { $newPart->{$key} = $value; } $res->addPart($newPart); } return $res; }
/** * bencode解码 * @param string $str 要解码的数据 * @return object 解码后的数据 */ public static function decode($str) { return Decode::decode($str); }