/**
  * @param Folder $folder
  * @return bool
  */
 function PurgeFolder(&$folder)
 {
     $result = true;
     //$fs = new FileSystem(INI_DIR.'/temp', $this->_account->Email, $this->_account->Id);
     if ($this->_account->MailProtocol == MAILPROTOCOL_POP3 || $this->_account->MailProtocol == MAILPROTOCOL_WMSERVER) {
         $messageUidSet = array();
         if ($this->DbStorage->Connect()) {
             $messageUidSet = $this->DbStorage->SelectAllMessagesUidSetByFolder($folder);
         }
     }
     if ($folder->SyncType != FOLDERSYNC_DirectMode) {
         if ($this->DbStorage->Connect()) {
             $result &= $this->DbStorage->PurgeFolder($folder);
             $result &= $this->DbStorage->UpdateMailboxSize();
         }
     }
     switch ($this->_account->MailProtocol) {
         case MAILPROTOCOL_IMAP4:
             if ($folder->SyncType != FOLDERSYNC_DontSync) {
                 if ($this->MailStorage->Connect()) {
                     $result &= $this->MailStorage->PurgeFolder($folder);
                 }
             }
             break;
         case MAILPROTOCOL_POP3:
         case MAILPROTOCOL_WMSERVER:
             if ($this->_account->MailMode == MAILMODE_DeleteMessageWhenItsRemovedFromTrash || $this->_account->MailMode == MAILMODE_KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash) {
                 $result &= $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
             }
             break;
     }
     //$fs->DeleteAccountDirs();
     return $result;
 }
 /**
  * @param Folder $folder
  * @return bool
  */
 function EmptyFolder(&$folder)
 {
     $result = true;
     $messageUidSet = array();
     if (USE_DB && $this->DbStorage->Connect() && $this->_account->MailProtocol != MAILPROTOCOL_WMSERVER) {
         $messageUidSet = $this->DbStorage->SelectAllMessagesUidSetByFolder($folder);
     }
     if ($folder->SyncType != FOLDERSYNC_DirectMode) {
         if (USE_DB && $this->DbStorage->Connect()) {
             $result &= $this->DbStorage->PurgeFolder($folder, true);
             $result &= $this->DbStorage->UpdateMailboxSize();
         }
     }
     switch ($this->_account->MailProtocol) {
         case MAILPROTOCOL_IMAP4:
             if ($folder->SyncType != FOLDERSYNC_DontSync) {
                 if ($this->MailStorage->Connect()) {
                     $messageUidSet = null;
                     $result &= $this->MailStorage->SetMessagesFlags($messageUidSet, true, $folder, MESSAGEFLAGS_Deleted, ACTION_Set);
                     $result &= $this->MailStorage->PurgeFolder($folder);
                 }
             }
             break;
         case MAILPROTOCOL_POP3:
             if ($this->_account->MailMode == MAILMODE_DeleteMessageWhenItsRemovedFromTrash || $this->_account->MailMode == MAILMODE_KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash) {
                 $newMessageUidSet = array();
                 foreach ($messageUidSet as $_uid) {
                     if (strlen(trim($_uid)) > 0) {
                         $newMessageUidSet[] = $_uid;
                     }
                 }
                 if (count($newMessageUidSet) > 0) {
                     $result &= $this->MailStorage->Connect() && $this->MailStorage->DeleteMessages($messageUidSet, true, $folder);
                 }
             }
             break;
         case MAILPROTOCOL_WMSERVER:
             $result &= $this->MailStorage->Connect() && $this->MailStorage->ClearFolder($folder);
             break;
     }
     //$fs->DeleteAccountDirs();
     return $result;
 }