Ejemplo n.º 1
0
 /**
  * Registers the directory $dir for removal when PHP shuts down.
  *
  * The directory and all of its contents will be removed recursively.
  *
  * @param string $dir
  */
 public static function registerForRemoval($dir)
 {
     if (self::$isRegistered === false) {
         register_shutdown_function(array("ezcMailParserShutdownHandler", "shutdownCallback"));
         self::$isRegistered = true;
     }
     self::$directories[] = $dir;
 }
Ejemplo n.º 2
0
 /**
  * Returns the filepointer of the opened file $fileName in a unique directory..
  *
  * This method will create a new unique folder in the temporary directory specified in ezcMailParser.
  * The fileName property of this class will be set to the location of the new file.
  *
  * @throws ezcBaseFileNotFoundException
  *         if the file could not be opened.
  * @param string $fileName
  * @return resource
  */
 private function openFile($fileName)
 {
     // The filename is now relative, we need to extend it with the absolute path.
     // To provide uniqueness we put the file in a directory based on processID and rand.
     $dirName = ezcMailParser::getTmpDir() . getmypid() . '-' . self::$counter++ . '/';
     if (!is_dir($dirName)) {
         mkdir($dirName, 0700);
     }
     // remove the directory and the file when PHP shuts down
     ezcMailParserShutdownHandler::registerForRemoval($dirName);
     $this->fileName = $dirName . $fileName;
     $fp = fopen($this->fileName, 'w');
     if ($this->fp === false) {
         throw new ezcBaseFileNotFoundException($this->fileName);
     }
     return $fp;
 }
Ejemplo n.º 3
0
 public function testShutdownHandler()
 {
     $parser = new ezcMailParser();
     $set = new SingleFileSet('gmail/mail_with_attachment.mail');
     $mail = $parser->parseMail($set);
     $this->assertEquals(1, count($mail));
     // call the registered shutdown function which deletes the temporary files
     ezcMailParserShutdownHandler::shutdownCallback();
     // try calling a second time, to account for the case of the temp dir missing
     ezcMailParserShutdownHandler::shutdownCallback();
 }