diff --git a/mail/inc/class.mail_hooks.inc.php b/mail/inc/class.mail_hooks.inc.php index f17ac7b34e..c7a0632969 100644 --- a/mail/inc/class.mail_hooks.inc.php +++ b/mail/inc/class.mail_hooks.inc.php @@ -794,27 +794,33 @@ class mail_hooks { return [ 'downloadOneAsFile' => [ - 'id' => 'downloadOneAsFile', + 'id' => 'downloadOneAsFile', 'label' => 'Download', - 'icon' => 'fileexport', + 'icon' => 'fileexport', 'value' => 'downloadOneAsFile' ], - 'saveOneToVfs' => [ - 'id' => 'saveOneToVfs', + 'collabora' => [ + 'id' => 'collabora', + 'label' => 'Open with Collabora', + 'icon' => 'open', + 'value' => 'collabora' + ], + 'saveOneToVfs' => [ + 'id' => 'saveOneToVfs', 'label' => 'Save in Filemanager', - 'icon' => 'filemanager/navbar.svg', + 'icon' => 'filemanager/navbar', 'value' => 'saveOneToVfs' ], - 'saveAllToVfs' => [ - 'id' => 'saveAllToVfs', + 'saveAllToVfs' => [ + 'id' => 'saveAllToVfs', 'label' => 'Save all to Filemanager', - 'icon' => 'mail/save_all', + 'icon' => 'mail/save_all', 'value' => 'saveAllToVfs' ], - 'downloadAllToZip' => [ - 'id' => 'downloadAllToZip', + 'downloadAllToZip' => [ + 'id' => 'downloadAllToZip', 'label' => 'Save as ZIP', - 'icon' => 'mail/save_zip', + 'icon' => 'mail/save_zip', 'value' => 'downloadAllToZip' ] ]; diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 8a9075b363..89f15be64c 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -2924,20 +2924,44 @@ $filter['before']= date("d-M-Y", $cutoffdate2); else { $subject = Api\Mail::clean_subject_for_filename($subject); - $mime='text/html'; $size=0; - Api\Header\Content::safe($message, $subject.".eml", $mime, $size, true, false); - print '
'. htmlspecialchars($message, ENT_NOQUOTES|ENT_SUBSTITUTE, 'utf-8') .''; + $mime = 'text/html'; + $size = 0; + Api\Header\Content::safe($message, $subject . ".eml", $mime, $size, true, false); + print '
' . htmlspecialchars($message, ENT_NOQUOTES | ENT_SUBSTITUTE, 'utf-8') . ''; } } + /** + * Ajax function to save message(s)/attachment(s) in the vfs + * + * @param string $attachment_id + * @param string $filename + * + * @return string Temporary path to open + */ + function ajax_vfsOpen($attachment_id, $filename) + { + // Use a sub-dir so we can give a nice filename + $temp_path = '/home/' . $GLOBALS['egw_info']['user']['account_lid'] . "/.mail/"; + if(!Vfs::is_dir($temp_path)) + { + Vfs::mkdir($temp_path); + } + + $result = $this->vfsSaveAttachments([$attachment_id], $temp_path . $filename, 'rename'); + + $response = Api\Json\Response::get(); + $response->data($result['savepath'][$attachment_id] ?? ""); + } + /** * Ajax function to save message(s)/attachment(s) in the vfs * * @param array $params array of mail ids and action name - * params = array ( - * ids => array of string - * action => string - * ) + * params = array ( + * ids => array of string + * action => string + * ) * @param string $path path to save the emails * @param string $submit_button_id dialog button id of triggered submit * @param string $savemode save mode: 'overwrite' or 'rename' @@ -3191,6 +3215,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2); { fclose($fp); } + $res['savepath'][$id] = $file; } $this->mail_bo->closeConnection(); diff --git a/mail/js/app.js b/mail/js/app.js index bf823218f7..ac4ac010c5 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -1102,14 +1102,14 @@ app.classes.mail = AppJS.extend( const actions = [ { id: 'downloadOneAsFile', - label:'Download', - icon:'fileexport', - value:'downloadOneAsFile' + label: 'Download', + icon: 'fileexport', + value: 'downloadOneAsFile' }, { id: 'saveOneToVfs', label: 'Save in Filemanager', - icon: 'filemanager/navbar.svg', + icon: 'filemanager/navbar', value: 'saveOneToVfs' }, { @@ -1125,14 +1125,24 @@ app.classes.mail = AppJS.extend( value: 'downloadAllToZip' } ]; + if (typeof this.egw.user('apps')['collabora'] !== "undefined") + { + actions.push({ + id: 'collabora', + label: 'Open', + icon: 'collabora/navbar', + value: 'collabora' + }); + } data.attachmentsBlockTitle = `${data.attachmentsBlock.length} attachments`; - data.attachmentsBlock.forEach(_item => { - _item.actions='downloadOneAsFile'; + data.attachmentsBlock.forEach(_item => + { + _item.actions = 'downloadOneAsFile'; // for some reason label needs to be set explicitly for the dropdown button. It needs more investigation. - _item.actionsDefaultLabel='Download'; + _item.actionsDefaultLabel = 'Download'; }); - sel_options.attachmentsBlock = {actions:actions}; + sel_options.attachmentsBlock = {actions: actions}; } mailPreview.set_value({content:data, sel_options:sel_options}); @@ -3127,11 +3137,36 @@ app.classes.mail = AppJS.extend( method: 'mail.mail_ui.ajax_vfsSave', button_label: this.egw.lang(action === 'saveOneToVfs' ? 'Save' : 'Save all'), dialog_title: this.egw.lang(action === 'saveOneToVfs' ? 'Save attachment' : 'Save attachments'), - method_id: ids.length > 1 ? {ids:ids, action:'attachment'} : {ids: ids[0], action: 'attachment'}, + method_id: ids.length > 1 ? {ids: ids, action: 'attachment'} : {ids: ids[0], action: 'attachment'}, name: action === 'saveOneToVfs' ? attachments[0]['filename'] : null }); vfs_select.click(); break; + case 'collabora': + attachment = attachments[row_id]; + let id = mail_id + '::' + attachment.partID + '::' + attachment.winmailFlag + '::' + attachment.filename; + + // This can take a few seconds, show loader + this.egw.loading_prompt('mail_open_file', true, attachment.filename); + + // Temp save to VFS + this.egw.request('mail.mail_ui.ajax_vfsOpen', [id, attachment.filename]).then((temp_path) => + { + if (temp_path) + { + // Open in Collabora + window.open(this.egw.link('/index.php', { + 'menuaction': 'collabora.EGroupware\\collabora\\Ui.editor', + 'path': temp_path, + 'cd': 'no' // needed to not reload framework in sharing + })); + } + }).finally(() => + { + // Hide load prompt + this.egw.loading_prompt('mail_open_file', false); + }); + break; case 'downloadOneAsFile': case 'downloadAllToZip':