/**
  * Parses the body of an rfc 2822 message.
  *
  * @throws ezcBaseFileNotFoundException
  *         if a neccessary temporary file could not be openened.
  * @param string $origLine
  */
 public function parseBody($origLine)
 {
     $line = rtrim($origLine, "\r\n");
     if ($this->parserState == self::PARSE_STATE_HEADERS && $line == '') {
         $this->parserState = self::PARSE_STATE_BODY;
         // clean up headers for the part
         // the rest of the headers should be set on the mail object.
         $headers = new ezcMailHeadersHolder();
         $headers['Content-Type'] = $this->headers['Content-Type'];
         if (isset($this->headers['Content-Transfer-Encoding'])) {
             $headers['Content-Transfer-Encoding'] = $this->headers['Content-Transfer-Encoding'];
         }
         if (isset($this->headers['Content-Disposition'])) {
             $headers['Content-Disposition'] = $this->headers['Content-Disposition'];
         }
         // get the correct body type
         $this->bodyParser = self::createPartParserForHeaders($headers);
     } else {
         if ($this->parserState == self::PARSE_STATE_HEADERS) {
             $this->parseHeader($line, $this->headers);
         } else {
             $this->bodyParser->parseBody($origLine);
         }
     }
 }
Exemple #2
0
 /**
  * Returns an array of ezcMail objects parsed from the mail set $set.
  *
  * You can optionally use ezcMailParserOptions to provide an alternate class
  * name which will be instantiated instead of ezcMail, if you need to extend
  * ezcMail.
  *
  * Example:
  * <code>
  * $options = new ezcMailParserOptions();
  * $options->mailClass = 'MyMailClass';
  *
  * $parser = new ezcMailParser( $options );
  * // if you want to use MyMailClass which extends ezcMail
  * </code>
  *
  * @apichange Remove second parameter
  *
  * @throws ezcBaseFileNotFoundException
  *         if a neccessary temporary file could not be openened.
  * @param ezcMailParserSet $set
  * @param string $class Deprecated. Use $mailClass in ezcMailParserOptions class instead.
  * @return array(ezcMail)
  */
 public function parseMail(ezcMailParserSet $set, $class = null)
 {
     $mail = array();
     if (!$set->hasData()) {
         return $mail;
     }
     if ($class === null) {
         $class = $this->options->mailClass;
     }
     do {
         $this->partParser = new ezcMailRfc822Parser();
         $data = "";
         $size = 0;
         while (($data = $set->getNextLine()) !== null) {
             $this->partParser->parseBody($data);
             $size += strlen($data);
         }
         $part = $this->partParser->finish($class);
         $part->size = $size;
         $mail[] = $part;
     } while ($set->nextMail());
     return $mail;
 }
 /**
  * Parses each line of the digest body.
  *
  * Every line is part of the digested mail. It is sent directly to the mail parser.
  *
  * @param string $line
  */
 public function parseBody($line)
 {
     $this->mailParser->parseBody($line);
     $this->size += strlen($line);
 }
 /**
  * Parses a multipart body.
  *
  * @throws ezcBaseFileNotFoundException
  *         if a neccessary temporary file could not be opened.
  * @param string $origLine
  */
 public function parseBody($origLine)
 {
     if ($this->parserState == self::PARSE_STATE_POST_LAST) {
         return;
     }
     $line = rtrim($origLine, "\r\n");
     // check if we hit any of the boundaries
     $newPart = false;
     $endOfMultipart = false;
     if (strlen($line) > 0 && $line[0] == "-") {
         if (strcmp(trim($line), '--' . $this->boundary) === 0) {
             $newPart = true;
         } else {
             if (strcmp(trim($line), '--' . $this->boundary . '--') === 0) {
                 $endOfMultipart = true;
             }
         }
     }
     // actions to do when starting or finishing a part
     if ($newPart || $endOfMultipart) {
         if ($this->parserState != self::PARSE_STATE_BODY) {
             // something is b0rked, we got a new separator before getting a body
             // we'll skip this part and continue to the next
             $this->currentPartParser = null;
             $this->currentPartHeaders = new ezcMailHeadersHolder();
             $this->parserState = $newPart ? self::PARSE_STATE_HEADERS : self::PARSE_STATE_POST_LAST;
         } else {
             // complete the work on the current part if there was any
             if ($this->currentPartParser !== null) {
                 $part = $this->currentPartParser->finish();
                 if ($part !== null) {
                     $this->partDone($part);
                 }
             }
             // prepare for a new part if any
             $this->currentPartParser = null;
             $this->parserState = self::PARSE_STATE_POST_LAST;
             if ($newPart) {
                 $this->parserState = self::PARSE_STATE_HEADERS;
                 $this->currentPartHeaders = new ezcMailHeadersHolder();
             }
         }
     } else {
         if ($this->parserState == self::PARSE_STATE_HEADERS && $line == '') {
             $this->currentPartParser = self::createPartParserForHeaders($this->currentPartHeaders);
             $this->parserState = self::PARSE_STATE_BODY;
         } else {
             if ($this->parserState == self::PARSE_STATE_HEADERS) {
                 $this->parseHeader($line, $this->currentPartHeaders);
             } else {
                 if ($this->parserState == self::PARSE_STATE_BODY) {
                     if ($this->currentPartParser) {
                         // send body data to the part
                         $this->currentPartParser->parseBody($origLine);
                     }
                 }
             }
         }
         // we are done parsing the multipart, ignore anything else pushed to us.
     }
 }