/** * @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; }
function checkSystemFolderAndCreate(&$_settings, &$_newprocessor, &$_account, &$folders, $folderType, $folderName) { $createSystemFoldersInInbox = 0 === strpos($_account->NameSpace, 'INBOX'); $createFoldersIfNotExist = CREATE_FOLDERS_IF_NOT_EXIST; /* custom class */ wm_Custom::StaticUseMethod('ChangeValueOfSystemFoldersInInbox', array(&$createSystemFoldersInInbox)); wm_Custom::StaticUseMethod('ChangeValueOfCreateFolderIfNotExist', array(&$createFoldersIfNotExist)); $folderByName = $folders->GetFolderByName($folderName); $folderByType = $folders->GetFolderByType($folderType); if ($folderByName && !$folderByType) { if ($folderByName->Type !== $folderType) { $folderByName->Type = $folderType; if ($createFoldersIfNotExist && $folderByName->SyncType == FOLDERSYNC_DontSync) { $folderByName->SetFolderSync($_account->GetDefaultFolderSync($_settings)); $_newprocessor->CreateFolder($folderByName); } else { if ($_newprocessor->DbStorage->Connect()) { $_newprocessor->DbStorage->UpdateFolder($folderByName); } } } } else { if (!$folderByType) { $prefix = ''; if ($createSystemFoldersInInbox) { $inboxFolder = $folders->GetFolderByType(FOLDERTYPE_Inbox); if ($inboxFolder) { $prefix = $inboxFolder->FullName . $_account->Delimiter; } } $folder = new Folder($_account->Id, -1, $prefix . $folderName, $folderName, FOLDERSYNC_DontSync, $folderType); if ($createFoldersIfNotExist) { $folder->SetFolderSync($_account->GetDefaultFolderSync($_settings)); } $_newprocessor->CreateFolder($folder); } } }
/** * @param Account $account * @param int $sync = null * @return bool */ function CreateAccount(&$account, $sync = null) { $result = true; if ($this->DbStorage->Connect()) { if ($account->DefaultAccount && !$account->IsInternal) { $defaultAccountArray = $this->DbStorage->SelectAccountDataByLogin($account->Email, $account->MailIncLogin, true); if (is_array($defaultAccountArray) && count($defaultAccountArray) > 0) { $this->SetError(ap_Utils::TakePhrase('WM_CANT_ADD_DEF_ACCT')); $result = false; } } if ($result) { if ($account->MailProtocol == WM_MAILPROTOCOL_IMAP4) { if (!$this->IsQuotaSupport()) { $account->ImapQuota = -1; } if ($account->ImapQuota === 1) { $quota = $this->GetQuota(); if (false !== $quota && $quota > 0) { $account->MailboxLimit = GetGoodBigInt($quota); } else { $account->ImapQuota = -1; } } } if ($this->DbStorage->InsertUserData($account)) { $addFolders = null; $folders = new FolderCollection(); $result = $account->IsInternal ? $this->DbStorage->UpdateEximAccountData($account) : $this->DbStorage->InsertAccountData($account); if ($result) { switch ($account->MailProtocol) { case WM_MAILPROTOCOL_POP3: $inboxFolder = new Folder($account->Id, -1, WM_FOLDERNAME_Inbox, WM_FOLDERNAME_Inbox, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_Inbox); if ($inboxFolder) { if ($account->_settings->AllowDirectMode && $account->_settings->DirectModeIsDefault) { $inboxFolder->SyncType = WM_FOLDERSYNC_DirectMode; } else { $inboxFolder->SyncType = $sync !== null ? $sync : WM_FOLDERSYNC_AllEntireMessages; } } $createSystemFoldersInInbox = false; $createSystemFoldersNameSpace = $inboxFolder && 0 === strpos($nameSpacePrefix, $inboxFolder->FullName); /* custom class */ ap_Custom::StaticUseMethod('wm_ChangeValueOfSystemFoldersInInbox', array(&$createSystemFoldersInInbox)); $folderPrefix = ''; if ($createSystemFoldersInInbox && $inboxFolder) { $folderPrefix = $inboxFolder->FullName . $account->Delimiter; $inboxFolder->SubFolders = $inboxFolder->SubFolders ? $inboxFolder->SubFolders : new FolderCollection(); $addFolders =& $inboxFolder->SubFolders; } else { $addFolders =& $folders; } $folders->Add($inboxFolder); $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_SentItems, WM_FOLDERNAME_SentItems, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_SentItems)); $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_Drafts, WM_FOLDERNAME_Drafts, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_Drafts)); $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_Spam, WM_FOLDERNAME_Spam, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_Spam)); $addFolders->Add(new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_Trash, WM_FOLDERNAME_Trash, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_Trash)); break; case WM_MAILPROTOCOL_IMAP4: $accountDelimiter = $account->Delimiter; $folders =& $this->MailStorage->GetFolders($accountDelimiter); if ($accountDelimiter != $account->Delimiter) { $account->Delimiter = $accountDelimiter; $this->DbStorage->UpdateAccountDelimiter($account->Id, $accountDelimiter); } $result &= $folders != null; if ($result) { $inb =& $folders->GetFolderByType(WM_FOLDERTYPE_Inbox); if ($inb === null) { $result = false; break; } $inboxSyncType = $sync !== null ? $sync : WM_FOLDERSYNC_AllHeadersOnly; if ($account->_settings->AllowDirectMode && $account->_settings->DirectModeIsDefault) { $inboxSyncType = WM_FOLDERSYNC_DirectMode; } $folders->SetSyncTypeToAll($inboxSyncType); $account->NameSpace = $this->MailStorage->GetNameSpacePrefix(); $this->DbStorage->UpdateAccountNameSpace($account->Id, $account->NameSpace); $createSystemFoldersInInbox = 0 === strpos($account->NameSpace, $inb->FullName); $createFoldersIfNotExist = $account->IsInternal; /* custom class */ ap_Custom::StaticUseMethod('wm_ChangeValueOfSystemFoldersInInbox', array(&$createSystemFoldersInInbox)); ap_Custom::StaticUseMethod('wm_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; } $s = $d = $t = $sp = null; $s =& $folders->GetFolderByType(WM_FOLDERTYPE_SentItems); $d =& $folders->GetFolderByType(WM_FOLDERTYPE_Drafts); if ($account->_settings->Imap4DeleteLikePop3) { $t =& $folders->GetFolderByType(WM_FOLDERTYPE_Trash); } $sp =& $folders->GetFolderByType(WM_FOLDERTYPE_Spam); if ($s === null) { $sentFolder = new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_SentItems, WM_FOLDERNAME_SentItems, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_SentItems); if ($createFoldersIfNotExist) { $sentFolder->SetFolderSync($inboxSyncType); $this->MailStorage->CreateFolder($sentFolder); } $addFolders->Add($sentFolder); } if ($d === null) { $draftsFolder = new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_Drafts, WM_FOLDERNAME_Drafts, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_Drafts); if ($createFoldersIfNotExist) { $draftsFolder->SetFolderSync($inboxSyncType); $this->MailStorage->CreateFolder($draftsFolder); } $addFolders->Add($draftsFolder); } if ($sp === null) { $spamFolder = new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_Spam, WM_FOLDERNAME_Spam, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_Spam); if ($createFoldersIfNotExist) { $spamFolder->SetFolderSync($inboxSyncType); $this->MailStorage->CreateFolder($spamFolder); } $addFolders->Add($spamFolder); } if ($account->_settings->Imap4DeleteLikePop3 && $t === null) { $trashFolder = new Folder($account->Id, -1, $folderPrefix . WM_FOLDERNAME_Trash, WM_FOLDERNAME_Trash, WM_FOLDERSYNC_DontSync, WM_FOLDERTYPE_Trash); if ($createFoldersIfNotExist) { $trashFolder->SetFolderSync($inboxSyncType); $this->MailStorage->CreateFolder($trashFolder); } $addFolders->Add($trashFolder); } } else { $this->DbStorage->DeleteUserData($account->IdUser, $account->Id); } $this->MailStorage->Disconnect(); break; } } else { $result = false; $this->DbStorage->DeleteUserData($account->IdUser); } if ($result && $folders && $folders->Count() > 0) { $folders = $folders->SortRootTree(); $this->DbStorage->CreateFolders($folders); } } } } else { $result = false; } if ($result && $account->IsInternal) { $this->DbStorage->SaveMailAliases($account); $this->DbStorage->SaveMailForwards($account); } if (!$result) { $this->SetError(ap_Utils::TakePhrase('WM_CANT_CREATE_ACCOUNT')); } return $result; }