R32824 - in /trunk/felamimail/inc: class.bocompose.inc.php class.uicompose.inc.php class.uidisplay.inc.php

Author: leithoff
New Revision: 32824

URL: http://www.egroupware.org/viewvc/egroupware?rev=32824&view=rev
Log:
implementing fallback for wrong headerdata encoding; try to detect encoding from headerdata to improve message header data display, due to wrong encoding

Modified:
trunk/felamimail/inc/class.bocompose.inc.php
trunk/felamimail/inc/class.uicompose.inc.php
trunk/felamimail/inc/class.uidisplay.inc.php

Modified: trunk/felamimail/inc/class.bocompose.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/felamimail/inc/class.bocompose.inc.php?rev=32824&r1=32823&r2=32824&view=diff

— trunk/felamimail/inc/class.bocompose.inc.php (original)
+++ trunk/felamimail/inc/class.bocompose.inc.php Thu Nov 4 14:58:10 2010
@@ -65,61 +65,21 @@
*/
function addAttachment($_formData)
{

  •   	//echo "addattachment<br>";
    
  •   	//_debug_array($_formData);
    
  •   	//error_log(__METHOD__.__LINE__.array2string($_formData));
    
  •   	$attachfailed = false;
      	// to gard against exploits the file must be either uploaded or be in the temp_dir
    
  •   	if ($_formData['size'] != 0 && (is_uploaded_file($_formData['file']) ||
    
  •   		realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir'])) ||
    
  •   		parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
    
  •   	{
    
  •   		// ensure existance of eGW temp dir
    
  •   		// note: this is different from apache temp dir,
    
  •   		// and different from any other temp file location set in php.ini
    
  •   		if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
    
  •   		{
    
  •   			@mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
    
  •   		}
    
  •   		// if we were NOT able to create this temp directory, then make an ERROR report
    
  •   		if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
    
  •   		{
    
  •   			$alert_msg .= 'Error:'.'<br>'
    
  •   				.'Server is unable to access phpgw tmp directory'.'<br>'
    
  •   				.$GLOBALS['egw_info']['server']['temp_dir'].'<br>'
    
  •   				.'Please check your configuration'.'<br>'
    
  •   				.'<br>';
    
  •   		}
    
  •   		// sometimes PHP is very clue-less about MIME types, and gives NO file_type
    
  •   		// rfc default for unknown MIME type is:
    
  •   		$mime_type_default = 'application/octet-stream';
    
  •   		// so if PHP did not pass any file_type info, then substitute the rfc default value
    
  •   		if (trim($_formData['type']) == '')
    
  •   		{
    
  •   			$_formData['type'] = $mime_type_default;
    
  •   		}
    
  •   		$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].
    
  •   			SEP.
    
  •   			md5(time().$GLOBALS['egw_info']['user']['account_id'].$this->composeID.basename($_formData['file']));
    
  •   		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
    
  •   		{
    
  •   			$tmpFileName = $_formData['file'];	// no need to store it somewhere
    
  •   		}
    
  •   		elseif (is_uploaded_file($_formData['file']))
    
  •   		{
    
  •   			//error_log(__METHOD__." Uploaded File:".$_formData['file']." with filesize:".filesize($_formData['file']));
    
  •   			move_uploaded_file($_formData['file'],$tmpFileName);	// requirement for safe_mode!
    
  •   			//error_log(__METHOD__." copy to :".$tmpFileName." with filesize:".filesize($tmpFileName));
    
  •   		}
    
  •   		else
    
  •   		{
    
  •   			rename($_formData['file'],$tmpFileName);
    
  •   		}
    
  •   		//$attachmentID = $this->getRandomString();
    
  •   		//error_log(__METHOD__." add Attachment with ID (random String):".$attachmentID);
    
  •   	// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
    
  •   	try
    
  •   	{
    
  •   		$tmpFileName = bofelamimail::checkFileBasics($_formData,$this->composeID,false);
    
  •   	}
    
  •   	catch (egw_exception_wrong_userinput $e)
    
  •   	{
    
  •   		$attachfailed = true;
    
  •   		$alert_msg = $e->getMessage();
    
  •   	}
    
  •   	if ($attachfailed === false)
    
  •   	{
      		$buffer = array(
      			'name'	=> $_formData['name'],
      			'type'	=> $_formData['type'],
    

@@ -131,6 +91,10 @@
//error_log(METHOD." add Attachment with ID:".$attachmentID." (md5 of serialized array)");
$this->sessionData[‘attachments’][$attachmentID] = $buffer;
unset($buffer);

  •   	}
    
  •   	else
    
  •   	{
    
  •   		error_log(__METHOD__.__LINE__.array2string($alert_msg));
      	}
    
      	$this->saveSessionData();
    

@@ -582,24 +546,33 @@
$bodyParts = $bofelamimail->getMessageBody($_uid, $this->preferencesArray[‘always_display’], $_partID);
//_debug_array($bodyParts);

  •   	$fromAddress = ($headers['FROM'][0]['PERSONAL_NAME'] != 'NIL') ? $headers['FROM'][0]['RFC822_EMAIL'] : $headers['FROM'][0]['EMAIL'];
    
  •   	$fromAddress = bofelamimail::htmlspecialchars($bofelamimail->decode_header(($headers['FROM'][0]['PERSONAL_NAME'] != 'NIL') ? $headers['FROM'][0]['RFC822_EMAIL'] : $headers['FROM'][0]['EMAIL']));
    
  •   	$toAddressA = array();
      	$toAddress = '';
      	foreach ($headers['TO'] as $mailheader) {
      		$toAddressA[] =  ($mailheader['PERSONAL_NAME'] != 'NIL') ? $mailheader['RFC822_EMAIL'] : $mailheader['EMAIL'];
      	}
    
  •   	if (count($toAddressA)>0) $toAddress = @htmlspecialchars(lang("to").": ".$bofelamimail->decode_header(implode(', ', $toAddressA)),ENT_QUOTES).($bodyParts['0']['mimeType'] == 'text/html'?"\r\n<br>":"\r\n");
    
  •   	if (count($toAddressA)>0)
    
  •   	{
    
  •   		$toAddress = bofelamimail::htmlspecialchars($bofelamimail->decode_header(implode(', ', $toAddressA)));
    
  •   		$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html'?"\r\n<br>":"\r\n");;
    
  •   	}
      	$ccAddressA = array();
      	$ccAddress = '';
      	foreach ($headers['CC'] as $mailheader) {
      		$ccAddressA[] =  ($mailheader['PERSONAL_NAME'] != 'NIL') ? $mailheader['RFC822_EMAIL'] : $mailheader['EMAIL'];
      	}
    
  •   	if (count($ccAddressA)>0) $ccAddress = @htmlspecialchars(lang("cc").": ".$bofelamimail->decode_header(implode(', ', $ccAddressA)),ENT_QUOTES).($bodyParts['0']['mimeType'] == 'text/html'?"\r\n<br>":"\r\n");
    
  •   	if (count($ccAddressA)>0) 
    
  •   	{
    
  •   		$ccAddress = bofelamimail::htmlspecialchars($bofelamimail->decode_header(implode(', ', $ccAddressA)));
    
  •   		$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddressA.($bodyParts['0']['mimeType'] == 'text/html'?"\r\n<br>":"\r\n");
    
  •   	}
      	if($bodyParts['0']['mimeType'] == 'text/html') {
      		$this->sessionData['body']	= "<br>&nbsp;\r\n<p>".'----------------'.lang("original message").'-----------------'."\r\n".'<br>'.
    
  •   			@htmlspecialchars(lang("from").": ".$bofelamimail->decode_header($fromAddress),ENT_QUOTES)."\r\n<br>".
    
  •   			@htmlspecialchars(lang("from")).": ".$fromAddress."\r\n<br>".
      			$toAddress.$ccAddress.
    
  •   			@htmlspecialchars(lang("date").": ".$headers['DATE'],ENT_QUOTES)."\r\n<br>".
    
  •   			@htmlspecialchars(lang("date").": ".$headers['DATE'],ENT_QUOTES | ENT_IGNORE,bofelamimail::$displayCharset, false)."\r\n<br>".
      			'----------------------------------------------------------'."\r\n</p>";
      		$this->sessionData['mimeType'] 	= 'html';
      		$this->sessionData['body']	.= '<blockquote type="cite">';
    

@@ -622,9 +595,9 @@
} else {
#$this->sessionData[‘body’] = @htmlspecialchars(lang(“on”)." “.$headers[‘DATE’].” “.$bofelamimail->decode_header($fromAddress), ENT_QUOTES) . " “.lang(“wrote”).”:\r\n”;
$this->sessionData[‘body’] = " \r\n \r\n".’----------------’.lang(“original message”).’-----------------’."\r\n".

  •                @htmlspecialchars(lang("from").": ".$bofelamimail->decode_header($fromAddress),ENT_QUOTES)."\r\n".
    
  •                @htmlspecialchars(lang("from")).": ".$fromAddress."\r\n".
      			$toAddress.$ccAddress.
    
  •   			@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES)."\r\n".
    
  •   			@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES | ENT_IGNORE,bofelamimail::$displayCharset, false)."\r\n".
                   '-------------------------------------------------'."\r\n \r\n ";
    
      		$this->sessionData['mimeType']	= 'plain';
    

Modified: trunk/felamimail/inc/class.uicompose.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/felamimail/inc/class.uicompose.inc.php?rev=32824&r1=32823&r2=32824&view=diff

— trunk/felamimail/inc/class.uicompose.inc.php (original)
+++ trunk/felamimail/inc/class.uicompose.inc.php Thu Nov 4 14:58:10 2010
@@ -173,7 +173,7 @@
$sessionData = $this->bocompose->getSessionData();
if (is_array($_REQUEST[‘preset’]))
{

  •   		#_debug_array($_REQUEST);
    
  •   		//_debug_array($_REQUEST);
      		if ($_REQUEST['preset']['mailto']) {
      			// handle mailto strings such as
      			// mailto:larry,dan?cc=mike&bcc=sue&subject=test&body=type+your&body=message+here
    

@@ -241,6 +241,7 @@
{
$sessionData[‘to’] = base64_decode($_REQUEST[‘send_to’]);
}
+
//is the MimeType set/requested
if (!empty($_REQUEST[‘mimeType’]))
{
@@ -369,7 +370,8 @@
foreach((array)$sessionData[$destination] as $key => $value) {
$selectDestination = html::select(‘destination[]’, $destination, $this->destinations, false, “style=‘width: 100%;’ onchange=‘fm_compose_changeInputType(this)’”);
$this->t->set_var(‘select_destination’, $selectDestination);

  •   			$this->t->set_var('address', @htmlentities($value, ENT_QUOTES, $this->displayCharset));
    
  •   			$address = bofelamimail::htmlentities($value, $this->displayCharset);
    
  •   			$this->t->set_var('address', $address);
      			$this->t->parse('destinationRows','destination_row',True);
      			$destinationRows++;
      		}
    

@@ -388,7 +390,10 @@
$this->t->set_var(‘address’, ‘’);
$this->t->parse(‘destinationRows’,‘destination_row’,True);

  •   	$this->t->set_var("subject",@htmlentities($sessionData['subject'],ENT_QUOTES,$this->displayCharset));
    
  •   	// handle subject
    
  •   	$subject = bofelamimail::htmlentities($sessionData['subject'],$this->displayCharset);
    
  •   	$this->t->set_var("subject",$subject);
    
  •   	if ($GLOBALS['egw_info']['user']['apps']['addressbook']) {
      		$this->t->set_var('addressbookButton','<button class="menuButton" type="button" onclick="addybook();" title="'.lang('addressbook').'">
                   <img src="'.$GLOBALS['egw']->common->image('phpgwapi/templates/phpgw_website','users').'">
    

Modified: trunk/felamimail/inc/class.uidisplay.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/felamimail/inc/class.uidisplay.inc.php?rev=32824&r1=32823&r2=32824&view=diff

— trunk/felamimail/inc/class.uidisplay.inc.php (original)
+++ trunk/felamimail/inc/class.uidisplay.inc.php Thu Nov 4 14:58:10 2010
@@ -455,9 +455,9 @@
@htmlspecialchars(bofelamimail::_strtotime($headers[‘DATE’],$GLOBALS[‘egw_info’][‘user’][‘preferences’][‘common’][‘dateformat’]).’ - '.bofelamimail::_strtotime($headers[‘DATE’],‘H:i:s’),
ENT_QUOTES,$this->displayCharset));

  •   	$this->t->set_var("subject_data",
    
  •   		@htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT']),false),
    
  •   		ENT_QUOTES,$this->displayCharset));
    
  •   	$subject = bofelamimail::htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT'])),
    
  •            $this->displayCharset);
    
  •   	$this->t->set_var("subject_data",$subject);
    
      	$this->t->parse("header","message_header",True);
    

@@ -741,9 +741,9 @@
$this->t->egroupware_hack = False;

		$this->translate();
  •        $this->t->set_var("subject_data",
    
  •            @htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT'])),
    
  •            ENT_QUOTES,$this->displayCharset));
    
  •   	$subject = bofelamimail::htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT'])),
    
  •            $this->displayCharset);
    
  •        $this->t->set_var("subject_data",$subject);
    
      	// attachments
      	if(is_array($attachments) && count($attachments) > 0) {
    

@@ -953,7 +953,7 @@
}

	static function emailAddressToHTML($_emailAddress, $_organisation='', $allwaysShowMailAddress=false, $showAddToAdrdessbookLink=true, $decode=true) {
  •   	#_debug_array($_emailAddress);
    
  •   	//_debug_array($_emailAddress);
      	// create some nice formated HTML for senderaddress
      	#if($_emailAddress['EMAIL'] == 'undisclosed-recipients: ;')
      	#	return $_emailAddress['EMAIL'];
    

@@ -975,18 +975,24 @@
continue;
}
if($addressData[‘PERSONAL_NAME’] != ‘NIL’) {

  •   				$newSenderAddress = $addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL'];
    
  •   				if ($decode) $newSenderAddress = bofelamimail::decode_header($newSenderAddress);
    
  •   				$decodedPersonalName = ($decode ? bofelamimail::decode_header($addressData['PERSONAL_NAME']):$addressData['PERSONAL_NAME']);
    
  •   				if ($decode) $addressData['EMAIL'] = bofelamimail::decode_header($addressData['EMAIL']);
    
  •   				$newSenderAddressORG = $newSenderAddress = $addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL'];
    
  •   				$decodedPersonalNameORG = $decodedPersonalName = $addressData['PERSONAL_NAME'];
    
  •   				if ($decode) 
    
  •   				{
    
  •   					$newSenderAddress = bofelamimail::decode_header($newSenderAddressORG);
    
  •   					$decodedPersonalName = bofelamimail::decode_header($decodedPersonalName);
    
  •   					$addressData['EMAIL'] = bofelamimail::decode_header($addressData['EMAIL']);
    
  •   				}
      				$realName =  $decodedPersonalName;
      				// add mailaddress
      				if ($allwaysShowMailAddress) {
      					$realName .= ' <'.$addressData['EMAIL'].'>';
    
  •   					$decodedPersonalNameORG .= ' <'.$addressData['EMAIL'].'>';
      				}
      				// add organization
      				if(!empty($_organisation)) {
      					$realName .= ' ('. $_organisation . ')';
    
  •   					$decodedPersonalNameORG .= ' ('. $_organisation . ')';
      				}
    
      				$linkData = array (
    

@@ -994,10 +1000,14 @@
‘send_to’ => base64_encode($newSenderAddress)
);
$link = $GLOBALS[‘egw’]->link(’/index.php’,$linkData);
+

  •   				$newSenderAddress = bofelamimail::htmlentities($newSenderAddress);
    
  •   				$realName = bofelamimail::htmlentities($realName);
    
  •   				$senderAddress .= sprintf('<a href="%s" title="%s">%s</a>',
      							$link,
    
  •   							@htmlentities($newSenderAddress,ENT_QUOTES,bofelamimail::$displayCharset),
    
  •   							@htmlentities($realName, ENT_QUOTES, bofelamimail::$displayCharset));
    
  •   							$newSenderAddress,
    
  •   							$realName);
    
      				$linkData = array (
      					'menuaction'		=> 'addressbook.addressbook_ui.edit',
    

@@ -1005,6 +1015,8 @@
‘presets[org_name]’ => $_organisation,
‘referer’ => $_SERVER[‘PHP_SELF’].’?’.$_SERVER[‘QUERY_STRING’]
);
+

  •   				$decodedPersonalName = $realName;
      				if (!empty($decodedPersonalName)) {
      					if($spacePos = strrpos($decodedPersonalName, ' ')) {
      						$linkData['presets[n_family]']	= substr($decodedPersonalName, $spacePos+1);
    

@@ -1014,6 +1026,7 @@
}
$linkData[‘presets[n_fn]’] = $decodedPersonalName;
}
+
if ($showAddToAdrdessbookLink && $GLOBALS[‘egw_info’][‘user’][‘apps’][‘addressbook’]) {
$urlAddToAddressbook = $GLOBALS[‘egw’]->link(’/index.php’,$linkData);
$onClick = “window.open(this,this.target,‘dependent=yes,width=850,height=440,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes’); return false;”;
@@ -1029,20 +1042,22 @@
lang(‘add to addressbook’));
}
} else {

  •   				if ($decode) $addressData['EMAIL'] = bofelamimail::decode_header($addressData['EMAIL']);
    
  •   				$addrEMailORG = $addrEMail = $addressData['EMAIL'];
    
  •   				if ($decode) $addrEMail = bofelamimail::decode_header($addrEMail);
      				$linkData = array (
      					'menuaction'	=> 'felamimail.uicompose.compose',
      					'send_to'	=> base64_encode($addressData['EMAIL'])
      				);
      				$link = $GLOBALS['egw']->link('/index.php',$linkData);
    
  •   				$senderEMail = bofelamimail::htmlentities($addrEMail);
      				$senderAddress .= sprintf('<a href="%s">%s</a>',
    
  •   							$link,@htmlentities($addressData['EMAIL'], ENT_QUOTES, bofelamimail::$displayCharset));
    
  •   							$link,$senderEMail);
      				//TODO: This uses old addressbook code, which should be removed in Version 1.4
      				//Please use addressbook.addressbook_ui.edit with proper paramenters
      				$linkData = array
      				(
      					'menuaction'		=> 'addressbook.addressbook_ui.edit',
    
  •   					'presets[email]'	=> $addressData['EMAIL'],
    
  •   					'presets[email]'	=> $senderEMail, //$addressData['EMAIL'],
      					'presets[org_name]'	=> $_organisation,
      					'referer'		=> $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']
      				);
    

@@ -1445,7 +1460,7 @@
@htmlspecialchars(bofelamimail::_strtotime($headers[‘DATE’],$GLOBALS[‘egw_info’][‘user’][‘preferences’][‘common’][‘dateformat’]).’ - '.bofelamimail::_strtotime($headers[‘DATE’],‘H:i:s’), ENT_QUOTES,$this->displayCharset));

		// link to go back to the message view. the link differs if the print was called from a normal viewing window, or from compose
  •   	$subject = @htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters, '', $envelope['SUBJECT']),false), ENT_QUOTES, $this->displayCharset);
    
  •   	$subject = bofelamimail::htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters, '', $envelope['SUBJECT']),false), $this->displayCharset);
      	$this->t->set_var("subject_data", $subject);
      	$this->t->set_var("full_subject_data", $subject);
      	$linkData = array (
    

The Next 800 Companies to Lead America’s Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book “Blueprint to a
Billion” shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev


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