@@ -721,7 +721,9 @@ public function getEncoding($structure) {
721721 * Find the folder containing this message.
722722 *
723723 * @param null|Folder $folder where to start searching from (top-level inbox by default)
724+ *
724725 * @return null|Folder
726+ * @throws Exceptions\ConnectionFailedException
725727 */
726728 public function getContainingFolder (Folder $ folder = null ) {
727729 $ folder = $ folder ?: $ this ->client ->getFolders ()->first ();
@@ -758,10 +760,10 @@ public function getContainingFolder(Folder $folder = null) {
758760
759761 /**
760762 * Move the Message into an other Folder
761- *
762- * @param string $mailbox
763+ * @param string $mailbox
763764 *
764765 * @return bool
766+ * @throws Exceptions\ConnectionFailedException
765767 */
766768 public function moveToFolder ($ mailbox = 'INBOX ' ) {
767769 $ this ->client ->createFolder ($ mailbox );
@@ -771,23 +773,30 @@ public function moveToFolder($mailbox = 'INBOX') {
771773
772774 /**
773775 * Delete the current Message
776+ * @param bool $expunge
774777 *
775778 * @return bool
779+ * @throws Exceptions\ConnectionFailedException
776780 */
777- public function delete () {
781+ public function delete ($ expunge = true ) {
778782 $ status = imap_delete ($ this ->client ->getConnection (), $ this ->uid , FT_UID );
779- $ this ->client ->expunge ();
783+ if ( $ expunge ) $ this ->client ->expunge ();
780784
781785 return $ status ;
782786 }
783787
784788 /**
785789 * Restore a deleted Message
790+ * @param boolean $expunge
786791 *
787792 * @return bool
793+ * @throws Exceptions\ConnectionFailedException
788794 */
789- public function restore () {
790- return imap_undelete ($ this ->client ->getConnection (), $ this ->uid , FT_UID );
795+ public function restore ($ expunge = true ) {
796+ $ status = imap_undelete ($ this ->client ->getConnection (), $ this ->uid , FT_UID );
797+ if ($ expunge ) $ this ->client ->expunge ();
798+
799+ return $ status ;
791800 }
792801
793802 /**
@@ -816,7 +825,10 @@ public function hasAttachments() {
816825 */
817826 public function setFlag ($ flag ) {
818827 $ flag = "\\" .trim (is_array ($ flag ) ? implode (" \\" , $ flag ) : $ flag );
819- return imap_setflag_full ($ this ->client ->getConnection (), $ this ->getUid (), $ flag , SE_UID );
828+ $ status = imap_setflag_full ($ this ->client ->getConnection (), $ this ->getUid (), $ flag , SE_UID );
829+ $ this ->parseFlags ();
830+
831+ return $ status ;
820832 }
821833
822834 /**
@@ -827,7 +839,10 @@ public function setFlag($flag) {
827839 */
828840 public function unsetFlag ($ flag ) {
829841 $ flag = "\\" .trim (is_array ($ flag ) ? implode (" \\" , $ flag ) : $ flag );
830- return imap_clearflag_full ($ this ->client ->getConnection (), $ this ->getUid (), $ flag , SE_UID );
842+ $ status = imap_clearflag_full ($ this ->client ->getConnection (), $ this ->getUid (), $ flag , SE_UID );
843+ $ this ->parseFlags ();
844+
845+ return $ status ;
831846 }
832847
833848 /**
0 commit comments