/** * Returns a ezcMailRfc822Digest with the digested mail in it. * * @return ezcMailRfc822Digest */ public function finish() { $digest = new ezcMailRfc822Digest($this->mailParser->finish()); ezcMailPartParser::parsePartHeaders($this->headers, $digest); $digest->size = $this->size; return $digest; }
/** * Completes the parsing of the multipart and returns the corresponding part. * * This method should not be overriden. Use finishMultipart() instead. * * @return ezcMailMultipart */ public function finish() { if ($this->parserState != self::PARSE_STATE_POST_LAST) { // this should never happen // let's give the last parser a chance to clean up after himself if ($this->currentPartParser !== null) { $part = $this->currentPartParser->finish(); $this->partDone($part); $this->currentPartParser = null; } } $multipart = $this->finishMultipart(); ezcMailPartParser::parsePartHeaders($this->headers, $multipart); $multipart->boundary = $this->boundary; return $multipart; }
/** * Returns an ezcMail corresponding to the parsed message. * You can specify an alternate class using the $class parameter, if you * extended ezcMail. * * @param string $class Class to instanciate instead of ezcMail. * @return ezcMail */ public function finish($class = "ezcMail") { $mail = new $class(); $mail->setHeaders($this->headers->getCaseSensitiveArray()); ezcMailPartParser::parsePartHeaders($this->headers, $mail); // from if (isset($this->headers['From'])) { $mail->from = ezcMailTools::parseEmailAddress($this->headers['From']); } // to if (isset($this->headers['To'])) { $mail->to = ezcMailTools::parseEmailAddresses($this->headers['To']); } // cc if (isset($this->headers['Cc'])) { $mail->cc = ezcMailTools::parseEmailAddresses($this->headers['Cc']); } // bcc if (isset($this->headers['Bcc'])) { $mail->bcc = ezcMailTools::parseEmailAddresses($this->headers['Bcc']); } // subject if (isset($this->headers['Subject'])) { $mail->subject = ezcMailTools::mimeDecode($this->headers['Subject']); $mail->subjectCharset = 'utf-8'; } // message ID if (isset($this->headers['Message-Id'])) { $mail->messageID = $this->headers['Message-Id']; } // Return-Path if (isset($this->headers['Return-Path'])) { $mail->returnPath = ezcMailTools::parseEmailAddress($this->headers['Return-Path']); } if ($this->bodyParser !== null) { $mail->body = $this->bodyParser->finish(); } return $mail; }
/** * 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; }
/** * Returns the ezcMailText part corresponding to the parsed message. * * @return ezcMailText */ public function finish() { $charset = "us-ascii"; // RFC 2822 default if (isset($this->headers['Content-Type'])) { preg_match('/\\s*charset\\s?=\\s?"?([^;"\\s]*);?/', $this->headers['Content-Type'], $parameters); if (count($parameters) > 0) { $charset = strtolower(trim($parameters[1], '"')); } } $encoding = strtolower($this->headers['Content-Transfer-Encoding']); if ($encoding == ezcMail::QUOTED_PRINTABLE) { $this->text = quoted_printable_decode($this->text); } else { if ($encoding == ezcMail::BASE64) { $this->text = base64_decode($this->text); } } $this->text = ezcMailCharsetConverter::convertToUTF8($this->text, $charset); $part = new ezcMailText($this->text, 'utf-8', ezcMail::EIGHT_BIT, $charset); $part->subType = $this->subType; $part->setHeaders($this->headers->getCaseSensitiveArray()); ezcMailPartParser::parsePartHeaders($this->headers, $part); $part->size = strlen($this->text); return $part; }
/** * Return the result of the parsed file part. * * This method is called automatically by the parent part. * * @return ezcMailFile */ public function finish() { fclose($this->fp); $this->fp = null; // FIXME: DIRTY PGP HACK // When we have PGP support these lines should be removed. They are here now to hide // PGP parts since they will show up as file attachments if not. if ($this->mainType == "application" && ($this->subType == 'pgp-signature' || $this->subType == 'pgp-keys' || $this->subType == 'pgp-encrypted')) { return null; } // END DIRTY PGP HACK $filePart = new self::$fileClass($this->fileName); // set content type $filePart->setHeaders($this->headers->getCaseSensitiveArray()); ezcMailPartParser::parsePartHeaders($this->headers, $filePart); switch (strtolower($this->mainType)) { case 'image': $filePart->contentType = ezcMailFile::CONTENT_TYPE_IMAGE; break; case 'audio': $filePart->contentType = ezcMailFile::CONTENT_TYPE_AUDIO; break; case 'video': $filePart->contentType = ezcMailFile::CONTENT_TYPE_VIDEO; break; case 'application': $filePart->contentType = ezcMailFile::CONTENT_TYPE_APPLICATION; break; } // set mime type $filePart->mimeType = $this->subType; // set inline disposition mode if set. $matches = array(); if (preg_match('/^\\s*inline;?/i', $this->headers['Content-Disposition'], $matches)) { $filePart->dispositionType = ezcMailFile::DISPLAY_INLINE; } if (preg_match('/^\\s*attachment;?/i', $this->headers['Content-Disposition'], $matches)) { $filePart->dispositionType = ezcMailFile::DISPLAY_ATTACHMENT; } $filePart->size = filesize($this->fileName); return $filePart; }
/** * Sets the option $propertyName to $propertyValue. * * @throws ezcBasePropertyNotFoundException * if the property $propertyName is not defined * @throws ezcBaseValueException * if $propertyValue is not correct for the property $propertyName * @throws ezcBaseInvalidParentClassException * if the class name passed as replacement mailClass does not * inherit from ezcMail. * @throws ezcBaseInvalidParentClassException * if the class name passed as replacement fileClass does not * inherit from ezcMailFile. * @param string $propertyName * @param mixed $propertyValue * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'mailClass': if (!is_string($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'string that contains a class name'); } // Check if the passed classname actually implements the // correct parent class. if ('ezcMail' !== $propertyValue && !in_array('ezcMail', class_parents($propertyValue))) { throw new ezcBaseInvalidParentClassException('ezcMail', $propertyValue); } $this->properties[$propertyName] = $propertyValue; break; case 'fileClass': if (!is_string($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'string that contains a class name'); } // Check if the passed classname actually implements the // correct parent class. if ('ezcMailFile' !== $propertyValue && !in_array('ezcMailFile', class_parents($propertyValue))) { throw new ezcBaseInvalidParentClassException('ezcMailFile', $propertyValue); } $this->properties[$propertyName] = $propertyValue; ezcMailFileParser::$fileClass = $propertyValue; break; case 'parseTextAttachmentsAsFiles': if (!is_bool($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'bool'); } $this->properties[$propertyName] = $propertyValue; ezcMailPartParser::$parseTextAttachmentsAsFiles = $propertyValue; break; default: throw new ezcBasePropertyNotFoundException($propertyName); } }