Example #1
0
 private static function _parse_structure($structure, $id, $uid, $level = 0)
 {
     $result = array();
     $result["contenttype"] = strtolower($structure->ctype_primary . "/" . $structure->ctype_secondary);
     $result["disposition"] = "inline";
     if (!empty($structure->headers["content-disposition"])) {
         $result["disposition"] = $structure->headers["content-disposition"];
         if ($pos = strpos($result["disposition"], ";")) {
             $result["disposition"] = substr($result["disposition"], 0, $pos);
         }
     }
     $result["charset"] = "";
     if (isset($structure->ctype_parameters["charset"])) {
         $result["charset"] = strtolower($structure->ctype_parameters["charset"]);
     }
     $result["name"] = str_replace(".", "_", $id) . "_" . $structure->ctype_primary . "." . str_replace("plain", "txt", $structure->ctype_secondary);
     if (!empty($structure->ctype_parameters["name"])) {
         $result["name"] = modify::decode_subject($structure->ctype_parameters["name"]);
     }
     if (!empty($structure->d_parameters["filename"])) {
         $result["name"] = modify::decode_subject($structure->d_parameters["filename"]);
     }
     if (!empty($structure->headers["content-id"])) {
         $result["cid"] = trim($structure->headers["content-id"], "<>");
     }
     $result["id"] = $id;
     $result["body"] = "";
     $result["size"] = 0;
     if (isset($structure->body)) {
         $result["size"] = strlen($structure->body);
         if (!self::_is_attachment($result) and $result["size"] > 0 and $structure->ctype_primary == "text") {
             $result["body"] =& $structure->body;
         }
         if ($result["contenttype"] == "text/calendar") {
             $result["disposition"] = "attachment";
             if (!strpos($result["name"], ".ics")) {
                 $result["name"] = "appointment.ics";
             }
         }
         if (self::_is_attachment($result)) {
             $result["disposition"] = "attachment";
             $local = sys_cache_get_file("pop3", $uid, "--" . $result["name"], true);
             if (!file_exists($local)) {
                 file_put_contents($local, $structure->body, LOCK_EX);
             }
         }
     }
     $result["header"] = array();
     if (isset($structure->headers)) {
         if (isset($structure->headers["subject"])) {
             $result["header"] = $structure->headers;
         }
     }
     $results = array($result);
     if (isset($structure->parts)) {
         foreach ($structure->parts as $key => $part) {
             $results = array_merge($results, self::_parse_structure($part, $id . "." . ($key + 1), $uid, $level + 1));
         }
     }
     if (count($results) > 2) {
         if ($results[1]["contenttype"] == "text/plain" and $results[2]["contenttype"] == "text/html") {
             // hide text/plain if text/plain is already present
             $results[1]["contenttype"] = "invalid";
         }
     }
     return $results;
 }
Example #2
0
 static function select($path, $fields, $where, $order, $limit, $vars, $mfolder)
 {
     if ($fields == array("*")) {
         $fields = array("id", "folder");
     }
     $rows = array();
     $entries = self::_select_xml($path, $mfolder);
     foreach ($entries as $entry) {
         $ext = modify::getfileext($entry->title);
         $row = array();
         foreach ($fields as $field) {
             switch ($field) {
                 case "filedata":
                 case "id":
                     $row[$field] = basename($entry->id);
                     break;
                 case "folder":
                     $row[$field] = $path;
                     break;
                 case "filedata_show":
                 case "filename":
                 case "searchcontent":
                     $row[$field] = (string) $entry->title;
                     break;
                 case "fileext":
                     $row[$field] = $ext;
                     break;
                 case "created":
                     $row[$field] = strtotime($entry->published);
                     break;
                 case "lastmodified":
                     $row[$field] = strtotime($entry->updated);
                     break;
                 case "lastmodifiedby":
                     $row[$field] = (string) $entry->author->name;
                     break;
                 case "filesize":
                     $row[$field] = (int) $entry->gd_quotaBytesUsed;
                     break;
                 default:
                     $row[$field] = "";
                     break;
             }
         }
         $row["_lastmodified"] = strtotime($entry->updated);
         $row["_url"] = (string) $entry->content["src"];
         $row["_filename"] = (string) $entry->title;
         $meta = sys_build_meta($entry->docs_description, array());
         if (empty($meta)) {
             $meta["description"] = (string) $entry->docs_description;
         }
         $row = array_merge($row, $meta);
         if (sys_select_where($row, $where, $vars)) {
             $rows[] = $row;
         }
     }
     $rows = sys_select($rows, $order, $limit, $fields);
     if (count($rows) > 0 and in_array("filedata", $fields)) {
         foreach ($rows as $key => $row) {
             $filename = sys_cache_get_file("gdocs", $row["id"] . $row["_lastmodified"], "--" . modify::basename($row["_filename"]), true);
             if (!file_exists($filename) and (!isset($row["filesize"]) or $row["filesize"] < GDOCS_PREVIEW_LIMIT)) {
                 $fout = fopen($filename, "wb");
                 $fin = fopen($row["_url"], "rb", false, self::_get_context($mfolder));
                 if (is_resource($fin) and is_resource($fout)) {
                     while (!feof($fin)) {
                         fwrite($fout, fread($fin, 8192));
                     }
                     fclose($fin);
                     fclose($fout);
                 }
             }
             $rows[$key]["filedata"] = $filename;
         }
     }
     return $rows;
 }
Example #3
0
 private static function _set_meta($data, $id, $mfolder, $ntlm)
 {
     $w = new Java("jcifs.smb.SmbFile", "smb://" . $id, $ntlm);
     $lastmodified = $w->getLastModified() / 1000;
     $sourcefile = sys_cache_get_file("cifs", $id . $lastmodified, "--" . modify::basename($id . ".meta"), true);
     if (file_exists($sourcefile)) {
         $data = sys_build_meta(file_get_contents($sourcefile), $data);
     }
     $drop = array("filedata", "folder", "created", "lastmodified", "handler", "mfolder", "dsize", "id");
     $data = sys_build_meta_str($data, array_diff(array_keys($data), $drop));
     if ($data == "") {
         $w = new Java("jcifs.smb.SmbFile", "smb://" . $id . ".meta", $ntlm);
         if ($w->exists()) {
             $w->delete();
         }
     } else {
         file_put_contents($sourcefile, $data, LOCK_EX);
         $in = new Java("java.io.FileInputStream", modify::realfilename($sourcefile, false));
         $w = new Java("jcifs.smb.SmbFile", "smb://" . $id . ".meta", $ntlm);
         $w->load($in);
     }
 }