Mail: Add attachment action to open in Collabora

This commit is contained in:
nathan 2023-01-31 15:03:18 -07:00
parent 49c9939e67
commit cce1088486
3 changed files with 93 additions and 27 deletions

View File

@ -799,10 +799,16 @@ class mail_hooks
'icon' => 'fileexport',
'value' => 'downloadOneAsFile'
],
'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' => [

View File

@ -2924,12 +2924,36 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
else
{
$subject = Api\Mail::clean_subject_for_filename($subject);
$mime='text/html'; $size=0;
$mime = 'text/html';
$size = 0;
Api\Header\Content::safe($message, $subject . ".eml", $mime, $size, true, false);
print '<pre>' . htmlspecialchars($message, ENT_NOQUOTES | ENT_SUBSTITUTE, 'utf-8') . '</pre>';
}
}
/**
* 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
*
@ -3191,6 +3215,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
{
fclose($fp);
}
$res['savepath'][$id] = $file;
}
$this->mail_bo->closeConnection();

View File

@ -1109,7 +1109,7 @@ app.classes.mail = AppJS.extend(
{
id: 'saveOneToVfs',
label: 'Save in Filemanager',
icon: 'filemanager/navbar.svg',
icon: 'filemanager/navbar',
value: 'saveOneToVfs'
},
{
@ -1125,8 +1125,18 @@ 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 => {
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';
@ -3132,6 +3142,31 @@ app.classes.mail = AppJS.extend(
});
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':