Example #1
0
 /**
  * @return int | false
  */
 function GetQuota()
 {
     if ($this->_account->MailProtocol == WM_MAILPROTOCOL_IMAP4 && $this->MailStorage->Connect()) {
         return $this->MailStorage->GetQuota();
     }
     return false;
 }
 /**
  * @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;
 }
Example #3
0
 /**
  * @param Account $account
  * @param int $inboxSyncType = FOLDERSYNC_NewEntireMessages
  * @param bool $integrCall = false
  * @return bool
  */
 function CreateAccount(&$account, $inboxSyncType = FOLDERSYNC_NewEntireMessages, $integrCall = false, $mailStorage = null)
 {
     $null = $folders = null;
     $account->IdUser = $this->Id;
     $result = false;
     setGlobalError(PROC_ERROR_ACCT_CREATE);
     $dbStorage =& DbStorageCreator::CreateDatabaseStorage($account);
     if ($dbStorage->Connect()) {
         if (USE_DB && !$account->IsInternal) {
             $defaultAccount =& $dbStorage->SelectAccountDataByLogin($account->Email, $account->MailIncLogin, true);
             if ($account->DefaultAccount && $defaultAccount != null && $defaultAccount[2] == 1) {
                 setGlobalError(ACCT_CANT_ADD_DEF_ACCT);
                 return false;
             }
         }
         $settings =& Settings::CreateInstance();
         if ($settings->AllowDirectMode && $settings->DirectModeIsDefault) {
             $inboxSyncType = FOLDERSYNC_DirectMode;
         }
         $addFolders = null;
         /* load or create folder tree here */
         switch ($account->MailProtocol) {
             case MAILPROTOCOL_POP3:
                 $result = $account->IsInternal ? $dbStorage->UpdateOnlyAccoutnData($account) : $dbStorage->InsertAccountData($account);
                 if ($result) {
                     $folders = new FolderCollection();
                     $inboxFolder = new Folder($account->Id, -1, FOLDERNAME_Inbox, FOLDERNAME_Inbox);
                     $inboxFolder->SyncType = $inboxSyncType;
                     $folders->Add($inboxFolder);
                     $createSystemFoldersInInbox = false;
                     /* custom class */
                     wm_Custom::StaticUseMethod('ChangeValueOfSystemFoldersInInbox', array(&$createSystemFoldersInInbox));
                     $folderPrefix = '';
                     if ($createSystemFoldersInInbox) {
                         $folderPrefix = $inboxFolder->FullName . $account->Delimiter;
                         $inboxFolder->SubFolders = $inboxFolder->SubFolders ? $inboxFolder->SubFolders : new FolderCollection();
                         $addFolders =& $inboxFolder->SubFolders;
                     } else {
                         $addFolders =& $folders;
                     }
                     $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_SentItems, FOLDERNAME_SentItems, FOLDERSYNC_DontSync));
                     $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_Drafts, FOLDERNAME_Drafts, FOLDERSYNC_DontSync));
                     $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_Spam, FOLDERNAME_Spam, FOLDERSYNC_DontSync));
                     $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_DontSync));
                 }
                 break;
             case MAILPROTOCOL_IMAP4:
                 setGlobalError(ACCT_CANT_CREATE_IMAP_ACCT);
                 if (null === $mailStorage) {
                     $mailStorage = new ImapStorage($account, $null);
                 }
                 if ($mailStorage->Connect()) {
                     if ($settings->TakeImapQuota) {
                         if ($mailStorage->IsQuotaSupport()) {
                             if ($account->ImapQuota === 1) {
                                 $mbl = $mailStorage->GetQuota();
                                 if (false !== $mbl) {
                                     $account->MailboxLimit = GetGoodBigInt($mbl);
                                 } else {
                                     $account->ImapQuota = -1;
                                 }
                             }
                         } else {
                             $account->ImapQuota = -1;
                         }
                     }
                     if (USE_DB) {
                         $result = $account->IsInternal ? $dbStorage->UpdateOnlyAccoutnData($account) : $dbStorage->InsertAccountData($account);
                         if (!$result) {
                             return false;
                         }
                     } else {
                         $result = true;
                     }
                     $folders =& $mailStorage->GetFolders();
                     if ($folders == null) {
                         if (USE_DB) {
                             $dbStorage->DeleteAccountData($account->Id);
                         }
                         setGlobalError(PROC_ERROR_ACCT_CREATE);
                         return false;
                     }
                     $inb =& $folders->GetFolderByType(FOLDERTYPE_Inbox);
                     if ($inb === null) {
                         if (USE_DB) {
                             $dbStorage->DeleteAccountData($account->Id);
                         }
                         setGlobalError(PROC_ERROR_ACCT_CREATE);
                         return false;
                     }
                     $folders->SetSyncTypeToAll($inboxSyncType);
                     if (!$result) {
                         return false;
                     }
                     $s = $d = $t = $sp = null;
                     $s =& $folders->GetFolderByType(FOLDERTYPE_SentItems);
                     $d =& $folders->GetFolderByType(FOLDERTYPE_Drafts);
                     $sp =& $folders->GetFolderByType(FOLDERTYPE_Spam);
                     if ($settings->Imap4DeleteLikePop3) {
                         $t =& $folders->GetFolderByType(FOLDERTYPE_Trash);
                     }
                     $account->NameSpace = $mailStorage->GetNameSpacePrefix();
                     $account->UpdateNameSpace();
                     $createSystemFoldersInInbox = 0 === strpos($account->NameSpace, $inb->FullName);
                     $createFoldersIfNotExist = $account->IsInternal ? true : CREATE_FOLDERS_IF_NOT_EXIST;
                     /* custom class */
                     wm_Custom::StaticUseMethod('ChangeValueOfSystemFoldersInInbox', array(&$createSystemFoldersInInbox));
                     wm_Custom::StaticUseMethod('ChangeValueOfCreateFolderIfNotExist', array(&$createFoldersIfNotExist));
                     $folderPrefix = '';
                     if ($createSystemFoldersInInbox) {
                         $folderPrefix = $inb->FullName . $account->Delimiter;
                         $inb->SubFolders = $inb->SubFolders ? $inb->SubFolders : new FolderCollection();
                         $addFolders =& $inb->SubFolders;
                     } else {
                         $addFolders =& $folders;
                     }
                     if ($s === null) {
                         $sentFolder = new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_SentItems, FOLDERNAME_SentItems, FOLDERSYNC_DontSync);
                         if ($createFoldersIfNotExist) {
                             $sentFolder->SetFolderSync($inboxSyncType);
                             $mailStorage->CreateFolder($sentFolder);
                         }
                         $addFolders->Add($sentFolder);
                     }
                     if ($d === null) {
                         $draftsFolder = new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_Drafts, FOLDERNAME_Drafts, FOLDERSYNC_DontSync);
                         if ($createFoldersIfNotExist) {
                             $draftsFolder->SetFolderSync($inboxSyncType);
                             $mailStorage->CreateFolder($draftsFolder);
                         }
                         $addFolders->Add($draftsFolder);
                     }
                     if ($sp === null) {
                         $spamFolder = new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_Spam, FOLDERNAME_Spam, FOLDERSYNC_DontSync);
                         if ($createFoldersIfNotExist) {
                             $spamFolder->SetFolderSync($inboxSyncType);
                             $mailStorage->CreateFolder($spamFolder);
                         }
                         $addFolders->Add($spamFolder);
                     }
                     if ($settings->Imap4DeleteLikePop3 && $t === null) {
                         $trashFolder = new Folder($account->Id, -1, $folderPrefix . FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_DontSync);
                         if ($createFoldersIfNotExist) {
                             $trashFolder->SetFolderSync($inboxSyncType);
                             $mailStorage->CreateFolder($trashFolder);
                         }
                         $addFolders->Add($trashFolder);
                     }
                     $mailStorage->Disconnect();
                 } else {
                     return false;
                 }
                 break;
             default:
                 return false;
         }
         if ($result && $folders) {
             $folders = $folders->SortRootTree();
             if (USE_DB) {
                 $result &= $dbStorage->CreateFolders($folders);
             }
         }
     }
     if ($result) {
         setGlobalError('');
         if ($account && $account->MailProtocol == MAILPROTOCOL_IMAP4 && $account->ImapQuota === 1) {
             $account->UpdateMailBoxLimit();
         }
     }
     return $result;
 }