diff --git a/functions/imap_general.php b/functions/imap_general.php index f4acc08c6..09543e740 100755 --- a/functions/imap_general.php +++ b/functions/imap_general.php @@ -11,8 +11,8 @@ return; define ('imap_general_php', true); - global $imap_general_debug; - $imap_general_debug = false; +global $imap_general_debug; +$imap_general_debug = false; /****************************************************************************** ** Sets an unique session id in order to avoid simultanous sessions crash. @@ -30,10 +30,11 @@ ******************************************************************************/ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors, - &$response, &$message) { - global $color, $squirrelmail_language, $imap_general_debug; + &$response, &$message) { + global $color, $squirrelmail_language; +global $imap_general_debug; - $read = ""; + $read = ''; $resultlist = array(); $more_msgs = true; @@ -48,11 +49,11 @@ $size = $regs[1]; } else if (ereg("^\\* [0-9]+ FETCH", $read, $regs)) { // Sizeless response, probably single-line - // For debugging purposes - if ($imap_general_debug) { - echo "$read
\n"; - flush(); - } +// For debugging purposes +if ($imap_general_debug) { + echo "$read
\n"; + flush(); +} $size = 0; $data[] = $read; $read = fgets($imap_stream, 9096); @@ -63,11 +64,11 @@ while (strpos($read, "\n") === false) { $read .= fgets($imap_stream, 9096); } - // For debugging purposes - if ($imap_general_debug) { - echo "$read
\n"; - flush(); - } +// For debugging purposes +if ($imap_general_debug) { + echo "$read
\n"; + flush(); +} // If we know the size, no need to look at the end parameters if ($size > 0) { if ($total_size == $size) { @@ -83,9 +84,9 @@ } else { $data[] = $read; $read = fgets($imap_stream, 9096); - while (strpos($read, "\n") === false) { - $read .= fgets($imap_stream, 9096); - } + while (strpos($read, "\n") === false) { + $read .= fgets($imap_stream, 9096); + } } $total_size += strlen($read); } else { @@ -108,7 +109,7 @@ $response = $regs[1]; $message = trim($regs[2]); - if ($imap_general_debug) echo '--
'; +if ($imap_general_debug) echo '--
'; if ($handle_errors == false) return $resultlist; @@ -137,10 +138,10 @@ } function sqimap_read_data ($imap_stream, $pre, $handle_errors, &$response, &$message) { - $res = sqimap_read_data_list($imap_stream, $pre, $handle_errors, $response, $message); - return $res[0]; + $res = sqimap_read_data_list($imap_stream, $pre, $handle_errors, $response, $message); + return $res[0]; } - + /****************************************************************************** ** Logs the user into the imap server. If $hide is set, no error messages ** will be displayed. This function returns the imap connection handle. @@ -151,7 +152,7 @@ $imap_stream = fsockopen ($imap_server_address, $imap_port, $error_number, $error_string, 15); $server_info = fgets ($imap_stream, 1024); - + // Decrypt the password $password = OneTimePadDecrypt($password, $onetimepad); @@ -165,7 +166,7 @@ exit; } - fputs ($imap_stream, sqimap_session_id() . ' LOGIN "' . quoteIMAP($username) . + fputs ($imap_stream, sqimap_session_id() . ' LOGIN "' . quoteIMAP($username) . '" "' . quoteIMAP($password) . "\"\r\n"); $read = sqimap_read_data ($imap_stream, sqimap_session_id(), false, $response, $message); @@ -181,12 +182,12 @@ printf (_("Unknown error: %s") . "
\n", $message); echo '
'; echo _("Read data:") . "
\n"; - if (is_array($read)) - { - foreach ($read as $line) - { - echo htmlspecialchars($line) . "
\n"; - } + if (is_array($read)) + { + foreach ($read as $line) + { + echo htmlspecialchars($line) . "
\n"; + } } exit; } else { @@ -198,9 +199,9 @@ // $squirrelmail_language is set by a cookie when // the user selects language and logs out - + set_up_language($squirrelmail_language, true); - + ?> @@ -251,32 +252,32 @@ } function sqimap_capability($imap_stream, $capability) { - global $sqimap_capabilities; - global $imap_general_debug; + global $sqimap_capabilities; +global $imap_general_debug; - if (!is_array($sqimap_capabilities)) { - fputs ($imap_stream, sqimap_session_id() . " CAPABILITY\r\n"); - $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b); + if (!is_array($sqimap_capabilities)) { + fputs ($imap_stream, sqimap_session_id() . " CAPABILITY\r\n"); + $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b); - $c = explode(' ', $read[0]); - for ($i=2; $i < count($c); $i++) { - $cap_list = explode('=', $c[$i]); - if (isset($cap_list[1])) - $sqimap_capabilities[$cap_list[0]] = $cap_list[1]; - else - $sqimap_capabilities[$cap_list[0]] = TRUE; - } - } - if (! isset($sqimap_capabilities[$capability])) - return false; - return $sqimap_capabilities[$capability]; -} + $c = explode(' ', $read[0]); + for ($i=2; $i < count($c); $i++) { + $cap_list = explode('=', $c[$i]); + if (isset($cap_list[1])) + $sqimap_capabilities[$cap_list[0]] = $cap_list[1]; + else + $sqimap_capabilities[$cap_list[0]] = TRUE; + } + } + if (! isset($sqimap_capabilities[$capability])) + return false; + return $sqimap_capabilities[$capability]; + } /****************************************************************************** ** Returns the delimeter between mailboxes: INBOX/Test, or INBOX.Test... ******************************************************************************/ function sqimap_get_delimiter ($imap_stream = false) { - global $imap_general_debug; +global $imap_general_debug; global $sqimap_delimiter; global $optional_delimiter; @@ -286,38 +287,38 @@ /* Do some caching here */ if (!$sqimap_delimiter) { - if (sqimap_capability($imap_stream, "NAMESPACE")) { - /* According to something that I can't find, this is supposed to work on all systems - OS: This won't work in Courier IMAP. - OS: According to rfc2342 response from NAMESPACE command is: - OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES) - OS: We want to lookup all personal NAMESPACES... - */ - fputs ($imap_stream, sqimap_session_id() . " NAMESPACE\r\n"); - $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b); - if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) { - if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) - $pn = $data2[1]; - $pna = explode(')(', $pn); - while (list($k, $v) = each($pna)) - { + if (sqimap_capability($imap_stream, "NAMESPACE")) { + /* According to something that I can't find, this is supposed to work on all systems + OS: This won't work in Courier IMAP. + OS: According to rfc2342 response from NAMESPACE command is: + OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES) + OS: We want to lookup all personal NAMESPACES... + */ + fputs ($imap_stream, sqimap_session_id() . " NAMESPACE\r\n"); + $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b); + if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) { + if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) + $pn = $data2[1]; + $pna = explode(')(', $pn); + while (list($k, $v) = each($pna)) + { $lst = explode('"', $v); if (isset($lst[3])) { $pn[$lst[1]] = $lst[3]; } else { $pn[$lst[1]] = ''; } - } - } - $sqimap_delimiter = $pn[0]; - } else { - fputs ($imap_stream, ". LIST \"INBOX\" \"\"\r\n"); - $read = sqimap_read_data($imap_stream, '.', true, $a, $b); - $quote_position = strpos ($read[0], '"'); - $sqimap_delimiter = substr ($read[0], $quote_position+1, 1); - } - } - return $sqimap_delimiter; + } + } + $sqimap_delimiter = $pn[0]; + } else { + fputs ($imap_stream, ". LIST \"INBOX\" \"\"\r\n"); + $read = sqimap_read_data($imap_stream, '.', true, $a, $b); + $quote_position = strpos ($read[0], '"'); + $sqimap_delimiter = substr ($read[0], $quote_position+1, 1); + } + } + return $sqimap_delimiter; } @@ -329,7 +330,7 @@ $read_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $result, $message); for ($i = 0; $i < count($read_ary); $i++) { if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) { - return $regs[1]; + return $regs[1]; } } return "BUG! Couldn't get number of messages in $mailbox!"; diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 9636d06de..43836e1ca 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -13,6 +13,8 @@ return; define('mailbox_display_php', true); + define( 'PG_SEL_MAX', 10 ); // Default value for page_selector_max + function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) { global $checkall; global $color, $msgs, $msort; @@ -269,7 +271,8 @@ $re_abbr = # Add more here! 'vedr|sv|' . # Danish 're|aw'; # English - if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) + + if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) $messages[$j]['SUBJECT-SORT'] = $regs[2]; $num = 0; @@ -379,9 +382,9 @@ $Message = ''; if ($startMessage < $endMessage) { - $Message = _("Viewing messages") ." $startMessage ". _("to") ." $endMessage ($numMessages " . _("total") . ")\n"; + $Message = _("Viewing messages") .":
$startMessage ". _("to") ." $endMessage ($numMessages " . _("total") . ")\n"; } elseif ($startMessage == $endMessage) { - $Message = _("Viewing message") ." $startMessage ($numMessages " . _("total") . ")\n"; + $Message = _("Viewing message") .":
$startMessage ($numMessages " . _("total") . ")\n"; } if ($sort == 6) { @@ -408,25 +411,30 @@ // Page selector block. Following code computes page links. $mMore = ''; - if( getPref($data_dir, $username, 'page_selector') && $numMessages > $show_num ) { - - $j = intval( $numMessages / $show_num ); + if( !getPref($data_dir, $username, 'page_selector') && + $numMessages > $show_num ) { + $j = intval( $numMessages / $show_num ); // Max pages + $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) ); if( $numMessages % $show_num <> 0 ) $j++; $startMessage = min( $startMessage, $numMessages ); - for( $i = 0; $i < $j; $i++ ) { - - $start = ( ( $i * $show_num ) + 1 ); - - if( $startMessage >= $start && - $startMessage < $start + $show_num ) { - $mMore .= '' . ($i+1) . ' '; - } else { - $mMore .= "" . - ($i+1) . - ' '; - } + $p = intval( $startMessage / $show_num ) + 1; + $i = 1; + while( $i < $p ) { + $pg = intval( $i ); + $start = ( ($pg-1) * $show_num ) + 1; + $mMore .= "$pg "; + $i+=$k; + } + $mMore .= "$p "; + $i += $k; + while( $i <= $j ) { + $pg = intval( $i ); + $start = ( ($pg-1) * $show_num ) + 1; + $mMore .= "$pg "; + $i+=$k; } $mMore .= ' | '; } @@ -493,11 +501,12 @@ echo "\n"; echo ""; - echo '
'; - echo "$lMore$mMore$rMore\n"; - if (!$startMessage) $startMessage=1; + echo "
'; + echo "$lMore$mMore$rMore"; + if (!$startMessage) + $startMessage=1; ShowSelectAllLink($startMessage, $sort); - echo '
'; /** End of message-list table */ do_hook('mailbox_index_after'); @@ -520,15 +529,8 @@ /** This is the beginning of the message list table. It wraps around all messages */ echo ''; - if ($Message) { - echo "\n"; - } echo "'; /** The delete and move options */ echo "'; + echo ""; + echo "
$Message
"; - echo '
'; - echo "$More\n"; - ShowSelectAllLink($startMessage, $sort); - echo '
"; @@ -536,18 +538,18 @@ echo "\n
\n"; echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n" . + " \n" . + " \n" . + " \n" . + " \n" . + " \n" . + " \n"; - echo " \n"; echo " \n"; echo " \n"; echo "
\n"; - echo '  ' . _("Move selected to:") . "\n"; - echo "  \n"; - echo '  ' . _("Transform Selected Messages") . ":  
\n"; - echo "
\n"; - echo '  
\n" . + '  ' . _("Move selected to:") . "\n" . + "
$Message
\n" . + '  ' . _("Transform Selected Messages") . ":  
\n" . + "
\n" . + '  '; echo " \n"; echo "     \n"; if (! $auto_expunge) { echo '  '. _("mailbox") ." \n"; } + echo " \n"; echo " \n"; echo "  \n"; + echo "
\n"; do_hook('mailbox_form_before'); echo '
\n"; + echo "
'; + echo "$More"; + ShowSelectAllLink($startMessage, $sort); + echo "
\n
"; echo "\n"; } +/* ----------------------------------------------------------------------- */ + function ShowSortButton($sort, $mailbox, $Up, $Down) { if ($sort != $Up && $sort != $Down) { $img = 'sort_none.gif'; @@ -642,21 +654,19 @@ { global $checkall, $PHP_SELF, $what, $where, $mailbox; - // This code is from Philippe Mingo - - ?> + ?>  - - - @@ -265,6 +267,7 @@ echo _("Yes, show me the HTML version of a mail message, if it is available."); "name="submit_display"> +
+ : @@ -247,14 +247,16 @@ echo _("Yes, show me the HTML version of a mail message, if it is available.");
- : - - ' . _("Show page selector"); + + '; + echo ' ' . _("Show page selector") . ' '; + $psw = getPref($data_dir, $username, 'page_selector_max', 10 ); + echo ""; + echo ' ' . _("pages max"); ?>