From 94b6d8e5ec14bdc0fe7f63c1de7776cbe2903992 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 9 Mar 2012 14:33:00 +0000 Subject: [PATCH] handle drafted versions of viewed messages on close window, when opened from vfs/filemanager; all other actions like composeasnew, reply, forward, print,etc. preserve the viewed (imported) message stored in draft folder; handle special chars in filename when saving messages to filemanager; treat import/view from vfs more gently (try to guess name and mimetype, and set some size, to pass checkFileBasics tests) --- felamimail/inc/class.uidisplay.inc.php | 12 ++++++-- felamimail/inc/class.uifelamimail.inc.php | 34 ++++++++++++++++++----- felamimail/inc/class.uiwidgets.inc.php | 22 +++++++-------- felamimail/js/jscode/viewMainScreen.js | 3 +- felamimail/js/jscode/view_message.js | 5 ++++ 5 files changed, 54 insertions(+), 22 deletions(-) diff --git a/felamimail/inc/class.uidisplay.inc.php b/felamimail/inc/class.uidisplay.inc.php index 7f6226e21f..9390631f4f 100644 --- a/felamimail/inc/class.uidisplay.inc.php +++ b/felamimail/inc/class.uidisplay.inc.php @@ -275,7 +275,8 @@ { $partID = $this->partID = $_GET['part']; if (!empty($_GET['mailbox'])) $this->mailbox = base64_decode($_GET['mailbox']); - + $deleteDraftOnClose = false; + if (!empty($_GET['deleteDraftOnClose']) && $this->bofelamimail->isDraftFolder($this->mailbox)) $deleteDraftOnClose = true; //$transformdate =& CreateObject('felamimail.transformdate'); //$htmlFilter =& CreateObject('felamimail.htmlfilter'); $uiWidgets = CreateObject('felamimail.uiwidgets'); @@ -345,7 +346,7 @@ $rawheaders .= wordwrap($value, 90, "\n "); } - $this->display_app_header(); + $this->display_app_header(NULL,$deleteDraftOnClose); if(!isset($_GET['printable'])) { $this->t->set_file(array("displayMsg" => "view_message.tpl")); } else { @@ -986,7 +987,7 @@ blockquote[type=cite] { exit; } - function display_app_header($printing = NULL) + function display_app_header($printing = NULL, $deleteDraftOnClose = false) { if ($_GET['menuaction'] != 'felamimail.uidisplay.printMessage' && $_GET['menuaction'] != 'felamimail.uidisplay.displayBody' && @@ -1007,6 +1008,11 @@ blockquote[type=cite] { $_GET['menuaction'] == 'felamimail.uidisplay.displayAttachments' ) { $GLOBALS['egw_info']['flags']['nofooter'] = true; } + if ($deleteDraftOnClose) + { + //window.opener.console.log('closing".$this->uid.'->'.$this->mailbox."'); + $GLOBALS['egw']->js->set_onunload("if (do_onunload) egw_appWindow('felamimail').xajax_doXMLHTTPsync('felamimail.ajaxfelamimail.deleteMessages',{msg:[".$this->uid."]});"); + } $GLOBALS['egw_info']['flags']['include_xajax'] = True; common::egw_header(); } diff --git a/felamimail/inc/class.uifelamimail.inc.php b/felamimail/inc/class.uifelamimail.inc.php index 6cd7f81342..28962a9586 100644 --- a/felamimail/inc/class.uifelamimail.inc.php +++ b/felamimail/inc/class.uifelamimail.inc.php @@ -617,7 +617,12 @@ class uifelamimail /** * importMessageFromVFS2DraftAndDisplay * - * @param array $_formData Array with information of name, type, file and size + * @param array $_formData Array with information of name, type, file and size; file is required, + * name, type and size may be set here to meet the requirements + * Example: $formData['name'] = 'a_email.eml'; + * $formData['type'] = 'message/rfc822'; + * $formData['file'] = 'vfs://default/home/leithoff/a_email.eml'; + * $formData['size'] = 2136; * @return mixed $messageUID or exception */ function importMessageFromVFS2DraftAndDisplay($formData='') @@ -626,12 +631,26 @@ class uifelamimail //error_log(array2string($formData)); $draftFolder = $this->bofelamimail->getDraftFolder(false); $importID =felamimail_bo::getRandomString(); -/* - $formData['name'] = 'a_email.eml'; - $formData['type'] = 'message/rfc822'; - $formData['file'] = 'vfs://default/home/leithoff/a_email.eml'; - $formData['size'] = 2136; -*/ + // name should be set to meet the requirements of checkFileBasics + if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && (!isset($formData['name']) || empty($formData['name']))) + { + $buff = explode('/',$_formData['file']); + $suffix = ''; + if (is_array($buff)) $formData['name'] = array_pop($buff); // take the last part as name + } + // type should be set to meet the requirements of checkFileBasics + if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && (!isset($formData['type']) || empty($formData['type']))) + { + $buff = explode('.',$_formData['file']); + $suffix = ''; + if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime + if (!empty($suffix)) $formData['type'] = mime_magic::ext2mime($suffix); + } + // size should be set to meet the requirements of checkFileBasics + if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && !isset($formData['size'])) + { + $formData['size'] = strlen($formData['file']); // set some size, to meet requirements of checkFileBasics + } try { $messageUid = $this->importMessageToFolder($formData,$draftFolder,$importID); @@ -640,6 +659,7 @@ class uifelamimail 'menuaction' => 'felamimail.uidisplay.display', 'uid' => $messageUid, 'mailbox' => base64_encode($draftFolder), + 'deleteDraftOnClose' => 1, ); } catch (egw_exception_wrong_userinput $e) diff --git a/felamimail/inc/class.uiwidgets.inc.php b/felamimail/inc/class.uiwidgets.inc.php index 7e0a065c7b..f89e55c5c4 100644 --- a/felamimail/inc/class.uiwidgets.inc.php +++ b/felamimail/inc/class.uiwidgets.inc.php @@ -1710,27 +1710,27 @@ $j(document).ready(function() { $navbarImages = array( 'new' => array( - 'action' => ($_forceNewWindow ? "egw_openWindowCentered('$asnewURL','composeasnew_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$asnewURL'"), + 'action' => 'do_onunload = false;'.($_forceNewWindow ? "egw_openWindowCentered('$asnewURL','composeasnew_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$asnewURL'"), 'tooltip' => lang('compose as new'), ), 'mail_reply' => array( - 'action' => ($_forceNewWindow ? "egw_openWindowCentered('$replyURL','reply_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$replyURL'"), + 'action' => 'do_onunload = false;'.($_forceNewWindow ? "egw_openWindowCentered('$replyURL','reply_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$replyURL'"), 'tooltip' => lang('reply'), ), 'mail_replyall' => array( - 'action' => ($_forceNewWindow ? "egw_openWindowCentered('$replyAllURL','replyAll_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$replyAllURL'"), + 'action' => 'do_onunload = false;'.($_forceNewWindow ? "egw_openWindowCentered('$replyAllURL','replyAll_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$replyAllURL'"), 'tooltip' => lang('reply all'), ), 'mail_forward' => array( - 'action' => ($_forceNewWindow ? "egw_openWindowCentered('$forwardURL','forward_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$forwardURL'"), + 'action' => 'do_onunload = false;'.($_forceNewWindow ? "egw_openWindowCentered('$forwardURL','forward_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$forwardURL'"), 'tooltip' => lang('forward'), ), 'revert' => array( - 'action' => ($_forceNewWindow ? "window.open('$deleteURL','_blank','dependent=yes,width=100,height=100,toolbar=no,scrollbars=no,status=no')": "window.location.href = '$deleteURL'"), + 'action' => 'do_onunload = false;'.($_forceNewWindow ? "window.open('$deleteURL','_blank','dependent=yes,width=100,height=100,toolbar=no,scrollbars=no,status=no')": "window.location.href = '$deleteURL'"), 'tooltip' => ($_headerData['deleted']?lang('undelete'):lang('delete')), ), 'delete' => array(// json_encode(array('msg'=>array($_headerData['uid']))) may be used for {msg:[".$_headerData['uid']."]} - 'action' => ($_forceNewWindow ? "mail_deleteMessages({msg:[".$_headerData['uid']."]});": "window.location.href = '$deleteURL'"), + 'action' => 'do_onunload = false;'.($_forceNewWindow ? "mail_deleteMessages({msg:[".$_headerData['uid']."]});": "window.location.href = '$deleteURL'"), 'tooltip' => ($_headerData['deleted']?lang('undelete'):lang('delete')), ), ); @@ -1807,7 +1807,7 @@ $j(document).ready(function() { //print email $navbarImages = array( 'print' => array( - 'action' => ($_forceNewWindow ? "egw_openWindowCentered('$printURL','print_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$printURL'"), + 'action' => 'do_onunload = false;'.($_forceNewWindow ? "egw_openWindowCentered('$printURL','print_".$_headerData['uid']."',".$fm_width.",".$fm_height.");": "window.location.href = '$printURL'"), 'tooltip' => lang('print it'), ), ); @@ -1815,25 +1815,25 @@ $j(document).ready(function() { { list($i_width,$i_height) = explode('x',egw_link::get_registry('infolog','add_popup')); $navbarImages['to_infolog'] = array( - 'action' => "window.open('$to_infologURL','_blank','dependent=yes,width=".$i_width.",height=".$i_height.",scrollbars=yes,status=yes')", + 'action' => 'do_onunload = false;'."window.open('$to_infologURL','_blank','dependent=yes,width=".$i_width.",height=".$i_height.",scrollbars=yes,status=yes')", 'tooltip' => lang('save as infolog')); } if ($GLOBALS['egw_info']['user']['apps']['tracker']) { list($i_width,$i_height) = explode('x',egw_link::get_registry('tracker','add_popup')); $navbarImages['to_tracker'] = array( - 'action' => "egw_openWindowCentered('$to_trackerURL','_blank',".$i_width.",".$i_height.")", + 'action' => 'do_onunload = false;'."egw_openWindowCentered('$to_trackerURL','_blank',".$i_width.",".$i_height.")", 'tooltip' => lang('Save as ticket')); } // save email as $navbarImages['fileexport'] = array( - 'action' => "document.location='$saveMessageURL';", + 'action' => 'do_onunload = false;'."document.location='$saveMessageURL';", 'tooltip' => lang('Save message to disk'), ); // view header lines $navbarImages['kmmsgread'] = array( - 'action' => "egw_openWindowCentered('$viewHeaderURL','fm_displayHeaderLines_".$_headerData['uid']."',".$fm_width.",".$fm_height.");", + 'action' => 'do_onunload = false;'."egw_openWindowCentered('$viewHeaderURL','fm_displayHeaderLines_".$_headerData['uid']."',".$fm_width.",".$fm_height.");", 'tooltip' => lang('view header lines'), ); diff --git a/felamimail/js/jscode/viewMainScreen.js b/felamimail/js/jscode/viewMainScreen.js index f372a0a872..f944c52bf8 100644 --- a/felamimail/js/jscode/viewMainScreen.js +++ b/felamimail/js/jscode/viewMainScreen.js @@ -249,7 +249,8 @@ function mail_save2fm(_action, _elems) url += 'menuaction=filemanager.filemanager_select.select'; // todo compose for Draft folder //url += '&icServer='+egw_appWindow('felamimail').activeServerID; url += '&mode=saveas'; - url += '&name='+encodeURIComponent(_elems[0].data.data.subject.data+'.eml'); + var filename = _elems[0].data.data.subject.data.replace(/[\f\n\t\v/\\:*?<>\|]/g,"_"); + url += '&name='+encodeURIComponent(filename+'.eml'); url += '&mime=message'+encodeURIComponent('/')+'rfc822'; url += '&method=felamimail.uidisplay.vfsSaveMessage' url += '&mailbox='+egw_appWindow('felamimail').activeFolderB64; diff --git a/felamimail/js/jscode/view_message.js b/felamimail/js/jscode/view_message.js index a1f8c786bf..464f69a772 100644 --- a/felamimail/js/jscode/view_message.js +++ b/felamimail/js/jscode/view_message.js @@ -8,6 +8,8 @@ var headerDIVHeight; var bodyDIVTop; +var do_onunload = true; + function getUrlPart(url, name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); @@ -21,11 +23,13 @@ function getUrlPart(url, name ) } function sendNotify (uid) { + do_onunload = false; ret = confirm(lang_sendnotify); xajax_doXMLHTTP("felamimail.ajaxfelamimail.sendNotify",uid,ret); } function goToMessage(url) { + do_onunload = false; //alert(getUrlPart(window.location.href,'uid')); var oldUid = getUrlPart(window.location.href,'uid'); var newUid = getUrlPart(url,'uid'); @@ -60,6 +64,7 @@ function initAll() window.onresize = fm_resizeBodyDIV; } updateTitle(); + do_onunload = true; } function updateTitle() {