From 95021fe0fc52f5c72bc6f0efc16efd6a69984b9f Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Thu, 12 Dec 2013 15:10:25 +0000 Subject: [PATCH] use new dialog.show_prompt for rename; handle encoding issues; catch possible exceptions and try to handle it correctly by attempting some kind of rollback --- mail/inc/class.mail_bo.inc.php | 17 +++++++++------- mail/inc/class.mail_ui.inc.php | 30 +++++++++++++++++++-------- mail/js/app.js | 37 +++++++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index f2dcc107c0..2960ebecaa 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -1688,9 +1688,9 @@ class mail_bo */ function renameFolder($_oldFolderName, $_parent, $_folderName) { - $oldFolderName = $this->_encodeFolderName($_oldFolderName); - $parent = $this->_encodeFolderName($_parent); - $folderName = $this->_encodeFolderName($_folderName); + $oldFolderName = $_oldFolderName;//$this->_encodeFolderName($_oldFolderName); + $parent = $_parent;//$this->_encodeFolderName($_parent); + $folderName = $_folderName;//$this->_encodeFolderName($_folderName); if(empty($parent)) { $newFolderName = $folderName; @@ -1699,10 +1699,13 @@ class mail_bo $newFolderName = $parent . $HierarchyDelimiter . $folderName; } if (self::$debug) error_log("create folder: $newFolderName"); - $rv = $this->icServer->renameMailbox($oldFolderName, $newFolderName); - if ( PEAR::isError($rv) ) { - if (self::$debug) error_log(__METHOD__." failed for $oldFolderName, $newFolderName with error: ".print_r($rv->message,true)); - return false; + try + { + $rv = $this->icServer->renameMailbox($oldFolderName, $newFolderName); + } + catch (Exception $e) + { + throw new egw_exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());; } return $newFolderName; diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index e79b5581d0..2f4b04d0b7 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -3229,11 +3229,11 @@ blockquote[type=cite] { */ function ajax_renameFolder($_folderName, $_newName) { - //error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName).' NewName:'.array2string($_newName)); + error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName).' NewName:'.array2string($_newName)); if ($_folderName) { $decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName); - $_newName = translation::convert($this->mail_bo->decodeEntityFolderName($_newName), $this->charset, 'UTF7-IMAP'); + $_newName = $this->mail_bo->decodeEntityFolderName($_newName); $del = $this->mail_bo->getHierarchyDelimiter(false); $oA = array(); list($profileID,$folderName) = explode(self::$delimiter,$decodedFolderName,2); @@ -3275,11 +3275,21 @@ blockquote[type=cite] { } $this->mail_bo->reopen('INBOX'); - if($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)) { - $this->mail_bo->resetFolderObjectCache($profileID); - //enforce the subscription to the newly named server, as it seems to fail for names with umlauts - $rv = $this->mail_bo->subscribe($newFolderName, true); - $rv = $this->mail_bo->subscribe($folderName, false); + $success = false; + try + { + if($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)) { + $this->mail_bo->resetFolderObjectCache($profileID); + //enforce the subscription to the newly named server, as it seems to fail for names with umlauts + $rv = $this->mail_bo->subscribe($newFolderName, true); + $rv = $this->mail_bo->subscribe($folderName, false); + $success = true; + } + } + catch (Exception $e) + { + $newFolderName=$folderName; + $msg = $e->getMessage(); } $this->mail_bo->reopen($newFolderName); $fS = $this->mail_bo->getFolderStatus($newFolderName,false); @@ -3337,11 +3347,15 @@ blockquote[type=cite] { $this->mail_bo->saveSessionData(); } //error_log(__METHOD__.__LINE__.array2string($oA)); - if ($oA) + if ($oA && $success) { $response = egw_json_response::get(); $response->call('app.mail.mail_setLeaf',$oA,'mail'); } + else + { + $response->call('egw_refresh',lang('failed to rename %1 ! Reason: %2',$oldFolderName,$msg),'mail'); + } } } diff --git a/mail/js/app.js b/mail/js/app.js index 316b96b1c8..69f9f7104d 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -1826,15 +1826,34 @@ app.classes.mail = AppJS.extend( OldFolderName = OldFolderName.trim(); OldFolderName = OldFolderName.replace(/\([0-9]*\)/g,'').trim(); //console.log(OldFolderName); - NewFolderName = prompt(this.egw.lang("Rename Folder %1 to:",OldFolderName)); - if (jQuery(NewFolderName).text().length>0) NewFolderName = jQuery(NewFolderName).text(); - //alert(NewFolderName); - if (NewFolderName && NewFolderName.length>0) - { - app.mail.app_refresh(this.egw.lang("Renaming Folder %1 to %2",OldFolderName,NewFolderName, 'mail')); - egw.json('mail.mail_ui.ajax_renameFolder',[_senders[0].iface.id, NewFolderName]) - .sendRequest(true); - } + var buttons = [ + {text: this.egw.lang("Rename"), id: "rename", class: "ui-priority-primary", "default": true}, + {text: this.egw.lang("Cancel"), id:"cancel"}, + ]; + var dialog = et2_dialog.show_prompt(function(_button_id, _value) { + var senders = this.my_data.data; + var NewFolderName = null; + if (_value.length>0) NewFolderName = _value; + //alert(NewFolderName); + if (NewFolderName && NewFolderName.length>0) + { + switch (_button_id) + { + case "rename": + egw.json('mail.mail_ui.ajax_renameFolder',[senders[0].iface.id, NewFolderName]) + .sendRequest(true); + return; + case "cancel": + } + } + }, + this.egw.lang("Rename Folder %1 to:",OldFolderName), + this.egw.lang("Rename Folder %1 ?",OldFolderName), + OldFolderName, buttons); + // setting required data for callback in as my_data + dialog.my_data = { + data: _senders, + }; }, /**