예제 #1
0
/**
 * This function loops through a group of messages in the mailbox
 * and shows them to the user.
 *
 * @param resource $imapConnection
 * @param array    $aMailbox associative array with mailbox related vars
 * @param array    $aProps
 * @param int      $iError error code, 0 is no error
 */
function showMessagesForMailbox($imapConnection, &$aMailbox, $aProps, &$iError)
{
    global $PHP_SELF;
    global $boxes, $show_copy_buttons;
    $highlight_list = isset($aProps['config']['highlight_list']) ? $aProps['config']['highlight_list'] : false;
    $fancy_index_highlite = isset($aProps['config']['fancy_index_highlite']) ? $aProps['config']['fancy_index_highlite'] : true;
    $aColumnsDesc = isset($aProps['columns']) ? $aProps['columns'] : false;
    $iAccount = isset($aProps['account']) ? (int) $aProps['account'] : 0;
    $sMailbox = isset($aProps['mailbox']) ? $aProps['mailbox'] : false;
    $sTargetModule = isset($aProps['module']) ? $aProps['module'] : 'read_body';
    $show_flag_buttons = isset($aProps['config']['show_flag_buttons']) ? $aProps['config']['show_flag_buttons'] : true;
    /* allows to control copy button in function call. If array key is not set, code follows user preferences */
    if (isset($aProps['config']['show_copy_buttons'])) {
        $show_copy_buttons = $aProps['config']['show_copy_buttons'];
    }
    $lastTargetMailbox = isset($aProps['config']['lastTargetMailbox']) ? $aProps['config']['lastTargetMailbox'] : '';
    $aOrder = array_keys($aProps['columns']);
    $trash_folder = isset($aProps['config']['trash_folder']) && $aProps['config']['trash_folder'] ? $aProps['config']['trash_folder'] : false;
    $sent_folder = isset($aProps['config']['sent_folder']) && $aProps['config']['sent_folder'] ? $aProps['config']['sent_folder'] : false;
    $draft_folder = isset($aProps['config']['draft_folder']) && $aProps['config']['draft_folder'] ? $aProps['config']['draft_folder'] : false;
    $page_selector = isset($aProps['config']['page_selector']) ? $aProps['config']['page_selector'] : false;
    $page_selector_max = isset($aProps['config']['page_selector_max']) ? $aProps['config']['page_selector_max'] : 10;
    $color = $aProps['config']['color'];
    /*
     * Form ID
     */
    static $iFormId;
    if (!isset($iFormId)) {
        $iFormId = 1;
    } else {
        ++$iFormId;
    }
    // store the columns to fetch so we can pick them up in read_body
    // where we validate the cache.
    calcFetchColumns($aMailbox, $aProps);
    $iError = fetchMessageHeaders($imapConnection, $aMailbox);
    if ($iError) {
        return array();
    } else {
        $aMessages = prepareMessageList($aMailbox, $aProps);
    }
    $iSetIndx = $aMailbox['SETINDEX'];
    $iLimit = $aMailbox['SHOWALL'][$iSetIndx] ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
    $iEnd = $aMailbox['PAGEOFFSET'] + ($iLimit - 1) < $aMailbox['EXISTS'] ? $aMailbox['PAGEOFFSET'] + $iLimit - 1 : $aMailbox['EXISTS'];
    $iNumberOfMessages = $aMailbox['TOTAL'][$iSetIndx];
    $iEnd = min($iEnd, $iNumberOfMessages);
    $php_self = $PHP_SELF;
    $urlMailbox = urlencode($aMailbox['NAME']);
    if (preg_match('/^(.+)\\?.+$/', $php_self, $regs)) {
        $source_url = $regs[1];
    } else {
        $source_url = $php_self;
    }
    $baseurl = $source_url . '?mailbox=' . urlencode($aMailbox['NAME']) . '&amp;account=' . $aMailbox['ACCOUNT'] . (strpos($source_url, 'src/search.php') ? '&amp;smtoken=' . sm_generate_security_token() : '');
    $where = urlencode($aMailbox['SEARCH'][$iSetIndx][0]);
    $what = urlencode($aMailbox['SEARCH'][$iSetIndx][1]);
    $baseurl .= '&amp;where=' . $where . '&amp;what=' . $what;
    /* build thread sorting links */
    $newsort = $aMailbox['SORT'];
    if (sqimap_capability($imapConnection, 'THREAD')) {
        if ($aMailbox['SORT'] & SQSORT_THREAD) {
            $newsort -= SQSORT_THREAD;
            $thread_name = _("Unthread View");
        } else {
            $thread_name = _("Thread View");
            $newsort = $aMailbox['SORT'] + SQSORT_THREAD;
        }
        $thread_link_uri = $baseurl . '&amp;srt=' . $newsort . '&amp;startMessage=1';
    } else {
        $thread_link_uri = '';
        $thread_name = '';
    }
    $sort = $aMailbox['SORT'];
    /* FIX ME ADD CHECKBOX CONTROL. No checkbox => no buttons */
    /* future admin control over displayable buttons */
    $aAdminControl = array('markFlagged' => 1, 'markUnflagged' => 1, 'markRead' => 1, 'markUnread' => 1, 'forward' => 1, 'delete' => 1, 'undeleteButton' => 1, 'bypass_trash' => 1, 'expungeButton' => 1, 'moveButton' => 1, 'copyButton' => 1);
    /* user prefs control */
    $aUserControl = array('markFlagged' => $show_flag_buttons, 'markUnflagged' => $show_flag_buttons, 'markRead' => 1, 'markUnread' => 1, 'forward' => 1, 'delete' => 1, 'undeleteButton' => 1, 'bypass_trash' => 1, 'expungeButton' => 1, 'moveButton' => 1, 'copyButton' => $show_copy_buttons);
    $showDelete = $aMailbox['RIGHTS'] != 'READ-ONLY' && in_array('\\deleted', $aMailbox['PERMANENTFLAGS'], true) ? true : false;
    $showByPassTrash = $aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' && in_array('\\deleted', $aMailbox['PERMANENTFLAGS'], true) && $trash_folder ? true : false;
    //
    $showUndelete = !$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' && in_array('\\deleted', $aMailbox['PERMANENTFLAGS'], true) ? true : false;
    $showMove = $aMailbox['RIGHTS'] != 'READ-ONLY' ? true : false;
    $showExpunge = !$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' && in_array('\\deleted', $aMailbox['PERMANENTFLAGS'], true) ? true : false;
    /* Button options that depend on IMAP server and selected folder */
    $aImapControl = array('markUnflagged' => in_array('\\flagged', $aMailbox['PERMANENTFLAGS'], true), 'markFlagged' => in_array('\\flagged', $aMailbox['PERMANENTFLAGS'], true), 'markRead' => in_array('\\seen', $aMailbox['PERMANENTFLAGS'], true), 'markUnread' => in_array('\\seen', $aMailbox['PERMANENTFLAGS'], true), 'forward' => 1, 'delete' => $showDelete, 'undeleteButton' => $showUndelete, 'bypass_trash' => $showByPassTrash, 'expungeButton' => $showExpunge, 'moveButton' => $showMove, 'copyButton' => 1);
    /* Button strings */
    $aButtonStrings = array('markFlagged' => _("Flag"), 'markUnflagged' => _("Unflag"), 'markRead' => _("Read"), 'markUnread' => _("Unread"), 'forward' => _("Forward"), 'delete' => _("Delete"), 'undeleteButton' => _("Undelete"), 'bypass_trash' => _("Bypass Trash"), 'expungeButton' => _("Expunge"), 'moveButton' => _("Move"), 'copyButton' => _("Copy"));
    /* Button access keys */
    global $accesskey_mailbox_flag, $accesskey_mailbox_unflag, $accesskey_mailbox_read, $accesskey_mailbox_unread, $accesskey_mailbox_forward, $accesskey_mailbox_delete, $accesskey_mailbox_undelete, $accesskey_mailbox_bypass_trash, $accesskey_mailbox_expunge, $accesskey_mailbox_move, $accesskey_mailbox_copy, $accesskey_mailbox_move_to;
    $aButtonAccessKeys = array('markFlagged' => $accesskey_mailbox_flag, 'markUnflagged' => $accesskey_mailbox_unflag, 'markRead' => $accesskey_mailbox_read, 'markUnread' => $accesskey_mailbox_unread, 'forward' => $accesskey_mailbox_forward, 'delete' => $accesskey_mailbox_delete, 'undeleteButton' => $accesskey_mailbox_undelete, 'bypass_trash' => $accesskey_mailbox_bypass_trash, 'expungeButton' => $accesskey_mailbox_expunge, 'moveButton' => $accesskey_mailbox_move, 'copyButton' => $accesskey_mailbox_copy);
    /**
     * Register buttons in order to an array
     * The key is the "name", the first element of the value array is the "value", second argument is the type.
     */
    $aFormElements = array();
    foreach ($aAdminControl as $k => $v) {
        if ($v & $aUserControl[$k] & $aImapControl[$k]) {
            switch ($k) {
                case 'markFlagged':
                case 'markUnflagged':
                case 'markRead':
                case 'markUnread':
                case 'delete':
                case 'undeleteButton':
                case 'expungeButton':
                case 'forward':
                    $aFormElements[$k] = array('value' => $aButtonStrings[$k], 'type' => 'submit', 'accesskey' => isset($aButtonAccessKeys[$k]) ? $aButtonAccessKeys[$k] : 'NONE');
                    break;
                case 'bypass_trash':
                    $aFormElements[$k] = array('value' => $aButtonStrings[$k], 'type' => 'checkbox', 'accesskey' => isset($aButtonAccessKeys[$k]) ? $aButtonAccessKeys[$k] : 'NONE');
                    break;
                case 'moveButton':
                case 'copyButton':
                    $aFormElements['targetMailbox'] = array('options_list' => sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes), 'type' => 'select', 'accesskey' => $accesskey_mailbox_move_to);
                    $aFormElements['mailbox'] = array('value' => $aMailbox['NAME'], 'type' => 'hidden');
                    $aFormElements['startMessage'] = array('value' => $aMailbox['PAGEOFFSET'], 'type' => 'hidden');
                    $aFormElements[$k] = array('value' => $aButtonStrings[$k], 'type' => 'submit', 'accesskey' => isset($aButtonAccessKeys[$k]) ? $aButtonAccessKeys[$k] : 'NONE');
                    break;
            }
        }
        $aFormElements['account'] = array('value' => $iAccount, 'type' => 'hidden');
    }
    do_hook('message_list_controls', $aFormElements);
    /*
     * This is the beginning of the message list table.
     * It wraps around all messages
     */
    $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
    $form_name = "FormMsgs" . $safe_name;
    //if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
    $align = array('left' => 'left', 'right' => 'right');
    //}
    //sm_print_r($align);
    /* finally set the template vars */
    // FIXME, before we support multiple templates we must review the names of the vars
    // BUMP!
    $aTemplate['color'] = $color;
    $aTemplate['form_name'] = "FormMsgs" . $safe_name;
    $aTemplate['form_id'] = 'mbx_' . $iFormId;
    $aTemplate['page_selector'] = $page_selector;
    $aTemplate['page_selector_max'] = $page_selector_max;
    $aTemplate['messagesPerPage'] = $aMailbox['LIMIT'];
    $aTemplate['showall'] = $aMailbox['SHOWALL'][$iSetIndx];
    $aTemplate['end_msg'] = $iEnd;
    $aTemplate['align'] = $align;
    $aTemplate['iNumberOfMessages'] = $iNumberOfMessages;
    $aTemplate['aOrder'] = $aOrder;
    $aTemplate['aFormElements'] = $aFormElements;
    $aTemplate['sort'] = $sort;
    $aTemplate['pageOffset'] = $aMailbox['PAGEOFFSET'];
    $aTemplate['baseurl'] = $baseurl;
    $aTemplate['aMessages'] =& $aMessages;
    $aTemplate['trash_folder'] = $trash_folder;
    $aTemplate['sent_folder'] = $sent_folder;
    $aTemplate['draft_folder'] = $draft_folder;
    $aTemplate['thread_link_uri'] = $thread_link_uri;
    $aTemplate['thread_name'] = $thread_name;
    $aTemplate['php_self'] = str_replace('&', '&amp;', $php_self);
    $aTemplate['mailbox'] = $sMailbox;
    //FIXME: javascript_on is always assigned to the template object in places like init.php; is there some reason to reassign it here?  is there some chance that it was changed?  if not, please remove this line!
    $aTemplate['javascript_on'] = isset($aProps['config']['javascript_on']) ? $aProps['config']['javascript_on'] : false;
    $aTemplate['enablesort'] = isset($aProps['config']['enablesort']) ? $aProps['config']['enablesort'] : false;
    $aTemplate['icon_theme'] = isset($aProps['config']['icon_theme']) ? $aProps['config']['icon_theme'] : false;
    $aTemplate['use_icons'] = isset($aProps['config']['use_icons']) ? $aProps['config']['use_icons'] : false;
    $aTemplate['alt_index_colors'] = isset($aProps['config']['alt_index_colors']) ? $aProps['config']['alt_index_colors'] : false;
    $aTemplate['fancy_index_highlite'] = $fancy_index_highlite;
    /**
     * Set up sort possibilities; one could argue that this is best
     * placed in the template, but most template authors won't understand
     * or need to understand it, so some advanced templates can override 
     * it if they do something different.
     */
    if (!($aTemplate['sort'] & SQSORT_THREAD) && $aTemplate['enablesort']) {
        $aTemplate['aSortSupported'] = array(SQM_COL_SUBJ => array(SQSORT_SUBJ_ASC, SQSORT_SUBJ_DESC), SQM_COL_DATE => array(SQSORT_DATE_DESC, SQSORT_DATE_ASC), SQM_COL_INT_DATE => array(SQSORT_INT_DATE_DESC, SQSORT_INT_DATE_ASC), SQM_COL_FROM => array(SQSORT_FROM_ASC, SQSORT_FROM_DESC), SQM_COL_TO => array(SQSORT_TO_ASC, SQSORT_TO_DESC), SQM_COL_CC => array(SQSORT_CC_ASC, SQSORT_CC_DESC), SQM_COL_SIZE => array(SQSORT_SIZE_ASC, SQSORT_SIZE_DESC));
    } else {
        $aTemplate['aSortSupported'] = array();
    }
    /**
     * 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
     *
     * This code also might be more appropriate in a template file, but
     * we are moving this complex stuff out of the way of template 
     * authors; advanced template sets are always free to override
     * the resultant values.
     *
     */
    $show_label_columns = array();
    $index_order_part = array();
    if (!($aTemplate['javascript_on'] && $aTemplate['fancy_index_highlite'])) {
        $get_next_two = 0;
        $last_order_part = 0;
        $last_last_order_part = 0;
        foreach ($aTemplate['aOrder'] as $index_order_part) {
            if ($index_order_part == SQM_COL_CHECK) {
                $get_next_two = 1;
                if ($last_last_order_part != SQM_COL_SUBJ) {
                    $show_label_columns[] = $last_last_order_part;
                }
                if ($last_order_part != SQM_COL_SUBJ) {
                    $show_label_columns[] = $last_order_part;
                }
            } else {
                if ($get_next_two > 0 && $get_next_two < 3 && $index_order_part != SQM_COL_SUBJ) {
                    $show_label_columns[] = $index_order_part;
                    $get_next_two++;
                }
            }
            $last_last_order_part = $last_order_part;
            $last_order_part = $index_order_part;
        }
    }
    $aTemplate['show_label_columns'] = $show_label_columns;
    return $aTemplate;
}
예제 #2
0
if (($mailbox == $sent_folder || $mailbox == $draft_folder) && !in_array(SQM_COL_TO, $index_order)) {
    $aNewOrder = array();
    // nice var name ;)
    foreach ($index_order as $iCol) {
        if ($iCol == SQM_COL_FROM) {
            $iCol = SQM_COL_TO;
        }
        $aColumns[$iCol] = array();
    }
} else {
    foreach ($index_order as $iCol) {
        $aColumns[$iCol] = array();
    }
}
$aProps = array('columns' => $aColumns, 'config' => array('highlight_list' => $message_highlight_list, 'trash_folder' => $trash_folder, 'sent_folder' => $sent_folder, 'draft_folder' => $draft_folder));
calcFetchColumns($aMailbox, $aProps);
/**
 End code to set the columns to fetch in case of hitting the next/prev link
*/
/**
 * Check if cache is still valid, $what contains the key
 * which gives us acces to the array with uid's. At this moment
 * 0 is used for a normal message list and search uses 1 as key. This can be
 * changed / extended in the future.
 * If on a select of a mailbox we detect that the cache should be invalidated due to
 * the delete of messages or due to new messages we empty the list with uid's and
 * that's what we detect below.
 */
if (!is_array($aMailbox['UIDSET'][$what])) {
    fetchMessageHeaders($imapConnection, $aMailbox);
}