/**
  * @param WebMailMessage $message
  * @param Folder $folder
  * @return bool
  */
 function SaveMessage(&$message, &$folder, $fromFolder = null)
 {
     if ($message == null || $folder == null) {
         return false;
     }
     //Get size all messages in DB
     $mailBoxesSize = $this->DbStorage->SelectMailboxesSize() + $message->GetMailSize();
     $this->DbStorage->SelectMailboxesSize();
     if ($this->MailStorage->_settings->EnableMailboxSizeLimit && $this->_account->MailboxLimit < $mailBoxesSize) {
         setGlobalError(ErrorGetMailLimit);
         return false;
     }
     switch ($this->_account->MailProtocol) {
         case MAILPROTOCOL_POP3:
             $result = true;
             if ($this->DbStorage->Connect()) {
                 //if ($message->IdMsg != -1)
                 //{
                 //$messageIdSet = array($message->IdMsg);
                 //$result &= $this->DbStorage->DeleteMessages($messageIdSet, false, $folder);
                 //}
                 //else
                 //{
                 $message->IdMsg = $this->DbStorage->SelectLastIdMsg() + 1;
                 //}
                 return $result && $this->DbStorage->SaveMessage($message, $folder);
             }
         case MAILPROTOCOL_IMAP4:
             $result = true;
             if ($message->IdMsg != -1) {
                 $messageIdUidSet = array();
                 $messageIdUidSet[$message->IdMsg] = $message->Uid;
                 $nfolder = $fromFolder ? $fromFolder : $folder;
                 $result &= $this->DeleteMessages($messageIdUidSet, $nfolder);
             }
             if ($folder->SyncType != FOLDERSYNC_DontSync) {
                 if ($this->MailStorage->Connect()) {
                     $result &= $this->MailStorage->SaveMessage($message, $folder);
                     $GLOBALS[MailDefaultCharset] = $this->_account->GetDefaultIncCharset();
                     unset($GLOBALS[MailInputCharset]);
                     $GLOBALS[MailOutputCharset] = $this->_account->GetUserCharset();
                     $result &= $this->MailStorage->SynchronizeFolder($folder);
                 }
                 return $result;
             } elseif ($this->DbStorage->Connect()) {
                 //if ($message->IdMsg == -1)
                 //{
                 $message->IdMsg = $this->DbStorage->SelectLastIdMsg() + 1;
                 //}
                 $result &= $this->DbStorage->SaveMessage($message, $folder);
                 return $result;
             }
         case MAILPROTOCOL_WMSERVER:
             $result = true;
             if ($this->DbStorage->Connect()) {
                 $message->IdMsg = $this->DbStorage->SelectLastIdMsg() + 1;
                 return $result && $this->DbStorage->SaveMessage($message, $folder);
             }
     }
     return false;
 }