static function build_history($old, $new) { return asset::build_diff(modify::htmlmessage($old), modify::htmlmessage($new)); }
static function select($path, $fields, $where, $order, $limit, $vars, $mfolder) { $cid = "pop3_" . md5(serialize(sys_credentials($mfolder))); $datas = self::_get_datas($mfolder, $cid); if (!isset($datas[0])) { return array(); } $rows = array(); foreach ($datas[0] as $key => $data) { $msg_id = $datas[1][$key]["msg_id"]; $msg_uid = $datas[1][$key]["uidl"]; $structure = array(); $row = array(); $row_id = "pop3_fields_" . md5(implode("_", $fields) . $msg_uid); if (!($row = sys_cache_get($row_id))) { if (!($pop3 = self::_connect($mfolder)) or !$pop3) { return array(); } foreach ($fields as $field) { switch ($field) { case "id": $row[$field] = $path . "/?" . md5($msg_uid); break; case "folder": $row[$field] = $path; break; case "searchcontent": $row[$field] = $data["subject"] . " " . $data["from"]; break; case "subject": $row[$field] = !empty($data["subject"]) ? $data["subject"] : "- {t}Empty{/t} -"; break; case "efrom": $row[$field] = isset($data["from"]) ? $data["from"] : ""; break; case "eto": $row[$field] = isset($data["to"]) ? $data["to"] : ""; break; case "cc": $row[$field] = isset($data["cc"]) ? $data["cc"] : ""; break; case "receipt": $row[$field] = !empty($data["disposition-notification-to"]) ? "1" : "0"; break; case "created": case "lastmodified": $row[$field] = isset($data["date"]) ? strtotime($data["date"]) : "0"; break; case "lastmodifiedby": $row[$field] = ""; break; case "dsize": case "size": $row[$field] = $datas[1][$key]["size"]; break; case "headers": $row[$field] = ""; foreach ($data as $data_key => $data_item) { $row[$field] .= ucfirst($data_key) . ": " . (is_array($data_item) ? implode("\n ", $data_item) : $data_item) . "\n"; } break; case "message_html": case "message": if ($field == "message_html") { $html = true; } else { $html = false; } $row[$field] = ""; if (empty($structure)) { $input = $pop3->getMsg($msg_id); $decode = new Mail_mimeDecode($input); $structure = self::_parse_structure($decode->decode(array("include_bodies" => true, "decode_bodies" => true)), 1, $msg_uid); $raw_file = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt", true); file_put_contents($raw_file, $input); } $file_index = -1; foreach ($structure as $skey => $item) { $is_attachment = self::_is_attachment($item); if ($is_attachment) { $file_index++; } $content = ""; if (sys_strbegins($item["contenttype"], "multipart") and $skey != 0) { if (isset($item["header"]["subject"])) { $content = self::_drawheader($item["header"]); if (!sys_contains($item["charset"], "utf")) { $content = modify::utf8_encode($content, $item["charset"]); } if ($html) { $content .= modify::nl2br(q(trim($content)), false, true); } } } else { if (!$is_attachment and $item["size"] > 0 and strpos($item["contenttype"], "text/") !== false) { $data_body = $item["body"]; if (!strpos("#" . $item["charset"], "utf")) { $data_body = modify::utf8_encode($data_body, $item["charset"]); } if ($html) { if ($content != "") { $content .= "<hr>"; } if ($item["contenttype"] != "text/html") { $data_body = modify::nl2br(q(trim($data_body)), false, true); if ($item["contenttype"] != "text/plain") { $content .= "<b>[" . $item["contenttype"] . "]</b><br>"; } } $item["level"] = substr_count($item["id"], "."); $content .= "<div style='margin-left:" . $item["level"] * 20 . "px;'><code>" . $data_body . "</code></div>"; } else { if ($content != "") { $content .= "\n"; } if ($item["contenttype"] == "text/html") { $data_body = modify::htmlmessage($data_body); } else { if ($item["contenttype"] != "text/plain") { $content .= "[" . $item["contenttype"] . "]\n"; } } $content .= trim($data_body) . "\n"; } } else { if (strpos($item["contenttype"], "image/") !== false and !empty($item["cid"])) { $url = "download.php?folder=@folder@&view=attachment_show&field=attachment&item[]=@id@&subitem=" . $file_index; $row[$field] = str_replace("cid:" . $item["cid"], $url, $row[$field]); } } } if ($row[$field] != "" and $content != "") { if ($html) { $row[$field] .= "<hr><br>"; } else { $row[$field] .= "\n----\n\n"; } } $row[$field] .= $content; } break; case "attachment": $row[$field] = ""; if (empty($structure)) { $input = $pop3->getMsg($msg_id); $decode = new Mail_mimeDecode($input); $structure = self::_parse_structure($decode->decode(array("include_bodies" => true, "decode_bodies" => true)), 1, $msg_uid); $raw_file = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt", true); file_put_contents($raw_file, $input); } $files = array(); foreach ($structure as $item) { if ($item["disposition"] == "attachment") { $files[] = sys_cache_get_file("pop3", $msg_uid, "--" . $item["name"]); } } $files[] = sys_cache_get_file("pop3", $msg_uid, "--original.eml.txt"); if (count($files) > 0) { $row[$field] = "|" . implode("|", $files) . "|"; } break; } } sys_cache_set($row_id, $row, POP3_MAIL_CACHE); } $row["_msg_id"] = $msg_id; $row["seen"] = file_exists(sys_cache_get_file("pop3", md5($msg_uid), "seen_" . $mfolder)) ? "1" : ""; if (sys_select_where($row, $where, $vars)) { $rows[] = $row; } } return sys_select($rows, $order, $limit, $fields); }
static function createemail($id, $data, $unused, $table) { if (empty($data["message_html"]) and !empty($data["message"])) { $message_html = nl2br(q(trim($data["message"]))); db_update($table, array("message_html" => $message_html), array("id=@id@"), array("id" => $id)); } if (empty($data["message"]) and !empty($data["message_html"])) { $message = modify::htmlmessage($data["message_html"]); db_update($table, array("message" => $message), array("id=@id@"), array("id" => $id)); } return ""; }