lots of stuff to create the foldertree

This commit is contained in:
Klaus Leithoff 2013-02-11 17:05:29 +00:00
parent 9181d6c526
commit f8581b8807
6 changed files with 881 additions and 244 deletions

View File

@ -522,6 +522,16 @@ class mail_bo
return $selectedID;
}
/**
* closes a connection on the active Server ($this->icServer)
*
* @return void
*/
function closeConnection() {
//if ($icServer->_connected) error_log(__METHOD__.__LINE__.' disconnect from Server');
if ($icServer->_connected) $this->icServer->disconnect();
}
/**
* reopens a connection for the active Server ($this->icServer), and selects the folder given
*
@ -1548,6 +1558,752 @@ class mail_bo
return translation::convert($_folderName, 'UTF7-IMAP', self::$displayCharset);
}
/**
* get IMAP folder objects
*
* returns an array of IMAP folder objects. Put INBOX folder in first
* position. Preserves the folder seperator for later use. The returned
* array is indexed using the foldername. Use cachedObjects when retrieving subscribedFolders
*
* @param boolean _subscribedOnly get subscribed or all folders
* @param boolean _getCounters get get messages counters
* @param boolean _alwaysGetDefaultFolders this triggers to ignore the possible notavailableautofolders - preference
* as activeSync needs all folders like sent, trash, drafts, templates and outbox - if not present devices may crash
*
* @return array with folder objects. eg.: INBOX => {inbox object}
*/
function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false)
{
if (self::$debug) error_log(__METHOD__.__LINE__.' '."subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders");
static $folders2return;
if ($_subscribedOnly && $_getCounters===false)
{
if (is_null($folders2return)) $folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
if (isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
{
//error_log(__METHOD__.__LINE__.' using Cached folderObjects');
return $folders2return[$this->icServer->ImapServerId];
}
}
$isUWIMAP = false;
$delimiter = $this->getHierarchyDelimiter();
$inboxData = new stdClass;
$inboxData->name = 'INBOX';
$inboxData->folderName = 'INBOX';
$inboxData->displayName = lang('INBOX');
$inboxData->delimiter = $delimiter;
$inboxData->shortFolderName = 'INBOX';
$inboxData->shortDisplayName = lang('INBOX');
$inboxData->subscribed = true;
if($_getCounters == true) {
$inboxData->counter = self::getMailBoxCounters('INBOX');
}
// force unsubscribed by preference showAllFoldersInFolderPane
if ($_subscribedOnly == true &&
isset($this->mailPreferences->preferences['showAllFoldersInFolderPane']) &&
$this->mailPreferences->preferences['showAllFoldersInFolderPane']==1)
{
$_subscribedOnly = false;
}
#$inboxData->attributes = 64;
$inboxFolderObject = array('INBOX' => $inboxData);
#_debug_array($folders);
//$nameSpace = $this->icServer->getNameSpaces();
$nameSpace = $this->_getNameSpaces();
//_debug_array($nameSpace);
//_debug_array($delimiter);
if(isset($nameSpace['#mh/'])) {
// removed the uwimap code
// but we need to reintroduce him later
// uw imap does not return the attribute of a folder, when requesting subscribed folders only
// dovecot has the same problem too
} else {
if (is_array($nameSpace)) {
foreach($nameSpace as $type => $singleNameSpace) {
$prefix_present = $nameSpace[$type]['prefix_present'];
$foldersNameSpace[$type] = $nameSpace[$type];
if(is_array($singleNameSpace)) {
// fetch and sort the subscribed folders
$subscribedMailboxes = $this->icServer->listsubscribedMailboxes($foldersNameSpace[$type]['prefix']);
if (empty($subscribedMailboxes) && $type == 'shared')
{
$subscribedMailboxes = $this->icServer->listsubscribedMailboxes('',0);
}
else
{
if ($prefix_present=='forced' && $type=='personal') // you cannot trust dovecots assumed prefix
{
$subscribedMailboxesAll = $this->icServer->listsubscribedMailboxes('',0);
if( PEAR::isError($subscribedMailboxesAll) ) continue;
foreach ($subscribedMailboxesAll as $ksMA => $sMA) if (!in_array($sMA,$subscribedMailboxes)) $subscribedMailboxes[] = $sMA;
}
}
//echo "subscribedMailboxes";_debug_array($subscribedMailboxes);
if( PEAR::isError($subscribedMailboxes) ) {
continue;
}
$foldersNameSpace[$type]['subscribed'] = $subscribedMailboxes;
if (is_array($foldersNameSpace[$type]['subscribed'])) sort($foldersNameSpace[$type]['subscribed']);
//_debug_array($foldersNameSpace);
if ($_subscribedOnly == true) {
$foldersNameSpace[$type]['all'] = (is_array($foldersNameSpace[$type]['subscribed']) ? $foldersNameSpace[$type]['subscribed'] :array());
continue;
}
// only check for Folder in FolderMaintenance for Performance Reasons
if(!$_subscribedOnly) {
foreach ((array)$foldersNameSpace[$type]['subscribed'] as $folderName)
{
if ($foldersNameSpace[$type]['prefix'] == $folderName || $foldersNameSpace[$type]['prefix'] == $folderName.$foldersNameSpace[$type]['delimiter']) continue;
//echo __METHOD__."Checking $folderName for existence<br>";
if (!self::folderExists($folderName,true)) {
echo("eMail Folder $folderName failed to exist; should be unsubscribed; Trying ...");
error_log(__METHOD__."-> $folderName failed to be here; should be unsubscribed");
if (self::subscribe($folderName, false))
{
echo " success."."<br>" ;
} else {
echo " failed."."<br>";
}
}
}
}
// fetch and sort all folders
//echo $type.'->'.$foldersNameSpace[$type]['prefix'].'->'.($type=='shared'?0:2)."<br>";
$allMailboxesExt = $this->icServer->getMailboxes($foldersNameSpace[$type]['prefix'],2,true);
if( PEAR::isError($allMailboxesExt) )
{
error_log(__METHOD__.__LINE__.' Failed to retrieve all Boxes:'.$allMailboxesExt->message);
$allMailboxesExt = array();
}
if (empty($allMailboxesExt) && $type == 'shared')
{
$allMailboxesExt = $this->icServer->getMailboxes('',0,true);
}
else
{
if ($prefix_present=='forced' && $type=='personal') // you cannot trust dovecots assumed prefix
{
$allMailboxesExtAll = $this->icServer->getMailboxes('',0,true);
foreach ($allMailboxesExtAll as $kaMEA => $aMEA)
{
if( PEAR::isError($aMEA) ) continue;
if (!in_array($aMEA,$allMailboxesExt)) $allMailboxesExt[] = $aMEA;
}
}
}
if( PEAR::isError($allMailboxesExt) ) {
#echo __METHOD__;_debug_array($allMailboxesExt);
continue;
}
$allMailBoxesExtSorted = array();
foreach ($allMailboxesExt as $mbx) {
//echo __METHOD__;_debug_array($mbx);
//error_log(__METHOD__.__LINE__.array2string($mbx));
if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
) continue;
//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
}
if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
//_debug_array($allMailBoxesExtSorted);
$allMailboxes = array();
foreach ((array)$allMailBoxesExtSorted as $mbx) {
//echo $mbx['MAILBOX']."<br>";
if (in_array('\HasChildren',$mbx["ATTRIBUTES"]) || in_array('\Haschildren',$mbx["ATTRIBUTES"])) {
unset($buff);
//$buff = $this->icServer->getMailboxes($mbx['MAILBOX'].$delimiter,0,false);
if (!in_array($mbx['MAILBOX'],$allMailboxes)) $buff = self::getMailBoxesRecursive($mbx['MAILBOX'],$delimiter,$foldersNameSpace[$type]['prefix'],1);
if( PEAR::isError($buff) ) {
continue;
}
#_debug_array($buff);
if (is_array($buff)) $allMailboxes = array_merge($allMailboxes,$buff);
}
if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
//echo "Result:";_debug_array($allMailboxes);
}
$foldersNameSpace[$type]['all'] = $allMailboxes;
if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
}
}
}
// check for autocreated folders
if(isset($foldersNameSpace['personal']['prefix'])) {
$personalPrefix = $foldersNameSpace['personal']['prefix'];
$personalDelimiter = $foldersNameSpace['personal']['delimiter'];
if(!empty($personalPrefix)) {
if(substr($personalPrefix, -1) != $personalDelimiter) {
$folderPrefix = $personalPrefix . $personalDelimiter;
} else {
$folderPrefix = $personalPrefix;
}
}
else
{
if(substr($personalPrefix, -1) != $personalDelimiter) {
$folderPrefixAsInbox = 'INBOX' . $personalDelimiter;
} else {
$folderPrefixAsInbox = 'INBOX';
}
}
if (!$_alwaysGetDefaultFolders && $this->mailPreferences->preferences['notavailableautofolders'] && !empty($this->mailPreferences->preferences['notavailableautofolders']))
{
$foldersToCheck = array_diff(self::$autoFolders,explode(',',$this->mailPreferences->preferences['notavailableautofolders']));
} else {
$foldersToCheck = self::$autoFolders;
}
//error_log(__METHOD__.__LINE__." foldersToCheck:".array2string($foldersToCheck));
//error_log(__METHOD__.__LINE__." foldersToCheck:".array2string( $this->mailPreferences->preferences['sentFolder']));
foreach($foldersToCheck as $personalFolderName) {
$folderName = (!empty($personalPrefix) ? $folderPrefix.$personalFolderName : $personalFolderName);
//error_log(__METHOD__.__LINE__." foldersToCheck: $personalFolderName / $folderName");
if(!is_array($foldersNameSpace['personal']['all']) || !in_array($folderName, $foldersNameSpace['personal']['all'])) {
$createfolder = true;
switch($personalFolderName)
{
case 'Drafts': // => Entwürfe
$draftFolder = $this->getDraftFolder();
if ($draftFolder && $draftFolder=='none')
$createfolder=false;
break;
case 'Junk': //] => Spammails
if ($this->mailPreferences->preferences['junkFolder'] && $this->mailPreferences->preferences['junkFolder']=='none')
$createfolder=false;
break;
case 'Sent': //] => Gesendet
// ToDo: we may need more sophistcated checking here
$sentFolder = $this->getSentFolder();
if ($sentFolder && $sentFolder=='none')
$createfolder=false;
break;
case 'Trash': //] => Papierkorb
$trashFolder = $this->getTrashFolder();
if ($trashFolder && $trashFolder=='none')
$createfolder=false;
break;
case 'Templates': //] => Vorlagen
$templateFolder = $this->getTemplateFolder();
if ($templateFolder && $templateFolder=='none')
$createfolder=false;
break;
case 'Outbox': // Nokia Outbox for activesync
//if ($this->mailPreferences->preferences['outboxFolder'] && $this->mailPreferences->preferences['outboxFolder']=='none')
$createfolder=false;
if ($GLOBALS['egw_info']['user']['apps']['activesync']) $createfolder = true;
break;
}
// check for the foldername as constructed with prefix (or not)
if ($createfolder && self::folderExists($folderName))
{
$createfolder = false;
}
// check for the folder as it comes (no prefix)
if ($createfolder && $personalFolderName != $folderName && self::folderExists($personalFolderName))
{
$createfolder = false;
$folderName = $personalFolderName;
}
// check for the folder as it comes with INBOX prefixed
$folderWithInboxPrefixed = $folderPrefixAsInbox.$personalFolderName;
if ($createfolder && $folderWithInboxPrefixed != $folderName && self::folderExists($folderWithInboxPrefixed))
{
$createfolder = false;
$folderName = $folderWithInboxPrefixed;
}
// now proceed with the folderName that may be altered in the progress of testing for existence
if ($createfolder === false && $_alwaysGetDefaultFolders)
{
if (!in_array($folderName,$foldersNameSpace['personal']['all'])) $foldersNameSpace['personal']['all'][] = $folderName;
if (!in_array($folderName,$foldersNameSpace['personal']['subscribed'])) $foldersNameSpace['personal']['subscribed'][] = $folderName;
}
if($createfolder === true && $this->createFolder('', $folderName, true)) {
$foldersNameSpace['personal']['all'][] = $folderName;
$foldersNameSpace['personal']['subscribed'][] = $folderName;
} else {
#print "FOLDERNAME failed: $folderName<br>";
}
}
}
}
}
//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
$autoFolderObjects = array();
foreach( array('personal', 'others', 'shared') as $type) {
if(isset($foldersNameSpace[$type])) {
if($_subscribedOnly) {
if( !PEAR::isError($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
} else {
if( !PEAR::isError($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
}
foreach((array)$listOfFolders as $folderName) {
//echo "<br>FolderToCheck:$folderName<br>";
if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
#echo "$folderName failed to be here <br>";
continue;
}
$folderParts = explode($delimiter, $folderName);
$shortName = array_pop($folderParts);
$folderObject = new stdClass;
$folderObject->delimiter = $delimiter;
$folderObject->folderName = $folderName;
$folderObject->shortFolderName = $shortName;
if(!$_subscribedOnly) {
#echo $folderName."->".$type."<br>";
#_debug_array($foldersNameSpace[$type]['subscribed']);
$folderObject->subscribed = in_array($folderName, $foldersNameSpace[$type]['subscribed']);
}
if($_getCounters == true) {
$folderObject->counter = $this->getMailBoxCounters($folderName);
}
if(strtoupper($folderName) == 'INBOX') {
$folderName = 'INBOX';
$folderObject->folderName = 'INBOX';
$folderObject->shortFolderName = 'INBOX';
$folderObject->displayName = lang('INBOX');
$folderObject->shortDisplayName = lang('INBOX');
$folderObject->subscribed = true;
// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
} elseif (in_array($shortName,self::$autoFolders)) {
$tmpfolderparts = explode($delimiter,$folderObject->folderName);
array_pop($tmpfolderparts);
$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
$folderObject->shortDisplayName = lang($shortName);
unset($tmpfolderparts);
} else {
$folderObject->displayName = $this->encodeFolderName($folderObject->folderName);
$folderObject->shortDisplayName = $this->encodeFolderName($shortName);
}
//$folderName = $folderName;
if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
$autoFolderObjects[$folderName] = $folderObject;
} else {
$folders[$folderName] = $folderObject;
}
}
}
}
if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
}
if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
//$folders2return = array_merge($autoFolderObjects,$folders);
//_debug_array($folders2return); #exit;
$folders2return[$this->icServer->ImapServerId] = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders);
if ($_subscribedOnly && $_getCounters===false) egw_cache::setCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
return $folders2return[$this->icServer->ImapServerId];
}
/**
* search Value In FolderObjects
*
* Helper function to search for a specific value within the foldertree objects
* @param string $needle
* @param array $haystack, array of folderobjects
* @return MIXED false or key
*/
static function searchValueInFolderObjects($needle, $haystack)
{
$rv = false;
foreach ($haystack as $k => $v)
{
foreach($v as $sk => $sv) if (trim($sv)==trim($needle)) return $k;
}
return $rv;
}
/**
* sortByDisplayName
*
* Helper function to sort folder-objects by displayname
* @param object $a
* @param object $b, array of folderobjects
* @return int expect values (0, 1 or -1)
*/
function sortByDisplayName($a,$b)
{
// 0, 1 und -1
return strcasecmp($a->displayName,$b->displayName);
}
/**
* sortByAutoFolderPos
*
* Helper function to sort folder-objects by auto Folder Position
* @param object $a
* @param object $b, array of folderobjects
* @return int expect values (0, 1 or -1)
*/
function sortByAutoFolderPos($a,$b)
{
// 0, 1 und -1
$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
if ($pos1 == $pos2) return 0;
return ($pos1 < $pos2) ? -1 : 1;
}
/**
* getMailBoxCounters
*
* function to retrieve the counters for a given folder
* @param string $folderName
* @return mixed false or array of counters array(MESSAGES,UNSEEN,RECENT,UIDNEXT,UIDVALIDITY)
*/
function getMailBoxCounters($folderName)
{
$folderStatus = $this->_getStatus($folderName);
error_log(__METHOD__.__LINE__." FolderStatus:".array2string($folderStatus));
if ( PEAR::isError($folderStatus)) {
if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".print_r($folderStatus->message,true));
return false;
}
if(is_array($folderStatus)) {
$status = new stdClass;
$status->messages = $folderStatus['MESSAGES'];
$status->unseen = $folderStatus['UNSEEN'];
$status->recent = $folderStatus['RECENT'];
$status->uidnext = $folderStatus['UIDNEXT'];
$status->uidvalidity = $folderStatus['UIDVALIDITY'];
return $status;
}
return false;
}
/**
* getMailBoxesRecursive
*
* function to retrieve mailboxes recursively from given mailbox
* @param string $_mailbox
* @param string $delimiter
* @param string $prefix
* @param string $reclevel 0, counter to keep track of the current recursionlevel
* @return array of mailboxes
*/
function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
{
#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
$maxreclevel=25;
if ($reclevel > $maxreclevel) {
error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
return array();
}
$reclevel++;
// clean up double delimiters
$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
//get that mailbox in question
$mbx = $this->icServer->getMailboxes($_mailbox,1,true);
#_debug_array($mbx);
if (is_array($mbx[0]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[0]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[0]["ATTRIBUTES"]))) {
// if there are children fetch them
//echo $mbx[0]['MAILBOX']."<br>";
unset($buff);
$buff = $this->icServer->getMailboxes($mbx[0]['MAILBOX'].($mbx[0]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
//$buff = $this->icServer->getMailboxes($mbx[0]['MAILBOX'],2,false);
//_debug_array($buff);
if( PEAR::isError($buff) ) {
if (self::$debug) error_log(__METHOD__." Error while retrieving Mailboxes for:".$mbx[0]['MAILBOX'].$delimiter.".");
return array();
} else {
$allMailboxes = array();
foreach ($buff as $mbxname) {
$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname);
#echo "About to recur in level $reclevel:".$mbxname."<br>";
if ( $mbxname != $mbx[0]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[0]['MAILBOX'].$delimiter) $allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
}
if (!(in_array('\NoSelect',$mbx[0]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[0]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[0]['MAILBOX'];
return $allMailboxes;
}
} else {
return array($_mailbox);
}
}
/**
* _getSpecialUseFolder
* abstraction layer for getDraftFolder, getTemplateFolder, getTrashFolder and getSentFolder
* @param string $type the type to fetch (Drafts|Template|Trash|Sent)
* @param boolean $_checkexistance, trigger check for existance
* @return mixed string or false
*/
function _getSpecialUseFolder($_type, $_checkexistance=TRUE)
{
static $types = array(
'Drafts'=>array('prefName'=>'draftFolder','profileKey'=>'draftfolder','autoFolderName'=>'Drafts'),
'Template'=>array('prefName'=>'templateFolder','profileKey'=>'templatefolder','autoFolderName'=>'Templates'),
'Trash'=>array('prefName'=>'trashFolder','profileKey'=>'trashfolder','autoFolderName'=>'Trash'),
'Sent'=>array('prefName'=>'sentFolder','profileKey'=>'sentfolder','autoFolderName'=>'Sent'),
);
if (!isset($types[$_type]))
{
error_log(__METHOD__.__LINE__.' '.$_type.' not supported for '.__METHOD__);
return false;
}
if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
//highest precedence
$_folderName = $this->mailPreferences->ic_server[$this->profileID]->$types[$_type]['profileKey'];
//check prefs next
if (empty($_folderName)) $_folderName = $this->mailPreferences->preferences[$types[$_type]['prefName']];
// does the folder exist???
if ($_checkexistance && $_folderName !='none' && !self::folderExists($_folderName)) {
$_folderName = false;
}
//no (valid) folder found yet; try specialUseFolders
if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
//no specialUseFolder; try some Defaults
if (empty($_folderName) && isset($types[$_type]))
{
$nameSpace = $this->_getNameSpaces();
$prefix='';
if (isset($nameSpace['personal'])) $prefix = $nameSpace['personal']['prefix'];
if (self::folderExists($prefix.$types[$_type]['autoFolderName'])) $_folderName = $prefix.$types[$_type]['autoFolderName'];
}
return $_folderName;
}
/**
* getDraftFolder wrapper for _getSpecialUseFolder Type Drafts
* @param boolean $_checkexistance, trigger check for existance
* @return mixed string or false
*/
function getDraftFolder($_checkexistance=TRUE)
{
return $this->_getSpecialUseFolder('Drafts', $_checkexistance);
}
/**
* getTemplateFolder wrapper for _getSpecialUseFolder Type Template
* @param boolean $_checkexistance, trigger check for existance
* @return mixed string or false
*/
function getTemplateFolder($_checkexistance=TRUE)
{
return $this->_getSpecialUseFolder('Template', $_checkexistance);
}
/**
* getTrashFolder wrapper for _getSpecialUseFolder Type Trash
* @param boolean $_checkexistance, trigger check for existance
* @return mixed string or false
*/
function getTrashFolder($_checkexistance=TRUE)
{
return $this->_getSpecialUseFolder('Trash', $_checkexistance);
}
/**
* getSentFolder wrapper for _getSpecialUseFolder Type Sent
* @param boolean $_checkexistance, trigger check for existance
* @return mixed string or false
*/
function getSentFolder($_checkexistance=TRUE)
{
return $this->_getSpecialUseFolder('Sent', $_checkexistance);
}
/**
* isSentFolder is the given folder the sent folder or at least a subfolder of it
* @param string $_foldername, folder to perform the check on
* @param boolean $_checkexistance, trigger check for existance
* @return boolean
*/
function isSentFolder($_folderName, $_checkexistance=TRUE)
{
$sentFolder = $this->getSentFolder();
if(empty($sentFolder)) {
return false;
}
// does the folder exist???
if ($_checkexistance && !self::folderExists($_folderName)) {
return false;
}
if(false !== stripos($_folderName, $sentFolder)) {
return true;
} else {
return false;
}
}
/**
* checks if the Outbox folder exists and is part of the foldername to be checked
* @param string $_foldername, folder to perform the check on
* @param boolean $_checkexistance, trigger check for existance
* @return boolean
*/
function isOutbox($_folderName, $_checkexistance=TRUE)
{
if (stripos($_folderName, 'Outbox')===false) {
return false;
}
// does the folder exist???
if ($_checkexistance && !self::folderExists($_folderName)) {
return false;
}
return true;
}
/**
* isDraftFolder is the given folder the sent folder or at least a subfolder of it
* @param string $_foldername, folder to perform the check on
* @param boolean $_checkexistance, trigger check for existance
* @return boolean
*/
function isDraftFolder($_folderName, $_checkexistance=TRUE)
{
$draftFolder = $this->getDraftFolder();
if(empty($draftFolder)) {
return false;
}
// does the folder exist???
if ($_checkexistance && !self::folderExists($_folderName)) {
return false;
}
if(false !== stripos($_folderName, $draftFolder)) {
return true;
} else {
return false;
}
}
/**
* isTrashFolder is the given folder the sent folder or at least a subfolder of it
* @param string $_foldername, folder to perform the check on
* @param boolean $_checkexistance, trigger check for existance
* @return boolean
*/
function isTrashFolder($_folderName, $_checkexistance=TRUE)
{
$trashFolder = $this->getTrashFolder();
if(empty($trashFolder)) {
return false;
}
// does the folder exist???
if ($_checkexistance && !self::folderExists($_folderName)) {
return false;
}
if(false !== stripos($_folderName, $trashFolder)) {
return true;
} else {
return false;
}
}
/**
* isTemplateFolder is the given folder the sent folder or at least a subfolder of it
* @param string $_foldername, folder to perform the check on
* @param boolean $_checkexistance, trigger check for existance
* @return boolean
*/
function isTemplateFolder($_folderName, $_checkexistance=TRUE)
{
$templateFolder = $this->getTemplateFolder();
if(empty($templateFolder)) {
return false;
}
// does the folder exist???
if ($_checkexistance && !self::folderExists($_folderName)) {
return false;
}
if(false !== stripos($_folderName, $templateFolder)) {
return true;
} else {
return false;
}
}
/**
* folderExists checks for existance of a given folder
* @param string $_foldername, folder to perform the check on
* @param boolean $_forceCheck, trigger check for existance on icServer
* @return mixed string or false
*/
function folderExists($_folder, $_forceCheck=false)
{
static $folderInfo;
$forceCheck = $_forceCheck;
if (empty($_folder))
{
// this error is more or less without significance, unless we force the check
if ($_forceCheck===true) error_log(__METHOD__.__LINE__.' Called with empty Folder:'.$_folder.function_backtrace());
return false;
}
// reduce traffic within the Instance per User; Expire every 5 Minutes
//error_log(__METHOD__.__LINE__.' Called with Folder:'.$_folder.function_backtrace());
if (is_null($folderInfo)) $folderInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*5);
//error_log(__METHOD__.__LINE__.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
{
//error_log(__METHOD__.__LINE__.' Using cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID);
return $folderInfo[$this->profileID][$_folder];
}
else
{
if ($forceCheck === false)
{
//error_log(__METHOD__.__LINE__.' No cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.' FolderExistsInfoCache:'.array2string($folderInfo[$this->profileID]));
$forceCheck = true; // try to force the check, in case there is no connection, we may need that
}
}
// does the folder exist???
//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
if ((!($this->icServer->_connected == 1)) && $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
//return false;
//try to connect
if (!$this->icServer->_connected) $this->openConnection($this->profileID,false);
}
if(($this->icServer instanceof defaultimap))
{
$folderInfo[$this->profileID][$_folder] = $this->icServer->mailboxExist($_folder); //LIST Command, may return OK, but no attributes
if ($folderInfo[$this->profileID][$_folder]==false)
{
// some servers dont serve the LIST command in certain cases; this is a ServerBUG and
// we try to work around it here.
if ((isset($this->mailPreferences->preferences['trustServersUnseenInfo']) &&
$this->mailPreferences->preferences['trustServersUnseenInfo']==false) ||
(isset($this->mailPreferences->preferences['trustServersUnseenInfo']) &&
$this->mailPreferences->preferences['trustServersUnseenInfo']==2)
)
{
$nameSpace = $this->_getNameSpaces();
if (isset($nameSpace['personal'])) unset($nameSpace['personal']);
$prefix = $this->getFolderPrefixFromNamespace($nameSpace, $_folder);
if ($prefix != '' && stripos($_folder,$prefix) !== false)
{
if(!PEAR::isError($r = $this->_getStatus($_folder)) && is_array($r)) $folderInfo[$this->profileID][$_folder] = true;
}
}
}
}
//error_log(__METHOD__.__LINE__.' Folder Exists:'.$folderInfo[$this->profileID][$_folder].function_backtrace());
if(!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
($folderInfo[$this->profileID][$_folder] instanceof PEAR_Error) || $folderInfo[$this->profileID][$_folder] !== true)
{
$folderInfo[$this->profileID][$_folder] = false; // set to false, whatever it was (to have a valid returnvalue for the static return)
}
egw_cache::setCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*5);
return (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) ? $folderInfo[$this->profileID][$_folder] : false);
}
/**
* Helper function to handle wrong or unrecognized timezones
* returns the date as it is parseable by strtotime, or current timestamp if everything failes
@ -1578,7 +2334,7 @@ class mail_bo
* htmlentities
* helperfunction to cope with wrong encoding in strings
* @param string $_string input to be converted
* @param mixed $charset false or string -> Target charset, if false bofelamimail displayCharset will be used
* @param mixed $charset false or string -> Target charset, if false mail_bo displayCharset will be used
* @return string
*/
static function htmlentities($_string, $_charset=false)
@ -1663,6 +2419,4 @@ class mail_bo
$ogServer->updateAccount($_hookValues);
}
}
}

View File

@ -49,7 +49,7 @@ class mail_hooks
{
if (($default_profile_id = emailadmin_bo::getDefaultProfileID()))
{
$mail_bo = felamimail_bo::forceEAProfileLoad($default_profile_id);
$mail_bo = mail_bo::forceEAProfileLoad($default_profile_id);
$ogServer = $mail_bo->mailPreferences->getOutgoingServer($default_profile_id);
//error_log(__METHOD__."() default_profile_id = $default_profile_id, get_class(ogServer)=".get_class($ogServer));
@ -78,17 +78,17 @@ class mail_hooks
{
return array(
'view' => array(
// 'menuaction' => 'felamimail.uidisplay.display',
// 'menuaction' => 'mail.uidisplay.display',
),
'view_popup' => '850xegw_getWindowOuterHeight()',
'add' => array(
// 'menuaction' => 'felamimail.uicompose.compose',
// 'menuaction' => 'mail.uicompose.compose',
),
'add_popup' => '850xegw_getWindowOuterHeight()',
// register fmail as handler for .eml files
'mime' => array(
'message/rfc822' => array(
// 'menuaction' => 'felamimail.uifelamimail.importMessageFromVFS2DraftAndDisplay',
// 'menuaction' => 'mail.mail_ui.importMessageFromVFS2DraftAndDisplay',
'mime_popup' => '850xegw_getWindowOuterHeight()',
'mime_url' => 'formData[file]',
),
@ -136,11 +136,11 @@ class mail_hooks
}
$availableAutoFolders['none'] = lang('none, create all');
foreach(felamimail_bo::$autoFolders as $aname) {
foreach(mail_bo::$autoFolders as $aname) {
$availableAutoFolders[$aname] = lang($aname);
}
$felamimailConfig = config::read('mail');
$mailConfig = config::read('mail');
}
$refreshTime = array(
'0' => lang('disabled'),
@ -268,9 +268,9 @@ class mail_hooks
$toggle = false;
if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode'] == 'EGW_SELECTMODE_TOGGLE') $toggle=true;
$rowOrderStyle = array(
'felamimail' => lang('FeLaMiMail'),
'mail' => lang('mail'),
'outlook' => 'Outlook',
'felamimail_wCB' => lang('FeLaMiMail').' '.($toggle?lang('(select mails by clicking on the line, like a checkbox)'):lang('(with checkbox enforced)')),
'mail_wCB' => lang('mail').' '.($toggle?lang('(select mails by clicking on the line, like a checkbox)'):lang('(with checkbox enforced)')),
'outlook_wCB' => 'Outlook'.' '.($toggle?lang('(select mails by clicking on the line, like a checkbox)'):lang('(with checkbox enforced)')),
);
@ -441,7 +441,7 @@ class mail_hooks
'values' => $rowOrderStyle,
'xmlrpc' => True,
'admin' => False,
'default'=> 'felamimail',
'default'=> 'mail',
),
'prefMailGridBehavior' => array(
'type' => 'select',
@ -675,7 +675,7 @@ class mail_hooks
'name' => 'sieveScriptName',
'xmlrpc' => True,
'admin' => False,
'forced' => 'felamimail',
'forced' => 'mail',
),
'prefcontroltestconnection' => array(
'type' => 'select',
@ -721,14 +721,14 @@ class mail_hooks
{
unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']);
// Only Modify the $file and $title variables.....
$title = $appname = 'felamimail';
$title = $appname = 'mail';
$profileID = 0;
if (isset($GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID']))
$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID'];
if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'];
$file = Array(
'Site Configuration' => egw::link('/index.php',array('menuaction'=>'admin.uiconfig.index','appname'=>'felamimail')),
'eMailAdmin: Profilemanagement' => egw::link('/index.php','menuaction=felamimail.uifelamimail.redirectToEmailadmin'),
'Site Configuration' => egw::link('/index.php',array('menuaction'=>'admin.uiconfig.index','appname'=>'mail')),
'eMailAdmin: Profilemanagement' => egw::link('/index.php','menuaction=emailadmin.emailadmin_ui.index'),
);
display_section($appname,$title,$file);
}
@ -742,26 +742,26 @@ class mail_hooks
{
unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']);
// Only Modify the $file and $title variables.....
$title = $appname = 'felamimail';
$title = $appname = 'mail';
$profileID = 0;
if (isset($GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID']))
$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID'];
if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'];
$mail_bo = felamimail_bo::getInstance(true,$profileID);
$profileID = $GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID'] = $mail_bo->profileID;
$mail_bo = mail_bo::getInstance(true,$profileID);
$profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $mail_bo->profileID;
$mailPreferences =& $mail_bo->mailPreferences;
$file['Preferences'] = egw::link('/index.php','menuaction=preferences.uisettings.index&appname=' . $appname);
/*
if($mailPreferences->userDefinedAccounts) {
$linkData = array
(
'menuaction' => 'felamimail.uipreferences.listAccountData',
'menuaction' => 'mail.uipreferences.listAccountData',
);
$file['Manage eMail Accounts and Identities'] = egw::link('/index.php',$linkData);
}
if(empty($mailPreferences->preferences['prefpreventmanagefolders']) || $mailPreferences->preferences['prefpreventmanagefolders'] == 0) {
$file['Manage Folders'] = egw::link('/index.php','menuaction=felamimail.uipreferences.listFolder');
$file['Manage Folders'] = egw::link('/index.php','menuaction=mail.uipreferences.listFolder');
}
if (is_object($mailPreferences))
{
@ -769,11 +769,12 @@ class mail_hooks
if($icServer->enableSieve) {
if(empty($mailPreferences->preferences['prefpreventeditfilterrules']) || $mailPreferences->preferences['prefpreventeditfilterrules'] == 0)
$file['filter rules'] = egw::link('/index.php', 'menuaction=felamimail.uisieve.listRules');
$file['filter rules'] = egw::link('/index.php', 'menuaction=mail.uisieve.listRules');
if(empty($mailPreferences->preferences['prefpreventabsentnotice']) || $mailPreferences->preferences['prefpreventabsentnotice'] == 0)
$file['vacation notice'] = egw::link('/index.php','menuaction=felamimail.uisieve.editVacation');
$file['vacation notice'] = egw::link('/index.php','menuaction=mail.uisieve.editVacation');
}
}
*/
//Do not modify below this line
display_section($appname,$title,$file);
}
@ -788,200 +789,25 @@ class mail_hooks
//error_log(__METHOD__);
// always show the side bar
unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']);
$appname = 'felamimail';
$appname = 'mail';
$menu_title = $GLOBALS['egw_info']['apps'][$appname]['title'] . ' '. lang('Menu');
$file = array();
$profileID = 0;
if (isset($GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID']))
$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID'];
if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'];
$mail_bo = felamimail_bo::getInstance(true,$profileID);
$profileID = $GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID'] = $mail_bo->profileID;
$mail_bo = mail_bo::getInstance(true,$profileID);
$profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $mail_bo->profileID;
$preferences =& $mail_bo->mailPreferences;
$showMainScreenStuff = false;
if(($_GET['menuaction'] == 'felamimail.uifelamimail.viewMainScreen' ||
$_GET['menuaction'] == 'felamimail.uifelamimail.changeFolder' ||
stripos($_GET['menuaction'],'ajax_sidebox') !== false) &&
$_GET['menuaction'] != 'felamimail.uipreferences.editAccountData' &&
$_GET['menuaction'] != 'felamimail.uifelamimail.redirectToPreferences' &&
$_GET['menuaction'] != 'felamimail.uifelamimail.redirectToConfig' &&
$_GET['menuaction'] != 'felamimail.uifelamimail.redirectToEmailadmin') {
if (isset($_GET["mailbox"]))
{
$mail_bo->sessionData['mailbox'] = urldecode($_GET["mailbox"]);
$mail_bo->sessionData['startMessage']= 1;
$mail_bo->sessionData['sort'] = $preferences->preferences['sortOrder'];
$mail_bo->sessionData['activeFilter']= -1;
$mail_bo->saveSessionData();
}
$uiwidgets = CreateObject('felamimail.uiwidgets');
$showMainScreenStuff = true;
}
if (!$showMainScreenStuff)
{
// action links that are mostly static and dont need any connection and additional classes ...
$file += array(
'felamimail' => egw::link('/index.php','menuaction=felamimail.uifelamimail.viewMainScreen&ajax=true'),
'mail' => egw::link('/index.php','menuaction=mail.mail_ui.index&ajax=true'),
);
// standard compose link
$linkData = array(
'menuaction' => 'felamimail.uicompose.compose'
);
$file += array(
'Compose' => "javascript:egw_openWindowCentered2('".egw::link('/index.php', $linkData,false)."','compose',700,750,'no','$appname');",
);
}
// select account box, treeview, we use a whileloop as we may want to break out
while($showMainScreenStuff) {
$mail_bo->restoreSessionData();
$mailbox = $mail_bo->sessionData['mailbox'];
//_debug_array($mailbox);
$icServerID = (int)$mail_bo->profileID;
if (is_object($preferences))
{
// gather profile data
$imapServer =& $mail_bo->icServer;
//error_log(__METHOD__.__LINE__.array2string($imapServer));
// account select box
$selectedID = $mail_bo->getIdentitiesWithAccounts($identities);
if (empty($selectedID) && isset($imapServer->ImapServerId)) $selectedID = $imapServer->ImapServerId;
//error_log(__METHOD__.__LINE__.' SelectedID:'.$selectedID.' IcServerID:'.$imapServer->ImapServerId);
// if nothing valid is found return to user defined account definition
if (empty($imapServer->host) && count($identities)==0 && $preferences->userDefinedAccounts)
{
$showMainScreenStuff= false;
break;
}
//error_log(__METHOD__.__LINE__.array2string($preferences->identities));
$activeIdentity =& $preferences->getIdentity($icServerID, true);
//error_log(__METHOD__.__LINE__.' ActiveIdentity for profileID'.$icServerID.'->'.array2string($activeIdentity));
if ($imapServer->_connected != 1) $connectionStatus = $mail_bo->openConnection($icServerID);
$folderObjects = $mail_bo->getFolderObjects(true, false);
$folderStatus = $mail_bo->getFolderStatus($mailbox);
// the data needed here are collected at the start of this function
if (!isset($activeIdentity->id) && $selectedID == $icServerID) {
$identities[$icServerID] = $activeIdentity->realName.' '.$activeIdentity->organization.' <'.$activeIdentity->emailAddress.'>';
}
// if you use user defined accounts you may want to access the profile defined with the emailadmin available to the user
if ($activeIdentity->id) {
$boemailadmin = new emailadmin_bo();
$defaultProfile = $boemailadmin->getUserProfile() ;
//error_log(__METHOD__.__LINE__.array2string($defaultProfile));
$identitys =& $defaultProfile->identities;
$icServers =& $defaultProfile->ic_server;
foreach ($identitys as $tmpkey => $identity)
{
if (empty($icServers[$tmpkey]->host)) continue;
$identities[$identity->id] = $identity->realName.' '.$identity->organization.' <'.$identity->emailAddress.'>';
}
//$identities[0] = $defaultIdentity->realName.' '.$defaultIdentity->organization.' <'.$defaultIdentity->emailAddress.'>';
}
$selectAccount = html::select('accountSelect', $selectedID, $identities, true, 'id="accountSelect" style="width:100%;" onchange="var appWindow=egw_appWindow(\''.$appname.'\');appWindow.changeActiveAccount(this);"',0,false);
//error_log(__METHOD__.__LINE__.$selectAccount);
$file[] = array(
'text' => "<div id=\"divAccountSelect\" style=\" width:100%;\">".$selectAccount."</div>",
'no_lang' => True,
'link' => False,
'icon' => False,
);
// show foldertree
//_debug_array($folderObjects);
$folderTree = $uiwidgets->createHTMLFolder
(
$folderObjects,
$mailbox,
$folderStatus['unseen'],
lang('IMAP Server'),
$imapServer->username.'@'.$imapServer->host,
'divFolderTree',
FALSE
);
//$mail_bo->closeConnection();
$file[] = array(
'text' => "<div id=\"divFolderTree\" class=\"dtree\" style=\"overflow:auto; max-width:400px; width:100%; max-height:450px; margin-bottom: 0px;padding-left: 0px; padding-right: 0px; padding-top:0px; z-index:100; \">
$folderTree
</div>
<script>
if (document.getElementById('accountSelect_chzn'))
{
var xchzn = document.getElementById('accountSelect_chzn');
xchzn.style.width = '100%';
if (xchzn.childElementCount>1)
{
xchzn.children[1].style.width='99%'; //chzn-drop
xchzn.children[1].children[0].children[0].style.width = '85%';
}
}
var wnd = egw_appWindow('".$appname."');
if (wnd && typeof wnd.refreshFolderStatus != 'undefined')
{
wnd.refreshFolderStatus();
}
</script>",
'no_lang' => True,
'link' => False,
'icon' => False,
);
}
break; // kill the while loop as we need only one go
}
// buttons
if($showMainScreenStuff) {
// some buttons
$linkData = array (
'menuaction' => 'felamimail.uicompose.compose'
);
$urlCompose = "egw_appWindow('".$appname."').openComposeWindow('".egw::link('/index.php',$linkData,false)."');";
$navbarImages = array(
'new' => array(
'action' => $urlCompose,
'tooltip' => lang('compose'),
),
'read_small' => array(
'action' => "egw_appWindow('".$appname."').mail_flagMessages('read')",
'tooltip' => lang('mark selected as read'),
),
'unread_small' => array(
'action' => "egw_appWindow('".$appname."').mail_flagMessages('unread')",
'tooltip' => lang('mark selected as unread'),
),
'unread_flagged_small' => array(
'action' => "egw_appWindow('".$appname."').mail_flagMessages('flagged')",
'tooltip' => lang('mark selected as flagged'),
),
'read_flagged_small' => array(
'action' => "egw_appWindow('".$appname."').mail_flagMessages('unflagged')",
'tooltip' => lang('mark selected as unflagged'),
),
'delete' => array(
'action' => "egw_appWindow('".$appname."').mail_deleteMessages(egw_appWindow('".$appname."').mailGridGetSelected())",
'tooltip' => lang('mark as deleted'),
),
);
foreach($navbarImages as $buttonName => $buttonInfo) {
$navbarButtons .= $uiwidgets->navbarButton($buttonName, $buttonInfo['action'], $buttonInfo['tooltip']);
}
/*$file[] = array(
'text' => "<TABLE WIDTH=\"100%\" CELLPADDING=\"0\" CELLSPACING=\"0\" style=\"border: solid #aaaaaa 1px; border-right: solid black 1px; \">
<tr class=\"navbarBackground\">
<td align=\"right\" width=\"100%\">".$navbarButtons."</td>
</tr>
</table>",
'no_lang' => True,
'link' => False,
'icon' => False,
);*/
}
// empty trash (if available -> move to trash )
if($preferences->preferences['deleteOptions'] == 'move_to_trash')
{
@ -1001,7 +827,7 @@ class mail_hooks
if ((@include_once 'Mail/mimeDecode.php') !== false)
{
$linkData = array(
'menuaction' => 'felamimail.uifelamimail.importMessage',
'menuaction' => 'mail.mail_ui.importMessage',
);
$file += array(
@ -1015,31 +841,31 @@ class mail_hooks
if ($GLOBALS['egw_info']['user']['apps']['preferences'])
{
#$mailPreferences = ExecMethod('felamimail.bopreferences.getPreferences');
#$mailPreferences = ExecMethod('mail.bopreferences.getPreferences');
$menu_title = lang('Preferences');
$file = array(
//'Preferences' => egw::link('/index.php','menuaction=preferences.uisettings.index&appname=felamimail'),
'Preferences' => egw::link('/index.php','menuaction=felamimail.uifelamimail.redirectToPreferences&appname=felamimail'),
'Preferences' => egw::link('/index.php','menuaction=preferences.uisettings.index&appname=mail'),
);
/*
if($preferences->userDefinedAccounts || $preferences->userDefinedIdentities) {
$linkData = array (
'menuaction' => 'felamimail.uipreferences.listAccountData',
'menuaction' => 'mail.uipreferences.listAccountData',
);
$file['Manage eMail Accounts and Identities'] = egw::link('/index.php',$linkData);
}
if ($preferences->preferences['prefcontroltestconnection'] <> 'none') $file['Test Connection'] = egw::link('/index.php','menuaction=felamimail.uifelamimail.TestConnection&appname=felamimail');
*/
if ($preferences->preferences['prefcontroltestconnection'] <> 'none') $file['Test Connection'] = egw::link('/index.php','menuaction=mail.mail_ui.TestConnection&appname=mail');
/*
if($preferences->ea_user_defined_signatures) {
$linkData = array (
'menuaction' => 'felamimail.uipreferences.listSignatures',
'menuaction' => 'mail.uipreferences.listSignatures',
);
$file['Manage Signatures'] = egw::link('/index.php',$linkData);
}
if(empty($preferences->preferences['prefpreventmanagefolders']) || $preferences->preferences['prefpreventmanagefolders'] == 0) {
$file['Manage Folders'] = egw::link('/index.php',array('menuaction'=>'felamimail.uipreferences.listFolder'));
$file['Manage Folders'] = egw::link('/index.php',array('menuaction'=>'mail.uipreferences.listFolder'));
}
if (is_object($preferences)) $ogServer = $preferences->getOutgoingServer(0);
if(($ogServer instanceof emailadmin_smtp)) {
@ -1047,14 +873,16 @@ class mail_hooks
{
$linkData = array
(
'menuaction' => 'felamimail.uipreferences.editForwardingAddress',
'menuaction' => 'mail.uipreferences.editForwardingAddress',
);
//if(empty($preferences->preferences['prefpreventforwarding']) || $preferences->preferences['prefpreventforwarding'] == 0)
$file['Forwarding'] = egw::link('/index.php',$linkData);
}
}
*/
display_sidebox($appname,$menu_title,$file);
unset($file);
/*
$menu_title = lang('Sieve');
if (is_object($preferences)) $icServer = $preferences->getIncomingServer($profileID);
if(($icServer instanceof defaultimap)) {
@ -1062,14 +890,14 @@ class mail_hooks
{
$linkData = array
(
'menuaction' => 'felamimail.uisieve.listRules',
'menuaction' => 'mail.uisieve.listRules',
);
if(empty($preferences->preferences['prefpreventeditfilterrules']) || $preferences->preferences['prefpreventeditfilterrules'] == 0)
$file['filter rules'] = egw::link('/index.php',$linkData);
$linkData = array
(
'menuaction' => 'felamimail.uisieve.editVacation',
'menuaction' => 'mail.uisieve.editVacation',
);
if(empty($preferences->preferences['prefpreventabsentnotice']) || $preferences->preferences['prefpreventabsentnotice'] == 0)
{
@ -1078,18 +906,20 @@ class mail_hooks
if((empty($preferences->preferences['prefpreventnotificationformailviaemail']) ||
$preferences->preferences['prefpreventnotificationformailviaemail'] == 0))
{
$file['email notification'] = egw::link('/index.php','menuaction=felamimail.uisieve.editEmailNotification'); //Added email notifications
$file['email notification'] = egw::link('/index.php','menuaction=mail.uisieve.editEmailNotification'); //Added email notifications
}
if (count($file)) display_sidebox($appname,$menu_title,$file);
unset($file);
}
}
*/
}
if ($GLOBALS['egw_info']['user']['apps']['admin'])
{
$file = Array(
'Site Configuration' => egw::link('/index.php','menuaction=felamimail.uifelamimail.redirectToConfig'), //'menuaction=admin.uiconfig.index&appname=felamimail'),
'eMailAdmin: Profilemanagement' => egw::link('/index.php','menuaction=felamimail.uifelamimail.redirectToEmailadmin'),
'Site Configuration' => egw::link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname),
'eMailAdmin: Profilemanagement' => egw::link('/index.php','menuaction=emailadmin.emailadmin_ui.index'),
);
display_sidebox($appname,lang('Admin'),$file);
}

View File

@ -69,8 +69,7 @@ class mail_ui
*/
function index(array $content=null,$msg=null)
{
//$this->TestConnection();
//_debug_array($content);
if (!is_array($content))
{
$content = array(
@ -100,14 +99,8 @@ class mail_ui
}
// filter is used to choose the mailbox
//if (!isset($content['nm']['foldertree'])) // maybe we fetch the folder here
$sel_options['foldertree'] = array(
//'--topfolder--'=>array('label'=>'IMAP Server','title'=>'IMAP Server','image'=>'thunderbird.png'),
'/INBOX'=>array('label'=>'INBOX','title'=>'INBOX','image'=>'kfm_home.png'),
'/INBOX/sub'=>array('label'=>'sub','title'=>'INBOX/sub'),
'/user' => array('label' => 'user'),
'/user/birgit' => 'birgit',
);
$content['nm']['foldertree'] = '/INBOX/sub';
$sel_options['foldertree'] = $this->getFolderTree();
$content['nm']['foldertree'] = '/INBOX';
$sel_options['cat_id'] = array(1=>'none');
if (!isset($content['nm']['filter'])) $content['nm']['filter'] = 'INBOX';
if (!isset($content['nm']['cat_id'])) $content['nm']['cat_id'] = 'All';
@ -121,13 +114,13 @@ $content['nm']['foldertree'] = '/INBOX/sub';
*/
function TestConnection ()
{
$preferences =& $this->mail_bo->mailPreferences;
// load translations
translation::add_app('mail');
common::egw_header();
parse_navbar();
//$GLOBALS['egw']->framework->sidebox();
$preferences =& $this->mail_bo->mailPreferences;
if ($preferences->preferences['prefcontroltestconnection'] == 'none') die('You should not be here!');
@ -258,6 +251,65 @@ $content['nm']['foldertree'] = '/INBOX/sub';
common::egw_footer();
}
/**
* getFolderTree, get folders from server and prepare the folder tree
*
* @return array something like that: array(
* '/INBOX'=>array('label'=>'INBOX','title'=>'INBOX','image'=>'kfm_home.png'),
* '/INBOX/sub'=>array('label'=>'sub','title'=>'INBOX/sub'),
* '/user' => array('label' => 'user'),
* '/user/birgit' => 'birgit',
* );
*/
function getFolderTree()
{
$folderObjects = $this->mail_bo->getFolderObjects();
$trashFolder = $this->mail_bo->getTrashFolder();
$templateFolder = $this->mail_bo->getTemplateFolder();
$draftFolder = $this->mail_bo->getDraftFolder();
$sentFolder = $this->mail_bo->getSentFolder();
$userDefinedFunctionFolders = array();
if (isset($trashFolder) && $trashFolder != 'none') $userDefinedFunctionFolders['Trash'] = $trashFolder;
if (isset($sentFolder) && $sentFolder != 'none') $userDefinedFunctionFolders['Sent'] = $sentFolder;
if (isset($draftFolder) && $draftFolder != 'none') $userDefinedFunctionFolders['Drafts'] = $draftFolder;
if (isset($templateFolder) && $templateFolder != 'none') $userDefinedFunctionFolders['Templates'] = $templateFolder;
//_debug_array($folderObjects);
foreach($folderObjects as $key => $obj)
{
$fS = $this->mail_bo->getFolderStatus($key);
//_debug_array($fS);
$path = str_replace($obj->delimiter,'/',$obj->folderName);
$oA =array('label'=> $obj->shortDisplayName, 'title'=> $obj->displayName);
if ($fS['unseen']) $oA['label'] = '<b>'.$oA['label'].' ('.$fS['unseen'].')</b>';
if ($path=='INBOX')
{
$oA['image'] = 'kfm_home.png';
}
elseif (in_array($obj->shortFolderName,mail_bo::$autoFolders))
{
//echo $obj->shortFolderName.'<br>';
$oA['image'] = $image1 = $image2 = $image3 = "MailFolder".$obj->shortFolderName.".png";
//$image2 = "'MailFolderPlain.png'";
//$image3 = "'MailFolderPlain.png'";
}
elseif (in_array($key,$userDefinedFunctionFolders))
{
$_key = array_search($key,$userDefinedFunctionFolders);
$oA['image'] = $image1 = $image2 = $image3 = "MailFolder".$_key.".png";
}
else
{
$oA['image'] = $image1 = "MailFolderPlain.png"; // one Level
$image2 = "folderOpen.gif";
if (stripos(array2string($fS['attributes']),'\hasChildren')!== false) $oA['image'] = $image3 = "MailFolderClosed.png"; // has Children
}
$out[$path] = $oA;
}
//_debug_array($out);
return (isset($out)?$out:array('/INBOX'=>array('label'=>'INBOX','title'=>'INBOX','image'=>'kfm_home.png')));
}
/**
* Get actions / context menu for index
*

View File

@ -2,7 +2,7 @@
/**
* EGroupware - eTemplates for Application mail
* http://www.egroupware.org
* generated by soetemplate::dump4setup() 2013-02-11 14:41
* generated by soetemplate::dump4setup() 2013-02-11 17:16
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package mail
@ -12,7 +12,7 @@
$templ_version=1;
$templ_data[] = array('name' => 'mail.index','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:2:{i:0;a:3:{s:4:"type";s:4:"tree";s:4:"name";s:14:"nm[foldertree]";s:7:"onclick";s:37:"alert(\'onChange node=\'+arguments[0]);";}i:1;a:3:{s:4:"type";s:9:"nextmatch";s:4:"name";s:2:"nm";s:4:"size";s:4:"rows";}}','size' => '100%,,,,0,3','style' => '','modified' => '1360577272',);
$templ_data[] = array('name' => 'mail.index','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:2:{i:0;a:3:{s:4:"type";s:4:"tree";s:4:"name";s:14:"nm[foldertree]";s:7:"onclick";s:39:"alert(\'on Changen node=\'+arguments[0]);";}i:1;a:3:{s:4:"type";s:9:"nextmatch";s:4:"name";s:2:"nm";s:4:"size";s:4:"rows";}}','size' => '100%,,,,0,3','style' => '','modified' => '1360577272',);
$templ_data[] = array('name' => 'mail.index.rows','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:6:{s:2:"c1";s:2:"th";s:1:"A";s:2:"25";s:1:"F";s:2:"50";s:1:"E";s:3:"120";s:1:"D";s:3:"120";s:1:"C";s:2:"95";}i:1;a:6:{s:1:"A";a:4:{s:4:"type";s:16:"nextmatch-header";s:5:"label";s:2:"ID";s:4:"name";s:3:"uid";s:8:"readonly";s:1:"1";}s:1:"B";a:3:{s:4:"type";s:20:"nextmatch-sortheader";s:4:"name";s:7:"subject";s:5:"label";s:7:"subject";}s:1:"C";a:4:{s:4:"type";s:20:"nextmatch-sortheader";s:5:"label";s:4:"date";s:4:"name";s:4:"date";s:5:"align";s:6:"center";}s:1:"D";a:3:{s:4:"type";s:20:"nextmatch-sortheader";s:5:"label";s:2:"to";s:4:"name";s:9:"toaddress";}s:1:"E";a:3:{s:4:"type";s:20:"nextmatch-sortheader";s:5:"label";s:4:"from";s:4:"name";s:11:"fromaddress";}s:1:"F";a:4:{s:4:"type";s:20:"nextmatch-sortheader";s:5:"label";s:4:"size";s:4:"name";s:4:"size";s:5:"align";s:6:"center";}}i:2;a:6:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"name";s:11:"${row}[uid]";s:8:"readonly";s:1:"1";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:15:"${row}[subject]";}s:1:"C";a:4:{s:4:"type";s:9:"date-time";s:4:"name";s:12:"${row}[date]";s:8:"readonly";s:1:"1";s:5:"align";s:6:"center";}s:1:"D";a:3:{s:4:"type";s:9:"url-email";s:4:"name";s:17:"${row}[toaddress]";s:8:"readonly";s:1:"1";}s:1:"E";a:3:{s:4:"type";s:9:"url-email";s:4:"name";s:19:"${row}[fromaddress]";s:8:"readonly";s:1:"1";}s:1:"F";a:5:{s:4:"type";s:5:"label";s:4:"name";s:12:"${row}[size]";s:7:"no_lang";s:1:"1";s:8:"readonly";s:1:"1";s:5:"align";s:5:"right";}}}s:4:"rows";i:2;s:4:"cols";i:6;}}','size' => '','style' => '','modified' => '1360252030',);

View File

@ -31,16 +31,17 @@ $setup_info['mail']['hooks']['addaccount'] = 'mail_hooks::accountHooks';
$setup_info['mail']['hooks']['deleteaccount'] = 'mail_hooks::accountHooks';
$setup_info['mail']['hooks']['editaccount'] = 'mail_hooks::accountHooks';
$setup_info['mail']['hooks']['search_link'] = 'mail_hooks::search_link';
$setup_info['mail']['hooks']['admin'] = 'mail_hooks::admin';
$setup_info['mail']['hooks']['settings'] = 'mail_hooks::settings';
$setup_info['mail']['hooks']['preferences'] = 'mail_hooks::preferences';
$setup_info['mail']['hooks']['sidebox_menu'] = 'mail_hooks::sidebox_menu';
$setup_info['mail']['hooks']['session_creation'] = 'mail_bo::resetConnectionErrorCache';
/*
$setup_info['mail']['hooks']['admin'] = 'mail_hooks::admin';
$setup_info['mail']['hooks']['preferences'] = 'mail_hooks::preferences';
$setup_info['mail']['hooks']['settings'] = 'mail_hooks::settings';
$setup_info['mail']['hooks'][] = 'home';
$setup_info['mail']['hooks']['sidebox_menu'] = 'mail_hooks::sidebox_menu';
$setup_info['mail']['hooks']['verify_settings'] = 'mail_bo::forcePrefReload';
$setup_info['mail']['hooks']['edit_user'] = 'mail_hooks::adminMenu';
$setup_info['mail']['hooks']['session_creation'] = 'mail_bo::resetConnectionErrorCache';
*/
/* Dependencies for this app to work */

View File

@ -32,7 +32,7 @@
</grid>
</template>
<template id="mail.index" template="" lang="" group="0" version="1.9.001">
<tree id="nm[foldertree]" onclick="alert('onChange node='+arguments[0]);"/>
<tree id="nm[foldertree]" onclick="alert('on Changen node='+arguments[0]);"/>
<nextmatch id="nm" options="mail.index.rows"/>
</template>
</overlay>