コード例 #1
0
ファイル: class_folders.php プロジェクト: JDevelopers/Mail
 /**
  * @access private
  * @param FolderCollection $folderList
  */
 function _createFolderListFromTree(&$folderList)
 {
     for ($i = 0, $c = $this->Count(); $i < $c; $i++) {
         $folder =& $this->Get($i);
         $folderList->Add($folder);
         if ($folder->SubFolders !== null && $folder->SubFolders->Count() > 0) {
             $folder->SubFolders->_createFolderListFromTree($folderList);
         }
         unset($folder);
     }
 }
コード例 #2
0
    /**
     * @param PageBuilder $pageBuilder
     * @return MessageListTable
     */
    function MessageListTable(&$pagebuilder)
    {
        $this->_pagebuilder =& $pagebuilder;
        $this->_proc =& $pagebuilder->_proc;
        $this->sortField = Get::val('s_fld', 0);
        $this->sortOrder = Get::val('s_ord', 0);
        $this->page = $this->_proc->sArray[PAGE];
        $this->_proc->account->DefaultOrder = $this->sortField + $this->sortOrder;
        $this->folders =& $this->_proc->GetFolders();
        if (isset($this->_proc->sArray[SEARCH_ARRAY][S_TEXT]) && strlen($this->_proc->sArray[SEARCH_ARRAY][S_TEXT]) > 0) {
            if ($this->_proc->sArray[SEARCH_ARRAY][S_FOLDER] > -2) {
                $this->folder =& $this->folders->GetFolderById((int) $this->_proc->sArray[FOLDER_ID]);
                $this->_proc->processor->GetFolderInfo($this->folder);
                $this->folders =& new FolderCollection();
                $this->folders->Add($this->folder);
            } else {
                $this->folder = null;
            }
            $field = $this->_proc->sArray[SEARCH_ARRAY][S_MODE] == 'onlyheaders';
            $condition = ConvertUtils::ConvertEncoding($this->_proc->sArray[SEARCH_ARRAY][S_TEXT], $this->_proc->account->GetUserCharset(), $this->_proc->account->DbCharset);
            $this->messCount = (int) $this->_proc->processor->SearchMessagesCount($condition, $this->folders, $field);
            $this->messageCollection =& $this->_proc->processor->SearchMessages($this->page, $condition, $this->folders, $field, $this->messCount);
        } else {
            $cfolder =& $this->_proc->GetCurrentFolder();
            if ($cfolder) {
                $this->folder =& $cfolder;
                $this->messCount = (int) $this->folder->MessageCount;
                if ($this->_proc->account->MailsPerPage * ($this->page - 1) >= $this->messCount) {
                    $this->page = (int) ceil($this->messCount / $this->_proc->account->MailsPerPage);
                }
                $this->page = $this->page < 1 ? $this->page = 1 : $this->page;
                $this->messageCollection =& $this->_proc->processor->GetMessageHeaders($this->page, $this->folder);
            } else {
                $this->folder = null;
                $this->messCount = 0;
                $this->page = 1;
                $this->messageCollection =& new WebMailMessageCollection();
            }
        }
        if ($this->folder && $this->folders) {
            $this->folders->InitToFolder($this->folder);
        }
        if ($this->messageCollection === null) {
            $this->folder = null;
            $this->messCount = 0;
            $this->page = 1;
            $this->messageCollection =& new WebMailMessageCollection();
            SetOnlineError(PROC_CANT_GET_MSG_LIST);
        }
        $jsTempString = $this->_proc->currentFolder && $this->_proc->currentFolder->Type == FOLDERTYPE_Drafts ? 'BaseForm.Form.action = "' . BASEFILE . '?' . SCREEN . '=' . SCREEN_NEWOREDIT . '";' : 'BaseForm.Form.action = "' . BASEFILE . '?' . SCREEN . '=' . SCREEN_FULLSCREEN . '";';
        $flagjs = '
		var line = InboxLines.GetLinesById(id);
		if (line.Flagged) {
			InboxLines.SetParams([id], "Flagged", false, false);
		} else {
			InboxLines.SetParams([id], "Flagged", true, false);
		}
		DoFlagOneMessage(line);
';
        if ($this->_proc->account->MailProtocol != MAILPROTOCOL_IMAP4 && $this->_proc->currentFolder && $this->_proc->currentFolder->SyncType == FOLDERSYNC_DirectMode) {
            $flagjs = '';
        }
        $this->_pagebuilder->AddJSText('
		
function CheckThisLine(e, trobj)
{
	var id = trobj.id;

	e = e ? e : window.event;
	if (e.ctrlKey) {
		InboxLines.CheckCtrlLine(id);
	} else if (e.shiftKey) {
		InboxLines.CheckShiftLine(id);
	} else {
		if (Browser.Mozilla) {var elem = e.target;}
		else {var elem = e.srcElement;}
		
		if (!elem || id == "" || elem.id == "none") {
			return false;
		}
		
		var loverTag = elem.tagName.toLowerCase();
		
		if (loverTag == "a") {
			LoadMessageFull(id);
		} else if (loverTag == "input") {
			InboxLines.CheckCBox(id);
		} else if (loverTag == "img") {
			' . $flagjs . '
		} else if (isPreviewPane) {
			InboxLines.CheckLine(id);
			LoadMessage(id);
		}
	}
}		

function CheckThisLineDb(e, trobj)
{
	var id = trobj.id;

	e = e ? e : window.event;

	if (Browser.Mozilla) {
		var elem = e.target;
	} else {
		var elem = e.srcElement;
	}
	
	if (!elem || id == "" || elem.id == "none" || elem.tagName.toLowerCase() == "input") {
		return false;
	}
	LoadMessageFull(id);
}

function LoadMessageFull(lineid)
{
	var parseObj = ParseLineId(lineid);
	var obj = InboxLines.GetLinesById(lineid);

	' . $jsTempString . '
	BaseForm.Form.target = "_self";
	BaseForm.MessId.value = obj.MsgId;
	BaseForm.MessUid.value = obj.MsgUid;
	BaseForm.FolderId.value = obj.MsgFolderId;
	BaseForm.FolderName.value = obj.MsgFolderFullName;
	BaseForm.Charset.value = parseObj.charset;
	BaseForm.Plain.value = "-1";
	BaseForm.Form.submit();
}
	
function LoadMessage(lineid)
{
	if (tempReq != lineid){
		InfoPanel._isError = false;
		InfoPanel.SetInfo(Lang.Loading);
		InfoPanel.Show();
		
		tempReq = lineid;
		var parseObj = ParseLineId(lineid);
		var obj = InboxLines.GetLinesById(lineid);
		
		BaseForm.MessId.value = obj.MsgId;
		BaseForm.MessUid.value = obj.MsgUid;
		BaseForm.FolderId.value = obj.MsgFolderId;
		BaseForm.FolderName.value = obj.MsgFolderFullName;
		BaseForm.Charset.value = parseObj.charset;
		BaseForm.Plain.value = "-1";
		BaseForm.Form.submit();
	}
}

function DoForwardButton()
{
	var lineobjs = InboxLines.GetCheckedLinesObj();
	if (lineobjs && lineobjs.length == 1) {
		var obj = lineobjs[0];
		var parseObj = ParseLineId(obj.Id);

		BaseForm.Form.action = "' . BASEFILE . '?' . SCREEN . '=' . SCREEN_NEWOREDIT . '";
		BaseForm.Form.target = "_self";
		BaseForm.MessId.value = obj.MsgId;
		BaseForm.MessUid.value = obj.MsgUid;
		BaseForm.FolderId.value = obj.MsgFolderId;
		BaseForm.FolderName.value = obj.MsgFolderFullName;
		BaseForm.Charset.value = parseObj.charset;
		BaseForm.Plain.value = "-1";
		BaseForm.Type.value = "forward";
		BaseForm.Form.submit();
	}
}

function DoReplyButton()
{
	var lineobjs = InboxLines.GetCheckedLinesObj();
	if (lineobjs && lineobjs.length == 1) {
		var obj = lineobjs[0];
		var parseObj = ParseLineId(obj.Id);

		BaseForm.Form.action = "' . BASEFILE . '?' . SCREEN . '=' . SCREEN_NEWOREDIT . '";
		BaseForm.Form.target = "_self";
		BaseForm.MessId.value = obj.MsgId;
		BaseForm.MessUid.value = obj.MsgUid;
		BaseForm.FolderId.value = obj.MsgFolderId;
		BaseForm.FolderName.value = obj.MsgFolderFullName;
		BaseForm.Charset.value = parseObj.charset;
		BaseForm.Plain.value = "-1";
		BaseForm.Type.value = "reply";
		BaseForm.Form.submit();
	}
}

function DoReplyAllButton()
{
	var lineobjs = InboxLines.GetCheckedLinesObj();
	if (lineobjs && lineobjs.length == 1) {
		var obj = lineobjs[0];
		var parseObj = ParseLineId(obj.Id);

		BaseForm.Form.action = "' . BASEFILE . '?' . SCREEN . '=' . SCREEN_NEWOREDIT . '";
		BaseForm.Form.target = "_self";
		BaseForm.MessId.value = obj.MsgId;
		BaseForm.MessUid.value = obj.MsgUid;
		BaseForm.FolderId.value = obj.MsgFolderId;
		BaseForm.FolderName.value = obj.MsgFolderFullName;
		BaseForm.Charset.value = parseObj.charset;
		BaseForm.Plain.value = "-1";
		BaseForm.Type.value = "replytoall";
		BaseForm.Form.submit();
	}
}


function ChangeCharset(newCharset)
{
	var idline = BaseForm.MessId.value + sep + BaseForm.MessUid.value + sep + BaseForm.FolderId.value + sep + BaseForm.Charset.value + sep;
	var newidline = BaseForm.MessId.value + sep + BaseForm.MessUid.value + sep + BaseForm.FolderId.value + sep + newCharset + sep;
	BaseForm.Charset.value = newCharset;
	
	for (var i=0; i<InboxLines.length; i++) {
		if (InboxLines.lines[i].Id == idline) {
			InboxLines.lines[i].Id = newidline;
			InboxLines.lines[i]._tr.id = newidline;
		}
	}
} 

function ParseLineId(lineid)
{
	var IdArray = lineid.split(sep);
	if (IdArray.length > 3) {
		var objcharset = (IdArray[3]) ? IdArray[3] : -1;
		return {id: IdArray[0], uid: IdArray[1], folder_id: IdArray[2], charset: objcharset}
	}
	return null;
}

	');
        $this->_pagebuilder->AddInitText('	
PageSwitcher.Show(' . $this->page . ', ' . $this->_proc->account->MailsPerPage . ', ' . $this->messCount . ', "document.location.replace(\'?s_ord=' . $this->sortOrder . '&s_fld=' . $this->sortField . '&page=", "\');");
tempReq = "";

function CBaseForm()
{
	this.Form = document.getElementById("messform");
	this.MessId = document.getElementById("m_id");
	this.MessUid = document.getElementById("m_uid");
	this.FolderId = document.getElementById("f_id");
	this.FolderName = document.getElementById("f_name");
	this.Charset = document.getElementById("charset");
	this.Plain = document.getElementById("plain");
	this.Type = document.getElementById("mtype");
}
BaseForm = new CBaseForm();
');
    }
コード例 #3
0
ファイル: class_folders.php プロジェクト: JDevelopers/Mail
 /**
  * @access private
  * @param FolderCollection $folderList
  */
 function _createFolderListFromTree(&$folderList)
 {
     for ($i = 0, $c = $this->Count(); $i < $c; $i++) {
         $folder =& $this->Get($i);
         if (!$folder) {
             continue;
         }
         $folderList->Add($folder);
         if (!is_null($folder->SubFolders) && $folder->SubFolders->Count() > 0) {
             $folder->SubFolders->_createFolderListFromTree($folderList);
         }
         unset($folder);
     }
 }
コード例 #4
0
ファイル: check-mail.php プロジェクト: JDevelopers/Mail
    $errorDesc = trim($errorDesc);
    if (strlen($errorDesc) > 0) {
        SetError($errorDesc);
    }
    echo '<script>parent.EndCheckMailHandler();</script>.CRLF';
} else {
    if (2 === $type) {
        $processor = new MailProcessor($account);
        $folders =& $processor->GetFolders();
        $processor->MailStorage->DownloadedMessagesHandler = null;
        $processor->MailStorage->UpdateFolderHandler = 'AddFolder4Update';
        $inboxFolder = $folders->GetFolderByType(FOLDERTYPE_Inbox);
        if ($inboxFolder) {
            $inboxFolder->SubFolders = null;
            $foldersForInboxSynchronize = new FolderCollection();
            $foldersForInboxSynchronize->Add($inboxFolder);
            if (!$processor->Synchronize($foldersForInboxSynchronize)) {
                $errorDesc = getGlobalError();
            }
            $processor->MailStorage->Disconnect();
        } else {
            $errorDesc = '';
        }
        $errorDesc = trim($errorDesc);
        echo '<script>
parent.SetUpdatedFolders(' . Folders4UpdateToJsArray() . ', false);
parent.EndCheckMailHandler("' . ConvertUtils::ClearJavaScriptString($errorDesc, '"') . '");
</script>' . CRLF;
    } else {
        ShowLoggingToServer();
        $processor = new MailProcessor($account);
コード例 #5
0
ファイル: class_dbstorage.php プロジェクト: JDevelopers/Mail
 /**
  * @access private
  * @param FolderCollection $folderCollection
  * @param Array $folders
  * @param string $rootPrefix optional
  */
 function _addLevelToFolderTree(&$folderCollection, &$folders, $rootPrefix = '', $isToFolder = false)
 {
     $prefixLen = strlen($rootPrefix);
     $foldersCount = count($folders);
     for ($i = 0; $i < $foldersCount; $i++) {
         $folderFullName = $folders[$i]->FullName;
         if ($rootPrefix != $folderFullName && strlen($folderFullName) > $prefixLen && substr($folderFullName, 0, $prefixLen) == $rootPrefix && strpos($folderFullName, $this->Account->Delimiter, $prefixLen + 1) === false) {
             $folderObj =& $folders[$i];
             $isTo = $isToFolder || $folderObj->Type == FOLDERTYPE_Drafts || $folderObj->Type == FOLDERTYPE_SentItems;
             $folderObj->ToFolder = $isTo;
             $folderCollection->Add($folderObj);
             $newCollection = new FolderCollection();
             $this->_addLevelToFolderTree($newCollection, $folders, $folderFullName . $this->Account->Delimiter, $isTo);
             if ($newCollection->Count() > 0) {
                 $folderObj->SubFolders = $newCollection;
             }
             unset($folderObj, $newCollection);
         }
     }
 }
コード例 #6
0
 /**
  * @param bool $sortSpecialFolders[optional] = false
  * @return FolderCollection
  */
 function _sortFolderCollection($sortSpecialFolders = false)
 {
     $newFoldersArray = $topArray = $footArray = $tempArray = array();
     $newFolders = new FolderCollection();
     foreach ($this->Instance() as $folder) {
         if (strlen($folder->Name) > 0 && $folder->Name[0] == '&') {
             $footArray[] = $folder->Name;
         } else {
             $topArray[] = $folder->Name;
         }
     }
     unset($folder);
     natcasesort($topArray);
     foreach ($topArray as $value) {
         $newFoldersArray[strtolower($value)] = $value;
     }
     foreach ($footArray as $value) {
         $newFoldersArray[strtolower($value)] = $value;
     }
     unset($topArray, $footArray);
     if ($sortSpecialFolders) {
         if (isset($newFoldersArray[strtolower(FOLDERNAME_Inbox)])) {
             $folder =& $this->GetFolderByName($newFoldersArray[strtolower(FOLDERNAME_Inbox)]);
             if ($folder) {
                 if ($folder->SubFolders && $folder->SubFolders->Count() > 1) {
                     $folder->SubFolders = $folder->SubFolders->_sortFolderCollection(true);
                 }
                 $newFolders->Add($folder);
                 unset($newFoldersArray[strtolower(FOLDERNAME_Inbox)]);
             }
         }
         if (isset($newFoldersArray[strtolower(FOLDERNAME_SentItems)])) {
             $folder =& $this->GetFolderByName($newFoldersArray[strtolower(FOLDERNAME_SentItems)]);
             if ($folder) {
                 if ($folder->SubFolders && $folder->SubFolders->Count() > 1) {
                     $folder->SubFolders = $folder->SubFolders->_sortFolderCollection();
                 }
                 $newFolders->Add($folder);
                 unset($newFoldersArray[strtolower(FOLDERNAME_SentItems)]);
             }
         }
         if (isset($newFoldersArray[strtolower(FOLDERNAME_Sent)])) {
             $folder =& $this->GetFolderByName($newFoldersArray[strtolower(FOLDERNAME_Sent)]);
             if ($folder) {
                 if ($folder->SubFolders && $folder->SubFolders->Count() > 1) {
                     $folder->SubFolders = $folder->SubFolders->_sortFolderCollection();
                 }
                 $newFolders->Add($folder);
                 unset($newFoldersArray[strtolower(FOLDERNAME_Sent)]);
             }
         }
         if (isset($newFoldersArray[strtolower(FOLDERNAME_Drafts)])) {
             $folder =& $this->GetFolderByName($newFoldersArray[strtolower(FOLDERNAME_Drafts)]);
             if ($folder) {
                 if ($folder->SubFolders && $folder->SubFolders->Count() > 1) {
                     $folder->SubFolders = $folder->SubFolders->_sortFolderCollection();
                 }
                 $newFolders->Add($folder);
                 unset($newFoldersArray[strtolower(FOLDERNAME_Drafts)]);
             }
         }
         if (isset($newFoldersArray[strtolower(FOLDERNAME_Trash)])) {
             $folder =& $this->GetFolderByName($newFoldersArray[strtolower(FOLDERNAME_Trash)]);
             if ($folder) {
                 if ($folder->SubFolders && $folder->SubFolders->Count() > 1) {
                     $folder->SubFolders = $folder->SubFolders->_sortFolderCollection();
                 }
                 $newFolders->Add($folder);
                 unset($newFoldersArray[strtolower(FOLDERNAME_Trash)]);
             }
         }
     }
     foreach ($newFoldersArray as $folderName) {
         $folder =& $this->GetFolderByName($folderName);
         if ($folder) {
             if ($folder->SubFolders && $folder->SubFolders->Count() > 1) {
                 $folder->SubFolders = $folder->SubFolders->_sortFolderCollection();
             }
             $newFolders->Add($folder);
         }
     }
     return $newFolders;
 }
コード例 #7
0
ファイル: class_account.php プロジェクト: JDevelopers/Mail
 /**
  * @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;
 }
コード例 #8
0
 /**
  * @access private
  * @param FolderCollection $folderCollection
  * @param array $folders
  * @param array $subsfolders
  * @param string $rootPrefix optional
  */
 function _addLevelToFolderTree(&$folderCollection, &$folders, $subsfolders, $rootPrefix = '', $isInbox = false)
 {
     static $InboxAdd = false;
     static $SentAdd = false;
     static $DraftsAdd = false;
     static $TrashAdd = false;
     $prefixLen = strlen($rootPrefix);
     $foldersCount = count($folders);
     for ($i = 0; $i < $foldersCount; $i++) {
         $folderFullName = $folders[$i];
         if ($rootPrefix != $folderFullName && strlen($folderFullName) > $prefixLen && substr($folderFullName, 0, $prefixLen) == $rootPrefix && strpos($folderFullName, $this->Account->Delimiter, $prefixLen + 1) === false) {
             $strLen = $prefixLen == 0 ? $prefixLen : $prefixLen - 1;
             $name = trim(substr($folderFullName, $strLen), $this->Account->Delimiter);
             $names = explode($this->Account->Delimiter, $name);
             $folderObj =& new Folder($this->Account->Id, -1, $folderFullName, $names[0]);
             if ($prefixLen == 0 || $isInbox) {
                 switch ($folderObj->Type) {
                     case FOLDERTYPE_Inbox:
                         if ($InboxAdd) {
                             $folderObj->Type = FOLDERTYPE_Custom;
                         }
                         $InboxAdd = true;
                         break;
                     case FOLDERTYPE_SentItems:
                         if ($SentAdd) {
                             $folderObj->Type = FOLDERTYPE_Custom;
                         }
                         $SentAdd = true;
                         break;
                     case FOLDERTYPE_Drafts:
                         if ($DraftsAdd) {
                             $folderObj->Type = FOLDERTYPE_Custom;
                         }
                         $DraftsAdd = true;
                         break;
                     case FOLDERTYPE_Trash:
                         if (USEIMAPTRASH) {
                             if ($TrashAdd) {
                                 $folderObj->Type = FOLDERTYPE_Custom;
                             }
                             $TrashAdd = true;
                         } else {
                             $folderObj->Type = FOLDERTYPE_Custom;
                         }
                         break;
                 }
             } else {
                 $folderObj->Type = FOLDERTYPE_Custom;
             }
             $folderObj->Hide = !in_array($folderObj->FullName, $subsfolders);
             if ($folderObj->Type != FOLDERTYPE_Custom) {
                 $folderObj->Hide = false;
             }
             $folderCollection->Add($folderObj);
             $newCollection =& new FolderCollection();
             if ($folderObj->Type == FOLDERTYPE_Inbox) {
                 $this->_addLevelToFolderTree($newCollection, $folders, $subsfolders, $folderFullName . $this->Account->Delimiter, true);
             } else {
                 $this->_addLevelToFolderTree($newCollection, $folders, $subsfolders, $folderFullName . $this->Account->Delimiter);
             }
             if ($newCollection->Count() > 0) {
                 $folderObj->SubFolders =& $newCollection;
             }
         }
     }
 }
コード例 #9
0
 function DoGetMessages()
 {
     $_dbStorage = $_settings = $_xmlObj = $_xmlRes = $_accountId = null;
     $this->_initFuncArgs($_dbStorage, $_settings, $_xmlObj, $_xmlRes, $_accountId);
     $_acct_id = $_xmlObj->GetParamValueByName('id_acct');
     if (strlen($_acct_id) == 0) {
         $_acct_id = $_accountId;
     }
     CXmlProcessing::CheckAccountAccess($_acct_id, $_xmlRes);
     $_account =& CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_acct_id, false, false);
     $_processor = new MailProcessor($_account);
     $_page = 1;
     $_folderNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('folder');
     $log =& CLog::CreateInstance();
     $_folders = $_folder = null;
     if (isset($_folderNode->Attributes['id'])) {
         $_folder = new Folder($_account->Id, $_folderNode->Attributes['id'], $_folderNode->GetChildValueByTagName('full_name'));
         if (!USE_DB) {
             $_folder->SyncType = FOLDERSYNC_DirectMode;
         }
     } else {
         CXmlProcessing::PrintErrorAndExit(PROC_CANT_GET_MSG_LIST, $_xmlRes);
     }
     $_searchNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('look_for');
     if (!isset($_searchNode->Attributes['fields'])) {
         CXmlProcessing::PrintErrorAndExit(PROC_CANT_GET_MSG_LIST, $_xmlRes);
     }
     $_sortField = $_xmlObj->GetParamValueByName('sort_field');
     $_sortOrder = $_xmlObj->GetParamValueByName('sort_order');
     if ($_sortField + $_sortOrder != $_account->DefaultOrder) {
         $_account->DefaultOrder = $_sortField + $_sortOrder;
         $_account->UpdateDefaultOrder();
     }
     if ($_searchNode->Value === '' || $_searchNode->Value === null) {
         $_processor->GetFolderInfo($_folder);
         $_processor->GetFolderMessageCount($_folder);
         if (ceil($_folder->MessageCount / $_account->MailsPerPage) < (int) $_xmlObj->GetParamValueByName('page')) {
             $_page = $_xmlObj->GetParamValueByName('page') - 1;
             $_page = $_page < 1 ? 1 : $_page;
         } else {
             $_page = $_xmlObj->GetParamValueByName('page');
         }
         $_messageCollection =& $_processor->GetMessageHeaders($_page, $_folder);
     } else {
         if ($_folder->IdDb == -1) {
             if (USE_DB) {
                 $_folders =& $_processor->GetFolders();
             } else {
                 $_Allfolders =& $_processor->GetFolders();
                 $_folder = $_Allfolders->GetFolderByType(FOLDERTYPE_Inbox);
             }
         } else {
             $_processor->GetFolderInfo($_folder);
             $_folders = new FolderCollection();
             $_folders->Add($_folder);
         }
         $_page = (int) $_xmlObj->GetParamValueByName('page');
         $log->WriteLine(print_r($_folder, true));
         if ($_account->MailProtocol == MAILPROTOCOL_IMAP4 && $_folder->SyncType == FOLDERSYNC_DirectMode && $_folder->IdDb > 0) {
             $_processor->GetFolderInfo($_folder);
             $msgCount = 0;
             $_messageCollection =& $_processor->DmImapSearchMessages($_page, $_searchNode->Value, $_folder, (bool) (!$_searchNode->Attributes['fields']), $msgCount);
             $_folder->MessageCount = $msgCount;
         } else {
             if ($_account->MailProtocol == MAILPROTOCOL_IMAP4 && (bool) $_searchNode->Attributes['fields'] && $_folder->IdDb > 0 && ($_folder->SyncType == FOLDERSYNC_AllHeadersOnly || $_folder->SyncType == FOLDERSYNC_NewHeadersOnly)) {
                 $_processor->GetFolderInfo($_folder);
                 $msgCount = 0;
                 $_messageCollection =& $_processor->HeadersFullImapSearchMessages($_page, $_searchNode->Value, $_folder, $msgCount);
                 $_folder->MessageCount = $msgCount;
             } else {
                 $_folder->MessageCount = $_processor->SearchMessagesCount(ConvertUtils::ConvertEncoding($_searchNode->Value, $_account->GetUserCharset(), $_account->DbCharset), $_folders, (bool) (!$_searchNode->Attributes['fields']));
                 $_messageCollection =& $_processor->SearchMessages($_page, ConvertUtils::ConvertEncoding($_searchNode->Value, $_account->GetUserCharset(), $_account->DbCharset), $_folders, (bool) (!$_searchNode->Attributes['fields']), $_folder->MessageCount);
             }
         }
     }
     CXmlProcessing::GetMessagesList($_xmlRes, $_messageCollection, $_account, $_settings, $_processor, $_folder, $_searchNode->Value, $_searchNode->Attributes['fields'], $_page, $_sortField, $_sortOrder);
 }
コード例 #10
0
 /**
  * @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;
 }