class.uebimiau.php
来自「极限网络智能办公系统 Office Automation V3.0官方100%源」· PHP 代码 · 共 636 行 · 第 1/2 页
PHP
636 行
<?
/************************************************************************
UebiMiau is a GPL'ed software developed by
- Aldoir Ventura - aldoir@users.sourceforge.net
- http://uebimiau.sourceforge.net
Fell free to contact, send donations or anything to me :-)
S鉶 Paulo - Brasil
*************************************************************************/
class UebiMiau_core {
var $mail_connection = 0;
var $mail_server = "localhost";
var $mail_port = 110;
var $mail_error_msg = "";
var $mail_user = "unknown";
var $mail_pass = "";
var $mail_email = "unknown@localhost";
var $mail_protocol = "pop3";
var $use_html = false;
var $charset = "iso-8859-1";
var $timezone = "+0000";
var $debug = false;
var $user_folder = "./";
var $temp_folder = "./";
var $timeout = 10;
var $displayimages = false;
var $save_temp_attachs = true;
// internal
var $_msgbody = "";
var $_content = Array();
var $_sid = "";
/*******************/
function _get_headers_from_cache($strfile) {
if(!file_exists($strfile)) return;
$f = fopen($strfile,"rb");
while(!feof($f)) {
$result .= chop(fread($f,1024))."\r\n";
$pos = strpos($result,"\r\n\r\n");
if(!($pos === false)) {
$result = substr($result,0,$pos);
break;
}
}
fclose($f);
unset($f); unset($pos); unset($strfile);
return $result;
}
function _read_file($strfile) {
if($strfile == "" || !file_exists($strfile)) return;
$fd = fopen($strfile,"rb");
while(!feof($fd)) {
$result .= chop(fgets($fd, 65536))."\r\n";
}
fclose($fd);
return $result;
}
function _save_file($filename,$content) {
$tmpfile = fopen($filename,"wb");
fwrite($tmpfile,$content);
fclose($tmpfile);
unset($content,$tmpfile);
}
// remove dirs recursivelly
function _RmdirR($location) {
if (substr($location,-1) <> "/") $location = $location."/";
$all=opendir($location);
while ($file=readdir($all)) {
if (is_dir($location.$file) && $file <> ".." && $file <> ".") {
$this->_RmdirR($location.$file);
unset($file);
} elseif (!is_dir($location.$file)) {
unlink($location.$file);
unset($file);
}
}
closedir($all);
unset($all);
rmdir($location);
}
/*******************/
function mime_encode_headers($string) {
if($string == "") return;
if(!eregi("^([[:print:]]*)$",$string))
$string = "=?".$this->charset."?Q?".str_replace("+","_",str_replace("%","=",urlencode($string)))."?=";
return $string;
}
function add_body($strbody) {
if($this->_msgbody == "")
$this->_msgbody = $strbody;
else
$this->_msgbody .= "\r\n<br>\r\n<br>\r\n<hr>\r\n<br>\r\n$strbody";
}
function decode_mime_string($subject) {
$string = $subject;
if(($pos = strpos($string,"=?")) === false) return $string;
while(!($pos === false)) {
$newresult .= substr($string,0,$pos);
$string = substr($string,$pos+2,strlen($string));
$intpos = strpos($string,"?");
$charset = substr($string,0,$intpos);
$enctype = strtolower(substr($string,$intpos+1,1));
$string = substr($string,$intpos+3,strlen($string));
$endpos = strpos($string,"?=");
$mystring = substr($string,0,$endpos);
$string = substr($string,$endpos+2,strlen($string));
if($enctype == "q") $mystring = quoted_printable_decode(ereg_replace("_"," ",$mystring));
else if ($enctype == "b") $mystring = base64_decode($mystring);
$newresult .= $mystring;
$pos = strpos($string,"=?");
}
$result = $newresult.$string;
if(ereg("koi8", $subject)) $result = convert_cyr_string($result, "k", "w");
return $result;
}
function decode_header($header) {
$headers = explode("\r\n",$header);
$decodedheaders = Array();
for($i=0;$i<count($headers);$i++) {
$thisheader = trim($headers[$i]);
if(!empty($thisheader))
if(!ereg("^[A-Z0-9a-z_-]+:",$thisheader))
$decodedheaders[$lasthead] .= " $thisheader";
else {
$dbpoint = strpos($thisheader,":");
$headname = strtolower(substr($thisheader,0,$dbpoint));
$headvalue = trim(substr($thisheader,$dbpoint+1));
if($decodedheaders[$headname] != "") $decodedheaders[$headname] .= "; $headvalue";
else $decodedheaders[$headname] = $headvalue;
$lasthead = $headname;
}
}
return $decodedheaders;
}
function get_names($strmail) {
$ARfrom = Array();
$strmail = stripslashes(ereg_replace("\t","",ereg_replace("\n","",ereg_replace("\r","",$strmail))));
if(trim($strmail) == "") return $ARfrom;
$armail = Array();
$counter = 0; $inthechar = 0;
$chartosplit = ",;"; $protectchar = "\""; $temp = "";
$lt = "<"; $gt = ">";
$closed = 1;
for($i=0;$i<strlen($strmail);$i++) {
$thischar = $strmail[$i];
if($thischar == $lt && $closed) $closed = 0;
if($thischar == $gt && !$closed) $closed = 1;
if($thischar == $protectchar) $inthechar = ($inthechar)?0:1;
if(!(strpos($chartosplit,$thischar) === false) && !$inthechar && $closed) {
$armail[] = $temp; $temp = "";
} else
$temp .= $thischar;
}
if(trim($temp) != "")
$armail[] = trim($temp);
for($i=0;$i<count($armail);$i++) {
$thisPart = trim(eregi_replace("^\"(.*)\"$", "\\1", trim($armail[$i])));
if($thisPart != "") {
if (eregi("(.*)<(.*)>", $thisPart, $regs)) {
$email = trim($regs[2]);
$name = trim($regs[1]);
} else {
if (eregi("([-a-z0-9_$+.]+@[-a-z0-9_.]+[-a-z0-9_]+)((.*))", $thisPart, $regs)) {
$email = $regs[1];
$name = $regs[2];
} else
$email = $thisPart;
}
$email = preg_replace("/<(.*)\\>/", "\\1", $email);
$name = preg_replace("/\"(.*)\"/", "\\1", trim($name));
$name = preg_replace("/\((.*)\)/", "\\1", $name);
if ($name == "") $name = $email;
if ($email == "") $email = $name;
$ARfrom[$i]["name"] = $this->decode_mime_string($name);
$ARfrom[$i]["mail"] = $email;
unset($name);unset($email);
}
}
return $ARfrom;
}
function build_alternative_body($ctype,$body) {
$boundary = $this->get_boundary($ctype);
$part = $this->split_parts($boundary,$body);
$thispart = ($this->use_html)?$part[1]:$part[0];
$email = $this->fetch_structure($thispart);
$header = $email["header"];
$body = $email["body"];
$headers = $this->decode_header($header);
$body = $this->compile_body($body,$headers["content-transfer-encoding"],$headers["content-type"]);
$this->add_body($body);
}
function build_complex_body($ctype,$body) {
global $sid,$lid,$ix,$folder;
$Rtype = trim(substr($ctype,strpos($ctype,"type=")+5,strlen($ctype)));
if(strpos($Rtype,";") != 0)
$Rtype = substr($Rtype,0,strpos($Rtype,";"));
if(substr($Rtype,0,1) == "\"" && substr($Rtype,-1) == "\"")
$Rtype = substr($Rtype,1,strlen($Rtype)-2);
$boundary = $this->get_boundary($ctype);
$part = $this->split_parts($boundary,$body);
for($i=0;$i<count($part);$i++) {
$email = $this->fetch_structure($part[$i]);
$header = $email["header"];
$body = $email["body"];
$headers = $this->decode_header($header);
$ctype = $headers["content-type"];
$cid = $headers["content-id"];
$Actype = split(";",$headers["content-type"]);
$types = split("/",$Actype[0]); $rctype = strtolower($Actype[0]);
$is_download = (ereg("name=",$headers["content-disposition"].$headers["content-type"]) || $headers["content-id"] != "" || $rctype == "message/rfc822");
if($rctype == "multipart/alternative") {
$this->build_alternative_body($ctype,$body);
} elseif($rctype == "text/plain" && !$is_download) {
$body = $this->compile_body($body,$headers["content-transfer-encoding"],$headers["content-type"]);
$this->add_body($this->build_text_body($body));
} elseif($rctype == "text/html" && !$is_download) {
$body = $this->compile_body($body,$headers["content-transfer-encoding"],$headers["content-type"]);
if(!$this->use_html) $body = $this->build_text_body(strip_tags($body));
$this->add_body($body);
} elseif($is_download) {
$thisattach = $this->build_attach($header,$body,$boundary,$i);
$thisfile = "download.php?sid=$sid&tid=$tid&lid=$lid&folder=".urlencode($folder)."&ix=".$ix."&bound=".base64_encode($thisattach["boundary"])."&part=".$thisattach["part"]."&filename=".urlencode($thisattach["name"]);
$temp_attach = false;
$filename = $this->user_folder."_attachments/".md5($thisattach["boundary"])."_".$thisattach["name"];
if($cid != "") {
$temp_attach = true;
if($this->save_temp_attachs)
$thisfile .= "&cache=true";
if(substr($cid,0,1) == "<" && substr($cid,-1) == ">")
$cid = substr($cid,1,strlen($cid)-2);
$cid = "cid:$cid";
$this->_msgbody = str_replace($cid,$thisfile,$this->_msgbody);
} elseif($this->displayimages) {
$ext = substr($thisattach["name"],-4);
$allowed_ext = Array(".gif",".jpg");
if(in_array($ext,$allowed_ext)) {
$temp_attach = true;
if($this->save_temp_attachs)
$thisfile .= "&cache=true";
$this->add_body("<img src=\"$thisfile\">");
}
}
if($temp_attach && $this->save_temp_attachs)
$this->save_attach($header,$body,$filename);
} else
$this->process_message($header,$body);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?