* eMail: improve control regarding the unwanted selection of NoSelect Folders

This commit is contained in:
Klaus Leithoff 2013-01-10 15:47:14 +00:00
parent d0183f6f22
commit bfb1923254
4 changed files with 114 additions and 33 deletions

View File

@ -64,6 +64,9 @@ class ajaxfelamimail
$this->uiwidgets = CreateObject('felamimail.uiwidgets');
$this->icServer = $this->bofelamimail->mailPreferences->getIncomingServer($this->imapServerID);
$this->_connectionStatus = $this->bofelamimail->openConnection($this->imapServerID);
if(!$this->bofelamimail->folderIsSelectable($folderToSelect)) {
$folderToSelect = null;
}
$this->sessionDataAjax =& $GLOBALS['egw']->session->appsession('ajax_session_data','felamimail');
$this->sessionData =& $GLOBALS['egw']->session->appsession('session_data','felamimail');
@ -234,7 +237,7 @@ class ajaxfelamimail
{
if($this->_debug) error_log(__METHOD__.__LINE__.array2string($_acl).function_backtrace());
$aclList = array('l','r','s','w','i','p','c','d','a');
$lang["lang_acl_l"] = "Look up the name of the mailbox (but not its contents).";
$lang["lang_acl_r"] = "Read the contents of the mailbox.";
$lang["lang_acl_s"] = "Preserve the 'seen' and 'recent' status of messages across IMAP sessions.";
@ -703,6 +706,15 @@ class ajaxfelamimail
$listMode = 0;
$this->bofelamimail->restoreSessionData();
$shortName = '';
if($folderStatus = $this->bofelamimail->getFolderStatus($_folderName)) {
$shortName =$folderStatus['shortDisplayName'];
if (stripos(array2string($folderStatus['attributes']),'noselect')!==false)
{
$_folderName = 'INBOX';
return $this->generateMessageList($_folderName,$modifyoffset,$listOnly);
}
}
//error_log($this->sessionData['previewMessage']);
//error_log(__METHOD__.__LINE__.' ->'.$_folderName.' ShowAsSent:'.$GLOBALS['egw_info']['user']['preferences']['felamimail']['messages_showassent_0']);
@ -776,10 +788,7 @@ class ajaxfelamimail
$lastMessage = (int)$headers['info']['last'];
$totalMessage = (int)$headers['info']['total'];
if ((int)$maxMessages<0) $totalMessage = $rowsFetched['messages'];
$shortName = '';
if($folderStatus = $this->bofelamimail->getFolderStatus($_folderName)) {
$shortName =$folderStatus['shortDisplayName'];
}
// moved getFolderStatus up, see there
if($totalMessage == 0) {
$response->addAssign("messageCounter", "innerHTML", '<b>'.$shortName.': </b>'.lang('no messages found...'));
} else {
@ -797,21 +806,22 @@ class ajaxfelamimail
}
}
if($folderStatus = $this->bofelamimail->getFolderStatus($_folderName)) {
if($folderStatus['unseen'] > 0) {
$response->addScript("egw_topWindow().tree.setItemText('$_folderName', '<b>". $folderStatus['shortDisplayName'] ." (". $folderStatus['unseen'] .")</b>');");
} else {
$response->addScript("egw_topWindow().tree.setItemText('$_folderName', '". $folderStatus['shortDisplayName'] ."');");
}
if($folderStatus['unseen'] > 0) {
$response->addScript("egw_topWindow().tree.setItemText('$_folderName', '<b>". $folderStatus['shortDisplayName'] ." (". $folderStatus['unseen'] .")</b>');");
} else {
$response->addScript("egw_topWindow().tree.setItemText('$_folderName', '". $folderStatus['shortDisplayName'] ."');");
}
if(!empty($GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder']) &&
$GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder'] != 'none' ) {
$folderStatus = $this->bofelamimail->getFolderStatus($GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder']);
if($folderStatus['unseen'] > 0) {
$response->addScript("egw_topWindow().tree.setItemText('". $GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder'] ."', '<b>". $folderStatus['shortDisplayName'] ." (". $folderStatus['unseen'] .")</b>');");
if ($_folderName != $GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder'])
{
$folderStatusT = $this->bofelamimail->getFolderStatus($GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder']);
}
if($folderStatusT['unseen'] > 0) {
$response->addScript("egw_topWindow().tree.setItemText('". $GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder'] ."', '<b>". $folderStatusT['shortDisplayName'] ." (". $folderStatusT['unseen'] .")</b>');");
} else {
$response->addScript("egw_topWindow().tree.setItemText('". $GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder'] ."', '". $folderStatus['shortDisplayName'] ."');");
$response->addScript("egw_topWindow().tree.setItemText('". $GLOBALS['egw_info']['user']['preferences']['felamimail']['trashFolder'] ."', '". $folderStatusT['shortDisplayName'] ."');");
}
}

View File

@ -124,6 +124,12 @@ class felamimail_bo
*/
static $autoFolders = array('Drafts', 'Templates', 'Sent', 'Trash', 'Junk', 'Outbox');
/**
* var to hold IDNA2 object
* @var class object
*/
static $idna2;
/**
* Autoload classes from emailadmin, 'til they get autoloading conform names
*
@ -220,6 +226,7 @@ class felamimail_bo
}
}
self::$instances[$_profileID]->profileID = $_profileID;
if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new egw_idna;
//if ($_profileID==0); error_log(__METHOD__.__LINE__.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
return self::$instances[$_profileID];
}
@ -410,6 +417,7 @@ class felamimail_bo
if (function_exists('mb_convert_encoding')) {
$this->mbAvailable = TRUE;
}
if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
}
@ -1636,6 +1644,27 @@ class felamimail_bo
return $rv;
}
/**
* get IMAP folder status regarding NoSelect
*
* returns true or false regarding the noselect attribute
*
* @param foldertoselect string the foldername
*
* @return boolean
*/
function folderIsSelectable($folderToSelect)
{
$retval = true;
if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect))) {
if (stripos(array2string($folderStatus['attributes']),'noselect')!==false)
{
$retval = false;
}
}
return $retval;
}
/**
* get IMAP folder status
*
@ -1652,6 +1681,7 @@ class felamimail_bo
{
return false;
}
static $folderInfoCache; // reduce traffic on single request
$retValue = array();
$retValue['subscribed'] = false;
if(!$icServer = $this->mailPreferences->getIncomingServer($this->profileID)) {
@ -1660,8 +1690,9 @@ class felamimail_bo
}
// does the folder exist???
$folderInfo = $this->icServer->getMailboxes('', $_folderName, true);
if (is_null($folderInfoCache) || !isset($folderInfoCache[$_folderName])) $folderInfoCache[$_folderName] = $this->icServer->getMailboxes('', $_folderName, true);
$folderInfo = $folderInfoCache[$_folderName];
//error_log(__METHOD__.__LINE__.array2string($folderInfo).'->'.function_backtrace());
if(($folderInfo instanceof PEAR_Error) || !is_array($folderInfo[0])) {
if (self::$debug||$folderInfo instanceof PEAR_Error) error_log(__METHOD__." returned Info for folder $_folderName:".print_r($folderInfo->message,true));
if ( ($folderInfo instanceof PEAR_Error) || PEAR::isError($r = $this->_getStatus($_folderName)) || $r == 0) return false;
@ -1676,11 +1707,6 @@ class felamimail_bo
# return false;
#}
$subscribedFolders = $this->icServer->listsubscribedMailboxes('', $_folderName);
if(is_array($subscribedFolders) && count($subscribedFolders) == 1) {
$retValue['subscribed'] = true;
}
$retValue['delimiter'] = $folderInfo[0]['HIERACHY_DELIMITER'];
$retValue['attributes'] = $folderInfo[0]['ATTRIBUTES'];
$shortNameParts = explode($retValue['delimiter'], $_folderName);
@ -1696,6 +1722,14 @@ class felamimail_bo
{
$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
}
if (stripos(array2string($retValue['attributes']),'noselect')!==false)
{
return $retValue;
}
$subscribedFolders = $this->icServer->listsubscribedMailboxes('', $_folderName);
if(is_array($subscribedFolders) && count($subscribedFolders) == 1) {
$retValue['subscribed'] = true;
}
if ( PEAR::isError($folderStatus = $this->_getStatus($_folderName,$ignoreStatusCache)) ) {
if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($folderStatus->message,true));
@ -2722,7 +2756,6 @@ class felamimail_bo
}
}
//if ($decode) _debug_array($newData);
return $newData;
}
}
@ -3881,10 +3914,10 @@ class felamimail_bo
//{
//error_log( "------------------------reopen- $_foldername <br>");
//error_log(__METHOD__.__LINE__.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
if ($this->icServer->_connected == 1) {
$tretval = $this->icServer->selectMailbox($_foldername);
} else {
if (!($this->icServer->_connected == 1)) {
$tretval = $this->openConnection($this->profileID,false);
}
if ($this->icServer->_connected == 1 && $this->folderIsSelectable($_foldername)) {
$tretval = $this->icServer->selectMailbox($_foldername);
}
$folderOpened = $_foldername;

View File

@ -108,6 +108,7 @@ class uiwidgets
if (isset($preferences->preferences['templateFolder']) &&
$preferences->preferences['templateFolder'] != 'none') $userDefinedFunctionFolders['Templates'] = $preferences->preferences['templateFolder'];
// create a list of all folders, also the ones which are not subscribed
$suFolders = array();
foreach($_folders as $key => $obj) {
//error_log('->'.array2string($key));
$folderParts = explode($obj->delimiter,$key);
@ -124,16 +125,39 @@ class uiwidgets
$allFolders[$string]->displayName = $this->encodeFolderName($allFolders[$string]->folderName);
$allFolders[$string]->shortDisplayName = $this->encodeFolderName($allFolders[$string]->shortFolderName);
//$prefix = array_shift(explode($obj->delimiter, $nameSpace['others']['prefix']));
//error_log('->'.$obj->delimiter.':'.$prefix.'<->'.$allFolders[$string]->shortFolderName);
if (array_shift(explode($obj->delimiter, $nameSpace['shared']['prefix'])) == $allFolders[$string]->shortFolderName) $allFolders[$string]->shortDisplayName = $this->encodeFolderName(lang('shared folders'));
if (array_shift(explode($obj->delimiter, $nameSpace['others']['prefix'])) == $allFolders[$string]->shortFolderName) $allFolders[$string]->shortDisplayName = $this->encodeFolderName(lang('shared user folders'));
//error_log('->'.$obj->delimiter.':'.$prefix.'<->'.$allFolders[$string]->shortFolderName.'#'.$allFolders[$string]->folderName);
if (array_shift(explode($obj->delimiter, $nameSpace['shared']['prefix'])) == $allFolders[$string]->shortFolderName)
{
$allFolders[$string]->shortDisplayName = $this->encodeFolderName(lang('shared folders'));
if (!in_array($allFolders[$string]->shortFolderName,$suFolders)) $suFolders[] =$allFolders[$string]->shortFolderName;
}
if (array_shift(explode($obj->delimiter, $nameSpace['others']['prefix'])) == $allFolders[$string]->shortFolderName)
{
$allFolders[$string]->shortDisplayName = $this->encodeFolderName(lang('shared user folders'));
if (!in_array($allFolders[$string]->shortFolderName,$suFolders)) $suFolders[] =$allFolders[$string]->shortFolderName;
}
if (!in_array($allFolders[$string]->folderName,$suFolders) && !$this->bofelamimail->folderIsSelectable($allFolders[$string]->folderName))
{
$suFolders[] = $allFolders[$string]->folderName;
}
}
}
}
$allFolders[$key] = $obj;
if (array_shift(explode($obj->delimiter, $nameSpace['shared']['prefix'])) == $obj->shortFolderName) $allFolders[$key]->shortDisplayName = $this->encodeFolderName(lang('shared folders'));
if (array_shift(explode($obj->delimiter, $nameSpace['others']['prefix'])) == $obj->shortFolderName) $allFolders[$key]->shortDisplayName = $this->encodeFolderName(lang('shared user folders'));
if (array_shift(explode($obj->delimiter, $nameSpace['shared']['prefix'])) == $obj->shortFolderName)
{
$allFolders[$key]->shortDisplayName = $this->encodeFolderName(lang('shared folders'));
if (!in_array($obj->shortFolderName,$suFolders)) $suFolders[] =$obj->shortFolderName;
}
if (array_shift(explode($obj->delimiter, $nameSpace['others']['prefix'])) == $obj->shortFolderName)
{
$allFolders[$key]->shortDisplayName = $this->encodeFolderName(lang('shared user folders'));
if (!in_array($obj->shortFolderName,$suFolders)) $suFolders[] =$obj->shortFolderName;
}
if (!in_array($obj->folderName,$suFolders) && !$this->bofelamimail->folderIsSelectable($obj->folderName))
{
$suFolders[] = $obj->folderName;
}
}
$folderImageDir = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/templates/default/images';
@ -150,6 +174,10 @@ class uiwidgets
}";
$folder_tree_new .= "var tree=new dhtmlXTreeObject('$_divName','100%','100%',0);";
$folder_tree_new .= "var felamimail_folders=[];";
$folder_tree_new .= "var donotclick_folders=[];";
$folder_tree_new .= "donotclick_folders.push('--topfolder--');";
//error_log(__METHOD__.__LINE__.array2string($suFolders));
foreach ($suFolders as $suFi => $suFv) $folder_tree_new .= "donotclick_folders.push('$suFv');";
$folder_tree_new .= "tree.parentObject.style.overflow=\"auto\";";
$folder_tree_new .= "tree.setImagePath('$folderImageDir/dhtmlxtree/');";
if($_displayCheckBox) {

View File

@ -637,7 +637,17 @@ function onNodeSelect(_nodeID) {
*/
CopyOrMoveCalled = false;
//- } else {
if (_nodeID=='--topfolder--') _nodeID = 'INBOX';
if (typeof egw_appWindow('felamimail').donotclick_folders == 'undefined')
{
//alert('donotclick folders not defined here');
var donotclick_folders=[];
donotclick_folders.push('--topfolder--');
}
for (var i=0; i<egw_appWindow('felamimail').donotclick_folders.length; i++)
{
//alert('node selected:'+_nodeID+'<->'+donotclick_folders[i]+'#');
if (_nodeID==egw_appWindow('felamimail').donotclick_folders[i]) _nodeID = 'INBOX';
}
mail_resetMessageSelect();
egw_appWindow('felamimail').setStatusMessage('<span style="font-weight: bold;">' + egw_appWindow('felamimail').lang_loading + ' ' + top.tree.getUserData(_nodeID, 'folderName') + '</span>');
mail_cleanup();