make uploaded/attached files clickable on compose

This commit is contained in:
Klaus Leithoff 2014-01-30 09:35:56 +00:00
parent 5a39c2d260
commit e70a7bcf07
4 changed files with 225 additions and 12 deletions

View File

@ -22,6 +22,7 @@ class mail_compose
var $public_functions = array
(
'compose' => True,
'getAttachment' => True,
);
/**
@ -1329,6 +1330,7 @@ class mail_compose
case 'composeasnew':
case 'composefromdraft':
$content = $this->getDraftData($icServer, $folder, $msgUID, $part_id);
$content['processedmail_id'] = $mail_id;
$_focusElement = 'body';
$suppressSigOnTop = true;
@ -1717,6 +1719,102 @@ class mail_compose
);
}
function getAttachment()
{
if(isset($_GET['filename'])) $attachment['filename'] = $_GET['filename'];
if(isset($_GET['tmpname'])) $attachment['tmp_name'] = $_GET['tmpname'];
if(isset($_GET['name'])) $attachment['name'] = $_GET['name'];
//if(isset($_GET['size'])) $attachment['size'] = $_GET['size'];
if(isset($_GET['type'])) $attachment['type'] = $_GET['type'];
error_log(__METHOD__.__LINE__.array2string($_GET));
if (isset($attachment['filename']) && parse_url($attachment['filename'],PHP_URL_SCHEME) == 'vfs')
{
egw_vfs::load_wrapper('vfs');
}
$attachment['attachment'] = file_get_contents($attachment['tmp_name']);
//error_log(__METHOD__.__LINE__.' FileSize:'.filesize($attachment['tmp_name']));
if ($_GET['mode'] != "save")
{
if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY')
{
$sfxMimeType = $attachment['type'];
$buff = explode('.',$attachment['filename']);
$suffix = '';
if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
if (!empty($suffix)) $sfxMimeType = mime_magic::ext2mime($suffix);
$attachment['type'] = $sfxMimeType;
if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') $attachment['type'] = strtoupper($sfxMimeType);
}
//error_log(__METHOD__.print_r($attachment,true));
if (strtoupper($attachment['type']) == 'TEXT/CALENDAR' || strtoupper($attachment['type']) == 'TEXT/X-VCALENDAR')
{
//error_log(__METHOD__."about to call calendar_ical");
$calendar_ical = new calendar_ical();
$eventid = $calendar_ical->search($attachment['attachment'],-1);
//error_log(__METHOD__.array2string($eventid));
if (!$eventid) $eventid = -1;
$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true);
//error_log(__METHOD__.$event);
if ((int)$event > 0)
{
$vars = array(
'menuaction' => 'calendar.calendar_uiforms.edit',
'cal_id' => $event,
);
$GLOBALS['egw']->redirect_link('../index.php',$vars);
}
//Import failed, download content anyway
}
if (strtoupper($attachment['type']) == 'TEXT/X-VCARD' || strtoupper($attachment['type']) == 'TEXT/VCARD')
{
$addressbook_vcal = new addressbook_vcal();
// double \r\r\n seems to end a vcard prematurely, so we set them to \r\n
//error_log(__METHOD__.__LINE__.$attachment['attachment']);
$attachment['attachment'] = str_replace("\r\r\n", "\r\n", $attachment['attachment']);
$vcard = $addressbook_vcal->vcardtoegw($attachment['attachment']);
if ($vcard['uid'])
{
$vcard['uid'] = trim($vcard['uid']);
//error_log(__METHOD__.__LINE__.print_r($vcard,true));
$contact = $addressbook_vcal->find_contact($vcard,false);
}
if (!$contact) $contact = null;
// if there are not enough fields in the vcard (or the parser was unable to correctly parse the vcard (as of VERSION:3.0 created by MSO))
if ($contact || count($vcard)>2)
{
$contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true);
}
if ((int)$contact > 0)
{
$vars = array(
'menuaction' => 'addressbook.addressbook_ui.edit',
'contact_id' => $contact,
);
$GLOBALS['egw']->redirect_link('../index.php',$vars);
}
//Import failed, download content anyway
}
}
header ("Content-Type: ".$attachment['type']."; name=\"". $attachment['filename'] ."\"");
if($_GET['mode'] == "save") {
// ask for download
header ("Content-Disposition: attachment; filename=\"". $attachment['filename'] ."\"");
} else {
// display it
header ("Content-Disposition: inline; filename=\"". $attachment['filename'] ."\"");
}
header("Expires: 0");
// the next headers are for IE and SSL
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
echo $attachment['attachment'];
$GLOBALS['egw']->common->egw_exit();
exit;
}
/**
* getRandomString - function to be used to fetch a random string and md5 encode that one
* @param none

View File

@ -4,9 +4,9 @@
*
* @link http://www.egroupware.org
* @package mail
* @author Klaus Leithoff [kl@stylite.de]
* @author Stylite AG [info@stylite.de]
* @version 1.0
* @copyright (c) 2013 by Klaus Leithoff <kl-AT-stylite.de>
* @copyright (c) 2013-2014 by Stylite AG <info-AT-stylite.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/

View File

@ -1413,13 +1413,16 @@ app.classes.mail = AppJS.extend(
},
/**
*
* displayAttachment
*/
displayAttachment: function(tag_info, widget)
displayAttachment: function(tag_info, widget, calledForCompose)
{
//console.log(this, arguments, widget);
var mailid;
var attgrid;
if (typeof calledForCompose == 'undefined') calledForCompose=false;
if (calledForCompose==false)
{
if (this.mail_isMainWindow)
{
mailid = this.mail_currentlyFocussed;//this.et2.getArrayMgr("content").getEntry('mail_id');
@ -1432,6 +1435,12 @@ app.classes.mail = AppJS.extend(
mailid = this.et2.getArrayMgr("content").getEntry('mail_id');
attgrid = this.et2.getArrayMgr("content").getEntry('mail_displayattachments')[widget.id.replace(/\[filename\]/,'')];
}
}
else
{
attgrid = this.et2.getArrayMgr("content").getEntry('attachments')[widget.id.replace(/\[name\]/,'')];
mailid = this.et2.getArrayMgr("content").getEntry('processedmail_id');
}
//console.log(mailid,attgrid.partID,attgrid.filename,attgrid.mimetype);
var url = window.egw_webserverUrl+'/index.php?';
var width;
@ -1516,6 +1525,112 @@ app.classes.mail = AppJS.extend(
egw_openWindowCentered(url,windowName,width,height);
},
/**
* displayUploadedFile
*/
displayUploadedFile: function(tag_info, widget)
{
//console.log(this, tag_info, widget);
var attgrid;
attgrid = this.et2.getArrayMgr("content").getEntry('attachments')[widget.id.replace(/\[name\]/,'')];
//console.log(attgrid);
if (attgrid.uid && attgrid.partID)
{
this.displayAttachment(tag_info, widget, true);
return;
}
var url = window.egw_webserverUrl+'/index.php?';
var width;
var height;
var windowName ='mail';
switch(attgrid.type.toUpperCase())
{
case 'IMAGE/JPEG':
case 'IMAGE/PNG':
case 'IMAGE/GIF':
case 'IMAGE/BMP':
case 'APPLICATION/PDF':
case 'TEXT/PLAIN':
case 'TEXT/HTML':
case 'TEXT/DIRECTORY':
/*
$sfxMimeType = $value['mimeType'];
$buff = explode('.',$value['name']);
$suffix = '';
if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
if (!empty($suffix)) $sfxMimeType = mime_magic::ext2mime($suffix);
if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD')
{
$attachments[$key]['mimeType'] = $sfxMimeType;
$value['mimeType'] = strtoupper($sfxMimeType);
}
*/
case 'TEXT/X-VCARD':
case 'TEXT/VCARD':
case 'TEXT/CALENDAR':
case 'TEXT/X-VCALENDAR':
url += 'menuaction=mail.mail_compose.getAttachment'; // todo compose for Draft folder
url += '&filename='+attgrid.file;
url += '&tmpname='+attgrid.tmp_name;
url += '&name='+attgrid.name;
//url += '&size='+attgrid.size;
url += '&type='+attgrid.type;
windowName = windowName+'displayAttachment_'+attgrid.file.replace(/\//g,"_");
var reg = '800x600';
var reg2;
// handle calendar/vcard
if (attgrid.type.toUpperCase()=='TEXT/CALENDAR')
{
windowName = 'maildisplayEvent_'+attgrid.file.replace(/\//g,"_");
reg2 = egw.link_get_registry('calendar');
if (typeof app_registry['view'] != 'undefined' && typeof app_registry['view_popup'] != 'undefined' )
{
reg = app_registry['view_popup'];
}
}
if (attgrid.type.toUpperCase()=='TEXT/X-VCARD' || attgrid.type.toUpperCase()=='TEXT/VCARD')
{
windowName = 'maildisplayContact_'+attgrid.file.replace(/\//g,"_");
reg2 = egw.link_get_registry('addressbook');
if (typeof app_registry['add'] != 'undefined' && typeof app_registry['add_popup'] != 'undefined' )
{
reg = app_registry['add_popup'];
}
}
var w_h =reg.split('x');
width = w_h[0];
height = w_h[1];
break;
case 'MESSAGE/RFC822':
/*
url += 'menuaction=mail.mail_ui.displayMessage'; // todo compose for Draft folder
url += '&id='+mailid;
url += '&part='+attgrid.partID;
url += '&is_winmail='+attgrid.winmailFlag;
windowName = windowName+'displayMessage_'+mailid+'_'+attgrid.partID;
width = 870;
height = egw_getWindowOuterHeight();
break;
*/
default:
url += 'menuaction=mail.mail_compose.getAttachment'; // todo compose for Draft folder
url += '&filename='+attgrid.file;
url += '&tmpname='+attgrid.tmp_name;
url += '&name='+attgrid.name;
//url += '&size='+attgrid.size;
url += '&type='+attgrid.type;
url += '&mode='+'save';
windowName = windowName+'displayAttachment_'+attgrid.file.replace(/\//g,"_");
width = 870;
height = 600;
//document.location = url;
//return;
}
egw_openWindowCentered(url,windowName,width,height);
},
saveAttachment: function(tag_info, widget)
{
//console.log(this, arguments);

View File

@ -122,7 +122,7 @@
<rows>
<row >
<description id="${row}[tmp_name]" />
<description id="${row}[name]" />
<description class="useEllipsis et2_link" id="${row}[name]" no_lang="1" onclick="app.mail.displayUploadedFile"/>
<description id="${row}[type]" />
<description align="right" id="${row}[size]" />
<button id="delete[$row_cont[tmp_name]]" value="Delete" image="delete" />