Пример #1
0
 function SetCurrentFolder()
 {
     $currentFolder = null;
     if (isset($this->sArray[GOTOFOLDER])) {
         $this->sArray[FOLDER_ID] = -1;
     }
     if ($this->sArray[FOLDER_ID] > -1) {
         $folderFullName = isset($this->sArray[FOLDER_FULLNAME]) ? $this->sArray[FOLDER_FULLNAME] : 'temp_001';
         $folder =& new Folder($this->account->Id, $this->sArray[FOLDER_ID], $folderFullName);
         $this->processor->GetFolderInfo($folder);
         if ($folder && $folder->Hide) {
             $newfolder = $this->folders ? $this->folders->GetFirstNotHideFolder() : null;
             if ($newfolder) {
                 $currentFolder =& $newfolder;
             }
         } else {
             $currentFolder =& $folder;
         }
     } else {
         if ($this->sArray[FOLDER_ID] == -1) {
             $folderType = FOLDERTYPE_Inbox;
             if (isset($this->sArray[GOTOFOLDER])) {
                 $folderType = $this->sArray[GOTOFOLDER];
                 unset($this->sArray[GOTOFOLDER]);
             }
             $folder =& $this->folders->GetFolderByType($folderType);
             $this->processor->GetFolderInfo($folder);
             if ($folder && $folder->Hide) {
                 $newfolder = $this->folders ? $this->folders->GetFirstNotHideFolder() : null;
                 if ($newfolder) {
                     $currentFolder =& $newfolder;
                 }
             } else {
                 $currentFolder =& $folder;
             }
         }
     }
     $this->currentFolder =& $currentFolder;
     if ($this->currentFolder) {
         $this->processor->GetFolderMessageCount($this->currentFolder);
         $this->sArray[FOLDER_ID] = $this->currentFolder->IdDb;
     } else {
         $this->sArray[FOLDER_ID] = -1;
     }
 }
Пример #2
0
 /**
  * @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);
     }
 }
Пример #3
0
 /**
  * @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
    /**
     * @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();
');
    }
Пример #5
0
 /**
  * @param int $pageNumber
  * @param string $condition
  * @param FolderCollection $folders
  * @param bool $inHeadersOnly
  * @return WebMailMessageCollection
  */
 function &SearchMessages($pageNumber, $condition, &$folders, $inHeadersOnly)
 {
     $mailCollection = null;
     if ($this->_dbConnection->Execute($this->_commandCreator->SearchMessages($pageNumber, $condition, $folders->CreateFolderListFromTree(), $inHeadersOnly, $this->Account))) {
         $mailCollection = new WebMailMessageCollection();
         while (false !== ($row = $this->_dbConnection->GetNextRecord())) {
             $msg =& $this->_rowToWebMailMessage($row);
             $mailCollection->Add($msg);
             unset($msg);
         }
     }
     return $mailCollection;
 }
Пример #6
0
 /**
  * @param FolderCollection $folderCollection
  * @return String
  */
 function CreateFolderTree($folderCollection)
 {
     $out = '';
     for ($i = 0, $c = $folderCollection->Count(); $i < $c; $i++) {
         $folder =& $folderCollection->Get($i);
         if ($folder->Hide) {
             continue;
         }
         if ($folder->SyncType == FOLDERSYNC_DirectMode && $this->_pagebuilder->_proc->account->MailProtocol == MAILPROTOCOL_POP3) {
             continue;
         }
         $foldername = '';
         if (ConvertUtils::IsLatin($folder->Name)) {
             $foldername = ConvertUtils::ConvertEncoding($folder->Name, CPAGE_UTF7_Imap, $this->_pagebuilder->_proc->account->GetUserCharset());
         } else {
             $foldername = ConvertUtils::ConvertEncoding($folder->Name, $this->_pagebuilder->_proc->account->DefaultIncCharset, $this->_pagebuilder->_proc->account->GetUserCharset());
         }
         $out .= '<div onclick="MoveToFolder(\'' . $folder->IdDb . '\');" class="wm_menu_item" onmouseover="this.className=\'wm_menu_item_over\';" onmouseout="this.className=\'wm_menu_item\';">' . str_repeat('&nbsp;', (int) $folder->Level * 4);
         switch ($folder->Type) {
             default:
             case FOLDERTYPE_Custom:
                 $out .= ConvertUtils::WMHtmlSpecialChars($foldername);
                 break;
             case FOLDERTYPE_Inbox:
                 $out .= FolderInbox;
                 break;
             case FOLDERTYPE_Drafts:
                 $out .= FolderDrafts;
                 break;
             case FOLDERTYPE_SentItems:
                 $out .= FolderSentItems;
                 break;
             case FOLDERTYPE_Trash:
                 $out .= FolderTrash;
                 break;
         }
         $out .= '</div>';
         if ($folder->SubFolders != null && $folder->SubFolders->Count() > 0) {
             $out .= $this->CreateFolderTree($folder->SubFolders);
         }
     }
     return $out;
 }
Пример #7
0
    /**
     * @param int $pageNumber
     * @param string $condition
     * @param FolderCollection $folders
     * @param bool $inHeadersOnly
     * @param Account $account
     * @return WebMailMessageCollection
     */
    function SearchMessages($pageNumber, $condition, &$folders, $inHeadersOnly, &$account)
    {
        $tempstr = '';
        $foldersId = '';
        foreach (array_keys($folders->Instance()) as $key) {
            $folder =& $folders->Get($key);
            $foldersId .= $foldersId == '' ? $folder->IdDb : ',' . $folder->IdDb;
        }
        $filter = '';
        $asc = true;
        $this->_setSortOrder($account->DefaultOrder, $filter, $asc);
        $condition = str_replace('[', '[[]', $condition);
        $condition = $this->_escapeString('%' . $condition . '%');
        if ($inHeadersOnly) {
            if (($pageNumber - 1) * $account->MailsPerPage > 0) {
                $tempstr = ' AND id_msg NOT IN 
								(SELECT TOP %d id_msg FROM %sawm_messages 
								WHERE id_acct = %d AND id_folder_db IN (%s) AND	
								(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
								LIKE %s OR subject LIKE %s) ORDER BY %s %s)';
                $tempstr = sprintf($tempstr, ($pageNumber - 1) * $account->MailsPerPage, $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $filter, $asc ? 'ASC' : 'DESC');
            }
            $sql = 'SELECT TOP %d id_msg, %s AS uid, id_folder_db, from_msg, to_msg, cc_msg,
							bcc_msg, subject, %s AS nmsg_date, size, priority, x_spam,
							attachments, seen, flagged, deleted, replied, forwarded, grayed
						FROM %sawm_messages
						WHERE id_acct = %d AND id_folder_db IN (%s) AND	
							(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
							LIKE %s OR subject LIKE %s)%s
						ORDER BY %s %s';
            return sprintf($sql, $account->MailsPerPage, $this->_getMsgIdUidFieldName(true, $account->MailProtocol), CDateTime::GetMsSqlDateFormat('msg_date'), $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $tempstr, $filter, $asc ? 'ASC' : 'DESC');
        } else {
            if (($pageNumber - 1) * $account->MailsPerPage > 0) {
                $tempstr = ' AND id_msg NOT IN 
							(SELECT TOP %d id_msg FROM %sawm_messages
							WHERE id_acct = %d AND id_folder_db IN (%s) AND	
								(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
								LIKE %s OR subject LIKE %s OR body_text LIKE %s) ORDER BY %s %s)';
                $tempstr = sprintf($tempstr, ($pageNumber - 1) * $account->MailsPerPage, $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $condition, $filter, $asc ? 'ASC' : 'DESC');
            }
            $sql = 'SELECT TOP %d id_msg, %s AS uid, id_folder_db, from_msg, to_msg, cc_msg,
							bcc_msg, subject, %s AS nmsg_date, size, priority, x_spam,
							attachments, seen, flagged, deleted, replied, forwarded, grayed
						FROM %sawm_messages
						WHERE id_acct = %d AND id_folder_db IN (%s) AND	
							(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
							LIKE %s OR subject LIKE %s OR body_text LIKE %s)%s
						ORDER BY %s %s';
            return sprintf($sql, $account->MailsPerPage, $this->_getMsgIdUidFieldName(true, $account->MailProtocol), CDateTime::GetMsSqlDateFormat('msg_date'), $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $condition, $tempstr, $filter, $asc ? 'ASC' : 'DESC');
        }
    }
Пример #8
0
 /**
  * @param FolderCollection $_folders
  * @param XmlDomNode $_nodeTree
  * @param MailProcessor $_processor
  */
 function GetFoldersTreeXml(&$_folders, &$_nodeTree, &$_processor)
 {
     for ($_i = 0, $_count = $_folders->Count(); $_i < $_count; $_i++) {
         $_folder =& $_folders->Get($_i);
         $_folderNode = new XmlDomNode('folder');
         $_folderNode->AppendAttribute('id', $_folder->IdDb);
         $_folderNode->AppendAttribute('id_parent', $_folder->IdParent);
         $_folderNode->AppendAttribute('type', $_folder->Type);
         $_folderNode->AppendAttribute('sync_type', $_folder->SyncType);
         $_folderNode->AppendAttribute('hide', (int) $_folder->Hide);
         $_folderNode->AppendAttribute('fld_order', (int) $_folder->FolderOrder);
         if ($_folder->SyncType == FOLDERSYNC_DirectMode) {
             $_processor->GetFolderMessageCount($_folder);
         }
         $_folderNode->AppendAttribute('count', $_folder->MessageCount);
         $_folderNode->AppendAttribute('count_new', $_folder->UnreadMessageCount);
         $_folderNode->AppendAttribute('size', $_folder->Size);
         if (ConvertUtils::IsLatin($_folder->Name)) {
             $_folderNode->AppendChild(new XmlDomNode('name', ConvertUtils::ConvertEncoding($_folder->Name, CPAGE_UTF7_Imap, CPAGE_UTF8), true));
         } else {
             $_folderNode->AppendChild(new XmlDomNode('name', ConvertUtils::ConvertEncoding($_folder->Name, $_processor->_account->DefaultIncCharset, CPAGE_UTF8), true));
         }
         $_folderNode->AppendChild(new XmlDomNode('full_name', $_folder->FullName, true));
         if ($_folder->SubFolders != null && $_folder->SubFolders->Count() > 0) {
             $_foldersNode = new XmlDomNode('folders');
             CXmlProcessing::GetFoldersTreeXml($_folder->SubFolders, $_foldersNode, $_processor);
             $_folderNode->AppendChild($_foldersNode);
             unset($_foldersNode);
         }
         $_nodeTree->AppendChild($_folderNode);
         unset($_folderNode, $_folder);
     }
 }
Пример #9
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;
 }
Пример #10
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;
             }
         }
     }
 }
Пример #11
0
 /**
  * @param int $pageNumber
  * @param string $condition
  * @param FolderCollection $folders
  * @param bool $inHeadersOnly
  * @return WebMailMessageCollection
  */
 function &SearchMessages($pageNumber, $condition, &$folders, $inHeadersOnly, $countMessages = 0)
 {
     $mailCollection = null;
     if ($this->_dbConnection->Execute($this->_commandCreator->SearchMessages($pageNumber, $condition, $folders->CreateFolderListFromTree(), $inHeadersOnly, $this->Account))) {
         $mailCollection =& new WebMailMessageCollection();
         while ($row = $this->_dbConnection->GetNextRecord()) {
             $msg =& new WebMailMessage();
             $msg->SetFromAsString($row->from_msg);
             $msg->SetToAsString($row->to_msg);
             $msg->SetCcAsString($row->cc_msg);
             $msg->SetBccAsString($row->bcc_msg);
             $date =& new CDateTime();
             $date->SetFromANSI($row->nmsg_date);
             $msg->SetDate($date);
             $msg->SetSubject($row->subject);
             $msg->IdMsg = $row->id_msg;
             $msg->IdFolder = $row->id_folder_db;
             $msg->Uid = $row->uid;
             $msg->Size = $row->size;
             $msg->DbPriority = $row->priority;
             $msg->DbXSpam = (bool) abs($row->x_spam);
             $msg->DbHasAttachments = $row->attachments;
             $msg->Flags = 0;
             if ($row->seen) {
                 $msg->Flags |= MESSAGEFLAGS_Seen;
             }
             if ($row->flagged) {
                 $msg->Flags |= MESSAGEFLAGS_Flagged;
             }
             if ($row->deleted) {
                 $msg->Flags |= MESSAGEFLAGS_Deleted;
             }
             if ($row->replied) {
                 $msg->Flags |= MESSAGEFLAGS_Answered;
             }
             if ($row->forwarded) {
                 $msg->Flags |= MESSAGEFLAGS_Forwarded;
             }
             if ($row->grayed) {
                 $msg->Flags |= MESSAGEFLAGS_Grayed;
             }
             $mailCollection->Add($msg);
         }
     }
     return $mailCollection;
 }
Пример #12
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);
 }
Пример #13
0
 /**
  * @param FolderCollection $folders
  * @return bool
  */
 function Synchronize(&$folders)
 {
     $result = true;
     $dbStorage =& DbStorageCreator::CreateDatabaseStorage($this->Account);
     if ($dbStorage->Connect() && $folders) {
         $folderList = $folders->CreateFolderListFromTree();
         //copy tree object here
         for ($i = 0, $icount = $folderList->Count(); $i < $icount; $i++) {
             $folder =& $folderList->Get($i);
             $result &= $this->_synchronizeFolderWithOpenDbConnection($folder, $dbStorage);
             unset($folder);
             if (!$result) {
                 break;
             }
         }
         return $result;
     }
     return false;
 }
Пример #14
0
 /**
  * @param FolderCollection $folders
  * @return bool
  */
 function CreateFolders(&$folders)
 {
     $result = true;
     if ($folders == null) {
         return $result;
     }
     for ($i = 0, $c = $folders->Count(); $i < $c; $i++) {
         $folder =& $folders->Get($i);
         if ($result && $folder) {
             $result &= $this->CreateFolder($folder);
             if ($folder->SubFolders && $result) {
                 for ($j = 0, $t = count($folder->SubFolders->Instance()); $j < $t; $j++) {
                     $subFolder =& $folder->SubFolders->Get($j);
                     $subFolder->IdParent = $folder->IdDb;
                     unset($subFolder);
                 }
                 $result &= $this->CreateFolders($folder->SubFolders);
             }
         }
         unset($folder);
     }
     return $result;
 }
Пример #15
0
    /**
     * @param FolderCollection $folders
     * @param int $messagesCount
     * @param int $messagesSize
     * @param Account $account
     * @return string
     */
    function CreateHtmlFolderTree(&$folders, &$messagesCount, &$messagesSize, &$account)
    {
        $out = array('', '');
        for ($i = 0, $count = $folders->Count(); $i < $count; $i++) {
            $folder =& $folders->Get($i);
            if ($i > 0) {
                $pr_folder =& $folders->Get($i - 1);
            }
            if ($i < $count - 1) {
                $nx_folder =& $folders->Get($i + 1);
            }
            $messagesCount += $folder->MessageCount;
            $messagesSize += $folder->Size;
            $foldername = '';
            if (ConvertUtils::IsLatin($folder->Name)) {
                $foldername = ConvertUtils::ConvertEncoding($folder->Name, CPAGE_UTF7_Imap, $this->setaccount->_pagebuilder->_proc->account->GetUserCharset());
            } else {
                $foldername = ConvertUtils::ConvertEncoding($folder->Name, $this->setaccount->_pagebuilder->_proc->account->DefaultIncCharset, $this->setaccount->_pagebuilder->_proc->account->GetUserCharset());
            }
            $folderUrl = 'skins/' . $this->setaccount->_pagebuilder->SkinName() . '/folders/' . GetFolderImg($folder->Type, MAILPROTOCOL_POP3);
            $hasChild = $folder->SubFolders != null;
            $hasMessages = $folder->MessageCount > 0;
            $disab = $hasChild || $hasMessages ? 'disabled="disabled" ' : '';
            $disab = $account->MailProtocol == MAILPROTOCOL_POP3 ? '' : $disab;
            $checkbox = $folder->Type == FOLDERTYPE_Custom ? '<input type="checkbox" id="ch_0" name="folders[' . ConvertUtils::AttributeQuote($folder->IdDb) . ']" value="' . ConvertUtils::AttributeQuote($folder->FullName) . '" class="wm_checkbox" ' . $disab . '/>' : '';
            $uphref = $i < 1 ? '<img src="skins/' . $this->setaccount->_pagebuilder->SkinName() . '/folders/up_inactive.gif" />' : '<a onclick="return DoAlert();" href="' . ACTIONFILE . '?action=update&req=folderorder&cf_id=' . $folder->IdDb . '&rf_id=' . $pr_folder->IdDb . '"><img
					src="skins/' . $this->setaccount->_pagebuilder->SkinName() . '/folders/up.gif" /></a>';
            $downhref = $i > $count - 2 ? '<img src="skins/' . $this->setaccount->_pagebuilder->SkinName() . '/folders/down_inactive.gif" />' : '<a onclick="return DoAlert();" href="' . ACTIONFILE . '?action=update&req=folderorder&cf_id=' . $folder->IdDb . '&rf_id=' . $nx_folder->IdDb . '"><img
					src="skins/' . $this->setaccount->_pagebuilder->SkinName() . '/folders/down.gif" /></a>';
            $eyeimg = $folder->Hide ? 'hide.gif' : 'show.gif';
            switch ($folder->Type) {
                default:
                case FOLDERTYPE_Custom:
                    $foldername = ConvertUtils::WMHtmlSpecialChars($foldername);
                    break;
                case FOLDERTYPE_Inbox:
                    $foldername = FolderInbox;
                    break;
                case FOLDERTYPE_Drafts:
                    $foldername = FolderDrafts;
                    break;
                case FOLDERTYPE_SentItems:
                    $foldername = FolderSentItems;
                    break;
                case FOLDERTYPE_Trash:
                    $foldername = FolderTrash;
                    break;
            }
            $nameSting = $folder->Type == FOLDERTYPE_Custom ? '<form action="' . ACTIONFILE . '?action=rename&req=folder" id="folder_form_' . $folder->IdDb . '" method="POST">
					<img src="' . $folderUrl . '" />
					<a href="#" onclick="EditFolder(' . $folder->IdDb . ');" id="folder_a_' . $folder->IdDb . '">' . $foldername . '</a>
					<input type="text" class="wm_hide" name="folderid" value="' . $folder->IdDb . '">
					<input type="text" class="wm_hide" name="fname" maxLength="30" id="folder_i_' . $folder->IdDb . '" value="' . ConvertUtils::AttributeQuote($foldername) . '"/></form>' : '<img src="' . ConvertUtils::AttributeQuote($folderUrl) . '" /> ' . $foldername;
            $imap4SyncTd = $this->setaccount->_editAccount->MailProtocol == MAILPROTOCOL_IMAP4 ? '
						<td><form id="syncform_' . $folder->IdDb . '" action="' . ACTIONFILE . '?action=update&req=foldersync" method="POST">
							<input type="hidden" name="folderid" value="' . $folder->IdDb . '">
							<select onchange="document.getElementById(\'syncform_' . $folder->IdDb . '\').submit();" name="synctype">
								<option value="' . FOLDERSYNC_DontSync . '" ' . ($folder->SyncType == FOLDERSYNC_DontSync ? 'selected="selected"' : '') . '>' . JS_LANG_SyncTypeNo . '</option>
								<option value="' . FOLDERSYNC_NewHeadersOnly . '" ' . ($folder->SyncType == FOLDERSYNC_NewHeadersOnly ? 'selected="selected"' : '') . '>' . JS_LANG_SyncTypeNewHeaders . '</option>
								<option value="' . FOLDERSYNC_AllHeadersOnly . '" ' . ($folder->SyncType == FOLDERSYNC_AllHeadersOnly ? 'selected="selected"' : '') . '>' . JS_LANG_SyncTypeAllHeaders . '</option>
								<option value="' . FOLDERSYNC_NewEntireMessages . '" ' . ($folder->SyncType == FOLDERSYNC_NewEntireMessages ? 'selected="selected"' : '') . '>' . JS_LANG_SyncTypeNewMessages . '</option>
								<option value="' . FOLDERSYNC_AllEntireMessages . '" ' . ($folder->SyncType == FOLDERSYNC_AllEntireMessages ? 'selected="selected"' : '') . '>' . JS_LANG_SyncTypeAllMessages . '</option>
								<option value="' . FOLDERSYNC_DirectMode . '" ' . ($folder->SyncType == FOLDERSYNC_DirectMode ? 'selected="selected"' : '') . '>' . JS_LANG_SyncTypeDirectMode . '</option>
							</select></form>
						</td>
							' : '<td class="wm_hide"></td>';
            $out[0] .= '
						<tr>
							<td>' . $checkbox . '</td>
							<td class="wm_settings_mf_folder">
							<div style="padding-left: ' . $folder->Level * 8 . 'px;">
							' . $nameSting . '
							</div></td>
							<td>' . $folder->MessageCount . '</td>
							<td>' . GetFriendlySize($folder->Size) . '</td>
							' . $imap4SyncTd . '
							<td><a href="#" onclick="if (!DoAlert()) return false; document.location=\'' . ACTIONFILE . '?action=update&req=folderhide&folderid=' . $folder->IdDb . '\'"><img class="wm_settings_mf_show_hide" src="skins/' . $this->setaccount->_pagebuilder->SkinName() . '/folders/' . $eyeimg . '"></a>
							</td>
							<td class="wm_settings_mf_up_down">
								' . $uphref . $downhref . '
							</td>
						</tr>			
				';
            $out[1] .= '<option value="' . $folder->IdDb . '">' . str_repeat('&nbsp;', $folder->Level * 3) . $foldername . '</option>' . "\r\n";
            if ($folder->SubFolders != null && $folder->SubFolders->Count() > 0) {
                $temp = $this->CreateHtmlFolderTree($folder->SubFolders, $messagesCount, $messagesSize, $account);
                $out[0] .= $temp[0];
                $out[1] .= $temp[1];
            }
        }
        return $out;
    }
Пример #16
0
 /**
  * @param bool $bCreateIfNull = false
  * @return \MailSo\Mail\FolderCollection
  */
 public function SubFolders($bCreateIfNull = false)
 {
     if ($bCreateIfNull && !$this->oSubFolders) {
         $this->oSubFolders = FolderCollection::NewInstance();
     }
     return $this->oSubFolders;
 }
Пример #17
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;
 }
Пример #18
0
    }
    $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();
Пример #19
0
 /**
  * @param FolderCollection $folders
  * @return bool
  */
 function Synchronize(&$folders)
 {
     $folderList = $folders->CreateFolderListFromTree();
     //copy tree object here
     $inboxFolder =& $folderList->GetFolderByType(FOLDERTYPE_Inbox);
     if ($inboxFolder == null) {
         return true;
     }
     $dbStorage =& DbStorageCreator::CreateDatabaseStorage($this->Account);
     if (!$dbStorage->Connect()) {
         return false;
     }
     return $this->_synchronizeFolderWithOpenDbConnection($inboxFolder, $dbStorage);
 }
Пример #20
0
 /**
  * @param int $foderId
  * @param int $id_acct
  * @return string|false
  */
 function GetFolderFullName($folderId, $id_acct)
 {
     if ($folderId > 0 && $this->DbStorage->Connect()) {
         if (USE_DB) {
             return $this->DbStorage->GetFolderFullName($folderId, $id_acct);
         } else {
             if (isset($_SESSION[ACCOUNT_FOLDERS])) {
                 $folder = null;
                 $folders = FolderCollection::GetFromSession();
                 if ($folders) {
                     $folder =& $folders->GetFolderById($folderId);
                 }
                 if ($folder) {
                     return $folder->FullName;
                 }
             }
         }
     }
     return false;
 }
Пример #21
0
 /**
  * @param string $sParent = ''
  * @param string $sListPattern = '*'
  * @param bool $bUseListStatus = false
  * @param bool $bUseListSubscribeStatus = false
  *
  * @return \MailSo\Mail\FolderCollection|false
  */
 public function Folders($sParent = '', $sListPattern = '*', $bUseListStatus = false, $bUseListSubscribeStatus = true)
 {
     $oFolderCollection = false;
     $aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
     $aSubscribedFolders = null;
     if ($bUseListSubscribeStatus) {
         try {
             $aSubscribedFolders = $this->oImapClient->FolderSubscribeList($sParent, $sListPattern);
         } catch (\Exception $oException) {
         }
     }
     // TODO
     //		$mStatusFolders = null;
     //		if ($bUseListStatus)
     //		{
     //			$mStatusFolders = $this->oImapClient->FolderStatusList($sParent, $sListPattern);
     //		}
     $aImapSubscribedFoldersHelper = null;
     if (\is_array($aSubscribedFolders)) {
         $aImapSubscribedFoldersHelper = array();
         foreach ($aSubscribedFolders as $oImapFolder) {
             $aImapSubscribedFoldersHelper[] = $oImapFolder->FullNameRaw();
         }
     }
     $aMailFoldersHelper = null;
     if (\is_array($aFolders)) {
         $aMailFoldersHelper = array();
         foreach ($aFolders as $oImapFolder) {
             $aMailFoldersHelper[] = Folder::NewInstance($oImapFolder, null === $aImapSubscribedFoldersHelper || \in_array($oImapFolder->FullNameRaw(), $aImapSubscribedFoldersHelper) || $oImapFolder->IsInbox());
         }
     }
     if (\is_array($aMailFoldersHelper)) {
         $oFolderCollection = FolderCollection::NewInstance();
         $oFolderCollection->InitByUnsortedMailFolderArray($aMailFoldersHelper);
     }
     if ($oFolderCollection) {
         $oFolderCollection->SortByCallback(function ($oFolderA, $oFolderB) {
             $sA = \strtoupper($oFolderA->FullNameRaw());
             $sB = \strtoupper($oFolderB->FullNameRaw());
             switch (true) {
                 case 'INBOX' === $sA:
                     return -1;
                 case 'INBOX' === $sB:
                     return 1;
                 case '[GMAIL]' === $sA:
                     return -1;
                 case '[GMAIL]' === $sB:
                     return 1;
             }
             return \strnatcmp($oFolderA->FullName(), $oFolderB->FullName());
         });
         $oNamespace = $this->oImapClient->GetNamespace();
         if ($oNamespace) {
             $oFolderCollection->SetNamespace($oNamespace->GetPersonalNamespace());
         }
         $oFolderCollection->IsThreadsSupported = $this->IsThreadsSupported();
     }
     return $oFolderCollection;
 }
Пример #22
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;
 }