* @param string $id The list of messages to move
* @param string $mailbox The destination to move to
* @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response
+ * @param string $source_mailbox (since 1.5.1) name of source mailbox. It is used to
+ * validate that target mailbox != source mailbox.
* @return bool If the move completed without errors
*/
-function sqimap_msgs_list_move($imap_stream, $id, $mailbox, $handle_errors = true) {
+function sqimap_msgs_list_move($imap_stream, $id, $mailbox, $handle_errors = true, $source_mailbox = false) {
+ if ($source_mailbox!==false && $source_mailbox==$mailbox) {
+ return false;
+ }
$msgs_id = sqimap_message_list_squisher($id);
if (sqimap_msgs_list_copy ($imap_stream, $id, $mailbox, $handle_errors)) {
return sqimap_toggle_flag($imap_stream, $id, '\\Deleted', true, true);
$aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true);
break;
case 'move':
- $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox);
+ $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox,true,$mailbox);
sqsession_register($targetMailbox,'lastTargetMailbox');
$bExpunge = true;
break;