R54269 - /trunk/emailadmin/inc/class.emailadmin_imapbase.inc.php

Author: leithoff
New Revision: 54269

URL: http://svn.stylite.de/viewvc/egroupware?rev=54269&view=rev
Log:
allow for option to retrieve part of the message-body for use as preview

Modified:
trunk/emailadmin/inc/class.emailadmin_imapbase.inc.php

Modified: trunk/emailadmin/inc/class.emailadmin_imapbase.inc.php
URL: http://svn.stylite.de/viewvc/egroupware/trunk/emailadmin/inc/class.emailadmin_imapbase.inc.php?rev=54269&r1=54268&r2=54269&view=diff

— trunk/emailadmin/inc/class.emailadmin_imapbase.inc.php (original)
+++ trunk/emailadmin/inc/class.emailadmin_imapbase.inc.php Fri Nov 13 14:44:58 2015
@@ -1263,9 +1263,10 @@
* @param array $_filter filter to apply to getSortedList
* @param mixed $_thisUIDOnly = null, if given fetch the headers of this uid only (either one, or array of uids)
* @param boolean $_cacheResult = true try touse the cache of getSortedList

    • @param boolean $_fetchPreviews = false fetch part of the body of the messages requested
    • @return array result as array(header=>array,total=>int,first=>int,last=>int)
      */
  • function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true)
  • function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
    {
    //self::$debug=true;
    if (self::$debug) error_log(METHOD.’ (’.LINE.’) '.function_backtrace());
    @@ -1386,6 +1387,8 @@
    $fquery->structure();
    $fquery->flags();
    $fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
  •   	// if $_fetchPreviews is activated fetch part of the messages too
    
  •   	if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>5000,'start'=>0));
      	$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
      		'ids' => $uidsToFetch,
      	));
    

@@ -1473,6 +1476,33 @@

			}
			$headerObject['FLAGS'] = $_headerObject->getFlags();
  •   		$headerObject['BODYPREVIEW']=null;
    
  •   		// this section fetches part of the message-body (if enabled) for some kind of preview
    
  •   		// if we fail to succeed, we fall back to the retrieval of the message-body with
    
  •   		// fetchPartContents (see below, when we iterate over the structure to determine the
    
  •   		// existance (and the details) for attachments)
    
  •   		if ($_fetchPreviews)
    
  •   		{
    
  •   			$bodyPreview = $_headerObject->getFullMsg();
    
  •   			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
    
  •   			$base = Horde_Mime_Part::parseMessage($bodyPreview);
    
  •   			foreach($base->partIterator() as $part)
    
  •   			{
    
  •   				//error_log(__METHOD__.__LINE__.'Part:'.$part->getPrimaryType());
    
  •   				if (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'text')
    
  •   				{
    
  •   					$charset = $part->getContentTypeParameter('charset');
    
  •   					$buffer = translation::convertHTMLToText($part->toString(array(
    
  •   										'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
    
  •   									)), $charset, 'utf-8');
    
  •   					$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',substr(translation::convert_jsonsafe($buffer),0,300)));
    
  •   				} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
    
  •   				{
    
  •   					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
    
  •   				}
    
  •   			}
    
  •   			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject['BODYPREVIEW']));
    
  •   		}
      		$mailStructureObject = $_headerObject->getStructure();
      		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
      		//error_log(__METHOD__.' ('.__LINE__.') '.' MimeMap:'.array2string($mailStructureObject->contentTypeMap()));
    

@@ -1486,6 +1516,22 @@
$part = $mailStructureObject->getPart($mime_id);
$partdisposition = $part->getDisposition();
$partPrimaryType = $part->getPrimaryType();

  •   			// this section fetches the body for the purpose of previewing a few lines
    
  •   			// drawback here it is talking to the mailserver for each mail thus consuming
    
  •   			// more time than expected; so we call this section only when there is no
    
  •   			// bodypreview could be found (multipart/....)
    
  •   			if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
    
  •   				((intval($mime_id) === 1) || !$mime_id) &&
    
  •   				($partdisposition !== 'attachment')) {
    
  •   					$_structure=$part;
    
  •   					$this->fetchPartContents($uid, $_structure, false,true);
    
  •   					$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',substr(translation::convertHTMLToText($_structure->getContents()),0,300)));
    
  •   					$charSet=translation::detect_encoding($headerObject['BODYPREVIEW']);
    
  •   					// add line breaks to $bodyParts
    
  •   					//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
    
  •   					$headerObject['BODYPREVIEW']  = translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
    
  •   					//error_log(__METHOD__.__LINE__.$headerObject['bodypreview']);
    
  •   			}
      			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
      			$cid = $part->getContentId();
      			if (empty($partdisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
    

@@ -1568,6 +1614,7 @@
$retValue[‘header’][$sortOrder[$uid]][‘mimetype’] = $messageMimeType;
$retValue[‘header’][$sortOrder[$uid]][‘id’] = $headerObject[‘MSG_NUM’];
$retValue[‘header’][$sortOrder[$uid]][‘uid’] = $headerObject[‘UID’];

  •   		$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
      		$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
      		//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
      		if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
    

@@ -4014,7 +4061,7 @@
// but they matter in

, so we rather don’t
//$_html = str_replace("\r\n",’ ‘,$_html);
//$_html = str_replace("\t",’ ',$_html);
  •   //error_log($_html);
    
  •   //error_log(__METHOD__.__LINE__.':'.$_html);
      //repair doubleencoded ampersands, and some stuff htmLawed stumbles upon with balancing switched on
      $_html = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>','</td></font>','<br><td>','<tr></tr>','<o:p></o:p>','<o:p>','</o:p>'),
      					 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
    

@@ -5447,7 +5494,7 @@
*/
function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
{

  •   error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
    
  •   //error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
      if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
    
      $uidsToFetch = new Horde_Imap_Client_Ids();
    


eGroupWare-cvs mailing list
eGroupWare-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/egroupware-cvs