public function getRawContent($id, $part = null) { if ($part !== null) { // TODO: implement throw new Exception\RuntimeException('not implemented'); } $content = $this->protocol->retrieve($id); // TODO: find a way to avoid decoding the headers $headers = null; // "Declare" variable since it's passed by reference $body = null; // "Declare" variable before first usage. Mime\Decode::splitMessage($content, $headers, $body); return $body; }
/** * Instantiate from raw message string * * @todo Restore body to Mime\Message * @param string $rawMessage * @return Message */ public static function fromString($rawMessage) { $message = new static(); $headers = null; $content = null; Mime\Decode::splitMessage($rawMessage, $headers, $content); if ($headers->has('mime-version')) { // todo - restore body to mime\message } $message->setHeaders($headers); $message->setBody($content); return $message; }
/** * Public constructor * * Part supports different sources for content. The possible params are: * - handler an instance of AbstractStorage for late fetch * - id number of message for handler * - raw raw content with header and body as string * - headers headers as array (name => value) or string, if a content part is found it's used as toplines * - noToplines ignore content found after headers in param 'headers' * - content content as string * - strict strictly parse raw content * * @param array $params full message with or without headers * @throws Exception\InvalidArgumentException */ public function __construct(array $params) { if (isset($params['handler'])) { if (!$params['handler'] instanceof AbstractStorage) { throw new Exception\InvalidArgumentException('handler is not a valid mail handler'); } if (!isset($params['id'])) { throw new Exception\InvalidArgumentException('need a message id with a handler'); } $this->mail = $params['handler']; $this->messageNum = $params['id']; } $params['strict'] = isset($params['strict']) ? $params['strict'] : false; if (isset($params['raw'])) { Mime\Decode::splitMessage($params['raw'], $this->headers, $this->content, Mime\Mime::LINEEND, $params['strict']); } elseif (isset($params['headers'])) { if (is_array($params['headers'])) { $this->headers = new Headers(); $this->headers->addHeaders($params['headers']); } else { if (empty($params['noToplines'])) { Mime\Decode::splitMessage($params['headers'], $this->headers, $this->topLines); } else { $this->headers = Headers::fromString($params['headers']); } } if (isset($params['content'])) { $this->content = $params['content']; } } }