diff --git a/README.md b/README.md index cba067a..d46a8df 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,13 @@ $connection = new Connection( $connection->connect(); ``` +After end of everything, you should close connection + +```php +$connection->disconnect(); +``` + + #### Connection Options ```php @@ -243,6 +250,15 @@ foreach ($attachments as $attachment) { } ``` +To do actions on message like delete or undelete + +```php +$message->action()->delete(); +$message->action()->undelete(); +// and don't forget to run the following to delete all messages marked for deletion +$mailbox->expunge(); +``` + Misc ==== diff --git a/src/Core/Connection.php b/src/Core/Connection.php index 08bd554..eac979a 100644 --- a/src/Core/Connection.php +++ b/src/Core/Connection.php @@ -266,7 +266,7 @@ class Connection * @param integer $flag * @return boolean */ - public function disconnect($flag = 0) + public function disconnect($flag = \CL_EXPUNGE) { if( !is_null($this->stream) && imap_ping($this->stream) ){ if( imap_close($this->stream, $flag) ){ diff --git a/src/Core/Message/Action.php b/src/Core/Message/Action.php index 3db6af5..3daaa45 100644 --- a/src/Core/Message/Action.php +++ b/src/Core/Message/Action.php @@ -55,4 +55,24 @@ class Action return $this; } + + /** + * Delete Message + * + * @return boolean + */ + public function delete() + { + return (boolean) imap_delete($this->connection->getStream(), $this->message_uid, \FT_UID); + } + + /** + * Undelete Message + * + * @return boolean + */ + public function undelete() + { + return (boolean) imap_undelete($this->connection->getStream(), $this->message_uid, \FT_UID); + } } \ No newline at end of file diff --git a/src/MailBox.php b/src/MailBox.php index b45e971..731ae44 100644 --- a/src/MailBox.php +++ b/src/MailBox.php @@ -130,12 +130,12 @@ class MailBox /** * Delete all messages marked for deletion * - * @return Mailbox + * @return boolean */ public function expunge() { $this->connection->survive($this->folder); - imap_expunge($this->connection->getStream()); + return (boolean) imap_expunge($this->connection->getStream()); } /**