*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
*/
/* $Id$ */
class uidisplay
{
var $public_functions = array
(
'display' => True,
'displayBody' => True,
'displayHeader' => True,
'displayImage' => True,
'displayAttachments' => True,
'printMessage' => True,
'saveMessage' => True,
'showHeader' => True,
'getAttachment' => True,
);
var $icServerID=0;
// the object storing the data about the incoming imap server
var $icServer=0;
// the non permanent id of the message
var $id;
// the permanent id of the message
var $uid;
var $bofelamimail;
var $bopreferences;
function uidisplay()
{
/* Having this defined in just one spot could help when changes need
* to be made to the pattern
* Make sure that the expression is evaluated case insensitively
*
* RFC2822 (and RFC822) defines the left side of an email address as (roughly):
* 1*atext *("." 1*atext)
* where atext is: a-zA-Z0-9!#$%&'*+-/=?^_`{|}~
*
* Here's pretty sophisticated IP matching:
* $IPMatch = '(2[0-5][0-9]|1?[0-9]{1,2})';
* $IPMatch = '\[?' . $IPMatch . '(\.' . $IPMatch . '){3}\]?';
*/
/* Here's enough: */
global $IP_RegExp_Match, $Host_RegExp_Match, $Email_RegExp_Match;
$IP_RegExp_Match = '\\[?[0-9]{1,3}(\\.[0-9]{1,3}){3}\\]?';
$Host_RegExp_Match = '('.$IP_RegExp_Match.'|[0-9a-z]([-.]?[0-9a-z])*\\.[a-z][a-z]+)';
#$atext = '([a-z0-9!#$&%*+/=?^_`{|}~-]|&)';
$atext = '([a-zA-Z0-9_\-\.])';
$dot_atom = $atext.'+(\.'.$atext.'+)*';
$Email_RegExp_Match = '~'.$dot_atom.'(%'.$Host_RegExp_Match.')?@'.$Host_RegExp_Match.'~i';
$this->t = CreateObject('phpgwapi.Template',EGW_APP_TPL);
$this->displayCharset = $GLOBALS['egw']->translation->charset();
$this->bofelamimail = CreateObject('felamimail.bofelamimail',$this->displayCharset);
$this->bopreferences = $this->bofelamimail->bopreferences; //CreateObject('felamimail.bopreferences');
$this->mailPreferences = $this->bopreferences->getPreferences();
$this->bofelamimail->openConnection($this->icServerID);
$this->mailbox = $this->bofelamimail->sessionData['mailbox'];
if (!empty($_GET['mailbox'])) $this->mailbox = base64_decode($_GET['mailbox']);
$this->sort = $this->bofelamimail->sessionData['sort'];
if(isset($_GET['uid'])) {
$this->uid = (int)$_GET['uid'];
}
if(isset($_GET['id'])) {
$this->id = (int)$_GET['id'];
}
if(isset($this->id) && !isset($this->uid)) {
if($uid = $this->bofelamimail->idToUid($this->mailbox, $this->id)) {
$this->uid = $uid;
}
}
if(isset($_GET['part'])) {
$this->partID = (int)$_GET['part'];
}
$this->rowColor[0] = $GLOBALS['egw_info']["theme"]["bg01"];
$this->rowColor[1] = $GLOBALS['egw_info']["theme"]["bg02"];
}
/**
* Parses a body and converts all found email addresses to clickable links.
*
* @param string body the body to process, by ref
* @return int the number of unique addresses found
*/
function parseEmail (&$body) {
global $Email_RegExp_Match;
$sbody = $body;
$addresses = array();
$i = 0;
/* Find all the email addresses in the body */
// stop cold after 100 adresses, as this is very time consuming
while(preg_match($Email_RegExp_Match, $sbody, $regs) && $i<=100) {
//_debug_array($regs);
$addresses[$regs[0]] = strtr($regs[0], array('&' => '&'));
$start = strpos($sbody, $regs[0]) + strlen($regs[0]);
$sbody = substr($sbody, $start);
$i++;
}
/* Replace each email address with a compose URL */
$lmail='';
if (is_array($addresses)) ksort($addresses);
foreach ($addresses as $text => $email) {
if ($lmail == $email) next($addresses);
//echo __METHOD__.' Text:'.$text."#
";
//echo $email."#
";
$comp_uri = $this->makeComposeLink($email, $text);
//echo __METHOD__.' Uri:'.$comp_uri.'#
';
$body = str_replace($text, $comp_uri, $body);
$lmail=$email;
}
/* Return number of unique addresses found */
return count($addresses);
}
function parseHREF (&$body) {
#echo __METHOD__."called
";
$webserverURL = $GLOBALS['egw_info']['server']['webserver_url'];
$alnum = 'a-z0-9';
#$domain = "(http(s?):\/\/)*";
#$domain .= "([$alnum]([-$alnum]*[$alnum]+)?)";
#$domain = "^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$ ";
$domain = "(http(s?):\/\/)+([[:alpha:]][-[:alnum:]]*[[:alnum:]])(\.[[:alpha:]][-[:alnum:]]*[[:alpha:]])*(\.[[:alpha:]][-[:alnum:]]*[[:alpha:]])+";
#$dir = "(/[[:alpha:]][-[:alnum:]]*[[:alnum:]])*";
#$trailingslash = "(\/?)";
#$page = "(/[[:alpha:]][-[:alnum:]]*\.[[:alpha:]]{3,5})?";
#$getstring = "(\?([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+)
# (&([[:alnum:]][-_%[:alnum:]]*=[-_%[:alnum:]]+))*)?";
#$pattern = "^".$domain.$dir.$trailingslash.$page.$getstring."$";
$pattern = "~\ $link) {
if (empty($link)) continue;
if ($llink == $link) next($addresses);
#echo $text."#
";
#echo $link."#
\n";
$comp_uri = "'.$text.'';
}
function highlightQuotes($text, $level = 5)
{
// Use a global var since the class is called statically.
$GLOBALS['_tmp_maxQuoteChars'] = 0;
// Tack a newline onto the beginning of the string so that we
// correctly highlight when the first character in the string
// is a quote character.
$text = "\n$text";
preg_replace_callback("/^\s*((>\s?)+)/m", array(&$this, '_countQuoteChars'), $text);
// Go through each level of quote block and put the
// appropriate style around it. Important to work downwards so
// blocks with fewer quote chars aren't matched until their
// turn.
for ($i = $GLOBALS['_tmp_maxQuoteChars']; $i > 0; $i--)
{
$text = preg_replace(
// Finds a quote block across multiple newlines.
"/(\n)( *(>\s?)\{$i}(?! ?>).*?)(\n|$)(?! *(> ?)\{$i})/s",
'\1\2\4',$text);
}
/* Unset the global variable. */
unset($GLOBALS['_tmp_maxQuoteChars']);
/* Remove the leading newline we added above. */
return substr($text, 1);
}
function _countQuoteChars($matches)
{
$num = count(preg_split('/>\s?/', $matches[1])) - 1;
if ($num > $GLOBALS['_tmp_maxQuoteChars'])
{
$GLOBALS['_tmp_maxQuoteChars'] = $num;
}
}
function display()
{
$partID = $_GET['part'];
if (!empty($_GET['mailbox'])) $this->mailbox = base64_decode($_GET['mailbox']);
//$transformdate =& CreateObject('felamimail.transformdate');
//$htmlFilter =& CreateObject('felamimail.htmlfilter');
$uiWidgets = CreateObject('felamimail.uiwidgets');
// (regis) seems to be necessary to reopen...
$this->bofelamimail->reopen($this->mailbox);
// retrieve the flags of the message, before touching it.
if (!empty($this->uid)) $flags = $this->bofelamimail->getFlags($this->uid);
#print "$this->mailbox, $this->uid, $partID
";
$headers = $this->bofelamimail->getMessageHeader($this->uid, $partID);
if (PEAR::isError($headers)) {
print lang("ERROR: Message could not be displayed.")."
";
print "In Mailbox: $this->mailbox, with ID: $this->uid, and PartID: $partID
";
print $headers->message."
";
_debug_array($headers->backtrace[0]);
exit;
}
#_debug_array($headers);exit;
$rawheaders = $this->bofelamimail->getMessageRawHeader($this->uid, $partID);
#_debug_array($rawheaders);exit;
$attachments = $this->bofelamimail->getMessageAttachments($this->uid, $partID);
#_debug_array($attachments); exit;
$envelope = $this->bofelamimail->getMessageEnvelope($this->uid, $partIDi,true);
#_debug_array($envelope); exit;
// if not using iFrames, we need to retrieve the messageBody here
// by now this is a fixed value and controls the use/loading of the template and how the vars are set.
// Problem is: the iFrame Layout provides the scrollbars.
#$bodyParts = $this->bofelamimail->getMessageBody($this->uid,'',$partID);
#_debug_array($bodyParts); exit;
#_debug_array($this->uid);
#_debug_array($this->bofelamimail->getFlags($this->uid)); #exit;
// flag the message as read/seen (if not already flagged)
if (!empty($this->uid) && strpos( array2string($flags),'Seen')===false) $this->bofelamimail->flagMessages('read', $this->uid);
$nextMessage = $this->bofelamimail->getNextMessage($this->mailbox, $this->uid);
$webserverURL = $GLOBALS['egw_info']['server']['webserver_url'];
$nonDisplayAbleCharacters = array('[\016]','[\017]',
'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
#print "
";print_r($rawheaders);print"";exit; // add line breaks to $rawheaders $newRawHeaders = explode("\n",$rawheaders); reset($newRawHeaders); if(isset($headers['ORGANIZATION'])) { $organization = $this->bofelamimail->decode_header(trim($headers['ORGANIZATION'])); } if ( isset($headers['DISPOSITION-NOTIFICATION-TO']) ) { $sent_not = $this->bofelamimail->decode_header(trim($headers['DISPOSITION-NOTIFICATION-TO'])); } else if ( isset($headers['RETURN-RECEIPT-TO']) ) { $sent_not = $this->bofelamimail->decode_header(trim($headers['RETURN-RECEIPT-TO'])); } else if ( isset($headers['X-CONFIRM-READING-TO']) ) { $sent_not = $this->bofelamimail->decode_header(trim($headers['X-CONFIRM-READING-TO'])); } else $sent_not = ""; // reset $rawheaders $rawheaders = ""; // create it new, with good line breaks reset($newRawHeaders); while(list($key,$value) = @each($newRawHeaders)) { $rawheaders .= wordwrap($value, 90, "\n "); } $this->display_app_header(); if(!isset($_GET['printable'])) { $this->t->set_file(array("displayMsg" => "view_message.tpl")); } else { $this->t->set_file(array("displayMsg" => "view_message_printable.tpl")); $this->t->set_var('charset',$GLOBALS['egw']->translation->charset()); } // only notify when requested, notify flag (MDNSent/MDNnotSent) not set, and message not already seen (some servers do not support the MDNSent/MDNnotSent flag) if ( $sent_not != "" && $this->bofelamimail->getNotifyFlags($this->uid) === null && strpos( array2string($flags),'Seen')===false) { $this->t->set_var('sentNotify','sendNotify("'.$this->uid.'");'); $this->t->set_var('lang_sendnotify',lang('The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?')); } else { $this->t->set_var('sentNotify',''); $this->t->set_var('lang_sendnotify',''); } $this->bofelamimail->closeConnection(); $this->t->set_block('displayMsg','message_main'); $this->t->set_block('displayMsg','message_main_attachment'); $this->t->set_block('displayMsg','message_header'); $this->t->set_block('displayMsg','message_raw_header'); $this->t->set_block('displayMsg','message_navbar'); $this->t->set_block('displayMsg','message_onbehalfof'); $this->t->set_block('displayMsg','message_cc'); $this->t->set_block('displayMsg','message_bcc'); $this->t->set_block('displayMsg','message_attachement_row'); $this->t->set_block('displayMsg','previous_message_block'); $this->t->set_block('displayMsg','next_message_block'); //$this->t->set_block('displayMsg','message_org'); $this->t->egroupware_hack = False; $this->translate(); // navBar buttons $headerData = array('uid'=>$this->uid); if($partID != '') { $headerData['partid'] = $partID; } $this->t->set_var('navbarButtonsLeft',$uiWidgets->displayMessageActions($headerData, $this->mailbox, $this->icServer)); $navbarButtons = ''; $navbarImages = array(); #_debug_array($nextMessage); exit; if($nextMessage['previous']) { $linkData = array ( 'menuaction' => 'felamimail.uidisplay.display', 'showHeader' => 'false', 'uid' => $nextMessage['previous'], 'mailbox' => base64_encode($this->mailbox) ); $previousURL = $GLOBALS['egw']->link('/index.php',$linkData); $previousURL = "goToMessage('$previousURL')"; $navbarImages['up.button'] = array( 'action' => $previousURL, 'tooltip' => lang('previous message'), ); } else { $previousURL = '#'; $navbarImages['up.grey'] = array( 'action' => $previousURL, 'tooltip' => lang('previous message'), ); } if($nextMessage['next']) { $linkData = array ( 'menuaction' => 'felamimail.uidisplay.display', 'showHeader' => 'false', 'uid' => $nextMessage['next'], 'mailbox' => base64_encode($this->mailbox) ); $nextURL = $GLOBALS['egw']->link('/index.php',$linkData); $nextURL = "goToMessage('$nextURL')"; $navbarImages['down.button'] = array( 'action' => $nextURL, 'tooltip' => lang('next message'), ); } else { $nextURL = '#'; $navbarImages['down.grey'] = array( #'action' => $nextURL, 'tooltip' => lang('next message'), ); } foreach($navbarImages as $buttonName => $buttonData) { $navbarButtons .= $uiWidgets->navbarButton($buttonName, $buttonData['action'], $buttonData['tooltip'], 'right'); } $this->t->set_var('navbarButtonsRight',$navbarButtons); $this->t->parse('navbar','message_navbar',True); // navbar end // header // sent by a mailinglist?? // parse the from header if($envelope['FROM'][0] != $envelope['SENDER'][0]) { $senderAddress = self::emailAddressToHTML($envelope['SENDER'],'',false,true,false); $fromAddress = self::emailAddressToHTML($envelope['FROM'], $organization,false,true,false); $this->t->set_var("from_data",$senderAddress); $this->t->set_var("onbehalfof_data",$fromAddress); $this->t->parse('on_behalf_of_part','message_onbehalfof',True); } else { $fromAddress = self::emailAddressToHTML($envelope['FROM'], $organization,false,true,false); $this->t->set_var("from_data", $fromAddress); $this->t->set_var('on_behalf_of_part',''); } // parse the to header $toAddress = self::emailAddressToHTML($envelope['TO'],'',false,true,false); $this->t->set_var("to_data",$toAddress); // parse the cc header if(count($envelope['CC'])) { $ccAddress = self::emailAddressToHTML($envelope['CC'],'',false,true,false); $this->t->set_var("cc_data",$ccAddress); $this->t->parse('cc_data_part','message_cc',True); } else { $this->t->set_var("cc_data_part",''); } // parse the bcc header if(count($envelope['BCC'])) { $bccAddress = self::emailAddressToHTML($envelope['BCC'],'',false,true,false); $this->t->set_var("bcc_data",$bccAddress); $this->t->parse('bcc_data_part','message_bcc',True); } else { $this->t->set_var("bcc_data_part",''); } $this->t->set_var("date_received", @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)); $this->t->parse("header","message_header",True); $this->t->set_var("rawheader",@htmlentities(preg_replace($nonDisplayAbleCharacters,'',$rawheaders),ENT_QUOTES,$this->displayCharset)); $linkData = array ( 'menuaction' => 'felamimail.uidisplay.displayBody', 'uid' => $this->uid, 'part' => $partID, 'mailbox' => base64_encode($this->mailbox) ); $this->t->set_var('url_displayBody', $GLOBALS['egw']->link('/index.php',$linkData)); // attachments if(is_array($attachments) && count($attachments) > 0) { $this->t->set_var('attachment_count',count($attachments)); } else { $this->t->set_var('attachment_count','0'); } if (is_array($attachments) && count($attachments) > 0) { $this->t->set_var('row_color',$this->rowColor[0]); $this->t->set_var('name',lang('name')); $this->t->set_var('type',lang('type')); $this->t->set_var('size',lang('size')); $this->t->set_var('url_img_save',html::image('felamimail','fileexport', lang('save'))); $url_img_vfs = html::image('filemanager','navbar', lang('Filemanager'), ' height="16"'); $url_img_vfs_save_all = html::image('felamimail','save_all', lang('Save all')); #$this->t->parse('attachment_rows','attachment_row_bold',True); $detectedCharSet=$charset2use=$this->displayCharset; foreach ($attachments as $key => $value) { #$detectedCharSet = mb_detect_encoding($value['name'].'a',strtoupper($this->displayCharset).",UTF-8, ISO-8559-1"); if (function_exists('mb_convert_variables')) mb_convert_variables("UTF-8","ISO-8559-1",$value['name']); # iso 2 UTF8 //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); $this->t->set_var('row_color',$this->rowColor[($key+1)%2]); $this->t->set_var('filename',($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)'))); $this->t->set_var('mimetype',mime_magic::mime2label($value['mimeType'])); $this->t->set_var('size',egw_vfs::hsize($value['size'])); $this->t->set_var('attachment_number',$key); switch(strtoupper($value['mimeType'])) { case 'MESSAGE/RFC822': $linkData = array ( 'menuaction' => 'felamimail.uidisplay.display', 'uid' => $this->uid, 'part' => $value['partID'], 'mailbox' => base64_encode($this->mailbox), 'is_winmail' => $value['is_winmail'] ); $windowName = 'displayMessage_'. $this->uid.'_'.$value['partID']; $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',700,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/CALENDAR': case 'TEXT/X-VCARD': $linkData = array ( 'menuaction' => 'felamimail.uidisplay.getAttachment', 'uid' => $this->uid, 'part' => $value['partID'], 'is_winmail' => $value['is_winmail'], 'mailbox' => base64_encode($this->mailbox), ); $windowName = 'displayAttachment_'. $this->uid; $reg = '800x600'; // handle calendar/vcard if (strtoupper($value['mimeType'])=='TEXT/CALENDAR') { $windowName = 'displayEvent_'. $this->uid; $reg2 = egw_link::get_registry('calendar','view_popup'); } if (strtoupper($value['mimeType'])=='TEXT/X-VCARD') { $windowName = 'displayContact_'. $this->uid; $reg2 = egw_link::get_registry('addressbook','add_popup'); } // apply to action list($width,$height) = explode('x',(!empty($reg2) ? $reg2 : $reg)); $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',$width,$height);"; break; default: $linkData = array ( 'menuaction' => 'felamimail.uidisplay.getAttachment', 'uid' => $this->uid, 'part' => $value['partID'], 'is_winmail' => $value['is_winmail'], 'mailbox' => base64_encode($this->mailbox), ); $linkView = "window.location.href = '".$GLOBALS['egw']->link('/index.php',$linkData)."';"; break; } $this->t->set_var("link_view",$linkView); $this->t->set_var("target",$target); $linkData = array ( 'menuaction' => 'felamimail.uidisplay.getAttachment', 'mode' => 'save', 'uid' => $this->uid, 'part' => $value['partID'], 'is_winmail' => $value['is_winmail'], 'mailbox' => base64_encode($this->mailbox), ); $this->t->set_var("link_save",$GLOBALS['egw']->link('/index.php',$linkData)); if ($GLOBALS['egw_info']['user']['apps']['filemanager']) { $link_vfs_save = egw::link('/index.php',array( 'menuaction' => 'filemanager.filemanager_select.select', 'mode' => 'saveas', 'name' => $value['name'], 'mime' => strtolower($value['mimeType']), 'method' => 'felamimail.uidisplay.vfsSaveAttachment', 'id' => $this->mailbox.'::'.$this->uid.'::'.$value['partID'].'::'.$value['is_winmail'], 'label' => lang('Save'), )); $vfs_save = "$url_img_vfs"; // add save-all icon for first attachment if (!$key && count($attachments) > 1) { foreach ($attachments as $key => $value) { $ids["id[$key]"] = $this->mailbox.'::'.$this->uid.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name']; } $link_vfs_save = egw::link('/index.php',array( 'menuaction' => 'filemanager.filemanager_select.select', 'mode' => 'select-dir', 'method' => 'felamimail.uidisplay.vfsSaveAttachment', 'label' => lang('Save all'), )+$ids); $vfs_save .= "\n$url_img_vfs_save_all"; } $this->t->set_var('vfs_save',$vfs_save); } else { $this->t->set_var('vfs_save',''); } $this->t->parse('attachment_rows','message_attachement_row',True); } } else { $this->t->set_var('attachment_rows',''); } #$this->t->pparse("out","message_attachment_rows"); // print it out if(is_array($attachments) && count($attachments) > 0) { $this->t->pparse('out','message_main_attachment'); } else { $this->t->pparse('out','message_main'); } } function displayBody() { $partID = $_GET['part']; if (empty($this->uid) && !empty($_GET['uid']) ) $this->uid = 9247;//$_GET['uid']; if (!empty($_GET['mailbox'])) $this->mailbox = base64_decode($_GET['mailbox']); $this->bofelamimail->reopen($this->mailbox); $bodyParts = $this->bofelamimail->getMessageBody($this->uid,'',$partID); $this->bofelamimail->closeConnection(); $this->display_app_header(); $this->showBody($this->getdisplayableBody($bodyParts), true); } function showBody(&$body, $print=true) { $BeginBody = '
'; $EndBody = ' |