Ejemplo n.º 1
0
 /**
  * Returns the parts parsed for this multipart.
  *
  * @return ezcMailMultipartRelated
  */
 public function finishMultipart()
 {
     $size = 0;
     if ($this->part->getMainPart()) {
         $size = $this->part->getMainPart()->size;
     }
     foreach ($this->part->getRelatedParts() as $part) {
         $size += $part->size;
     }
     $this->part->size = $size;
     return $this->part;
 }
 /**
  * Returns an ezcMailPart based on the HTML provided.
  *
  * This method adds local files/images to the mail itself using a
  * {@link ezcMailMultipartRelated} object.
  *
  * @throws ezcBaseFileNotFoundException
  *         if $fileName does not exists.
  * @throws ezcBaseFilePermissionProblem
  *         if $fileName could not be read.
  * @return ezcMailPart
  */
 private function generateHtmlPart()
 {
     $result = false;
     if ($this->htmlText != '') {
         $matches = array();
         if ($this->options->automaticImageInclude === true) {
             /*
                              1.7.1 regex is buggy filename are not extract correctly
                              http://issues.ez.no/IssueView.php?Id=16612&
             
                              preg_match_all( '(
                                 <img \\s+[^>]*
                                     src\\s*=\\s*
                                         (?:
                                             (?# Match quoted attribute)
                                             ([\'"])file://(?P<quoted>[^>]+)\\1
             
                                             (?# Match unquoted attribute, which may not contain spaces)
                                         |   file://(?P<unquoted>[^>\\s]+)
                                     )
                                 [^>]* >)ix', $htmlText, $matches );
             
             
                              * */
             // CJW Newsletter regex change only find all  file://ezroot/
             // so it is secure
             // recognize file://ezroot/ and pick out the image, add it as a part and then..:)
             preg_match_all("/<img[\\s\\*\\s]src=[\\'\"]file:\\/\\/ezroot\\/([^ >\\'\"]+)/i", $this->htmlText, $matches);
             // pictures/files can be added multiple times. We only need them once.
             $matches = array_unique($matches[1]);
         }
         $result = new ezcMailText($this->htmlText, $this->charset, $this->encoding);
         $result->subType = "html";
         if (count($matches) > 0) {
             $htmlPart = $result;
             // wrap already existing message in an alternative part
             $result = new ezcMailMultipartRelated($result);
             // create a filepart and add it to the related part
             // also store the ID for each part since we need those
             // when we replace the originals in the HTML message.
             foreach ($matches as $fileName) {
                 if (is_readable($fileName)) {
                     // @todo waiting for fix of the fileinfo extension
                     // $contents = file_get_contents( $fileName );
                     $mimeType = null;
                     $contentType = null;
                     if (ezcBaseFeatures::hasExtensionSupport('fileinfo')) {
                         // if fileinfo extension is available
                         $filePart = new ezcMailFile($fileName);
                     } elseif (ezcMailTools::guessContentType($fileName, $contentType, $mimeType)) {
                         // if fileinfo extension is not available try to get content/mime type
                         // from the file extension
                         $filePart = new ezcMailFile($fileName, $contentType, $mimeType);
                     } else {
                         // fallback in case fileinfo is not available and could not get content/mime
                         // type from file extension
                         $filePart = new ezcMailFile($fileName, "application", "octet-stream");
                     }
                     $cid = $result->addRelatedPart($filePart);
                     // replace the original file reference with a reference to the cid
                     $this->htmlText = str_replace('file://ezroot/' . $fileName, 'cid:' . $cid, $this->htmlText);
                 } else {
                     if (file_exists($fileName)) {
                         throw new ezcBaseFilePermissionException($fileName, ezcBaseFileException::READ);
                     } else {
                         throw new ezcBaseFileNotFoundException($fileName);
                     }
                     // throw
                 }
             }
             // update mail, with replaced URLs
             $htmlPart->text = $this->htmlText;
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Returns an ezcMailPart based on the HTML provided.
  *
  * This method adds local files/images to the mail itself using a
  * {@link ezcMailMultipartRelated} object.
  *
  * @throws ezcBaseFileNotFoundException
  *         if $fileName does not exists.
  * @throws ezcBaseFilePermissionProblem
  *         if $fileName could not be read.
  * @return ezcMailPart
  */
 private function generateHtmlPart()
 {
     $result = false;
     if ($this->htmlText != '') {
         $matches = array();
         if ($this->options->automaticImageInclude === true) {
             // recognize file:// and file:///, pick out the image, add it as a part and then..:)
             preg_match_all("/<img[\\s\\*\\s]src=[\\'\"]file:\\/\\/([^ >\\'\"]+)/i", $this->htmlText, $matches);
             // pictures/files can be added multiple times. We only need them once.
             $matches = array_unique($matches[1]);
         }
         $result = new ezcMailText($this->htmlText, $this->charset, $this->encoding);
         $result->subType = "html";
         if (count($matches) > 0) {
             $htmlPart = $result;
             // wrap already existing message in an alternative part
             $result = new ezcMailMultipartRelated($result);
             // create a filepart and add it to the related part
             // also store the ID for each part since we need those
             // when we replace the originals in the HTML message.
             foreach ($matches as $fileName) {
                 if (is_readable($fileName)) {
                     // @todo waiting for fix of the fileinfo extension
                     // $contents = file_get_contents( $fileName );
                     $mimeType = null;
                     $contentType = null;
                     if (ezcBaseFeatures::hasExtensionSupport('fileinfo')) {
                         // if fileinfo extension is available
                         $filePart = new ezcMailFile($fileName);
                     } elseif (ezcMailTools::guessContentType($fileName, $contentType, $mimeType)) {
                         // if fileinfo extension is not available try to get content/mime type
                         // from the file extension
                         $filePart = new ezcMailFile($fileName, $contentType, $mimeType);
                     } else {
                         // fallback in case fileinfo is not available and could not get content/mime
                         // type from file extension
                         $filePart = new ezcMailFile($fileName, "application", "octet-stream");
                     }
                     $cid = $result->addRelatedPart($filePart);
                     // replace the original file reference with a reference to the cid
                     $this->htmlText = str_replace('file://' . $fileName, 'cid:' . $cid, $this->htmlText);
                 } else {
                     if (file_exists($fileName)) {
                         throw new ezcBaseFilePermissionException($fileName, ezcBaseFileException::READ);
                     } else {
                         throw new ezcBaseFileNotFoundException($fileName);
                     }
                     // throw
                 }
             }
             // update mail, with replaced URLs
             $htmlPart->text = $this->htmlText;
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 public function testGetMultipartRelatedWithoutMain()
 {
     $part = new ezcMailMultipartRelated();
     $part->addRelatedPart(new ezcMailText('a'));
     $this->assertEquals(1, count($part->getRelatedParts()));
 }