-/** The standard includes.. */
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'functions/html.php');
-require_once(SM_PATH . 'class/html.class.php');
-require_once(SM_PATH . 'functions/imap_mailbox.php');
-require_once(SM_PATH . 'functions/imap_messages.php');
-require_once(SM_PATH . 'functions/imap_asearch.php');
-require_once(SM_PATH . 'functions/mime.php');
-require_once(SM_PATH . 'functions/forms.php');
-
-/**
- * default value for page_selector_max
- */
-define('PG_SEL_MAX', 10);
-
-/**
- * The number of pages to cache msg headers
- */
-define('SQM_MAX_PAGES_IN_CACHE',5);
-
-/**
- * Sort constants used for sorting of messages
- */
-define('SQSORT_NONE',0);
-define('SQSORT_DATE_ASC',1);
-define('SQSORT_DATE_DEC',2);
-define('SQSORT_FROM_ASC',3);
-define('SQSORT_FROM_DEC',4);
-define('SQSORT_SUBJ_ASC',5);
-define('SQSORT_SUBJ_DEC',6);
-define('SQSORT_SIZE_ASC',7);
-define('SQSORT_SIZE_DEC',8);
-define('SQSORT_TO_ASC',9);
-define('SQSORT_TO_DEC',10);
-define('SQSORT_CC_ASC',11);
-define('SQSORT_CC_DEC',12);
-define('SQSORT_INT_DATE_ASC',13);
-define('SQSORT_INT_DATE_DEC',14);
-
-define('SQSORT_THREAD',32);
-
-
-define('MBX_PREF_SORT',0);
-define('MBX_PREF_LIMIT',1);
-define('MBX_PREF_AUTO_EXPUNGE',2);
-define('MBX_PREF_INTERNALDATE',3);
-define('SQM_MAX_MBX_IN_CACHE',3);
-// define('MBX_PREF_FUTURE',unique integer key);
-
-/**
- * @param mixed $start UNDOCUMENTED
- */
-function elapsed($start) {
-
- $end = microtime();
- list($start2, $start1) = explode(" ", $start);
- list($end2, $end1) = explode(" ", $end);
- $diff1 = $end1 - $start1;
- $diff2 = $end2 - $start2;
- if( $diff2 < 0 ){
- $diff1 -= 1;
- $diff2 += 1.0;
- }
- return $diff2 + $diff1;
-}
-
-/**
- * Displays message header row in messages list
- *
- * @param array $aMsg contains all message related parameters
- * @return void
- */
-
-function printMessageInfo($aMsg) {
- // FIX ME, remove these globals as well by adding an array as argument for the user settings
- // specificly meant for header display
- global $checkall,
- $color,
- $default_use_priority,
- $message_highlight_list,
- $index_order,
- $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
- $email_address,
- $show_recipient_instead, /* show recipient name instead of default identity */
- $use_icons, /* indicates to use icons or text markers */
- $icon_theme, /* icons theming */
- $javascript_on,
- $fancy_index_highlite;
-
- $color_string = $color[4];
-
- // initialisation:
- $mailbox = $aMsg['MAILBOX'];
- $msg = $aMsg['HEADER'];
- $t = $aMsg['INDX'];
- $start_msg = $aMsg['PAGEOFFSET'];
- $last = $aMsg['LAST'];
- if (isset($aMsg['SEARCH']) && count($aMsg['SEARCH']) >1 ) {
- $where = $aMsg['SEARCH'][0];
- $what = $aMsg['SEARCH'][1];
- } else {
- $where = false;
- $what = false;
- }
- $iIndent = $aMsg['INDENT'];
-
- $sSubject = (isset($msg['SUBJECT']) && $msg['SUBJECT'] != '') ? $msg['SUBJECT'] : _("(no subject)");
- $sFrom = (isset($msg['FROM'])) ? $msg['FROM'] : _("Unknown sender");
- $sTo = (isset($msg['TO'])) ? $msg['TO'] : _("Unknown recipient");
- $sCc = (isset($msg['CC'])) ? $msg['CC'] : '';
- $aFlags = (isset($msg['FLAGS'])) ? $msg['FLAGS'] : array();
- $iPrio = (isset($msg['PRIORITY'])) ? $msg['PRIORITY'] : 3;
- $iSize = (isset($msg['SIZE'])) ? $msg['SIZE'] : 0;
-
- // These don't appear to be used... are they safe to remove
- $sType0 = (isset($msg['TYPE0'])) ? $msg['TYPE0'] : 'text';
- $sType1 = (isset($msg['TYPE1'])) ? $msg['TYPE1'] : 'plain';
- if (isset($msg['INTERNALDATE'])) {
- $sDate = getDateString(getTimeStamp(explode(' ',$msg['INTERNALDATE'])));
- } else {
- $sDate = (isset($msg['DATE'])) ? getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : '';
- }
- $iId = (isset($msg['UID'])) ? $msg['UID'] : false;
-
- if (!$iId) {
- return;
- }
-
- if ($GLOBALS['alt_index_colors']) {
- if (!($t % 2)) {
- if (!isset($color[12])) {
- $color[12] = '#EAEAEA';
- }
- $color_string = $color[12];
- }
- }
-
- $urlMailbox = urlencode($mailbox);
-
- // FIXME, foldertype should be set in right_main.php
- // in other words, handle as sent is obsoleted from now.
- // We replace that by providing an array to aMailbox with the to shown headers
- // that way we are free to show the user different layouts for different folders
- $bSentFolder = handleAsSent($mailbox);
- if ((!$bSentFolder) && ($show_recipient_instead)) {
- // If the From address is the same as $email_address, then handle as Sent
- $from_array = parseAddress($sFrom, 1);
- if (!isset($email_address)) {
- global $data_dir, $username;
- $email_address = getPref($data_dir, $username, 'email_address');
- }
- $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
- } else {
- $bHandleAsSent = $bSentFolder;
- }
- // If this is a Sent message, display To address instead of From
- if ($bHandleAsSent) {
- $sFrom = $sTo;
- }
- // Passing 1 below results in only 1 address being parsed, thus defeating the following code
- $sFrom = parseAddress($sFrom/*,1*/);
-
- /*
- * This is done in case you're looking into Sent folders,
- * because you can have multiple receivers.
- */
- $senderNames = $sFrom;
- $senderName = '';
- $senderAddress = '';
- if (sizeof($senderNames)){
- foreach ($senderNames as $senderNames_part) {
- if ($senderName != '') {
- $senderName .= ', ';
- $senderAddress .= ', ';
- }
- $sender_address_part = htmlspecialchars($senderNames_part[0]);
- $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
- if ($sender_name_part) {
- $senderName .= $sender_name_part;
- $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
- } else {
- $senderName .= $sender_address_part;
- $senderAddress .= $sender_address_part;
- }
- }
- }
- // If Sent, prefix with To: but only if not Sent folder
- if ($bHandleAsSent ^ $bSentFolder) {
- $senderName = _("To") . ': ' . $senderName;
- $senderAddress = _("To") . ': ' . $senderAddress;
- }
-
- // this is a column property which can apply to multiple columns. Do not use vars for one column
- // only. instead we should use something like this:
- // 1ed column $aMailbox['columns']['SUBJECT'] value: aray with properties ...
- // 2ed column $aMailbox['columns']['FROM'] value: aray with properties ...
- // NB in case of the sentfolder this could be the TO field
- // properties array example:
- // 'truncate' => length (0 is no truncate)
- // 'prefix => if (x in b then do that )
- if ($truncate_sender > 0) {
- $senderName = truncateWithEntities($senderName, $truncate_sender);
- }
-
- $flag = $flag_end = $fontstr = $fontstr_end = $italic = $italic_end = '';
- $bold = '<b>';
- $bold_end = '</b>';
-
- foreach ($aFlags as $sFlag => $value) {
- switch ($sFlag) {
- case '\\flagged':
- if ($value) {
- $flag = "<font color=\"$color[2]\">";
- $flag_end = '</font>';
- }
- break;
- case '\\seen':
- if ($value) {
- $bold = '';
- $bold_end = '';
- }
- break;
- case '\\deleted':
- if ($value) {
- $fontstr = "<font color=\"$color[9]\">";
- $fontstr_end = '</font>';
- }
- break;
- }
- }
- if ($bHandleAsSent) {
- $italic = '<i>';
- $italic_end = '</i>';
- }
-
- if ($where && $what) {
- $searchstr = '&where='.$where.'&what='.$what;
- } else {
- $searchstr = '';
- }
- /*
- * Message highlight code
- */
- $matches = array('TO' => 'sTo', 'CC' => 'sCc', 'FROM' => 'sFrom', 'SUBJECT' => 'sSubject');
- if (is_array($message_highlight_list) && count($message_highlight_list)) {
- $sTo = parseAddress($sTo);
- $sCc = parseAddress($sCc);
- foreach ($message_highlight_list as $message_highlight_list_part) {
- if (trim($message_highlight_list_part['value']) != '') {
- $high_val = strtolower($message_highlight_list_part['value']);
- $match_type = strtoupper($message_highlight_list_part['match_type']);
- if($match_type == 'TO_CC') {
- $match = array('TO', 'CC');
- } else {
- $match = array($match_type);
- }
- foreach($match as $match_type) {
- switch($match_type) {
- case('TO'):
- case('CC'):
- case('FROM'):
- foreach ($$matches[$match_type] as $address) {
- $address[0] = decodeHeader($address[0], true, false);
- $address[1] = decodeHeader($address[1], true, false);
- if (strstr('^^' . strtolower($address[0]), $high_val) ||
- strstr('^^' . strtolower($address[1]), $high_val)) {
- $hlt_color = $message_highlight_list_part['color'];
- break 4;
- }
- }
- break;
- default:
- $headertest = strtolower(decodeHeader($$matches[$match_type], true, false));
- if (strstr('^^' . $headertest, $high_val)) {
- $hlt_color = $message_highlight_list_part['color'];
- break 3;
- }
- break;
- }
- }
- }
- }
- } /* end Message highlight code */
-
- if (!isset($hlt_color)) {
- $hlt_color = $color_string;
- }
- $col = 0;
- $sSubject = str_replace(' ', ' ', decodeHeader($sSubject));
- $subject = processSubject($sSubject, $iIndent);
-
-
- $row_extra = 'valign="top"';
-
-
- // this stuff does the auto row highlighting on mouseover
- //
- if ($javascript_on && $fancy_index_highlite) {
-
- $mouseoverColor = $color[5];
-
- // set this to an empty string to turn off extra
- // highlighting of checked rows
- //
- //$clickedColor = '';
- $clickedColor = $color[2];
-
- $row_extra .= ' onmouseover="setPointer(this, ' . $t . ', \'over\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');" onmouseout="setPointer(this, ' . $t . ', \'out\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');" onmousedown="setPointer(this, ' . $t . ', \'click\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');"';
-
- }
-
-
- echo html_tag( 'tr','','','',$row_extra) . "\n";
-
-
- // this does the auto-checking of the checkbox no matter
- // where on the row you click
- //
- $javascript_auto_click = '';
- if ($javascript_on && $fancy_index_highlite)
- $javascript_auto_click = ' onMouseDown="row_click(\'msg[' . $t . ']\')"';
-
-
- if (sizeof($index_order)) {
-
- // figure out which columns should serve as labels for checkbox:
- // we try to grab the two columns before and after the checkbox,
- // except the subject column, since it is the link that opens
- // the message view
- //
- // if $javascript_on is set, then the highlighting code takes
- // care of this; just skip it
- //
- $show_label_columns = array();
- if (!($javascript_on && $fancy_index_highlite)) {
- $get_next_two = 0;
- $last_order_part = 0;
- $last_last_order_part = 0;
- foreach ($index_order as $index_order_part) {
-
- if ($index_order_part == 1) {
- $get_next_two = 1;
- if ($last_last_order_part != 4)
- $show_label_columns[] = $last_last_order_part;
- if ($last_order_part != 4)
- $show_label_columns[] = $last_order_part;
-
- } else if ($get_next_two > 0 && $get_next_two < 3 && $index_order_part != 4) {
- $show_label_columns[] = $index_order_part;
- $get_next_two++;
- }
- $last_last_order_part = $last_order_part;
- $last_order_part = $index_order_part;
- }
- }
-
-
- // build the actual columns for display
- //
- foreach ($index_order as $index_order_part) {
- if (in_array($index_order_part, $show_label_columns)) {
- $label_start = '<label for="msg[' . $t . ']">';
- $label_end = '</label>';
- } else {
- $label_start = '';
- $label_end = '';
- }
- switch ($index_order_part) {
- case 1: /* checkbox */
- echo html_tag( 'td',
- addCheckBox("msg[$t]", $checkall, $iId),
- 'center',
- $hlt_color );
- break;
- case 2: /* from */
- if ($senderAddress != $senderName) {
- $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
- $title = ' title="' . str_replace(array('"', '<', '>'), array("''", '<', '>'), $senderAddress) . '"';
- } else {
- $title = '';
- }
- echo html_tag( 'td',
- $label_start . $italic . $bold . $flag . $fontstr . $senderName .
- $fontstr_end . $flag_end . $bold_end . $italic_end . $label_end,
- 'left',
- $hlt_color, $title . $javascript_auto_click);
- break;
- case 3: /* date */
- if ($sDate == '') {
- $sDate = _("Unknown date");
- }
- echo html_tag( 'td',
- $label_start . $bold . $flag . $fontstr . $sDate .
- $fontstr_end . $flag_end . $bold_end . $label_end,
- 'center',
- $hlt_color,
- 'style="white-space: nowrap;"' . $javascript_auto_click );
- break;
- case 4: /* subject */
- $td_str = $bold;
- if ($iIndent) {
- $td_str .= str_repeat(" ",$iIndent);
- }
- $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
- . '&passed_id='. $iId
- . '&startMessage='.$start_msg.$searchstr.'"';
-
- // don't highlight the row or check the checkbox
- // when clicking subject link (when fancy highlighting is on)
- //
- // parentNode property is DOM Level 1
- //
- if ($javascript_on && $fancy_index_highlite)
- $td_str .= ' onClick="row_click(\'msg[' . $t . ']\'); setPointer(this.parentNode.parentNode, ' . $t . ', \'click\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');"';
-
- $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
- if ($subject != $sSubject) {
- $title = get_html_translation_table(HTML_SPECIALCHARS);
- $title = array_flip($title);
- $title = strtr($sSubject, $title);
- $title = str_replace(array('"', '<', '>'), array("''", '<', '>'), $title);
- $td_str .= " title=\"$title\"";
- }
- $td_str .= ">$flag$subject$flag_end</a>$bold_end";
- echo html_tag( 'td', $td_str, 'left', $hlt_color, $javascript_auto_click );
- break;
- case 5: /* flags */
-
- // icon message markers
- //
- if ($use_icons && $icon_theme != 'none') {
- $td_str = "<b><small>";
- if (isset($aFlags['\\flagged']) && $aFlags['\\flagged'] == true) {
- $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/flagged.png" border="0" height="10" width="10" /> ';
- }
- if ($default_use_priority) {
- if ( ($iPrio == 1) || ($iPrio == 2) ) {
- $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_high.png" border="0" height="10" width="5" /> ';
- }
- else if ($iPrio == 5) {
- $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_low.png" border="0" height="10" width="5" /> ';
- }
- else {
- $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="5" /> ';
- }
- }
- if ($sType1 == 'mixed') {
- $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/attach.png" border="0" height="10" width="6" />';
- } else {
- $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="6" />';
- }
-
- $msg_icon = '';
- if (!isset($aFlags['\\seen']) || ($aFlags['\\seen']) == false) {
- $msg_alt = '(' . _("New") . ')';
- $msg_title = '(' . _("New") . ')';
- $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_new';
- } else {
- $msg_alt = '(' . _("Read") . ')';
- $msg_title = '(' . _("Read") . ')';
- $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_read';
- }
- if (isset($aFlags['\\deleted']) && ($aFlags['\\deleted']) == true) {
- $msg_icon .= '_deleted';
- }
- if (isset($aFlags['\\answered']) && ($aFlags['\\answered']) == true) {
- $msg_alt = '(' . _("Answered") . ')';
- $msg_title = '(' . _("Answered") . ')';
- $msg_icon .= '_reply';
- }
- $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />';
- $td_str .= '</small></b>';
- echo html_tag( 'td',
- $label_start . $td_str . $label_end,
- 'right',
- $hlt_color,
- 'style="white-space: nowrap;"' . $javascript_auto_click );
- }
-
- // plain text message markers
- //
- else {
- $stuff = false;
- $td_str = "<b><small>";
- if (isset($aFlags['\\answered']) && $aFlags['\\answered'] == true) {
- $td_str .= _("A");
- $stuff = true;
- }
- if ($sType1 == 'mixed') {
- $td_str .= '+';
- $stuff = true;
- }
- if ($default_use_priority) {
- if ( ($iPrio == 1) || ($iPrio == 2) ) {
- $td_str .= "<font color=\"$color[1]\">!</font>";
- $stuff = true;
- }
- if ($iPrio == 5) {
- $td_str .= "<font color=\"$color[8]\">?</font>";
- $stuff = true;
- }
- }
- if (isset($aFlags['\\deleted']) && $aFlags['\\deleted'] == true) {
- $td_str .= "<font color=\"$color[1]\">D</font>";
- $stuff = true;
- }
- if (!$stuff) {
- $td_str .= ' ';
- }
- $td_str .= '</small></b>';
- echo html_tag( 'td',
- $label_start . $td_str . $label_end,
- 'center',
- $hlt_color,
- 'style="white-space: nowrap;"' . $javascript_auto_click );
- }
- break;
- case 6: /* size */
- echo html_tag( 'td',
- $label_start . $bold . $fontstr . show_readable_size($iSize) .
- $fontstr_end . $bold_end . $label_end,
- 'right',
- $hlt_color, $javascript_auto_click );
- break;
- }
- ++$col;
- }
- }
- /* html for separationlines between rows */
- if ($last) {
- echo '</tr>'."\n";
- } else {
- echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
- $color[0] . '" height="1"></td></tr>' . "\n";
- }
-}
-
-
-function setUserPref($username, $pref, $value) {
- global $data_dir;
- setPref($data_dir,$username,$pref,$value);
-}