Author: ralfbecker
New Revision: 34208
URL: http://www.egroupware.org/viewvc/egroupware?rev=34208&view=rev
Log:
using data uris for embeded images in a mail, also added some caching to improve speed to felamimail_bo::getAttachmentByCID()
Modified:
trunk/felamimail/inc/class.felamimail_bo.inc.php
trunk/felamimail/inc/class.uidisplay.inc.php
Modified: trunk/felamimail/inc/class.felamimail_bo.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/felamimail/inc/class.felamimail_bo.inc.php?rev=34208&r1=34207&r2=34208&view=diff
— trunk/felamimail/inc/class.felamimail_bo.inc.php (original)
+++ trunk/felamimail/inc/class.felamimail_bo.inc.php Fri Mar 18 10:32:42 2011
@@ -1265,14 +1265,29 @@
return $attachmentData;
}
-
// this function is based on a on "Building A PHP-Based Mail Client" -
// http://www.devshed.com -
// fetch a specific attachment from a message
-
/** -
* Fetch a specific attachment from a message by it's cid -
* -
* this function is based on a on "Building A PHP-Based Mail Client" -
* http://www.devshed.com -
* -
* @param string|int $_uid -
* @param string $_cid -
* @param string $_part -
* @return array with values for keys 'type', 'filename' and 'attachment' -
*/ function getAttachmentByCID($_uid, $_cid, $_part) { -
// some static variables to avoid fetching the same mail multible times -
static $uid,$part,$attachments,$structure; -
if ($_uid != $uid || $_part != $part) -
{ -
$attachments = $this->getMessageAttachments($uid=$_uid, $part=$_part); -
$structure = null; -
} $partID = false; #error_log("getAttachmentByCID:$_uid, $_cid, $_part");
-
$attachments = $this->getMessageAttachments($_uid, $_part); foreach($attachments as $attachment) { //error_log(print_r($attachment,true)); if(isset($attachment['cid']) && (strpos($attachment['cid'], $_cid) !== false || strpos($_cid, $attachment['cid']) !== false)) {
@@ -1288,9 +1303,12 @@
}
// parse message structure
-
$structure = $this->icServer->getStructure($_uid, true); -
$structure = $this->_getSubStructure($structure, $partID); -
$filename = self::getFileNameFromStructure($structure);
-
if (is_null($structure)) -
{ -
$structure = $this->icServer->getStructure($_uid, true); -
} -
$part_structure = $this->_getSubStructure($structure, $partID); -
$filename = self::getFileNameFromStructure($part_structure); $attachment = $this->icServer->getBodyPart($_uid, $partID, true); if (PEAR::isError($attachment)) {
@@ -1310,7 +1328,7 @@
);
}
-
switch ($structure->encoding) {
-
switch ($part_structure->encoding) { case 'BASE64': // use imap_base64 to decode $attachment = imap_base64($attachment);
@@ -1325,7 +1343,7 @@
}
$attachmentData = array(
-
'type' => $structure->type .'/'. $structure->subType,
-
'type' => $part_structure->type .'/'. $part_structure->subType, 'filename' => $filename, 'attachment' => $attachment );
Modified: trunk/felamimail/inc/class.uidisplay.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/felamimail/inc/class.uidisplay.inc.php?rev=34208&r1=34207&r2=34208&view=diff
— trunk/felamimail/inc/class.uidisplay.inc.php (original)
+++ trunk/felamimail/inc/class.uidisplay.inc.php Fri Mar 18 10:32:42 2011
@@ -56,7 +56,17 @@
// the permanent id of the message
var $uid;
-
/** -
* Reference to felamimail_bo -
* -
* @var felamimail_bo -
*/ var $bofelamimail; -
/** -
* Reference to bopreference instance of felamimail_bo -
* -
* @var bopreferences -
*/ var $bopreferences; function uidisplay()
@@ -1389,19 +1399,7 @@
// create links for inline images
if ($modifyURI)
{
-
$linkData = array ( -
'menuaction' => 'felamimail.uidisplay.displayImage', -
'uid' => $this->uid, -
'mailbox' => base64_encode($this->mailbox) -
); -
$imageURL = $GLOBALS['egw']->link('/index.php', $linkData); -
if ($this->partID) { -
$newBody = preg_replace("/src=(\"|\')cid:(.*)(\"|\')/iUe", -
"'src=\"$imageURL&cid='.base64_encode('$2').'&partID='.urlencode($this->partID).'\"'", $newBody); -
} else { -
$newBody = preg_replace("/src=(\"|\')cid:(.*)(\"|\')/iUe", -
"'src=\"$imageURL&cid='.base64_encode('$2').'&partID='.'\"'", $newBody); -
}
-
$newBody = preg_replace_callback("/src=(\"|\')cid:(.*)(\"|\')/iU",array($this,'image_callback'),$newBody); } // create links for email addresses
@@ -1427,6 +1425,47 @@
$body = preg_replace($nonDisplayAbleCharacters,’’,$body);
return $body;
-
} -
/** -
* preg_replace callback to replace image cid url's -
* -
* @param array $matches matches from preg_replace("/src=(\"|\')cid:(.*)(\"|\')/iU",...) -
* @return string src attribute to replace -
*/ -
function image_callback($matches) -
{ -
static $cache = array(); // some caching, if mails containing the same image multiple times -
$linkData = array ( -
'menuaction' => 'felamimail.uidisplay.displayImage', -
'uid' => $this->uid, -
'mailbox' => base64_encode($this->mailbox), -
'cid' => base64_encode($matches[2]), -
'partId' => $this->partID, -
); -
$imageURL = $GLOBALS['egw']->link('/index.php', $linkData); -
// to test without data uris, comment the if close incl. it's body -
if (html::$user_agent != 'msie' || html::$ua_version >= 8) -
{ -
if (!isset($cache[$imageURL])) -
{ -
$attachment = $this->bofelamimail->getAttachmentByCID($this->uid, $matches[2], $this->partID); -
// only use data uri for "smaller" images, as otherwise the first display of the mail takes to long -
if (bytes($attachment['attachment']) < 8192) // msie=8 allows max 32k data uris -
{ -
$cache[$imageURL] = 'data:'.$attachment['type'].';base64,'.base64_encode($attachment['attachment']); -
} -
else -
{ -
$cache[$imageURL] = $imageURL; -
} -
} -
$imageURL = $cache[$imageURL]; -
} -
return 'src="'.$imageURL.'"'; } function printMessage($messageId = NULL, $callfromcompose = NULL)
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
eGroupWare-cvs mailing list
eGroupWare-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/egroupware-cvs