fix import-mail from local file; convert attachment block in display to grid widget;

This commit is contained in:
Klaus Leithoff 2013-10-16 11:25:46 +00:00
parent e5aa8a4873
commit 00fb069dc2
4 changed files with 207 additions and 17 deletions

View File

@ -2262,7 +2262,7 @@ class mail_compose
#error_log("(re)opened Connection");
}
// if copying mail to folder, or saving mail to infolog, we need to gather the needed information
if (count($folder) > 0 || $_formData['to_infolog'] == 'on') {
if (count($folder) > 0 || $_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') {
foreach((array)$this->sessionData['bcc'] as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {

View File

@ -1422,14 +1422,14 @@ unset($query['actions']);
}
if (count($attachments)==1)
{
$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'], $_folder);
$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'], $_folder,true);
$imageTag = json_encode($attachments);
$image = html::image('mail','attach',$attachments[0]['name'].(!empty($attachments[0]['mimeType'])?' ('.$attachments[0]['mimeType'].')':''));
}
}
if (count($attachments)>1)
{
$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'], $_folder);
$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'], $_folder,true);
$imageTag = json_encode($attachments);
$image = html::image('mail','attach',lang('%1 attachments',count($attachments)));
}
@ -1721,9 +1721,10 @@ unset($query['actions']);
* @param string $rowID, rowid of the message
* @param int $uid, uid of the message
* @param string $mailbox, the mailbox identifier
* @return string html or empty string
* @param boolean $_returnFullHTML, flag wether to return HTML or data array
* @return mixed array/string data array or html or empty string
*/
static function createAttachmentBlock($attachments, $rowID, $uid, $mailbox)
static function createAttachmentBlock($attachments, $rowID, $uid, $mailbox,$_returnFullHTML=false)
{
$attachmentHTMLBlock='';
if (is_array($attachments) && count($attachments) > 0) {
@ -1739,11 +1740,14 @@ unset($query['actions']);
//if (mb_convert_variables("ISO-8859-1","UTF-8",$value['name'])){echo "Juhu utf8 2 ISO\n";};
//echo $value['name']."\n";
$filename=htmlentities($value['name'], ENT_QUOTES, $detectedCharSet);
$attachmentHTML[$key]['filename']= ($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)'));
$attachmentHTML[$key]['type']=$value['mimeType'];
$attachmentHTML[$key]['mimetype']=mime_magic::mime2label($value['mimeType']);
$attachmentHTML[$key]['size']=egw_vfs::hsize($value['size']);
$attachmentHTML[$key]['attachment_number']=$key;
$attachmentHTML[$key]['partID']=$value['partID'];
$attachmentHTML[$key]['winmailFlag']=$value['is_winmail'];
$attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "mail_DisplayNone";
switch(strtoupper($value['mimeType']))
{
@ -1753,7 +1757,6 @@ unset($query['actions']);
'menuaction' => 'mail.mail_ui.displayMessage',
'id' => $rowID,
'part' => $value['partID'],
'mailbox' => base64_encode($mailbox),
'is_winmail' => $value['is_winmail']
);
$windowName = 'displayMessage_'. $rowID.'_'.$value['partID'];
@ -1849,6 +1852,7 @@ unset($query['actions']);
// add save-all icon for first attachment
if (!$key && count($attachments) > 1)
{
$attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "";
foreach ($attachments as $ikey => $value)
{
//$rowID
@ -1876,7 +1880,7 @@ unset($query['actions']);
}
$attachmentHTMLBlock .= "</table>";
}
return $attachmentHTMLBlock;
return ($_returnFullHTML?$attachmentHTMLBlock:$attachmentHTML);
}
/**
@ -2807,18 +2811,25 @@ blockquote[type=cite] {
if (!empty($content))
{
error_log(__METHOD__.__LINE__.array2string($content));
$content['divImportArea']['vfsfile'] = array(
'name' => egw_vfs::basename($content['divImportArea']['vfsfile']),
'type' => egw_vfs::mime_content_type($content['divImportArea']['vfsfile']),
'file' => egw_vfs::PREFIX.$content['divImportArea']['vfsfile'],
'size' => filesize(egw_vfs::PREFIX.$content['divImportArea']['vfsfile']),
);
if ($content['divImportArea']['vfsfile'])
{
$file = $content['divImportArea']['vfsfile'] = array(
'name' => egw_vfs::basename($content['divImportArea']['vfsfile']),
'type' => egw_vfs::mime_content_type($content['divImportArea']['vfsfile']),
'file' => egw_vfs::PREFIX.$content['divImportArea']['vfsfile'],
'size' => filesize(egw_vfs::PREFIX.$content['divImportArea']['vfsfile']),
);
}
else
{
$file = $content['divImportArea']['uploadForImport'];
}
$destination = $content['divImportArea']['FOLDER'][0];
$importID = mail_bo::getRandomString();
$importFailed = false;
try
{
$messageUid = $this->importMessageToFolder($content['divImportArea']['vfsfile'],$destination,$importID);
$messageUid = $this->importMessageToFolder($file,$destination,$importID);
$linkData = array
(
'id' => $this->createRowID($destination, $messageUid, true),

View File

@ -1133,6 +1133,156 @@ app.mail = AppJS.extend(
console.log(this, arguments);
},
/**
*
*/
displayAttachment: function(tag_info, widget)
{
//console.log(this, arguments, widget);
var mailid = this.et2.getArrayMgr("content").getEntry('mail_id');
var attgrid = this.et2.getArrayMgr("content").getEntry('mail_displayattachments')[widget.id.replace(/\[filename\]/,'')];
//console.log(mailid,attgrid.partID,attgrid.filename,attgrid.mimetype);
var url = window.egw_webserverUrl+'/index.php?';
var width;
var height;
var windowName ='mail';
switch(attgrid.type.toUpperCase())
{
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;
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_ui.getAttachment'; // todo compose for Draft folder
url += '&id='+mailid;
url += '&part='+attgrid.partID;
url += '&is_winmail='+attgrid.winmailFlag;
windowName = windowName+'displayAttachment_'+mailid+'_'+attgrid.partID;
var reg = '800x600';
var reg2;
// handle calendar/vcard
if (attgrid.type.toUpperCase()=='TEXT/CALENDAR')
{
windowName = 'maildisplayEvent_'+mailid+'_'+attgrid.partID;
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_'+mailid+'_'+attgrid.partID;
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;
default:
url += 'menuaction=mail.mail_ui.getAttachment'; // todo compose for Draft folder
url += '&id='+mailid;
url += '&part='+attgrid.partID;
url += '&is_winmail='+attgrid.winmailFlag;
windowName = windowName+'displayAttachment_'+mailid+'_'+attgrid.partID;
width = 870;
height = 600;
//document.location = url;
//return;
}
egw_openWindowCentered(url,windowName,width,height);
},
saveAttachment: function(tag_info, widget)
{
//console.log(this, arguments);
var mailid = this.et2.getArrayMgr("content").getEntry('mail_id');
var attgrid = this.et2.getArrayMgr("content").getEntry('mail_displayattachments')[widget.id.replace(/\[save\]/,'')];
//console.log(mailid,attgrid.partID,attgrid.filename,attgrid.mimetype);
var url = window.egw_webserverUrl+'/index.php?';
var width;
var height;
var windowName ='mail';
url += 'menuaction=mail.mail_ui.getAttachment'; // todo compose for Draft folder
url += '&mode=save';
url += '&id='+mailid;
url += '&part='+attgrid.partID;
url += '&is_winmail='+attgrid.winmailFlag;
document.location = url;
},
saveAttachmentToVFS: function(tag_info, widget)
{
//console.log(this, arguments);
var mailid = this.et2.getArrayMgr("content").getEntry('mail_id');
var attgrid = this.et2.getArrayMgr("content").getEntry('mail_displayattachments')[widget.id.replace(/\[saveAsVFS\]/,'')];
//console.log(mailid,attgrid.partID,attgrid.filename,attgrid.mimetype);
var url = window.egw_webserverUrl+'/index.php?';
var width=640;
var height=570;
var windowName ='mail';
url += 'menuaction=filemanager.filemanager_select.select'; // todo compose for Draft folder
url += '&mode=saveas';
url += '&id='+mailid+'::'+attgrid.partID+'::'+attgrid.winmailFlag;
url += '&name='+attgrid.filename;
url += '&type='+attgrid.type.toLowerCase();
url += '&method=mail.mail_ui.vfsSaveAttachment';
url += '&label='+egw.lang('Save');
egw_openWindowCentered(url,windowName,width,height);
},
saveAllAttachmentsToVFS: function(tag_info, widget)
{
var mailid = this.et2.getArrayMgr("content").getEntry('mail_id');
var attgrid = this.et2.getArrayMgr("content").getEntry('mail_displayattachments');
console.log(mailid,attgrid);
var url = window.egw_webserverUrl+'/index.php?';
var width=640;
var height=570;
var windowName ='mail';
url += 'menuaction=filemanager.filemanager_select.select'; // todo compose for Draft folder
url += '&mode=select-dir';
url += '&method=mail.mail_ui.vfsSaveAttachment';
url += '&label='+egw.lang('Save all');
for (i=0;i<attgrid.length;i++)
{
if (attgrid[i] != null) url += '&id['+i+']='+mailid+'::'+attgrid[i].partID+'::'+attgrid[i].winmailFlag+'::'+attgrid[i].filename;
}
egw_openWindowCentered(url,windowName,width,height);
},
/**
* Save a message to filemanager
*
@ -1215,7 +1365,7 @@ app.mail = AppJS.extend(
}
}
//alert('mail_infolog('+_elems[0].id+')');return;
console.log(_action, _elems);
//console.log(_action, _elems);
var url = window.egw_webserverUrl+'/index.php?';
url += 'menuaction=infolog.infolog_ui.import_mail'; // todo compose for Draft folder
url += '&rowid='+_elems[0].id;

View File

@ -39,7 +39,36 @@
<html id="mail_displaybody"/>
</box>
<box class="$cont[mailDisplayAttachmentsClass]">
<html id="mail_displayattachments"/>
<!-- <html id="mail_displayattachments"/> -->
<grid disabled="@no_griddata" id="mail_displayattachments">
<columns>
<column disabled="!@showtempname"/>
<column disabled="!@showtempname"/>
<column disabled="!@showtempname"/>
<column disabled="!@showtempname"/>
<column width="50%" />
<column width="20%" />
<column width="11%" />
<column width="3%"/>
<column width="3%"/>
<column width="3%"/>
<column />
</columns>
<rows>
<row >
<description id="${row}[attachment_number]" />
<description id="${row}[partID]" />
<description id="${row}[type]" />
<description id="${row}[winmailFlag]" />
<description class="useEllipsis et2_link" id="${row}[filename]" onclick="app.mail.displayAttachment"/>
<description id="${row}[mimetype]" />
<description align="right" id="${row}[size]" />
<buttononly id="${row}[save]" value="save" image="fileexport" onclick="app.mail.saveAttachment"/>
<buttononly id="${row}[saveAsVFS]" value="save" image="filemanager/navbar" onclick="app.mail.saveAttachmentToVFS"/>
<buttononly class="$row_cont[classSaveAllPossiblyDisabled]" id="${row}[save_all]" value="save_all" image="mail/save_all" onclick="app.mail.saveAllAttachmentsToVFS"/>
</row>
</rows>
</grid>
</box>
</vbox>
</template>