header & body class added

This commit is contained in:
Clivern 2017-08-14 13:24:33 +02:00
parent d0a4c23ac9
commit 7504487401
3 changed files with 78 additions and 100 deletions

View file

@ -183,103 +183,4 @@ class Message
return $body;
}
/**
* Parse Address List
*
* @param string $address_string
* @return array
*/
public function parseAddressList($address_string, $default_host = "example.com")
{
$address_array = imap_rfc822_parse_adrlist($address_string, $default_host);
$address_list = [];
foreach ($address_array as $id => $val) {
$address_list[] = [
'mailbox' => $val->mailbox,
'host' => $val->host,
'personal' => $val->personal,
'adl' => $val->adl
];
}
return $address_list;
}
/**
* Fetch Body
*
* @param mixed $section
* @param mixed $options
* @return string
*/
public function fetchBody($section = 0, $options = 0)
{
return imap_fetchbody($this->connection->getStream(), $this->msg_number, $section, $options);
}
/**
* Fetch Overview
*
* @param boolean $sequence
* @param mixed $options
* @return array
*/
public function fetchOverview($sequence = false, $options = 0)
{
if( $sequence == false ){
$overview = imap_fetch_overview($this->connection->getStream(), $this->msg_number, $options);
}else{
$overview = imap_fetch_overview($this->connection->getStream(), $sequence, $options);
}
$items_overview = [];
foreach ($overview as $key => $item_overview) {
$items_overview[] = [
'subject' => (isset($item_overview->subject)) ? $item_overview->subject : false,
'from' => (isset($item_overview->from)) ? $item_overview->from : false,
'to' => (isset($item_overview->to)) ? $item_overview->to : false,
'date' => (isset($item_overview->date)) ? $item_overview->date : false,
'message_id' => (isset($item_overview->message_id)) ? $item_overview->message_id : false,
'size' => (isset($item_overview->size)) ? $item_overview->size : false,
'uid' => (isset($item_overview->uid)) ? $item_overview->uid : false,
'msgno' => (isset($item_overview->msgno)) ? $item_overview->msgno : false,
'recent' => (isset($item_overview->recent)) ? $item_overview->recent : false,
'flagged' => (isset($item_overview->flagged)) ? $item_overview->flagged : false,
'answered' => (isset($item_overview->answered)) ? $item_overview->answered : false,
'deleted' => (isset($item_overview->deleted)) ? $item_overview->deleted : false,
'seen' => (isset($item_overview->seen)) ? $item_overview->seen : false,
'draft' => (isset($item_overview->draft)) ? $item_overview->draft : false,
'udate' => (isset($item_overview->udate)) ? $item_overview->udate : false
];
}
return $items_overview;
}
/**
* Fetch Header
*
* @param mixed $options
* @return string
*/
public function fetchHeader($options = 0)
{
return imap_fetchheader($this->connection->getStream(), $this->msg_number, $options);
}
/**
* Fetch Structure
*
* @param mixed $options
* @return stdClass
*/
public function fetchStructure($options = 0)
{
$structure = imap_fetchstructure($this->connection->getStream(), $this->msg_number, $options);
return $structure;
}
}

View file

@ -30,6 +30,16 @@ class Body
*/
protected $message_uid;
/**
* @var integer
*/
protected $encoding;
/**
* @var string
*/
protected $message = '';
/**
* Class Constructor
@ -55,4 +65,46 @@ class Body
return $this;
}
/**
* Get Message
*
* @param integer $option
* @return string
*/
public function getMessage($option = 2)
{
if( !empty($this->message) ){
return $this->message;
}
$structure = imap_fetchstructure($this->connection->getStream(), $this->message_number);
if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
$part = $structure->parts[1];
$this->message = imap_fetchbody($this->connection->getStream(),$this->message_number , $option);
$this->encoding = $part->encoding;
if($part->encoding == 3) {
$this->message = imap_base64($this->message);
} elseif($part->encoding == 1) {
$this->message = imap_8bit($this->message);
} else {
$this->message = imap_qprint($this->message);
}
}
return $this->message;
}
/**
* Get Encoding
*
* @return integer
*/
public function getEncoding()
{
return $this->encoding;
}
}

View file

@ -89,6 +89,29 @@ class Header
return (isset($this->header[strtolower($key)]));
}
/**
* Parse Address List
*
* @param string $address_string
* @return array
*/
public function parseAddressList($address_string, $default_host = "example.com")
{
$address_array = imap_rfc822_parse_adrlist($address_string, $default_host);
$address_list = [];
foreach ($address_array as $id => $val) {
$address_list[] = [
'mailbox' => $val->mailbox,
'host' => $val->host,
'personal' => $val->personal,
'adl' => $val->adl
];
}
return $address_list;
}
/**
* Load Header Data
*
@ -100,11 +123,13 @@ class Header
$overview = imap_fetch_overview($this->connection->getStream(), $this->message_number, $options);
foreach ($overview as $key => $item_overview) {
$this->header['subject'] = (isset($item_overview->subject)) ? $item_overview->subject : false;
$this->header['subject'] = (isset($item_overview->subject)) ? imap_utf8($item_overview->subject) : false;
$this->header['from'] = (isset($item_overview->from)) ? $item_overview->from : false;
$this->header['to'] = (isset($item_overview->to)) ? $item_overview->to : false;
$this->header['date'] = (isset($item_overview->date)) ? $item_overview->date : false;
$this->header['message_id'] = (isset($item_overview->message_id)) ? $item_overview->message_id : false;
$this->header['in_reply_to'] = (isset($item_overview->in_reply_to)) ? $item_overview->in_reply_to : false;
$this->header['references'] = (isset($item_overview->references)) ? explode(" ", $item_overview->references) : false;
$this->header['size'] = (isset($item_overview->size)) ? $item_overview->size : false;
$this->header['uid'] = (isset($item_overview->uid)) ? $item_overview->uid : false;
$this->header['msgno'] = (isset($item_overview->msgno)) ? $item_overview->msgno : false;