From 72b991fa505ab2091aeafa280e6d9851ca4b784b Mon Sep 17 00:00:00 2001 From: Clivern Date: Thu, 10 Aug 2017 16:10:07 +0200 Subject: [PATCH] new methods added to message class --- src/Core/Connection.php | 18 +++++++ src/Core/Message.php | 107 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 117 insertions(+), 8 deletions(-) diff --git a/src/Core/Connection.php b/src/Core/Connection.php index e771dc9..07ae719 100644 --- a/src/Core/Connection.php +++ b/src/Core/Connection.php @@ -182,6 +182,24 @@ class Connection ]; } + /** + * Check MailBox Data + * + * @return array + */ + public function check() + { + $data = imap_check($this->stream); + + return [ + 'date' => (isset($data->Date)) ? $data->Date : false, + 'driver' => (isset($data->Driver)) ? $data->Driver : false, + 'mailbox' => (isset($data->Mailbox)) ? $data->Mailbox : false, + 'nmsgs' => (isset($data->Nmsgs)) ? $data->Nmsgs : false, + 'recent' => (isset($data->Recent)) ? $data->Recent : false + ]; + } + /** * Ping Connection * diff --git a/src/Core/Message.php b/src/Core/Message.php index 1423476..ed002fc 100644 --- a/src/Core/Message.php +++ b/src/Core/Message.php @@ -22,7 +22,12 @@ class Message /** * @var integer */ - protected $id; + protected $uid; + + /** + * @var integer + */ + protected $msg_number; /** * Message Constructor @@ -35,23 +40,109 @@ class Message } /** - * Set Message ID + * Set Message Number * * @param integer $id - * @return void + * @return Message */ - public function setId($id) + public function setMsgNo($msg_number) { - $this->id = $id; + $this->msg_number = $msg_number; + + return $this; } /** - * Get Message ID + * Get Message Number * * @return integer */ - public function getId() + public function getMsgNo() { - return $this->id; + return $this->msg_number; } + + /** + * Set UID + * + * @param integer $uid + * @return Message + */ + public function setUid($uid) + { + $this->uid = $uid; + + return $this; + } + + /** + * Get UID + * + * @return integer + */ + public function getUid() + { + return $this->uid; + } + + /** + * Config Message Number & UID + * + * @return Message + */ + public function config() + { + if( !this->msg_number && $this->uid ){ + $this->msg_number = imap_msgno($this->connection->getStream(), $this->uid); + } + + if( !this->uid && $this->msg_number ){ + $this->uid = imap_uid($this->connection->getStream(), $this->msg_number); + } + + return $this; + } + + /** + * Get Body + * + * @param integer $options + * @return string + */ + public function getBody($options = 0) + { + $body = imap_body($this->connection->getStream(), $this->msg_number, $options); + + 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; + } + + +// imap_fetchbody +// imap_fetchheader +// imap_fetchstructure +// imap_fetch_overview + } \ No newline at end of file