public function stream_open($path, $mode, $options, &$opened_path)
 {
     // parse URL
     $parts = parse_url($path);
     $this->repositoryId = $parts["host"];
     $mainCacheDir = defined('AJXP_SHARED_CACHE_DIR') ? AJXP_SHARED_CACHE_DIR : AJXP_CACHE_DIR;
     if (!isset(self::$delimiter) && file_exists($mainCacheDir . "/access.imap/mailbox_delim_" . $this->repositoryId)) {
         self::$delimiter = file_get_contents($mainCacheDir . "/access.imap/mailbox_delim_" . $this->repositoryId);
     }
     $this->path = substr($parts["path"], 1);
     //$this->mailbox = "INBOX";
     $pathParts = explode("/", $this->path);
     $pathParts = array_filter($pathParts, "rejectEmpty");
     if (count($pathParts) > 1) {
         $this->path = array_pop($pathParts);
         $this->mailbox = implode("/", $pathParts);
     } else {
         if (count($pathParts) == 1) {
             $this->mailbox = implode("/", $pathParts);
             $this->path = "";
         } else {
             $this->mailbox = "";
             $this->path = "";
         }
     }
     $this->fragment = $parts["fragment"];
     if (empty($this->path) && $mode !== 'np') {
         return false;
     }
     if (!empty($this->mailbox)) {
         $this->mailbox = mb_convert_encoding($this->mailbox, "UTF7-IMAP", SystemTextEncoding::getEncoding());
         $this->mailbox = str_replace("__delim__", isset(self::$delimiter) ? self::$delimiter : "/", $this->mailbox);
     }
     if (!empty($this->fragment) && strpos($this->fragment, "attachments") === 0 && strpos($this->fragment, "/") !== false) {
         // remove fragment
         $ar = explode("#", $path);
         $mailPath = array_shift($ar);
         $ar = explode("/", $this->fragment);
         $attachmentId = array_pop($ar);
         $this->currentAttachmentData = array("realPath" => $mailPath, "attachmentId" => $attachmentId);
         // EXTRACT ATTACHMENT AND RETURN
         require_once AJXP_INSTALL_PATH . "/plugins/editor.eml/class.EmlParser.php";
         $emlParser = new EmlParser("", "");
         $attachMeta = array();
         $this->data = $emlParser->getAttachmentBody($this->currentAttachmentData["realPath"], $this->currentAttachmentData["attachmentId"], true, $attachMeta);
         if (self::$attachmentsMetadata == null) {
             self::$attachmentsMetadata = array($attachMeta);
         }
         $this->currentAttachmentData["size"] = strlen($this->data);
         $this->pos = 0;
         $this->size = strlen($this->data);
         return true;
     }
     // open IMAP connection
     if (self::$currentStream != null) {
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "Using currently opened stream! " . print_r(self::$currentStream, true));
         $this->ih = self::$currentStream;
         // Rewind everything
         $this->dir_rewinddir();
         $this->stream_seek(0);
     } else {
         $repository = ConfService::getRepositoryById($this->repositoryId);
         $ssl = $repository->getOption("SSL") == "true" ? true : false;
         $this->pop3 = $repository->getOption("BOX_TYPE") == "pop3" ? true : false;
         $this->host = $repository->getOption("HOST");
         $this->port = $repository->getOption("PORT");
         $this->username = $repository->getOption("USER");
         $this->password = $repository->getOption("PASS");
         $server = "{" . $this->host . ":" . $this->port . "/" . ($this->pop3 ? "pop3/" : "") . ($ssl ? "ssl/novalidate-cert" : "novalidate-cert") . "}";
         self::$currentRef = $server;
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "Opening a new stream " . $server . " with mailbox '" . $this->mailbox . "'");
         try {
             $this->ih = imap_open($server . $this->mailbox, $this->username, $this->password, !$this->pop3 && empty($this->mailbox) ? OP_HALFOPEN : NULL, 1);
         } catch (Exception $e) {
             throw new Exception($e->getMessage() . " - imap errors  : " . print_r(imap_errors(), true), $e->getCode());
         }
         self::$currentStream = $this->ih;
         register_shutdown_function(array("imapAccessWrapper", "closeStreamFunc"));
     }
     if ($this->ih) {
         if (!empty($this->path)) {
             list($stats, ) = imap_fetch_overview($this->ih, $this->path);
             $this->size = $stats->size;
             $this->time = strtotime($stats->date);
         }
         return true;
     } else {
         return false;
     }
 }