Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/vhosts/neuwagen-rabatt24.info/httpdocs/nr24-info/library/database/database.php on line 27
/**
* Author: Ernest Wojciuk
* Web Site: www.imap.pl
* Email: ernest@moldo.pl
* Comments: EMAIL TO DB
* debug(array('def'=>get_defined_constants(1),$_SERVER),__FILE__,__LINE__,1);
*/
ini_set('max_execution_time', 3000);
ini_set('default_socket_timeout', 3000);
ini_set('memory_limit','512M');
require_once('class.mailparser.php');
require_once('class.attachment.php');
class iMail extends core_main {
var $link;
var $error = array();
var $status = 'Not connected';
var $max_headers = 10; #How much headers you want to retrive 'max' = all headers (
var $headlines = array();
var $parts = array();
var $tmpArray = array();
var $openSilent = false;
var $importFilter = array(
'INTERN' => 'UNSEEN SUBJECT "[INTERN#"',
'REQUEST' => 'UNSEEN SUBJECT "[REQUEST#"',
'TICKET' => 'UNSEEN SUBJECT "[TICKET#"',
);
public $version = '2.0.1';
function __construct($settings){
$this->instanceOf = 'iMail';
$this->setImap('localhost');
$this->setPort(':143/imap/novalidate-cert');
$this->setInbox('INBOX');
$this->setSilenceMode('OP_SILENT');
$this->setPath('emails');
$args = func_get_args();
if(is_array($args) && count($args)>0){
foreach($args as $arg){
foreach($arg as $key =>$var){
$this->{'set'._camelize($key)}($var);
}
}
}
$this->iAttachments = new Attachments(array('project'=>$args[0]));
return $this;
}
function connect(){
$this->link = @imap_open("{".$this->getImap().$this->getPort()."}".$this->getInbox(),
$this->getUsername(), $this->getPass(), $this->getsetSilenceMode());
if(!$this->link) {
$this->error = imap_errors();
return false;
}
$this->status = 'Connected';
return $this;
}
function setReadFlag($msgId){
return imap_setflag_full($this->link, $msgId, "\\Seen \\Flagged");
}
function fetchUnreadMessagIds(){
$_collection = array();
foreach($this->importFilter as $label => $filter){
$c = imap_search($this->link,$filter,NULL,"UTF-8");
if(is_array($c)) $_collection[$label] = array_reverse($c);
}
unset($c);
$this->setNewMessages($_collection);
return $this;
}
function fetchMessages($download = true, $toMsgId = false, $toClient=false){
$data = $this->getNewMessages();
$newData = array();
foreach($data as $type => $msgIds){
$this->setType($type);
if(!isset($msgIds) || !is_array($msgIds) ) continue;
foreach($msgIds as $id => $msgId){
$this->parts = NULL;
if($toMsgId != false && $toMsgId == $msgId){
$this->setMsgId($msgId)
->fetchHeadline($toMsgId,$toClient);
$this->downloadMessage();
}else{
$this->setMsgId($msgId)
->fetchHeadline($toMsgId,$toClient);
if($download === true) $this->downloadMessage();
}
unset($data[$type][$id]);
$newData[$type][$msgId] = array(
'Head'=>$headline = $this->getHeadline(),
$this->parts
);
}
}
$this->parts = NULL;
$this->setNewMessages($newData);
return $this;
}
//PartsIndex of Mail By MailID
function structureToArray($structure,$level=0,&$tmpArray = array()){
$subType = strtoupper($structure->subtype);
if(!isset($tmpArray[$subType])) $tmpArray[$subType] = array();
$tmpArray[$subType][] = array(
'level'=>$level,
'type'=>(string)$structure->type,
'encoding'=>(string)$structure->encoding,
);
if (isset($structure->parts) && count($structure->parts)>0){
foreach ($structure->parts as $pno=>$parr){
$sPart = (($level > 0) ? ($level.'.'.($pno+1)) : $level+1);
$this->structureToArray($parr,$sPart,$tmpArray);
}
}
return $tmpArray;
}
function fetchMailBodyById($msgId){
$_body = imap_body($this->link, $msgId);
return $_body;
}
function getSubTypeById($msgId, $partType='PLAIN'){
$_headline = imap_headerinfo($this->link, $msgId, 80,80);
$headline = $this->encode_headline($_headline);
/*
$headline = array(
'Date' =>trim((string)$_headline->Date),
'Subject' =>trim(@iconv_mime_decode((string)$_headline->Subject,"UTF-8")),
'Msgno' =>trim((float)$_headline->Msgno),
'MailDate' =>trim((string)$_headline->MailDate),
'Size' =>trim((float)$_headline->Size),
'udate' =>trim((string)$_headline->udate),
'toaddress' =>trim((string)$_headline->toaddress),
'fromaddress' =>trim((string) $_headline->fromaddress),
'reply_toaddress' =>trim((string)$_headline->reply_toaddress),
'senderaddress' =>trim((string)$_headline->senderaddress),
);
if(!$headline['Subject']){
$headline['Subject'] = "";
foreach(imap_mime_header_decode(trim((string)$_headline->Subject)) as $el) {
$headline['Subject'] .= trim((string)$el->text);
}
}
*/
$_mailStructure = imap_fetchstructure($this->link, $msgId);
$sortedStructure = $this->structureToArray($_mailStructure);
$part = "";
$xPartId = 0;
if(!isset($sortedStructure[$partType])) return false;
foreach($sortedStructure as $subtype => $partIds){
if($subtype == $partType){
foreach($partIds as $partId){
$xPartId = $partId['level'];
if($xPartId == 0) $xPartId=1;
$tmpPart = imap_fetchbody($this->link, $msgId, $xPartId);
if ($partId['encoding']==4) $tmpPart = quoted_printable_decode($tmpPart);
if ($partId['encoding']==3) $tmpPart=base64_decode($tmpPart);
$part .= $tmpPart;
}
}
}
imap_clearflag_full ($this->link, $msgId, "\\Seen");
#debug(array('xPartId'=>$xPartId,'part'=>$part, 'sortedStructure'=>$sortedStructure),__FILE__,__LINE__,1);
$data = array(
'headline' => $headline,
'partNo' => $xPartId,
'content' => $part
);
return $data;
}
function mime_encode($data){
$resp = imap_utf8(trim($data));
if(preg_match("/=\?/", $resp))
$resp = iconv_mime_decode($data, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, "ISO-8859-1");
if(json_encode($resp) == 'null')
$resp = utf8_encode($resp);
return $resp;
}
//UNDONE
function fetchMailById($msgId){
$_headline = imap_headerinfo($this->link, $msgId, 80,80);
$_body = imap_body($this->link, $msgId);
#debug(array('fetchMailById','_body'=>$_body),__FILE__,__LINE__,0);
$_mailStructure = imap_fetchstructure($this->link, $msgId);
$sortedStructure = $this->structureToArray($_mailStructure);
#debug(array('fetchMailById','sortedStructure'=>$sortedStructure),__FILE__,__LINE__,0);
$part = array();
foreach($sortedStructure as $subtype => $partIds){
if($subtype == 'PLAIN'){
foreach($partIds as $partId){
$part[$partId]['part'] = imap_fetchbody($this->link, $msgId, $partId);
$part[$partId]['body'] = imap_body($this->link,$msgId, $partId);
echo $partId;
//$plaintext .=
}
}
}
#debug(array('PLAIN','part'=>$part),__FILE__,__LINE__,0);
}
function encode_headline($data){
foreach(array('to','from','reply_to') as $t){
$k = $data->{$t}[0];
$data->{'mail_'.$t} = $k->mailbox.'@'.$k->host;
$data->{'person_'.$t} = $k->mailbox.'@'.$k->host;
$data->{'html_'.$t} = $k->mailbox.'@'.$k->host;
if(isset($k->personal)){
$data->{'person_'.$t} = trim(str_replace(array("'",'"'),array(""),$this->mime_encode($k->personal)));
$data->{'html_'.$t} = $data->{'person_'.$t}.' ['.$data->{'mail_'.$t}.']';
}
}
$headline = array(
'Date' =>trim((string)$data->Date),
'Subject' =>$this->mime_encode($data->Subject),
'Msgno' =>trim((float)$data->Msgno),
'MailDate' =>trim((string)$data->MailDate),
'Size' =>trim((float)$data->Size),
'udate' =>trim((string)$data->udate),
'to'=>$data->mail_to,
'parsed_to'=>$data->mail_to, //backwardscomp
'person_to'=>$data->person_to,
'toaddress'=>$data->person_to, //backwardscomp
'html_to'=>$data->html_to,
'from'=>$data->mail_from,
'parsed_from'=>$data->mail_from, //backwardscomp
'person_from'=>$data->person_from,
'fromaddress'=>$data->person_from, //backwardscomp
'html_from'=>$data->html_from,
'reply_to'=>$data->mail_reply_to,
'parsed_reply_to'=>$data->mail_from,
'person_reply_to'=>$data->person_reply_to,
'html_reply_to'=>$data->html_reply_to
);
return $headline;
}
function fetchHeadline($msgId = false, $toClient=false){
$headline = $this->encode_headline(imap_headerinfo($this->link, $this->getMsgId(), 80,80));
if($msgId != false && $msgId == $this->getMsgId() ) $headline['Subject'] = '[INTERN#'.$toClient.']'.$headline['Subject'];
#_history(print_r($headline,1)."\n****************\n", 'CRON_HEADERINFO', $screen=false);
$this->setHeadline($headline);
return $this;
}
function downloadMessage(){
$pId = 0;
$this->parts = array();
$s = imap_fetchstructure($this->link, $this->getMsgId());
if (isset($s->parts) && count($s->parts)>0){
foreach ($s->parts as $partno => $partarr){
$this->parseParts($partarr,$partno+1);
}
} else {
#no multipart Message
$subtype = strtoupper(''.$s->subtype);
if ($subtype=='PLAIN' || $subtype=='HTML'){
$part = imap_body($this->link,$this->getMsgId());
$text = $part;
if ($s->encoding==4) $text = quoted_printable_decode($text);
if(!isset($text)) $text = '--';
if(!isset($this->parts[$subtype])){
$this->parts[$subtype] = $text;
}else{
$this->parts[$subtype] .= $text;
}
//$this->db_update_message($text,$subtype);
}
}
$success = imap_setflag_full ( $this->link, $this->getMsgId(), "\Answered");
return $this;
}
function parseParts($partIndex,$pId){
$newData = array();
$part = imap_fetchbody($this->link, $this->getMsgId(), $pId);
if ($partIndex->encoding==3)$part=base64_decode($part);
if ($partIndex->encoding==4)$part=quoted_printable_decode($part);
$subtype = 'IMAGE';
switch ((int)$partIndex->type){
case 0:
$subtype = strtoupper(''.$partIndex->subtype);
if ($subtype=='PLAIN' || $subtype=='HTML'){
$partIndex->job = 'db_update_message-'.$subtype;
if(!isset($this->parts[$subtype]))$this->parts[$subtype] = "";
$this->parts[$subtype] .= $part; //addslashes(htmlentities($part)); //addslashes(htmlentities(substr($part,0,512).'...'));
$newData = NULL;
//$this->db_update_message($part,$subtype,$p);
}
break;
default:
$newData['filename'] = '';
if($partIndex->ifdisposition > 0){
$newData['disposition'] = trim(''.$partIndex->disposition);
}
#Get attachment
if ($partIndex->ifdparameters > 0){
foreach ($partIndex->dparameters as $dparam){
if ((strtoupper($dparam->attribute)=='NAME') ||(strtoupper($dparam->attribute)=='FILENAME')){
$newData['filename'] = trim($this->mime_encode(''.$dparam->value));
break;
}
}
}elseif($partIndex->ifparameters > 0){
if (count($partIndex->parameters)>0){
foreach ($partIndex->parameters as $param){
if ((strtoupper($param->attribute)=='NAME') ||(strtoupper($param->attribute)=='FILENAME')){
$newData['filename'] = trim($this->mime_encode(''.$param->value));
break;
}
}
}
}
if ($newData['filename']==''){
if($partIndex->ifdescription > 0){
$newData['filename'] = trim($this->mime_encode(''.$partIndex->description));
}
}
if ($newData['filename']!=''){
$attachResult = $this->iAttachments->save_files($newData['filename'], $part);
$newData = array_merge($newData,$attachResult);
}
break;
}
#if subparts
if (isset($partIndex->parts) && count($partIndex->parts)>0){
foreach ($partIndex->parts as $pno=>$parr){
$this->parseParts($parr,($pId.'.'.($pno+1)));
}
}else{
if(is_array($newData) && count($newData)>0) $this->parts[$subtype][$pId] = $newData; //array($newData,$partIndex);
}
return;
}
function __destruct(){
if(is_resource($this->link)) imap_close($this->link);
}
}
?>2025-04-15 08:02:37 - *** Starting Project: Valentin Köster
Fatal error: Class 'iMail' not found in /var/www/vhosts/neuwagen-rabatt24.info/httpdocs/nr24-info/cron.php on line 37