@@ -636,7 +636,8 @@ public function getFolder(){
636
636
637
637
/**
638
638
* Copy the current Messages to a mailbox
639
- * @param string $folder
639
+ * @param string $folder_path
640
+ * @param boolean $expunge
640
641
*
641
642
* @return null|Message
642
643
* @throws Exceptions\ConnectionFailedException
@@ -647,14 +648,20 @@ public function getFolder(){
647
648
* @throws MessageHeaderFetchingException
648
649
* @throws Exceptions\EventNotFoundException
649
650
*/
650
- public function copy ($ folder ) {
651
- $ this ->client ->openFolder ($ this ->folder_path );
652
- $ status = $ this ->client ->getConnection ()->examineFolder ($ folder );
653
- /** @var Folder $folder */
654
- $ folder = $ this ->client ->getFolder ($ folder );
655
- if (isset ($ status ["uidnext " ]) && $ folder !== null ) {
651
+ public function copy ($ folder_path , $ expunge = false ) {
652
+ $ this ->client ->openFolder ($ folder_path );
653
+ $ status = $ this ->client ->getConnection ()->examineFolder ($ folder_path );
654
+
655
+ if (isset ($ status ["uidnext " ])) {
656
656
$ next_uid = $ status ["uidnext " ];
657
+
658
+ /** @var Folder $folder */
659
+ $ folder = $ this ->client ->getFolder ($ folder_path );
660
+
661
+ $ this ->client ->openFolder ($ this ->folder_path );
657
662
if ($ this ->client ->getConnection ()->copyMessage ($ folder ->path , $ this ->msgn ) == true ) {
663
+ if ($ expunge ) $ this ->client ->expunge ();
664
+
658
665
$ this ->client ->openFolder ($ folder ->path );
659
666
$ message_num = $ this ->client ->getConnection ()->getMessageNumber ($ next_uid );
660
667
0 commit comments