* EMail: speed improvment by loading mails with a single request

This commit is contained in:
Ralf Becker 2011-03-17 14:56:54 +00:00
commit 46f505bb1f
3 changed files with 146 additions and 13 deletions

View File

@ -337,7 +337,6 @@
$this->t->set_var('sentNotify',''); $this->t->set_var('sentNotify','');
$this->t->set_var('lang_sendnotify',''); $this->t->set_var('lang_sendnotify','');
} }
$this->bofelamimail->closeConnection();
$this->t->set_block('displayMsg','message_main'); $this->t->set_block('displayMsg','message_main');
$this->t->set_block('displayMsg','message_main_attachment'); $this->t->set_block('displayMsg','message_main_attachment');
@ -475,6 +474,20 @@
); );
$this->t->set_var('url_displayBody', $GLOBALS['egw']->link('/index.php',$linkData)); $this->t->set_var('url_displayBody', $GLOBALS['egw']->link('/index.php',$linkData));
// if browser supports data uri: ie<8 does NOT and ie>=8 does NOT support html as content :-(
// --> use it to send the mail as data uri
if (!isset($_GET['printable']))
{
$bodyParts = $this->bofelamimail->getMessageBody($this->uid,'',$partID);
$frameHtml = base64_encode(
$this->get_email_header().
$this->showBody($this->getdisplayableBody($bodyParts), false));
$iframe_url = egw::link('/phpgwapi/js/egw_instant_load.html').'" onload="if (this.contentWindow && typeof this.contentWindow.egw_instant_load != \'undefined\') this.contentWindow.egw_instant_load(\''.$frameHtml.'\', true);';
$this->t->set_var('url_displayBody', $iframe_url);
}
// attachments // attachments
if(is_array($attachments) && count($attachments) > 0) { if(is_array($attachments) && count($attachments) > 0) {
$this->t->set_var('attachment_count',count($attachments)); $this->t->set_var('attachment_count',count($attachments));
@ -953,7 +966,25 @@
$GLOBALS['egw_info']['flags']['nofooter'] = true; $GLOBALS['egw_info']['flags']['nofooter'] = true;
} }
$GLOBALS['egw_info']['flags']['include_xajax'] = True; $GLOBALS['egw_info']['flags']['include_xajax'] = True;
$GLOBALS['egw']->common->egw_header(); common::egw_header();
}
static function get_email_header()
{
return '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<style>
body, td, textarea {
font-family: Verdana, Arial, Helvetica,sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
';
} }
static function emailAddressToHTML($_emailAddress, $_organisation='', $allwaysShowMailAddress=false, $showAddToAdrdessbookLink=true, $decode=true) { static function emailAddressToHTML($_emailAddress, $_organisation='', $allwaysShowMailAddress=false, $showAddToAdrdessbookLink=true, $decode=true) {

View File

@ -18,26 +18,33 @@
class uiwidgets class uiwidgets
{ {
var $charset; var $charset;
/**
* Reference to felamimail_bo
*
* @var felamimail_bo
*/
var $bofelamimail; var $bofelamimail;
/** /**
* the contructor * Instance of template class for felamimail
* *
* @var Template
*/
var $template;
/**
* Constructor
*/ */
function uiwidgets() function uiwidgets()
{ {
$template = CreateObject('phpgwapi.Template',common::get_tpl_dir('felamimail')); $this->template = new Template(common::get_tpl_dir('felamimail'));
$this->template = $template;
$this->template->set_file(array("body" => 'uiwidgets.tpl')); $this->template->set_file(array("body" => 'uiwidgets.tpl'));
$this->charset = $GLOBALS['egw']->translation->charset(); $this->charset = $GLOBALS['egw']->translation->charset();
$this->bofelamimail =& CreateObject('felamimail.bofelamimail',$GLOBALS['egw']->translation->charset()); $this->bofelamimail =& CreateObject('felamimail.bofelamimail',$GLOBALS['egw']->translation->charset());
if (!is_object($GLOBALS['egw']->html)) {
$GLOBALS['egw']->html = CreateObject('phpgwapi.html');
}
} }
function encodeFolderName($_folderName) function encodeFolderName($_folderName)
{ {
return $GLOBALS['egw']->translation->convert($_folderName, 'UTF7-IMAP', $this->charset); return translation::convert($_folderName, 'UTF7-IMAP', $this->charset);
} }
/** /**
@ -170,7 +177,7 @@ class uiwidgets
} }
if($_useDisplayCharset == true) { if($_useDisplayCharset == true) {
$folderName = $GLOBALS['egw']->translation->convert($obj->folderName, 'UTF7-IMAP', $this->charset); $folderName = translation::convert($obj->folderName, 'UTF7-IMAP', $this->charset);
$folderName = @htmlspecialchars($folderName, ENT_QUOTES, $this->charset,false); $folderName = @htmlspecialchars($folderName, ENT_QUOTES, $this->charset,false);
} else { } else {
$folderName = @htmlspecialchars($obj->folderName, ENT_QUOTES, $this->charset,false); $folderName = @htmlspecialchars($obj->folderName, ENT_QUOTES, $this->charset,false);
@ -713,6 +720,21 @@ class uiwidgets
'uid' => $headerData['uid'], 'uid' => $headerData['uid'],
'mailbox' => base64_encode($_folderName) 'mailbox' => base64_encode($_folderName)
); );
$iframe_url = $GLOBALS['egw']->link('/index.php',$linkData);
// if browser supports data uri: ie<8 does NOT and ie>=8 does NOT support html as content :-(
// --> use it to send the mail as data uri
if (!isset($_GET['printable']))
{
$bodyParts = $this->bofelamimail->getMessageBody($headerData['uid'],'',$partID);
$uidisplay = CreateObject('felamimail.uidisplay');
$frameHtml = base64_encode(
$uidisplay->get_email_header().
$uidisplay->showBody($uidisplay->getdisplayableBody($bodyParts), false));
$iframe_url = egw::link('/phpgwapi/js/egw_instant_load.html').'" onload="if (this.contentWindow && typeof this.contentWindow.egw_instant_load != \'undefined\') this.contentWindow.egw_instant_load(\''.$frameHtml.'\', true);';
}
//_debug_array($GLOBALS['egw']->link('/index.php',$linkData)); //_debug_array($GLOBALS['egw']->link('/index.php',$linkData));
$IFRAMEBody = "<TABLE BORDER=\"1\" rules=\"rows\" style=\"table-layout:fixed;width:100%;\"> $IFRAMEBody = "<TABLE BORDER=\"1\" rules=\"rows\" style=\"table-layout:fixed;width:100%;\">
<TR class=\"th\" style=\"width:100%;\"> <TR class=\"th\" style=\"width:100%;\">
@ -733,7 +755,7 @@ class uiwidgets
</TR> </TR>
<TR> <TR>
<TD nowrap id=\"tdmessageIFRAME\" valign=\"top\" colspan=\"3\" height=\"".$IFrameHeight."\"> <TD nowrap id=\"tdmessageIFRAME\" valign=\"top\" colspan=\"3\" height=\"".$IFrameHeight."\">
<iframe ".(!empty($jscall) ? $jscall:"")." id=\"messageIFRAME\" frameborder=\"1\" height=\"".$IFrameHeight."\" scrolling=\"auto\" src=\"".$GLOBALS['egw']->link('/index.php',$linkData)."\"> <iframe ".(!empty($jscall) ? $jscall:"")." id=\"messageIFRAME\" frameborder=\"1\" height=\"".$IFrameHeight."\" scrolling=\"auto\" src=\"".$iframe_url."\">
</iframe> </iframe>
</TD> </TD>
</TR> </TR>

View File

@ -0,0 +1,80 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<!--
Open this file from inside egroupware in a popup/iframe and call the egw_instant_load
function in its "onload" event.
-->
<head>
<title>EGroupware [Loading Data]</title>
<meta http-equiv="Cache-control" content="public" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
</head>
<body style="background-color: #F0F0F0">
<script type="text/javascript">
/*
* base64.js - Base64 encoding and decoding functions
*
* See: http://developer.mozilla.org/en/docs/DOM:window.btoa
* http://developer.mozilla.org/en/docs/DOM:window.atob
*
* Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
* Released under the MIT license
*/
if (typeof atob == 'undefined') {
function atob(str) {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var invalid = {
strlen: (str.length % 4 != 0),
chars: new RegExp('[^' + chars + ']').test(str),
equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
};
if (invalid.strlen || invalid.chars || invalid.equals)
throw new Error('Invalid base64 data');
var decoded = [];
var c = 0;
while (c < str.length) {
var i0 = chars.indexOf(str.charAt(c++));
var i1 = chars.indexOf(str.charAt(c++));
var i2 = chars.indexOf(str.charAt(c++));
var i3 = chars.indexOf(str.charAt(c++));
var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
var b0 = (buf & (255 << 16)) >> 16;
var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
var b2 = (i3 == 64) ? -1 : (buf & 255);
decoded[decoded.length] = String.fromCharCode(b0);
if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
}
return decoded.join('');
}
}
window.egw_instant_load = function(_data, _base64Encoded)
{
if (typeof _base64Encoded == "undefined")
{
_base64Encoded = false;
}
if (_base64Encoded)
{
_data = atob(_data);
}
// Empty the document tree
while (document.childNodes.length > 0)
{
document.removeChild(document.childNodes[0]);
}
// Write the given content
document.write(_data);
// Close the document
document.close();
}
</script>
</body>
</html>