/** * {@inheritdoc} */ public static function fromUploadId(AwsClientInterface $client, UploadIdInterface $uploadId) { $transferState = new static($uploadId); $listParts = $client->getIterator('ListParts', $uploadId->toParams()); foreach ($listParts as $part) { list($firstByte, $lastByte) = explode('-', $part['RangeInBytes']); $partSize = (double) $listParts->getLastResult()->get('PartSizeInBytes'); $partData = array('partNumber' => $firstByte / $partSize + 1, 'checksum' => $part['SHA256TreeHash'], 'contentHash' => self::ALREADY_UPLOADED, 'size' => $lastByte - $firstByte + 1, 'offset' => $firstByte); $transferState->addPart(UploadPart::fromArray($partData)); } return $transferState; }
/** * 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; }
/** * 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; }