Beispiel #1
0
 /**
  * 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'];
         }
     }
 }