Esempio n. 1
0
/**
 * Check the preferences into the session cache.
 *
 * @param string $data_dir
 * @param string $username
 *
 * @since 1.1.3
 *
 */
function cachePrefValues($data_dir, $username)
{
    global $prefs_are_cached, $prefs_cache;
    sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION);
    if (isset($prefs_are_cached) && $prefs_are_cached) {
        sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION);
        //        sm_print_r($prefs_cache);
        //        exit;
        return;
    }
    sqsession_unregister('prefs_cache');
    sqsession_unregister('prefs_are_cached');
    /* Calculate the filename for the user's preference file */
    $filename = getHashedFile($username, $data_dir, "{$username}.pref");
    /* A call to checkForPrefs here should take eliminate the need for */
    /* this to be called throughout the rest of the SquirrelMail code. */
    checkForPrefs($data_dir, $username, $filename);
    /* Make sure that the preference file now DOES exist. */
    if (!file_exists($filename)) {
        logout_error(sprintf(_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename));
        exit;
    }
    /* Open the file, or else display an error to the user. */
    if (!($file = @fopen($filename, 'r'))) {
        logout_error(sprintf(_("Preference file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename));
        exit;
    }
    /* Read in the preferences. */
    $highlight_num = 0;
    while (!feof($file)) {
        $pref = '';
        /* keep reading a pref until we reach an eol (\n (or \r for macs)) */
        while ($read = fgets($file, 1024)) {
            $pref .= $read;
            if (strpos($read, "\n") || strpos($read, "\r")) {
                break;
            }
        }
        $pref = trim($pref);
        $equalsAt = strpos($pref, '=');
        if ($equalsAt > 0) {
            $key = substr($pref, 0, $equalsAt);
            $value = substr($pref, $equalsAt + 1);
            //FIXME: this code is not in db_prefs.php that I can see
            /* this is to 'rescue' old-style highlighting rules. */
            if (substr($key, 0, 9) == 'highlight') {
                $key = 'highlight' . $highlight_num;
                $highlight_num++;
            }
            //FIXME: this code is not in db_prefs.php that I can see
            if ($value != '') {
                $prefs_cache[$key] = $value;
            }
        }
    }
    fclose($file);
    $prefs_are_cached = TRUE;
    sqsession_register($prefs_cache, 'prefs_cache');
    sqsession_register($prefs_are_cached, 'prefs_are_cached');
}
function cachePrefValues($username)
{
    global $prefs_are_cached, $prefs_cache;
    if ($prefs_are_cached) {
        return;
    }
    sqsession_unregister('prefs_cache');
    sqsession_unregister('prefs_are_cached');
    $db = new dbPrefs();
    if (isset($db->error)) {
        printf(_("Preference database error (%s). Exiting abnormally"), $db->error);
        exit;
    }
    $db->fillPrefsCache($username);
    if (isset($db->error)) {
        printf(_("Preference database error (%s). Exiting abnormally"), $db->error);
        exit;
    }
    $prefs_are_cached = true;
    sqsession_register($prefs_cache, 'prefs_cache');
    sqsession_register($prefs_are_cached, 'prefs_are_cached');
}
function get_thread_sort($imap_stream)
{
    global $thread_new, $sort_by_ref, $default_charset, $server_sort_array, $uid_support;
    if (sqsession_is_registered('thread_new')) {
        sqsession_unregister('thread_new');
    }
    if (sqsession_is_registered('server_sort_array')) {
        sqsession_unregister('server_sort_array');
    }
    $sid = sqimap_session_id($uid_support);
    $thread_temp = array();
    if ($sort_by_ref == 1) {
        $sort_type = 'REFERENCES';
    } else {
        $sort_type = 'ORDEREDSUBJECT';
    }
    $thread_query = "{$sid} THREAD {$sort_type} " . strtoupper($default_charset) . " ALL\r\n";
    fputs($imap_stream, $thread_query);
    $thread_test = sqimap_read_data($imap_stream, $sid, false, $response, $message);
    if (isset($thread_test[0])) {
        if (preg_match("/^\\* THREAD (.+)\$/", $thread_test[0], $regs)) {
            $thread_list = trim($regs[1]);
        }
    } else {
        $thread_list = "";
    }
    if (!preg_match("/OK/", $response)) {
        $server_sort_array = 'no';
        return $server_sort_array;
    }
    if (isset($thread_list)) {
        $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
    }
    $char_count = count($thread_temp);
    $counter = 0;
    $thread_new = array();
    $k = 0;
    $thread_new[0] = "";
    for ($i = 0; $i < $char_count; $i++) {
        if ($thread_temp[$i] != ')' && $thread_temp[$i] != '(') {
            $thread_new[$k] = $thread_new[$k] . $thread_temp[$i];
        } elseif ($thread_temp[$i] == '(') {
            $thread_new[$k] .= $thread_temp[$i];
            $counter++;
        } elseif ($thread_temp[$i] == ')') {
            if ($counter > 1) {
                $thread_new[$k] .= $thread_temp[$i];
                $counter = $counter - 1;
            } else {
                $thread_new[$k] .= $thread_temp[$i];
                $k++;
                $thread_new[$k] = "";
                $counter = $counter - 1;
            }
        }
    }
    sqsession_register($thread_new, 'thread_new');
    $thread_new = array_reverse($thread_new);
    $thread_list = implode(" ", $thread_new);
    $thread_list = str_replace("(", " ", $thread_list);
    $thread_list = str_replace(")", " ", $thread_list);
    $thread_list = preg_split("/\\s/", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
    $server_sort_array = $thread_list;
    sqsession_register($server_sort_array, 'server_sort_array');
    return $thread_list;
}
Esempio n. 4
0
function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, $start_msg, $sort, $color, $show_num, $use_cache, $mode = '')
{
    global $msgs, $msort, $auto_expunge, $thread_sort_messages, $allow_server_sort, $server_sort_order;
    /*
     * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
     * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
     * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
     */
    if (!isset($msort)) {
        $msort = array();
    }
    if (!isset($msgs)) {
        $msgs = array();
    }
    //$start = microtime();
    /* If autoexpunge is turned on, then do it now. */
    $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
    $srt = $sort;
    /* If autoexpunge is turned on, then do it now. */
    if ($auto_expunge == true) {
        $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
        $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
        $num_msgs = $mbxresponse['EXISTS'];
    }
    if ($mbxresponse['EXISTS'] > 0) {
        /* if $start_msg is lower than $num_msgs, we probably deleted all messages
         * in the last page. We need to re-adjust the start_msg
         */
        if ($start_msg > $num_msgs) {
            $start_msg -= $show_num;
            if ($start_msg < 1) {
                $start_msg = 1;
            }
        }
        /* This code and the next if() block check for
         * server-side sorting methods. The $id array is
         * formatted and $sort is set to 6 to disable
         * SM internal sorting
         */
        if ($thread_sort_messages == 1) {
            $mode = 'thread';
        } elseif ($allow_server_sort == 1) {
            $mode = 'serversort';
        } else {
            $mode = '';
        }
        if ($use_cache) {
            sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
            sqgetGlobalVar('msort', $msort, SQ_SESSION);
        } else {
            sqsession_unregister('msort');
            sqsession_unregister('msgs');
        }
        switch ($mode) {
            case 'thread':
                $id = get_thread_sort($imapConnection);
                $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
                if ($msgs === false) {
                    echo '<b><small><center><font color="red">' . _("Thread sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</font></center></small></b>';
                    $thread_sort_messages = 0;
                    $msort = $msgs = array();
                } else {
                    $msort = $msgs;
                    $sort = 6;
                }
                break;
            case 'serversort':
                $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
                $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
                if ($msgs === false) {
                    echo '<b><small><center><font color="red">' . _("Server-side sorting is not supported by your IMAP server.") . '<br />' . _("Please contact your system administrator and report this error.") . '</font></center></small></b>';
                    $sort = $server_sort_order;
                    $allow_server_sort = FALSE;
                    $msort = $msgs = array();
                    $id = array();
                } else {
                    $msort = $msgs;
                    $sort = 6;
                }
                break;
            default:
                if (!$use_cache) {
                    $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num, $num_msgs, $sort, $mbxresponse);
                    $msort = calc_msort($msgs, $sort);
                }
                /* !use cache */
                break;
        }
        // switch
        sqsession_register($msort, 'msort');
        sqsession_register($msgs, 'msgs');
    }
    /* if exists > 0 */
    $res = getEndMessage($start_msg, $show_num, $num_msgs);
    $start_msg = $res[0];
    $end_msg = $res[1];
    if ($num_msgs > 0) {
        $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
    } else {
        $paginator_str = '';
    }
    $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
    do_hook('mailbox_index_before');
    $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
    $form_name = "FormMsgs" . $safe_name;
    echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' . "\n" . '<input type="hidden" name="mailbox" value="' . htmlspecialchars($mailbox) . '">' . "\n" . '<input type="hidden" name="startMessage" value="' . htmlspecialchars($start_msg) . '">' . "\n";
    echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
    echo '<tr><td>';
    mail_message_listing_beginning($imapConnection, $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
    /* line between the button area and the list */
    echo '<tr><td height="5" bgcolor="' . $color[4] . '"></td></tr>';
    echo '<tr><td>';
    echo '    <table width="100%" cellpadding="1" cellspacing="0" align="center"' . ' border="0" bgcolor="' . $color[9] . '">';
    echo '     <tr><td>';
    echo '       <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="' . $color[5] . '">';
    printHeader($mailbox, $srt, $color, !$thread_sort_messages);
    displayMessageArray($imapConnection, $num_msgs, $start_msg, $msort, $mailbox, $sort, $color, $show_num, 0, 0);
    echo '</table></td></tr></table>';
    mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
    echo '</table>';
    echo "\n</form>\n\n";
    //$t = elapsed($start);
    //echo("elapsed time = $t seconds\n");
}
Esempio n. 5
0
        $mailbox = '';
    }
    if ($compose_new_win == '1') {
        compose_Header($color, $mailbox);
    } else {
        displayPageHeader($color, $mailbox);
    }
    showInputForm($session, false);
    exit;
}
if (!isset($composesession)) {
    $composesession = 0;
    sqsession_register(0, 'composesession');
}
if (!isset($session) || isset($newmessage) && $newmessage) {
    sqsession_unregister('composesession');
    $session = "{$composesession}" + 1;
    $composesession = $session;
    sqsession_register($composesession, 'composesession');
}
if (!isset($compose_messages)) {
    $compose_messages = array();
}
if (!isset($compose_messages[$session]) || $compose_messages[$session] == NULL) {
    /* if (!array_key_exists($session, $compose_messages)) {  /* We can only do this in PHP >= 4.1 */
    $composeMessage = new Message();
    $rfc822_header = new Rfc822Header();
    $composeMessage->rfc822_header = $rfc822_header;
    $composeMessage->reply_rfc822_header = '';
    $compose_messages[$session] = $composeMessage;
    sqsession_register($compose_messages, 'compose_messages');
Esempio n. 6
0
/**
 * Change the column order of a mailbox
 *
 * @param array  $index_order (reference) contains an ordered list with columns
 * @param string $method action to take, move, add and remove are supported
 * @param int    $num target column
 * @param int    $pos positions to move a column in the index_order array
 * @return bool  $r A change in the ordered list took place.
 */
function change_columns_list(&$index_order, $method, $num, $pos = 0)
{
    $r = false;
    switch ($method) {
        case 'move':
            $r = sqm_array_move_value($index_order, $num, $pos);
            break;
        case 'add':
            $index_order[] = (int) $num;
            $r = true;
            /**
             * flush the cache in order to retrieve the new columns
             */
            sqsession_unregister('mailbox_cache');
            break;
        case 'remove':
            if (in_array($num, $index_order)) {
                unset($index_order[array_search($num, $index_order)]);
                $index_order = array_values($index_order);
                $r = true;
            }
            break;
        default:
            break;
    }
    return $r;
}
Esempio n. 7
0
    exit;
}
/* SquirrelMail required files. */
require_once SM_PATH . 'functions/imap_asearch.php';
require_once SM_PATH . 'functions/imap_general.php';
require_once SM_PATH . 'functions/imap_messages.php';
require_once SM_PATH . 'functions/date.php';
require_once SM_PATH . 'functions/mime.php';
require_once SM_PATH . 'functions/mailbox_display.php';
require_once SM_PATH . 'functions/compose.php';
/* lets get the global vars we may need */
sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION);
if (is_array($delayed_errors)) {
    $oErrorHandler->AssignDelayedErrors($delayed_errors);
    sqsession_unregister("delayed_errors");
}
sqgetGlobalVar('mailbox', $mailbox);
sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
sqgetGlobalVar('note', $note, SQ_GET);
sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
if (sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit')) {
    $startMessage = (int) $temp;
} else {
    $startMessage = 1;
}
// sort => srt because of the changed behaviour which can break new behaviour
if (sqgetGlobalVar('srt', $temp, SQ_GET)) {
    $srt = (int) $temp;
}
Esempio n. 8
0
function compatibility_sqsession_unregister($name)
{
    sqsession_unregister($name);
}
Esempio n. 9
0
$js_pref = SMPREF_JS_ON;
if ($javascript_setting != SMPREF_JS_ON) {
    if ($javascript_setting == SMPREF_JS_AUTODETECT) {
        if ($js_autodetect_results == SMPREF_JS_OFF) {
            $js_pref = SMPREF_JS_OFF;
        }
    } else {
        $js_pref = SMPREF_JS_OFF;
    }
}
/* Update the prefs */
setPref($data_dir, $username, 'javascript_on', $js_pref);
/* Compute the URL to forward the user to. */
$redirect_url = 'webmail.php';
if (sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION)) {
    sqsession_unregister('session_expired_location');
    if ($session_expired_location == 'compose') {
        $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
        if ($compose_new_win) {
            // do not prefix $location here because $session_expired_location is set to the PAGE_NAME
            // of the last page
            $redirect_url = $session_expired_location . '.php';
        } else {
            $redirect_url = 'webmail.php?right_frame=' . urlencode($session_expired_location . '.php');
        }
    } else {
        if ($session_expired_location != 'webmail' && $session_expired_location != 'left_main') {
            $redirect_url = 'webmail.php?right_frame=' . urlencode($session_expired_location . '.php');
        }
    }
    unset($session_expired_location);
Esempio n. 10
0
 /**
  * Display the error array in the error template
  * @return void
  * @since 1.5.1
  */
 function DisplayErrors()
 {
     // Check for delayed errors...
     if (!$this->delayed_errors) {
         sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION);
         if (is_array($delayed_errors)) {
             $this->AssignDelayedErrors($delayed_errors);
             sqsession_unregister("delayed_errors");
         }
     }
     if (isset($this->Template->values['aErrors']) && count($this->Template->values['aErrors']) > 0) {
         foreach ($this->Template->values['aErrors'] as $err) {
             if (!in_array($err, $this->aErrors, true)) {
                 $this->aErrors[] = $err;
             }
         }
         $this->Template->assign('aErrors', $this->aErrors);
     }
     if (count($this->aErrors) > 0) {
         if ($this->delayed_errors) {
             sqsession_register($this->aErrors, "delayed_errors");
         } else {
             $this->Template->display($this->TemplateName);
         }
     }
 }
Esempio n. 11
0
require_once SM_PATH . 'functions/imap.php';
require_once SM_PATH . 'functions/plugin.php';
require_once SM_PATH . 'functions/i18n.php';
require_once SM_PATH . 'functions/auth.php';
require_once SM_PATH . 'functions/global.php';
if (!function_exists('sqm_baseuri')) {
    require_once SM_PATH . 'functions/display_messages.php';
}
$base_uri = sqm_baseuri();
sqsession_is_active();
sqgetGlobalVar('username', $username, SQ_SESSION);
sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
sqgetGlobalVar('right_frame', $right_frame, SQ_GET);
if (isset($_SESSION['session_expired_post'])) {
    sqsession_unregister('session_expired_post');
}
if (!sqgetGlobalVar('mailto', $mailto)) {
    $mailto = '';
}
is_logged_in();
do_hook('webmail_top');
/**
 * We'll need this to later have a noframes version
 *
 * Check if the user has a language preference, but no cookie.
 * Send him a cookie with his language preference, if there is
 * such discrepancy.
 */
$my_language = getPref($data_dir, $username, 'language');
if ($my_language != $squirrelmail_language) {
Esempio n. 12
0
if (sqgetGlobalVar('set_thread', $temp, SQ_GET)) {
    $set_thread = (int) $temp;
}
if (!sqgetGlobalVar('composenew', $composenew, SQ_GET)) {
    $composenew = false;
}
/* end of get globals */
/* Open a connection on the imap port (143) */
$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
if (isset($PG_SHOWALL)) {
    if ($PG_SHOWALL) {
        $PG_SHOWNUM = 999999;
        $show_num = $PG_SHOWNUM;
        sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
    } else {
        sqsession_unregister('PG_SHOWNUM');
        unset($PG_SHOWNUM);
    }
} else {
    if (isset($PG_SHOWNUM)) {
        $show_num = $PG_SHOWNUM;
    }
}
if (!isset($show_num) || empty($show_num) || $show_num == 0) {
    setPref($data_dir, $username, 'show_num', 15);
    $show_num = 15;
}
if (isset($newsort) && $newsort != $sort) {
    setPref($data_dir, $username, 'sort', $newsort);
}
/* If the page has been loaded without a specific mailbox, */