/**
  * @param Array $messageIdUidSet
  * @param Folder $folder optional
  * @return bool
  */
 function DeleteMessages(&$messageIdUidSet, &$folder)
 {
     $messageIdSet = array_keys($messageIdUidSet);
     $messageUidSet = array_values($messageIdUidSet);
     @set_time_limit(TIMELIMIT);
     //$fs = new FileSystem(INI_DIR.'/temp', $this->_account->Email, $this->_account->Id);
     $result = true;
     switch ($this->_account->MailProtocol) {
         case MAILPROTOCOL_POP3:
             if ($folder->Type == FOLDERTYPE_Trash) {
                 if ($folder->SyncType != FOLDERSYNC_DirectMode) {
                     if ($this->DbStorage->Connect()) {
                         $result &= $this->DbStorage->DeleteMessages($messageIdSet, false, $folder);
                         $result &= $this->DbStorage->UpdateMailboxSize();
                     }
                 }
                 if ($this->_account->MailMode == MAILMODE_DeleteMessageWhenItsRemovedFromTrash || $this->_account->MailMode == MAILMODE_KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash) {
                     $result &= $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
                 }
                 //$fs->DeleteAccountDirs();
                 return $result;
             } elseif ($folder->SyncType == FOLDERSYNC_DirectMode) {
                 //$fs->DeleteAccountDirs();
                 return $result && $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
             }
             $folderList =& $this->GetFolders();
             $trashFolder =& $folderList->GetFolderByType(FOLDERTYPE_Trash);
             //$fs->DeleteAccountDirs();
             return $this->MoveMessages($messageIdUidSet, $folder, $trashFolder);
         case MAILPROTOCOL_IMAP4:
             if (USEIMAPTRASH) {
                 if ($folder->Type == FOLDERTYPE_Trash) {
                     $result = true;
                     $result &= $this->SetFlags($messageIdUidSet, $folder, MESSAGEFLAGS_Deleted, ACTION_Set);
                     $result &= $this->PurgeFolder($folder);
                     return $result;
                 }
                 $folderList =& $this->GetFolders();
                 if ($folderList) {
                     $trashFolder =& $folderList->GetFolderByType(FOLDERTYPE_Trash);
                     if ($trashFolder) {
                         return $this->MoveMessages($messageIdUidSet, $folder, $trashFolder);
                     }
                 }
                 return false;
             } else {
                 return $this->SetFlags($messageIdUidSet, $folder, MESSAGEFLAGS_Deleted, ACTION_Set);
             }
         case MAILPROTOCOL_WMSERVER:
             if ($folder->Type == FOLDERTYPE_Trash) {
                 if ($folder->SyncType != FOLDERSYNC_DirectMode) {
                     if ($this->DbStorage->Connect()) {
                         $result &= $this->DbStorage->DeleteMessages($messageIdSet, false, $folder);
                         $result &= $this->DbStorage->UpdateMailboxSize();
                     }
                 }
                 if ($this->_account->MailMode == MAILMODE_DeleteMessageWhenItsRemovedFromTrash || $this->_account->MailMode == MAILMODE_KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash) {
                     $result &= $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
                 }
                 //$fs->DeleteAccountDirs();
                 return $result;
             } elseif ($folder->SyncType == FOLDERSYNC_DirectMode) {
                 //$fs->DeleteAccountDirs();
                 return $result && $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
             }
             $folderList =& $this->GetFolders();
             $trashFolder =& $folderList->GetFolderByType(FOLDERTYPE_Trash);
             //$fs->DeleteAccountDirs();
             return $this->MoveMessages($messageIdUidSet, $folder, $trashFolder);
     }
 }
Esempio n. 2
0
 /**
  * @param Array $messageIdUidSet
  * @param Folder $folder optional
  * @return bool
  */
 function DeleteMessages(&$messageIdUidSet, &$folder, $noMove = false)
 {
     ConvertUtils::SetLimits();
     $messageIdSet = array_keys($messageIdUidSet);
     $messageUidSet = array_values($messageIdUidSet);
     $settings =& Settings::CreateInstance();
     $result = true;
     switch ($this->_account->MailProtocol) {
         default:
             return false;
         case MAILPROTOCOL_POP3:
             if ($folder->Type == FOLDERTYPE_Trash || $noMove) {
                 if ($folder->SyncType != FOLDERSYNC_DirectMode) {
                     if ($this->DbStorage->Connect()) {
                         $result &= $this->DbStorage->DeleteMessages($messageIdSet, false, $folder);
                         $result &= $this->DbStorage->UpdateMailboxSize();
                     }
                 }
                 if ($this->_account->MailMode == MAILMODE_DeleteMessageWhenItsRemovedFromTrash || $this->_account->MailMode == MAILMODE_KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash) {
                     $result &= $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
                 }
                 return $result;
             } else {
                 if ($folder->SyncType == FOLDERSYNC_DirectMode) {
                     return $result && $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
                 }
             }
             $folderList =& $this->GetFolders();
             $trashFolder =& $folderList->GetFolderByType(FOLDERTYPE_Trash);
             return $noMove ? true : $this->MoveMessages($messageIdUidSet, $folder, $trashFolder);
         case MAILPROTOCOL_WMSERVER:
             if ($folder->Type == FOLDERTYPE_Trash || $folder->Type == FOLDERTYPE_Spam || $noMove) {
                 if ($folder->SyncType != FOLDERSYNC_DirectMode) {
                     if ($this->DbStorage->Connect()) {
                         $result &= $this->DbStorage->DeleteMessages($messageIdSet, false, $folder);
                         $result &= $this->DbStorage->UpdateMailboxSize();
                     }
                 }
                 return $result && $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
             } else {
                 if ($folder->SyncType == FOLDERSYNC_DirectMode) {
                     return $result && $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
                 }
             }
             $folderList =& $this->GetFolders();
             $trashFolder =& $folderList->GetFolderByType(FOLDERTYPE_Trash);
             if (!$trashFolder) {
                 $trashFolder = new Folder($this->_account->Id, -1, FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_AllHeadersOnly);
                 if (!$this->CreateFolder($trashFolder)) {
                     return false;
                 }
             }
             return $noMove ? true : $this->MoveMessages($messageIdUidSet, $folder, $trashFolder);
         case MAILPROTOCOL_IMAP4:
             //if ($settings->Imap4DeleteLikePop3 && $folder->SyncType != FOLDERSYNC_DirectMode)
             if ($settings->Imap4DeleteLikePop3) {
                 $trashFolder = null;
                 $folderList =& $this->GetFolders();
                 if ($folderList) {
                     $trashFolderType =& $folderList->GetFolderByType(FOLDERTYPE_Trash);
                     if (!$trashFolderType) {
                         $trashFolderName =& $folderList->GetFolderByName(FOLDERNAME_Trash);
                         if ($trashFolderName) {
                             $trashFolderName->Type = FOLDERTYPE_Trash;
                             $trashFolder = $trashFolderName;
                             if (USE_DB && $this->DbStorage->Connect()) {
                                 $result &= $this->DbStorage->UpdateFolder($trashFolderName);
                             }
                         } else {
                             $inboxFolderType =& $folderList->GetFolderByType(FOLDERTYPE_Inbox);
                             if ($inboxFolderType && $inboxFolderType->SubFolders && $inboxFolderType->SubFolders->Count() > 0) {
                                 $trashFolderName2 =& $inboxFolderType->SubFolders->GetFolderByName(FOLDERNAME_Trash);
                                 if ($trashFolderName2) {
                                     $trashFolderName2->Type = FOLDERTYPE_Trash;
                                     $trashFolder = $trashFolderName2;
                                     if (USE_DB && $this->DbStorage->Connect()) {
                                         $result &= $this->DbStorage->UpdateFolder($trashFolderName2);
                                     }
                                 }
                             }
                             if (!$trashFolder) {
                                 $trashFolder = new Folder($this->_account->Id, -1, FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_DontSync);
                                 /*
                                 $trashFolder = new Folder($this->_account->Id, -1,
                                 	FOLDERNAME_Trash, FOLDERNAME_Trash, $this->_account->GetDefaultFolderSync($settings));
                                 */
                                 if (!$this->CreateFolder($trashFolder)) {
                                     $trashFolder = null;
                                 }
                             }
                         }
                     } else {
                         $trashFolder = $trashFolderType;
                     }
                     if ($trashFolder) {
                         if ($folder->Type == FOLDERTYPE_Trash || $noMove) {
                             $result = true;
                             $result &= $this->SetFlags($messageIdUidSet, $folder, MESSAGEFLAGS_Deleted, ACTION_Set);
                             $result &= $this->PurgeFolder($folder);
                             return $result;
                         }
                         return $noMove ? true : $this->MoveMessages($messageIdUidSet, $folder, $trashFolder);
                     }
                     return false;
                 }
             }
             return $this->SetFlags($messageIdUidSet, $folder, MESSAGEFLAGS_Deleted, ACTION_Set) && $this->PurgeFolder($folder);
     }
 }