diff --git a/Message/Mail/EmailAbstract.php b/Message/Mail/EmailAbstract.php index d5e3df4af..8fe899e90 100644 --- a/Message/Mail/EmailAbstract.php +++ b/Message/Mail/EmailAbstract.php @@ -26,16 +26,56 @@ namespace phpOMS\Message\Mail; */ class MailAbstract { + /** + * Host. + * + * @var string + * @since 1.0.0 + */ private $host = ''; + /** + * Port. + * + * @var int + * @since 1.0.0 + */ private $port = 25; + /** + * Use ssl. + * + * @var bool + * @since 1.0.0 + */ private $ssl = false; + /** + * Mailbox base. + * + * @var string + * @since 1.0.0 + */ private $mailbox = ''; + /** + * Timeout. + * + * @var int + * @since 1.0.0 + */ private $timeout = 30; + /** + * Construct + * + * @param string $host Host + * @param int $port Host port + * @param int $timeout Timeout + * @param bool $ssl Use ssl + * + * @since 1.0.0 + */ public function __construct(string $host = 'localhost', int $port = 25, int $timeout = 30, bool $ssl = false) { $this->host = $host; @@ -49,7 +89,15 @@ class MailAbstract imap_timeout(IMAP_CLOSETIMEOUT, $timeout); } - public static function decode($content, $encoding) + /** + * Decode + * + * @param string $host Content to decode + * @param int $encoding Encoding type + * + * @since 1.0.0 + */ + public static function decode(string $content, int $encoding) { if ($encoding == 3) { return imap_base64($content); @@ -62,11 +110,21 @@ class MailAbstract } } + /** + * Descrutor + * + * @since 1.0.0 + */ public function __destruct() { $this->disconnect(); } + /** + * Disconnect server + * + * @since 1.0.0 + */ public function disconnect() { if(!isset($this->con)) { @@ -75,7 +133,17 @@ class MailAbstract } } - public function connect(string $user = '', string $pass = '') + /** + * Connect to server + * + * @param string $user Username + * @param string $pass Password + * + * @return void + * + * @since 1.0.0 + */ + public function connect(string $user = '', string $pass = '') /* : void */ { $this->mailbox = substr($this->mailbox, 0, -1) . ($this->ssl ? '/ssl/validate-cert' : '/novalidate-cert') . '}'; @@ -85,6 +153,13 @@ class MailAbstract } } + /** + * Test connection + * + * @return bool + * + * @since 1.0.0 + */ public function isConnected() : bool { return imap_ping($this->con); @@ -321,36 +396,97 @@ class MailAbstract return $this->getInboxOverview('TEXT "' . $text . '"'); } + /** + * List mailboxes + * + * @return array + * + * @since 1.0.0 + */ public function listMailbox() : array { return imap_listmailbox($this->con, $this->mailbox, '*'); } + /** + * Create mailbox + * + * @param string $mailbox Mailbox to create + * + * @return bool + * + * @since 1.0.0 + */ public function createMailbox(string $mailbox) : bool { return imap_createmailbox($this->con, $mailbox); } + /** + * Rename mailbox + * + * @param string $old Old mailbox name + * @param string $new New mailbox name + * + * @return bool + * + * @since 1.0.0 + */ public function renameMailbox(string $old, string $new) : bool { return imap_renamemailbox($this->con, $old, $new); } + /** + * Delete mailbox + * + * @param string $mailbox Mailbox to delete + * + * @return bool + * + * @since 1.0.0 + */ public function deleteMailbox(string $mailbox) : bool { return imap_deletemailbox($this->con, $mailbox); } + /** + * Check message to delete + * + * @param int $id Message id + * + * @return bool + * + * @since 1.0.0 + */ public function deleteMessage(int $id) : bool { return imap_delete($this->con, $id); } + /** + * Delete all marked messages + * + * @return bool + * + * @since 1.0.0 + */ public function deleteMarkedMessages() : bool { return imap_expunge($this->con); } + /** + * Check message to delete + * + * @param int $length Amount of message overview + * @param int $start Start index of the overview for pagination + * + * @return array + * + * @since 1.0.0 + */ public function getMessageOverview(int $length = 0, int $start = 1) : array { if($length === 0) { @@ -361,13 +497,29 @@ class MailAbstract return imap_fetch_overview($mbox, $start . ':' . ($length + $start), 0); } + /** + * Count messages + * + * @return int + * + * @since 1.0.0 + */ public function countMessages() : int { return imap_num_msg($this->con); } + /** + * Get message header + * + * @param int $id Message id + * + * @return string + * + * @since 1.0.0 + */ public function getMessageHeader(int $id) : string { return imap_fetchheader($this->con, $id); } -} \ No newline at end of file +} diff --git a/Message/Mail/Imap.php b/Message/Mail/Imap.php index b5f26e27a..4e19db672 100644 --- a/Message/Mail/Imap.php +++ b/Message/Mail/Imap.php @@ -26,12 +26,32 @@ namespace phpOMS\Message\Mail; */ class Imap extends EmailAbstract { + /** + * Construct + * + * @param string $host Host + * @param int $port Host port + * @param int $timeout Timeout + * @param bool $ssl Use ssl + * + * @since 1.0.0 + */ public function __construct(string $host = 'localhost', int $port = 25, int $timeout = 30, bool $ssl = false) { - parent::__construct($host, $port, $timeout, $options); + parent::__construct($host, $port, $timeout, $ssl); } - public function connect(string $user = '', string $pass = '') + /** + * Connect to server + * + * @param string $user Username + * @param string $pass Password + * + * @return void + * + * @since 1.0.0 + */ + public function connect(string $user = '', string $pass = '') /* : void */ { $this->mailbox = '{' . $this->host . ':' . $this->port . '/imap}'; parent::connect(); diff --git a/Message/Mail/Mail.php b/Message/Mail/Mail.php index f8fbbc88f..bc52fb4c5 100644 --- a/Message/Mail/Mail.php +++ b/Message/Mail/Mail.php @@ -138,14 +138,6 @@ class Mail */ protected $encoding = 0; - /** - * Mail type. - * - * @var int - * @since 1.0.0 - */ - protected $type = MailType::MAIL; - /** * Mail host name. * @@ -178,11 +170,6 @@ class Mail */ protected $messageDate = null; - /** - * todo: ??? - */ - protected $mailer = null; - /** * Constructor. * diff --git a/Message/Mail/Nntp.php b/Message/Mail/Nntp.php index 1428235a7..a0a905d23 100644 --- a/Message/Mail/Nntp.php +++ b/Message/Mail/Nntp.php @@ -26,12 +26,32 @@ namespace phpOMS\Message\Mail; */ class Nntp extends EmailAbstract { + /** + * Construct + * + * @param string $host Host + * @param int $port Host port + * @param int $timeout Timeout + * @param bool $ssl Use ssl + * + * @since 1.0.0 + */ public function __construct(string $host = 'localhost', int $port = 25, int $timeout = 30, bool $ssl = false) { - parent::__construct($host, $port, $timeout, $options); + parent::__construct($host, $port, $timeout, $ssl); } - public function connect(string $user = '', string $pass = '') + /** + * Connect to server + * + * @param string $user Username + * @param string $pass Password + * + * @return void + * + * @since 1.0.0 + */ + public function connect(string $user = '', string $pass = '') /* : void */ { $this->mailbox = '{' . $this->host . ':' . $this->port . '/nntp' . '}'; parent::connect(); diff --git a/Message/Mail/Pop3.php b/Message/Mail/Pop3.php index 9c97886ca..38830a32d 100644 --- a/Message/Mail/Pop3.php +++ b/Message/Mail/Pop3.php @@ -26,12 +26,32 @@ namespace phpOMS\Message\Mail; */ class Pop3 extends EmailAbstract { + /** + * Construct + * + * @param string $host Host + * @param int $port Host port + * @param int $timeout Timeout + * @param bool $ssl Use ssl + * + * @since 1.0.0 + */ public function __construct(string $host = 'localhost', int $port = 25, int $timeout = 30, bool $ssl = false) { - parent::__construct($host, $port, $timeout, $options); + parent::__construct($host, $port, $timeout, $ssl); } - public function connect(string $user = '', string $pass = '') + /** + * Connect to server + * + * @param string $user Username + * @param string $pass Password + * + * @return void + * + * @since 1.0.0 + */ + public function connect(string $user = '', string $pass = '') /* : void */ { $this->mailbox = '{' . $this->host . ':' . $this->port . '/pop3' . '}'; parent::connect();