/**
 * FIXME: Undocumented function
 */
function processSubject($subject, $threadlevel = 0)
{
    /* Shouldn't ever happen -- caught too many times in the IMAP functions */
    if ($subject == '') {
        return _("(no subject)");
    }
    global $truncate_subject;
    /* number of characters for Subject field (<= 0 for unchanged) */
    $trim_at = $truncate_subject;
    /* if this is threaded, subtract two chars per indentlevel */
    if ($threadlevel > 0 && $threadlevel <= 10) {
        $trim_at -= 2 * $threadlevel;
    }
    return truncateWithEntities($subject, $trim_at);
}
Example #2
0
function printMessageInfo($imapConnection, $t, $not_last = true, $key, $mailbox, $start_msg, $where, $what)
{
    global $checkall, $preselected, $color, $msgs, $msort, $td_str, $msg, $default_use_priority, $message_highlight_list, $index_order, $indent_array, $pos, $thread_sort_messages, $server_sort_order, $row_count, $allow_server_sort, $truncate_subject, $truncate_sender;
    $color_string = $color[4];
    if ($GLOBALS['alt_index_colors']) {
        if (!isset($row_count)) {
            $row_count = 0;
        }
        $row_count++;
        if ($row_count % 2) {
            if (!isset($color[12])) {
                $color[12] = '#EAEAEA';
            }
            $color_string = $color[12];
        }
    }
    $msg = $msgs[$key];
    if ($mailbox == 'None') {
        $boxes = sqimap_mailbox_list($imapConnection);
        $mailbox = $boxes[0]['unformatted'];
        unset($boxes);
    }
    $urlMailbox = urlencode($mailbox);
    if (handleAsSent($mailbox)) {
        $msg['FROM'] = $msg['TO'];
    }
    $msg['FROM'] = parseAddress($msg['FROM'], 1);
    /*
     * This is done in case you're looking into Sent folders,
     * because you can have multiple receivers.
     */
    $senderNames = $msg['FROM'];
    $senderName = '';
    $senderFrom = '';
    if (sizeof($senderNames)) {
        foreach ($senderNames as $senderNames_part) {
            if ($senderName != '') {
                $senderName .= ', ';
            }
            if ($senderFrom != '') {
                $senderFrom .= ', ';
            }
            if ($senderNames_part[1]) {
                $senderName .= decodeHeader($senderNames_part[1]);
            } else {
                $senderName .= htmlspecialchars($senderNames_part[0]);
            }
            $senderFrom .= htmlspecialchars($senderNames_part[0]);
        }
    }
    $senderName = str_replace('&nbsp;', ' ', $senderName);
    echo html_tag('tr', '', '', '', 'valign="top"') . "\n";
    if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true) {
        $flag = "<font color=\"{$color['2']}\">";
        $flag_end = '</font>';
    } else {
        $flag = '';
        $flag_end = '';
    }
    if (!isset($msg['FLAG_SEEN']) || $msg['FLAG_SEEN'] == false) {
        $bold = '<b>';
        $bold_end = '</b>';
    } else {
        $bold = '';
        $bold_end = '';
    }
    if (handleAsSent($mailbox)) {
        $italic = '<i>';
        $italic_end = '</i>';
    } else {
        $italic = '';
        $italic_end = '';
    }
    if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
        $fontstr = "<font color=\"{$color['9']}\">";
        $fontstr_end = '</font>';
    } else {
        $fontstr = '';
        $fontstr_end = '';
    }
    if ($where && $what) {
        $searchstr = '&amp;where=' . $where . '&amp;what=' . $what;
    } else {
        $searchstr = '';
    }
    if (is_array($message_highlight_list) && count($message_highlight_list)) {
        $msg['TO'] = parseAddress($msg['TO']);
        $msg['CC'] = parseAddress($msg['CC']);
        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 ($msg[$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($msg[$match_type], true, false));
                            if (strstr('^^' . $headertest, $high_val)) {
                                $hlt_color = $message_highlight_list_part['color'];
                                break 3;
                            }
                            break;
                    }
                }
            }
        }
    }
    if (!isset($hlt_color)) {
        $hlt_color = $color_string;
    }
    if ($checkall == 1 || in_array($msg['ID'], $preselected)) {
        $checked = ' checked="checked"';
    } else {
        $checked = '';
    }
    $col = 0;
    $msg['SUBJECT'] = decodeHeader($msg['SUBJECT']);
    //    $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
    $subject = truncateWithEntities(str_replace('&nbsp;', ' ', $msg['SUBJECT']), $truncate_subject);
    if (sizeof($index_order)) {
        foreach ($index_order as $index_order_part) {
            switch ($index_order_part) {
                case 1:
                    /* checkbox */
                    echo html_tag('td', "<input type=\"checkbox\" name=\"msg[{$t}]\" id=\"msg" . $msg['ID'] . "\" value=\"" . $msg['ID'] . "\"{$checked}>", 'center', $hlt_color);
                    break;
                case 2:
                    /* from */
                    $from_xtra = '';
                    $from_xtra = 'title="' . $senderFrom . '"';
                    echo html_tag('td', html_tag('label', $italic . $bold . $flag . $fontstr . truncateWithEntities($senderName, $truncate_sender) . $fontstr_end . $flag_end . $bold_end . $italic_end, '', '', 'for="msg' . $msg['ID'] . '"'), 'left', $hlt_color, $from_xtra);
                    break;
                case 3:
                    /* date */
                    $date_string = $msg['DATE_STRING'] . '';
                    if ($date_string == '') {
                        $date_string = _("Unknown date");
                    }
                    echo html_tag('td', $bold . $flag . $fontstr . $date_string . $fontstr_end . $flag_end . $bold_end, 'center', $hlt_color, 'nowrap');
                    break;
                case 4:
                    /* subject */
                    $td_str = $bold;
                    if ($thread_sort_messages == 1) {
                        if (isset($indent_array[$msg['ID']])) {
                            $td_str .= str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;", $indent_array[$msg['ID']]);
                        }
                    }
                    $td_str .= '<a href="read_body.php?mailbox=' . $urlMailbox . '&amp;passed_id=' . $msg["ID"] . '&amp;startMessage=' . $start_msg . $searchstr . '"';
                    $td_str .= ' ' . concat_hook_function('subject_link', array($start_msg, $searchstr));
                    if ($subject != $msg['SUBJECT']) {
                        $title = get_html_translation_table(HTML_SPECIALCHARS);
                        $title = array_flip($title);
                        $title = strtr($msg['SUBJECT'], $title);
                        $title = str_replace('"', "''", $title);
                        $td_str .= " title=\"{$title}\"";
                    }
                    $td_str .= ">{$flag}{$subject}{$flag_end}</a>{$bold_end}";
                    echo html_tag('td', $td_str, 'left', $hlt_color);
                    break;
                case 5:
                    /* flags */
                    $stuff = false;
                    $td_str = "<b><small>";
                    if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
                        $td_str .= _("A");
                        $stuff = true;
                    }
                    if ($msg['TYPE0'] == 'multipart' && $msg['TYPE1'] == 'mixed') {
                        $td_str .= '+';
                        $stuff = true;
                    }
                    if ($default_use_priority) {
                        if ($msg['PRIORITY'] == 1 || $msg['PRIORITY'] == 2) {
                            $td_str .= "<font color=\"{$color['1']}\">!</font>";
                            $stuff = true;
                        }
                        if ($msg['PRIORITY'] == 5) {
                            $td_str .= "<font color=\"{$color['8']}\">?</font>";
                            $stuff = true;
                        }
                    }
                    if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
                        $td_str .= "<font color=\"{$color['1']}\">D</font>";
                        $stuff = true;
                    }
                    if (!$stuff) {
                        $td_str .= '&nbsp;';
                    }
                    do_hook("msg_envelope");
                    $td_str .= '</small></b>';
                    echo html_tag('td', $td_str, 'center', $hlt_color, 'nowrap');
                    break;
                case 6:
                    /* size */
                    echo html_tag('td', $bold . $fontstr . show_readable_size($msg['SIZE']) . $fontstr_end . $bold_end, 'right', $hlt_color);
                    break;
            }
            ++$col;
        }
    }
    if ($not_last) {
        echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' . $color[0] . '" height="1"></td></tr>' . "\n";
    } else {
        echo '</tr>' . "\n";
    }
}