From b8609009dc36ca60bd11e1327a2edcc3e6bfccd7 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 12 Apr 2013 09:22:23 +0000 Subject: [PATCH] broken mail app - to debug for nathan --- mail/inc/class.mail_bo.inc.php | 73 ++++++++++ mail/inc/class.mail_ui.inc.php | 222 ++++++++++++++++++++++++++++++- mail/js/app.js | 92 +++++++++++-- mail/templates/default/index.xet | 69 +++++++++- 4 files changed, 437 insertions(+), 19 deletions(-) diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index 2fb1dd715c..6a2fb7d545 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -1563,6 +1563,16 @@ class mail_bo } + /** + * decodeEntityFolderName - remove html entities + * @param string _folderName the foldername + * @return string the converted string + */ + function decodeEntityFolderName($_folderName) + { + return html_entity_decode($_folderName, ENT_QUOTES, self::$displayCharset); + } + /** * convert a mailboxname from utf7-imap to displaycharset * @@ -1574,6 +1584,69 @@ class mail_bo return translation::convert($_folderName, 'UTF7-IMAP', self::$displayCharset); } + /** + * convert the foldername from display charset to UTF-7 + * + * @param string _parent the parent foldername + * @return ISO-8859-1 / UTF7-IMAP encoded string + */ + function _encodeFolderName($_folderName) { + return translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1'); + #return translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP'); + } + + /** + * rename a folder + * + * @param string _oldFolderName the old foldername + * @param string _parent the parent foldername + * @param string _folderName the new foldername + * + * @return mixed name of the newly created folder or false on error + */ + function renameFolder($_oldFolderName, $_parent, $_folderName) + { + $oldFolderName = $this->_encodeFolderName($_oldFolderName); + $parent = $this->_encodeFolderName($_parent); + $folderName = $this->_encodeFolderName($_folderName); + + if(empty($parent)) { + $newFolderName = $folderName; + } else { + $HierarchyDelimiter = $this->getHierarchyDelimiter(); + $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; + } + + return $newFolderName; + + } + + function subscribe($_folderName, $_status) + { + 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); + return false; + } + } else { + $rv = $this->icServer->unsubscribeMailbox($_folderName); + if ( PEAR::isError($rv)) { + error_log(__METHOD__."::".($_status?"":"un")."subscribe:".$_folderName." failed:".$rv->message); + return false; + } + } + + return true; + } + /** * get IMAP folder objects * diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index f795af0b00..e6897f9116 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -26,6 +26,7 @@ class mail_ui 'displayHeader' => True, 'saveMessage' => True, 'vfsSaveMessage' => True, + 'importMessage' => True, 'TestConnection' => True, ); @@ -149,7 +150,7 @@ class mail_ui unset($msg); unset($content['msg']); } - $content['preview'] = ""; + //$content['preview'] = ""; $this->mail_bo->restoreSessionData(); // filter is used to choose the mailbox @@ -209,7 +210,8 @@ class mail_ui // Tree doesn't support this one - yet 'rename' => array( 'caption' => 'Rename', - 'type' => 'popup' + 'type' => 'popup', + 'onExecute' => 'javaScript:app.mail.mail_RenameFolder' ) )); @@ -636,7 +638,7 @@ class mail_ui 'open' => array( 'caption' => lang('Open'), 'group' => ++$group, - 'onExecute' => 'javaScript:app.mail.open', //dummy by nathan + 'onExecute' => 'javaScript:app.mail.mail_preview', //dummy by nathan 'allowOnMultiple' => false, 'default' => true, ), @@ -1477,8 +1479,8 @@ unset($query['actions']); */ function vfsSaveMessage($ids,$path) { - return "alert('".__METHOD__.'("'.array2string($id).'","'.$path."\")'); window.close();"; -/* + error_log(__METHOD__.' IDs:'.array2string($ids).' SaveToPath:'.$path); + if (is_array($ids) && !egw_vfs::is_writable($path) || !is_array($ids) && !egw_vfs::is_writable(dirname($path))) { return 'alert("'.addslashes(lang('%1 is NOT writable by you!',$path)).'"); window.close();'; @@ -1497,15 +1499,172 @@ unset($query['actions']); } if ($fp) fclose($fp); } - $this->mail_bo->closeConnection(); + //$this->mail_bo->closeConnection(); return $err.'window.close();'; + } + + /** + * importMessage + */ + function importMessage() + { + error_log(array2string($_POST)); +/* + if (empty($importtype)) $importtype = htmlspecialchars($_POST["importtype"]); + if (empty($toggleFS)) $toggleFS = htmlspecialchars($_POST["toggleFS"]); + if (empty($importID)) $importID = htmlspecialchars($_POST["importid"]); + if (empty($addFileName)) $addFileName =html::purify($_POST['addFileName']); + if (empty($importtype)) $importtype = 'file'; + if (empty($toggleFS)) $toggleFS= false; + if (empty($addFileName)) $addFileName = false; + if ($toggleFS == 'vfs' && $importtype=='file') $importtype='vfs'; + if (!$toggleFS && $importtype=='vfs') $importtype='file'; + + // get passed messages + if (!empty($_GET["msg"])) $alert_message[] = html::purify($_GET["msg"]); + if (!empty($_POST["msg"])) $alert_message[] = html::purify($_POST["msg"]); + unset($_GET["msg"]); + unset($_POST["msg"]); + //_debug_array($alert_message); + //error_log(__METHOD__." called from:".function_backtrace()); + $proceed = false; + if(is_array($_FILES["addFileName"])) + { + //phpinfo(); + //error_log(print_r($_FILES,true)); + if($_FILES['addFileName']['error'] == $UPLOAD_ERR_OK) { + $proceed = true; + $formData['name'] = $_FILES['addFileName']['name']; + $formData['type'] = $_FILES['addFileName']['type']; + $formData['file'] = $_FILES['addFileName']['tmp_name']; + $formData['size'] = $_FILES['addFileName']['size']; + } + } + if ($addFileName && $toggleFS == 'vfs' && $importtype == 'vfs' && $importID) + { + $sessionData = $GLOBALS['egw']->session->appsession('compose_session_data_'.$importID, 'felamimail'); + //error_log(__METHOD__.__LINE__.array2string($sessionData)); + foreach((array)$sessionData['attachments'] as $attachment) { + //error_log(__METHOD__.__LINE__.array2string($attachment)); + if ($addFileName == $attachment['name']) + { + $proceed = true; + $formData['name'] = $attachment['name']; + $formData['type'] = $attachment['type']; + $formData['file'] = $attachment['file']; + $formData['size'] = $attachment['size']; + break; + } + } + } + if ($proceed === true) + { + $destination = html::purify($_POST['newMailboxMoveName']?$_POST['newMailboxMoveName']:''); + try + { + $messageUid = $this->importMessageToFolder($formData,$destination,$importID); + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.display', + 'uid' => $messageUid, + 'mailbox' => base64_encode($destination), + ); + } + catch (egw_exception_wrong_userinput $e) + { + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.importMessage', + 'msg' => htmlspecialchars($e->getMessage()), + ); + } + egw::redirect_link('/index.php',$linkData); + exit; + } + + if(!@is_object($GLOBALS['egw']->js)) + { + $GLOBALS['egw']->js = CreateObject('phpgwapi.javascript'); + } + // this call loads js and css for the treeobject + html::tree(false,false,false,null,'foldertree','','',false,'/',null,false); + $GLOBALS['egw']->common->egw_header(); + + #$uiwidgets =& CreateObject('felamimail.uiwidgets'); + + $this->t->set_file(array("importMessage" => "importMessage.tpl")); + + $this->t->set_block('importMessage','fileSelector','fileSelector'); + $importID =felamimail_bo::getRandomString(); + + // prepare saving destination of imported message + $linkData = array + ( + 'menuaction' => 'felamimail.uipreferences.listSelectFolder', + ); + $this->t->set_var('folder_select_url',$GLOBALS['egw']->link('/index.php',$linkData)); + + // messages that may be passed to the Form + if (isset($alert_message) && !empty($alert_message)) + { + $this->t->set_var('messages', implode('; ',$alert_message)); + } + else + { + $this->t->set_var('messages',''); + } + + // preset for saving destination, we use draftfolder + $savingDestination = $this->mail_bo->getDraftFolder(); + + $this->t->set_var('mailboxNameShort', $savingDestination); + $this->t->set_var('importtype', $importtype); + $this->t->set_var('importid', $importID); + if ($toggleFS) $this->t->set_var('toggleFS_preset','checked'); else $this->t->set_var('toggleFS_preset',''); + + $this->translate(); + + $linkData = array + ( + 'menuaction' => 'mail.mail_ui.importMessage', + ); + $this->t->set_var('file_selector_url', $GLOBALS['egw']->link('/index.php',$linkData)); + + $this->t->set_var('vfs_selector_url', egw::link('/index.php',array( + 'menuaction' => 'filemanager.filemanager_select.select', + 'mode' => 'open-multiple', + 'method' => 'felamimail.uifelamimail.selectFromVFS', + 'id' => $importID, + 'label' => lang('Attach'), + ))); + if ($GLOBALS['egw_info']['user']['apps']['filemanager'] && $importtype == 'vfs') + { + $this->t->set_var('vfs_attach_button',' +        + +     '); + $this->t->set_var('filebox_readonly','readonly="readonly"'); + } + else + { + $this->t->set_var('vfs_attach_button',''); + $this->t->set_var('filebox_readonly',''); + } + + $maxUploadSize = ini_get('upload_max_filesize'); + $this->t->set_var('max_uploadsize', $maxUploadSize); + + $this->t->set_var('ajax-loader', $GLOBALS['egw']->common->image('felamimail','ajax-loader')); + + $this->t->pparse("out","fileSelector"); */ } /** - * getFolderStatus - its called via json, so the function must start with ajax (or the class-name must contain ajax) + * ajax_setFolderStatus - its called via json, so the function must start with ajax (or the class-name must contain ajax) * gets the counters and sets the text of a treenode if needed (unread Messages found) + * @param array $_folder folders to refresh its unseen message counters * @return nothing */ function ajax_setFolderStatus($_folder) @@ -1542,6 +1701,55 @@ unset($query['actions']); } } + /** + * ajax_renameFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) + * @param string $_folderName folder to rename and refresh + * @param string $_newName new foldername + * @return nothing + */ + function ajax_renameFolder($_folderName, $_newName) + { + //error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName).' NewName:'.array2string($_newName)); + if ($_folderName) + { + $_folderName = $this->mail_bo->decodeEntityFolderName($_folderName); + $_newName = translation::convert($this->mail_bo->decodeEntityFolderName($_newName), $this->charset, 'UTF7-IMAP'); + $del = $this->mail_bo->getHierarchyDelimiter(false); + $oA = array(); + list($profileID,$folderName) = explode(self::$delimiter,$_folderName,2); + if (is_numeric($profileID)) + { + if ($profileID != $this->mail_bo->profileID) return; // only current connection + $pA = explode($del,$folderName); + array_pop($pA); + $parentFolder = implode($del,$pA); + if (strtoupper($folderName)!= 'INBOX') + { + //error_log(__METHOD__.__LINE__."$folderName, $parentFolder, $_newName"); + 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); + } + $fS = $this->mail_bo->getFolderStatus($newFolderName,false); + //error_log(__METHOD__.__LINE__.array2string($fS)); + if ($fS['unseen']) + { + $oA[$_folderName] = ''.$fS['shortDisplayName'].' ('.$fS['unseen'].')'; + + } + } + } + //error_log(__METHOD__.__LINE__.array2string($oA)); + if ($oA) + { + $response = egw_json_response::get(); + $response->call('app.mail.mail_setFolderStatus',$oA,'mail'); + } + } + } + /** * empty changeProfile - its called via json, so the function must start with ajax (or the class-name must contain ajax) * diff --git a/mail/js/app.js b/mail/js/app.js index d66b0dec7b..eff7fdfb1e 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -24,7 +24,6 @@ mail_queuedFoldersIndex: 0, init: function() { this._super.apply(this,arguments); - window.register_app_refresh("mail", this.app_refresh); this.mail_startTimerFolderStatusUpdate(this.mail_refreshTimeOut); @@ -33,8 +32,36 @@ init: function() { window.setTimeout(function() {self.mail_refreshFolderStatus.apply(self);},1000); }, -open: function(action, senders, ids) { - console.log("open",action, senders, ids); +/** + * mail_open - implementation of the open action + * + * @param _action + * @param _senders - the representation of the elements(s) the action is to be performed on + */ +mail_open: function(_action, _senders) { + console.log("mail_open",_action, _senders); + var _id = _senders[0].id; + var dataElem = egw.dataGetUIDdata(_id); + var subject =dataElem.data.subject; + var sw = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('previewSubject'); +}, + +/** + * mail_preview - implementation of the copy action + * + * @param _action + * @param _senders - the representation of the elements(s) the action is to be performed on + */ +mail_preview: function(_action, _senders) { + //console.log("mail_preview",_action, _senders); + var _id = _senders[0].id; + var dataElem = egw.dataGetUIDdata(_id); + console.log("mail_preview",dataElem); + var subject =dataElem.data.subject; + etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('previewFromAddress').set_value(dataElem.data.fromaddress); + etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('previewToAddress').set_value(dataElem.data.toaddress); + etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('previewDate').set_value(dataElem.data.date); + etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('previewSubject').set_value(subject); }, /** @@ -71,13 +98,16 @@ mail_refreshFolderStatus: function(_nodeID,mode) { if (mode) { if (mode == "forced") {mode2use = mode;} } - var tree_wdg = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('nm[foldertree]'); + try + { + var tree_wdg = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('nm[foldertree]'); - var activeFolders = tree_wdg.getTreeNodeOpenItems(nodeToRefresh,mode2use); - //alert(activeFolders.join('#,#')); - this.mail_queueRefreshFolderList(activeFolders); + var activeFolders = tree_wdg.getTreeNodeOpenItems(nodeToRefresh,mode2use); + //alert(activeFolders.join('#,#')); + this.mail_queueRefreshFolderList(activeFolders); - this.mail_refreshMessageGrid(); + this.mail_refreshMessageGrid(); + } catch(e) { } // ignore the error; maybe the template is not loaded yet }, @@ -491,10 +521,24 @@ mail_setRowClass: function(_actionObjects,_class) { }, // Tree widget stubs +/** + * mail_dragStart - displays information while dragging + * + * @param action + * @param _senders - the representation of the elements dragged + * @return the ddhelper + */ mail_dragStart: function(action,_senders) { //console.log(action,_senders); return $j("
" + _senders.length + " Mails selected
") }, +/** + * mail_move - implementation of the move action from drag n drop + * + * @param _action + * @param _senders - the representation of the elements dragged + * @param _target - the representation of the target + */ mail_move: function(_action,_senders,_target) { //console.log(_action,_senders,_target); var target = _action.id == 'drop_move_mail' ? _target.iface.id : _action.id.substr(5); @@ -506,6 +550,13 @@ mail_move: function(_action,_senders,_target) { request.sendRequest(false); this.mail_refreshMessageGrid() }, +/** + * mail_copy - implementation of the copy action from drag n drop + * + * @param _action + * @param _senders - the representation of the elements dragged + * @param _target - the representation of the target + */ mail_copy: function(_action,_senders,_target) { //console.log(_action,_senders,_target); var target = _action.id == 'drop_copy_mail' ? _target.id : _action.id.substr(5); @@ -516,5 +567,30 @@ mail_copy: function(_action,_senders,_target) { var request = new egw_json_request('mail.mail_ui.ajax_copyMessages',[target, messages]); request.sendRequest(false); this.mail_refreshMessageGrid() +}, +/** + * mail_RenameFolder - implementation of the RenameFolder action of right click options on the tree + * + * @param _action + * @param _senders - the representation of the tree leaf to be manipulated + */ +mail_RenameFolder: function(action,_senders) { + //console.log(action,_senders); + //action.id == 'rename' + //_senders.iface.id == target leaf / leaf to edit + var ftree = etemplate2.getByApplication('mail')[0].widgetContainer.getWidgetById('nm[foldertree]'); + OldFolderName = ftree.getLabel(_senders[0].iface.id); + if (jQuery(OldFolderName).text().length>0) OldFolderName = jQuery(OldFolderName).text(); + OldFolderName = OldFolderName.trim(); + OldFolderName = OldFolderName.replace(/\([0-9]*\)/g,'').trim(); + //console.log(OldFolderName); + NewFolderName = prompt(egw.lang("Rename Folder %1 to:",OldFolderName)); + if (jQuery(NewFolderName).text().length>0) NewFolderName = jQuery(NewFolderName).text(); + //alert(NewFolderName); + if (NewFolderName && NewFolderName.length>0) + { + var request = new egw_json_request('mail.mail_ui.ajax_renameFolder',[_senders[0].iface.id, NewFolderName]); + request.sendRequest(false); + } } }); diff --git a/mail/templates/default/index.xet b/mail/templates/default/index.xet index c64074a004..3510f8ce90 100644 --- a/mail/templates/default/index.xet +++ b/mail/templates/default/index.xet @@ -40,9 +40,70 @@