diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index 08792ada96..f2dcc107c0 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -1648,8 +1648,8 @@ class mail_bo function createFolder($_parent, $_folderName, $_subscribe=false) { if (self::$debug) error_log(__METHOD__.__LINE__."->"."$_parent, $_folderName, $_subscribe"); - $parent = $this->_encodeFolderName($_parent); - $folderName = $this->_encodeFolderName($_folderName); + $parent = $_parent;//$this->_encodeFolderName($_parent); + $folderName = $_folderName;//$this->_encodeFolderName($_folderName); if(empty($parent)) { $newFolderName = $folderName; @@ -1718,13 +1718,15 @@ class mail_bo */ function deleteFolder($_folderName) { - $folderName = $this->_encodeFolderName($_folderName); - - $this->icServer->subscribeMailbox($folderName,false); - $rv = $this->icServer->deleteMailbox($folderName); - if ( PEAR::isError($rv) ) { - if (self::$debug) error_log(__METHOD__." failed for $folderName with error: ".print_r($rv->message,true)); - return $rv; + //$folderName = $this->_encodeFolderName($_folderName); + try + { + $this->icServer->subscribeMailbox($_folderName,false); + $this->icServer->deleteMailbox($_folderName); + } + catch (Exception $e) + { + throw new egw_exception("Deleting Folder $_foldername failed! Error:".$e->getMessage());; } return true; @@ -1734,15 +1736,23 @@ class mail_bo { if (self::$debug) error_log(__METHOD__."::".($_status?"":"un")."subscribe:".$_folderName); if($_status === true) { - $rv = $this->icServer->subscribeMailbox($_folderName); - if ( PEAR::isError($rv)) { - error_log(__METHOD__."::".($_status?"":"un")."subscribe:".$_folderName." failed:".$rv->message); + try + { + $rv = $this->icServer->subscribeMailbox($_folderName); + } + catch (Exception $e) + { + error_log(__METHOD__."::".($_status?"":"un")."subscribe:".$_folderName." failed:".$e->getMessage); return false; } } else { - $rv = $this->icServer->subscribeMailbox($_folderName,false); - if ( PEAR::isError($rv)) { - error_log(__METHOD__."::".($_status?"":"un")."subscribe:".$_folderName." failed:".$rv->message); + try + { + $rv = $this->icServer->subscribeMailbox($_folderName,false); + } + catch (Exception $e) + { + error_log(__METHOD__."::".($_status?"":"un")."subscribe:".$_folderName." failed:".$e->getMessage); return false; } } @@ -1774,7 +1784,7 @@ class mail_bo 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 ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId])) { - //error_log(__METHOD__.__LINE__.' using Cached folderObjects'); + //error_log(__METHOD__.__LINE__.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId])); return $folders2return[$this->icServer->ImapServerId]; } } @@ -1881,15 +1891,12 @@ class mail_bo } } } - if( PEAR::isError($allMailboxesExt) ) { - #echo __METHOD__;_debug_array($allMailboxesExt); - continue; - } $allMailBoxesExtSorted = array(); if (!is_array($allMailboxesExt)) { - error_log(__METHOD__.__LINE__.' Expected Array but got:'.array2string($allMailboxesExt)); - $allMailboxesExt=array(); + //error_log(__METHOD__.__LINE__.' Expected Array but got:'.array2string($allMailboxesExt). 'Type:'.$type.' Prefix:'.$foldersNameSpace[$type]['prefix']); + continue; + //$allMailboxesExt=array(); } foreach ($allMailboxesExt as $mbx) { //echo __METHOD__;_debug_array($mbx); diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index e1be9ffb23..e79b5581d0 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -193,6 +193,10 @@ class mail_ui $this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities //$toSchema = $this->mail_bo->isDraftFolder($sessionFolder)||$this->mail_bo->isSentFolder($sessionFolder)||$this->mail_bo->isTemplateFolder($sessionFolder); } + else + { + $sessionFolder = $this->mail_bo->sessionData['mailbox'] = 'INBOX'; + } //error_log(__METHOD__.__LINE__.' SessionFolder:'.$sessionFolder.' isToSchema:'.$toSchema); //_debug_array($content); if (!is_array($content)) @@ -1152,13 +1156,16 @@ unset($query['actions']); } //save selected Folder to sessionData (mailbox)->currentFolder if (isset($query['selectedFolder'])) $this->mail_bo->sessionData['mailbox']=$_folderName; - $this->mail_bo->saveSessionData(); $toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default) if ($this->mail_bo->folderExists($_folderName)) { $toSchema = $this->mail_bo->isDraftFolder($_folderName)||$this->mail_bo->isSentFolder($_folderName)||$this->mail_bo->isTemplateFolder($_folderName); } - + else + { + $query['selectedFolder']=$this->mail_bo->sessionData['mailbox']=$_folderName='INBOX'; + } + $this->mail_bo->saveSessionData(); $rowsFetched['messages'] = null; $offset = $query['start']+1; // we always start with 1 $maxMessages = $query['num_rows']; @@ -3172,7 +3179,8 @@ blockquote[type=cite] { { $created = false; $decodedFolderName = $this->mail_bo->decodeEntityFolderName($_parentFolderName); - $_newName = translation::convert($this->mail_bo->decodeEntityFolderName($_newName), $this->charset, 'UTF7-IMAP'); + //the conversion is handeled by horde, frontend interaction is all utf-8 + $_newName = $this->mail_bo->decodeEntityFolderName($_newName);//translation::convert($this->mail_bo->decodeEntityFolderName($_newName), $this->charset, 'UTF7-IMAP'); $del = $this->mail_bo->getHierarchyDelimiter(false); list($profileID,$parentFolderName) = explode(self::$delimiter,$decodedFolderName,2); if (is_numeric($profileID)) @@ -3366,25 +3374,58 @@ blockquote[type=cite] { { //error_log(__METHOD__.__LINE__."$folderName, $parentFolder, $_newName"); $oA = array(); + $subFolders = array(); $oldFolderInfo = $this->mail_bo->getFolderStatus($folderName,false); //error_log(__METHOD__.__LINE__.array2string($oldFolderInfo)); if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']),'\hasnochildren')=== false) { $hasChildren=true; // translates to: hasChildren -> dynamicLoading - $msg = lang("refused to delete folder with subfolders"); + //$msg = lang("refused to delete folder with subfolders"); + $delimiter = $this->mail_bo->getHierarchyDelimiter(); + $nameSpace = $this->mail_bo->_getNameSpaces(); + $prefix = $this->mail_bo->getFolderPrefixFromNamespace($nameSpace, $folderName); + //error_log(__METHOD__.__LINE__.'->'."$_folderName, $delimiter, $prefix"); + $subFolders = $this->mail_bo->getMailBoxesRecursive($folderName, $delimiter, $prefix); + //error_log(__METHOD__.__LINE__.'->'."$folderName, $delimiter, $prefix"); + foreach ($subFolders as $k => $f) + { + if (!isset($ftD[substr_count($f,$delimiter)])) $ftD[substr_count($f,$delimiter)]=array(); + $ftD[substr_count($f,$delimiter)][]=$f; + } + krsort($ftD,SORT_NUMERIC);//sort per level + //we iterate per level of depth of the subtree, deepest nesting is to be deleted first, and then up the tree + foreach($ftD as $k => $lc)//collection per level + { + foreach($lc as $i => $f)//folders contained in that level + { + try + { + //error_log(__METHOD__.__LINE__.array2string($f).'<->'.$folderName); + $this->mail_bo->deleteFolder($f); + $success = true; + if ($f==$folderName) $oA[$_folderName] = $oldFolderInfo['shortDisplayName']; + } + catch (Exception $e) + { + $msg .= ($msg?' ':'').lang("Failed to delete %1. Server responded:",$f).$e->getMessage(); + $success = false; + } + } + } } else { - $success = $this->mail_bo->deleteFolder($folderName); - if (PEAR::isError($success)) - { - $msg = $success->message; - $success = false; - } - else + try { + $this->mail_bo->deleteFolder($folderName); + $success = true; $oA[$_folderName] = $oldFolderInfo['shortDisplayName']; } + catch (Exception $e) + { + $msg = $e->getMessage(); + $success = false; + } } } else @@ -3395,6 +3436,19 @@ blockquote[type=cite] { $response = egw_json_response::get(); if ($success) { + $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->mail_bo->profileID])) + { + //error_log(__METHOD__.__LINE__.array2string($folders2return[$this->mail_bo->profileID])); + if (empty($subFolders)) $subFolders = array($folderName); + //error_log(__METHOD__.__LINE__.array2string($subFolders)); + foreach($subFolders as $i => $f) + { + //error_log(__METHOD__.__LINE__.$f.'->'.array2string($folders2return[$this->mail_bo->profileID][$f])); + if (isset($folders2return[$this->mail_bo->profileID][$f])) unset($folders2return[$this->mail_bo->profileID][$f]); + } + } + egw_cache::setCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return, $expiration=60*60*1); //error_log(__METHOD__.__LINE__.array2string($oA)); $response->call('app.mail.mail_removeLeaf',$oA,'mail'); } @@ -3412,6 +3466,7 @@ blockquote[type=cite] { */ function ajax_changeProfile($icServerID) { + //lang('Connect to Profile %1',$icServerID); if ($icServerID && $icServerID != $this->mail_bo->profileID) { //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); diff --git a/mail/js/app.js b/mail/js/app.js index 10da932e72..316b96b1c8 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -997,6 +997,7 @@ app.classes.mail = AppJS.extend( */ mail_changeProfile: function(folder,_widget) { // alert(folder); + egw_message(this.egw.lang('Connect to Profile %1',_widget.getSelectedLabel())); egw.json('mail.mail_ui.ajax_changeProfile',[folder]) .sendRequest(); @@ -1013,11 +1014,13 @@ app.classes.mail = AppJS.extend( var server = folder.split('::'); app.mail.app_refresh(this.egw.lang('change folder')+'...', 'mail'); var img = _widget.getSelectedNode().images[0]; // fetch first image + var profileChange = false; if (!(img.search(eval('/'+'NoSelect'+'/'))<0) || !(img.search(eval('/'+'thunderbird'+'/'))<0)) { if (!(img.search(eval('/'+'thunderbird'+'/'))<0)) { rv = this.mail_changeProfile(folder,_widget); + profileChange = true; } else if (_widget.event_args.length==2) { @@ -1050,7 +1053,7 @@ app.classes.mail = AppJS.extend( } } myMsg = (displayname?displayname:folder)+' '+this.egw.lang('selected'); - egw_message(myMsg); + if (profileChange == false) egw_message(myMsg); //mail_refreshMessageGrid();// its done in refreshFolderStatus already this.mail_refreshFolderStatus(folder,'forced'); @@ -1850,13 +1853,29 @@ app.classes.mail = AppJS.extend( OldFolderName = OldFolderName.trim(); OldFolderName = OldFolderName.replace(/\([0-9]*\)/g,'').trim(); //console.log(OldFolderName); - reallyDelete = confirm(this.egw.lang("Do you really want to DELETE Folder %1 ?",OldFolderName)+" \r\n"+(ftree.hasChildren(_senders[0].iface.id)?this.egw.lang("All subfolders will be deleted too, and all messages in all affected folders will be lost"):this.egw.lang("All messages in the folder will be lost"))); - if (reallyDelete) - { - app.mail.app_refresh(this.egw.lang("Deleting Folder %1",OldFolderName, 'mail')); - egw.json('mail.mail_ui.ajax_deleteFolder',[_senders[0].iface.id]) - .sendRequest(true); - } + var buttons = [ + {text: this.egw.lang("Yes"), id: "delete", class: "ui-priority-primary", "default": true}, + {text: this.egw.lang("Cancel"), id:"cancel"}, + ]; + var dialog = et2_dialog.show_dialog(function(_button_id, _value) { + var senders = this.my_data.data; + switch (_button_id) + { + case "delete": + egw.json('mail.mail_ui.ajax_deleteFolder',[senders[0].iface.id]) + .sendRequest(true); + return; + case "cancel": + } + }, + this.egw.lang("Do you really want to DELETE Folder %1 ?",OldFolderName)+" "+(ftree.hasChildren(_senders[0].iface.id)?this.egw.lang("All subfolders will be deleted too, and all messages in all affected folders will be lost"):this.egw.lang("All messages in the folder will be lost")), + this.egw.lang("DELETE Folder %1 ?",OldFolderName), + OldFolderName, buttons); + // setting required data for callback in as my_data + dialog.my_data = { + data: _senders, + }; + }, /**