added caching of messages in mailbox, as well as next and previous message
[squirrelmail.git] / src / right_main.php
1 <?php
2 /**
3 ** right_main.php
4 **
5 ** This is where the mailboxes are listed. This controls most of what
6 ** goes on in SquirrelMail.
7 **
8 **/
9
10 session_start();
11
12 if(!isset($logged_in)) {
13 echo _("You must login first.");
14 exit;
15 }
16 if(!isset($username) || !isset($key)) {
17 echo _("You need a valid user and password to access this page!");
18 exit;
19 }
20
21 if (!isset($config_php))
22 include("../config/config.php");
23 if (!isset($imap_php))
24 include("../functions/imap.php");
25 if (!isset($strings_php))
26 include("../functions/strings.php");
27 if (!isset($date_php))
28 include("../functions/date.php");
29 if (!isset($page_header_php))
30 include("../functions/page_header.php");
31 if (!isset($array_php))
32 include("../functions/array.php");
33 if (!isset($mime_php))
34 include("../functions/mime.php");
35 if (!isset($mailbox_display_php))
36 include("../functions/mailbox_display.php");
37 if (!isset($display_messages_php))
38 include("../functions/display_messages.php");
39 ?>
40 <HTML>
41 <FONT FACE="Arial,Helvetica">
42 <?php
43 /////////////////////////////////////////////////////////////////////////////////
44 //
45 // incoming variables from URL:
46 // $sort Direction to sort by date
47 // values: 0 - descending order
48 // values: 1 - ascending order
49 // $startMessage Message to start at
50 // $mailbox Full Mailbox name
51 //
52 // incoming from cookie:
53 // $username duh
54 // $key pass
55 //
56 /////////////////////////////////////////////////////////////////////////////////
57
58 // open a connection on the imap port (143)
59 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
60
61 /** If it was a successful login, lets load their preferences **/
62 include("../src/load_prefs.php");
63 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
64
65 // If the page has been loaded without a specific mailbox,
66 // just show a page of general info.
67 if (!isset($mailbox)) {
68 displayPageHeader($color, "None");
69 general_info($motd, $org_logo, $version, $org_name, $color);
70 echo "</BODY></HTML>";
71 exit;
72 }
73
74 sqimap_mailbox_select($imapConnection, $mailbox);
75 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
76 displayPageHeader($color, $mailbox);
77
78 // Check to see if we can use cache or not. Currently the only time when you wont use it is
79 // when a link on the left hand frame is used. Also check to make sure we actually have the
80 // array in the registered session data. :)
81 if ($use_mailbox_cache && session_is_registered("msgs")) {
82 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color,$show_num);
83 } else {
84 if (session_is_registered("msgs"))
85 unset($msgs);
86
87 // i have found that only global variables can be registered successfully with a session. therefore
88 // i am passing in a simple empty variable (msgs) which will be returned with an array and can be
89 // then registered here as a global variable. whew.
90 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $msgs);
91
92 if (session_is_registered("msgs") && isset($msgs))
93 session_register("msgs");
94 }
95
96 // close the connection
97 sqimap_logout ($imapConnection);
98 ?>
99 </FONT>
100 </BODY>
101 </HTML>