*
* 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',
'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;
function uidisplay()
{
$this->t =& CreateObject('phpgwapi.Template',EGW_APP_TPL);
$this->displayCharset = $GLOBALS['egw']->translation->charset();
$this->bofelamimail =& CreateObject('felamimail.bofelamimail',$this->displayCharset);
$this->bopreferences =& CreateObject('felamimail.bopreferences');
$this->kses =& CreateObject('phpgwapi.kses');
$this->botranslation =& CreateObject('phpgwapi.translation');
$this->mailPreferences = $this->bopreferences->getPreferences();
$this->bofelamimail->openConnection($this->icServerID);
$this->mailbox = $this->bofelamimail->sessionData['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"];
}
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'];
$transformdate =& CreateObject('felamimail.transformdate');
$htmlFilter =& CreateObject('felamimail.htmlfilter');
$uiWidgets =& CreateObject('felamimail.uiwidgets');
// (regis) seems to be necessary to reopen...
$this->bofelamimail->reopen($this->mailbox);
#print "$this->mailbox, $this->uid, $partID
";
$headers = $this->bofelamimail->getMessageHeader($this->uid, $partID);
#_debug_array($headers);exit;
$rawheaders = $this->bofelamimail->getMessageRawHeader($this->uid, $partID);
$attachments = $this->bofelamimail->getMessageAttachments($this->uid, $partID);
#_debug_array($attachments); exit;
$envelope = $this->bofelamimail->getMessageEnvelope($this->uid, $partID);
$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'])); } // reset $rawheaders $rawheaders = ""; // create it new, with good line breaks reset($newRawHeaders); while(list($key,$value) = @each($newRawHeaders)) { $rawheaders .= wordwrap($value, 90, "\n "); } $this->bofelamimail->closeConnection(); $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()); } $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_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(); // if(!isset($_GET['printable'])) // { // navbar start // reply url $linkData = array ( 'menuaction' => 'felamimail.uicompose.reply', 'icServer' => $this->icServer, 'folder' => base64_encode($this->mailbox), 'reply_id' => $this->uid, ); if($partID != '') { $linkData['part_id'] = $partID; } $replyURL = $GLOBALS['egw']->link('/index.php',$linkData); // reply all url $linkData = array ( 'menuaction' => 'felamimail.uicompose.replyAll', 'icServer' => $this->icServer, 'folder' => base64_encode($this->mailbox), 'reply_id' => $this->uid, ); if($partID != '') { $linkData['part_id'] = $partID; } $replyAllURL = $GLOBALS['egw']->link('/index.php',$linkData); // forward url $linkData = array ( 'menuaction' => 'felamimail.uicompose.forward', 'reply_id' => $this->uid, 'folder' => base64_encode($this->mailbox), ); if($partID != '') { $linkData['part_id'] = $partID; } $forwardURL = $GLOBALS['egw']->link('/index.php',$linkData); //delete url $linkData = array ( 'menuaction' => 'felamimail.uifelamimail.deleteMessage', 'icServer' => $this->icServer, 'folder' => base64_encode($this->mailbox), 'message' => $this->uid, ); $deleteURL = $GLOBALS['egw']->link('/index.php',$linkData); $navbarImages = array( 'mail_reply' => array( 'action' => "window.location.href = '$replyURL'", 'tooltip' => lang('reply'), ), 'mail_replyall' => array( 'action' => "window.location.href = '$replyAllURL'", 'tooltip' => lang('reply all'), ), 'mail_forward' => array( 'action' => "window.location.href = '$forwardURL'", 'tooltip' => lang('forward'), ), 'delete' => array( 'action' => "window.location.href = '$deleteURL'", 'tooltip' => lang('delete'), ), ); foreach($navbarImages as $buttonName => $buttonInfo) { $navbarButtons .= $uiWidgets->navbarButton($buttonName, $buttonInfo['action'], $buttonInfo['tooltip']); } $navbarButtons .= $uiWidgets->navbarSeparator(); // print url $linkData = array ( 'menuaction' => 'felamimail.uidisplay.printMessage', 'uid' => $this->uid ); if($partID != '') { $linkData['part'] = $partID; } $printURL = $GLOBALS['egw']->link('/index.php',$linkData); $to_infologURL = $GLOBALS['egw']->link('/index.php',array( 'menuaction' => 'infolog.uiinfolog.import_mail', 'uid' => $this->uid, 'mailbox' => $this->mailbox )); // viewheader url $linkData = array ( 'menuaction' => 'felamimail.uidisplay.displayHeader', 'uid' => $this->uid ); if($partID != '') { $linkData['part'] = $partID; } $viewHeaderURL = $GLOBALS['egw']->link('/index.php',$linkData); $navbarImages = array(); // viewheader url $linkData = array ( 'menuaction' => 'felamimail.uidisplay.saveMessage', 'uid' => $this->uid ); if($partID != '') { $linkData['part'] = $partID; } $saveMessageURL = $GLOBALS['egw']->link('/index.php',$linkData); $navbarImages = array(); //print email $navbarImages = array( 'fileprint' => array( 'action' => "window.location.href = '$printURL'", 'tooltip' => lang('print it'), ), 'to_infolog' => array( 'action' => "window.open('$to_infologURL','_blank','dependent=yes,width=750,height=550,scrollbars=yes,status=yes')", 'tooltip' => lang('save as infolog'), ), ); // save email as $navbarImages['fileexport'] = array( 'action' => "window.location.href = '$saveMessageURL'", 'tooltip' => lang('save message to disk'), ); // view header lines $navbarImages['kmmsgread'] = array( 'action' => "fm_displayHeaderLines('$viewHeaderURL')", 'tooltip' => lang('view header lines'), ); foreach($navbarImages as $buttonName => $buttonData) { $navbarButtons .= $uiWidgets->navbarButton($buttonName, $buttonData['action'], $buttonData['tooltip']); } $this->t->set_var('navbarButtonsLeft',$navbarButtons); $navbarButtons = ''; $navbarImages = array(); #_debug_array($nextMessage); exit; if($nextMessage['previous']) { $linkData = array ( 'menuaction' => 'felamimail.uidisplay.display', 'showHeader' => 'false', 'uid' => $nextMessage['previous'] ); $previousURL = $GLOBALS['egw']->link('/index.php',$linkData); $previousURL = "window.location.href = '$previousURL'"; $navbarImages['up.button'] = array( 'action' => $previousURL, 'tooltip' => lang('previous message'), ); } else { $previousURL = ''; } if($nextMessage['next']) { $linkData = array ( 'menuaction' => 'felamimail.uidisplay.display', 'showHeader' => 'false', 'uid' => $nextMessage['next'] ); $nextURL = $GLOBALS['egw']->link('/index.php',$linkData); $nextURL = "window.location.href = '$nextURL'"; $navbarImages['down.button'] = array( 'action' => $nextURL, 'tooltip' => lang('next message'), ); } else { $nextURL = ''; } 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 = $this->emailAddressToHTML($envelope['SENDER']); $fromAddress = $this->emailAddressToHTML($envelope['FROM'], $organization); $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 = $this->emailAddressToHTML($envelope['FROM'], $organization); $this->t->set_var("from_data", $fromAddress); $this->t->set_var('on_behalf_of_part',''); } // parse the to header $toAddress = $this->emailAddressToHTML($envelope['TO']); $this->t->set_var("to_data",$toAddress); // parse the cc header if(count($envelope['CC'])) { $ccAddress = $this->emailAddressToHTML($envelope['CC']); $this->t->set_var("cc_data",$ccAddress); $this->t->parse('cc_data_part','message_cc',True); } else { $this->t->set_var("cc_data_part",''); } $this->t->set_var("date_received", @htmlspecialchars($GLOBALS['egw']->common->show_date(strtotime($headers['DATE'])), ENT_QUOTES,$this->displayCharset)); $this->t->set_var("subject_data", @htmlspecialchars($this->bofelamimail->decode_header(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT'])), 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 ); $this->t->set_var('url_displayBody', $GLOBALS['egw']->link('/index.php',$linkData)); #$this->t->set_var("signature", $sessionData['signature']); // 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',$GLOBALS['egw']->html->image('felamimail','fileexport', lang('save'))); #$this->t->parse('attachment_rows','attachment_row_bold',True); foreach ($attachments as $key => $value) { $this->t->set_var('row_color',$this->rowColor[($key+1)%2]); $this->t->set_var('filename',$value['name'] ? @htmlentities($value['name'], ENT_QUOTES, $this->displayCharset) : lang('(no subject)')); $this->t->set_var('mimetype',$value['mimeType']); $this->t->set_var('size',$value['size']); $this->t->set_var('attachment_number',$key); switch($value['mimeType']) { case 'MESSAGE/RFC822': $linkData = array ( 'menuaction' => 'felamimail.uidisplay.display', 'uid' => $this->uid, 'part' => $value['partID'] ); $windowName = 'displayMessage_'. $this->uid; $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',700,egw_getWindowOuterHeight());"; break; case 'IMAGE/JPEG': case 'IMAGE/PNG': case 'IMAGE/GIF': #case 'application/pdf': $linkData = array ( 'menuaction' => 'felamimail.uidisplay.getAttachment', 'uid' => $this->uid, 'part' => $value['partID'] ); $windowName = 'displayAttachment_'. $this->uid; $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',800,600);"; break; default: $linkData = array ( 'menuaction' => 'felamimail.uidisplay.getAttachment', 'uid' => $this->uid, 'part' => $value['partID'] ); $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'] ); $this->t->set_var("link_save",$GLOBALS['egw']->link('/index.php',$linkData)); $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']; $this->bofelamimail->reopen($this->mailbox); $bodyParts = $this->bofelamimail->getMessageBody($this->uid,'',$partID); $this->bofelamimail->closeConnection(); $this->display_app_header(); $body = $this->getdisplayableBody($bodyParts); print '
'; print $body.' |