21c3249f |
1 | <? |
2 | /** |
3 | ** right_main.php3 |
4 | ** |
5 | ** This is where the mailboxes are listed. This controls most of what |
6 | ** goes on in SquirrelMail. |
7 | ** |
8 | **/ |
9 | |
10 | if(!isset($logged_in)) { |
11 | echo "You must <a href=\"login.php3\">login</a> first."; |
12 | exit; |
13 | } |
14 | if(!isset($username) || !isset($key)) { |
15 | echo "You need a valid user and password to access this page!"; |
16 | exit; |
17 | } |
18 | ?> |
19 | <HTML> |
20 | <BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#0000EE" ALINK="#0000EE"> |
21 | <FONT FACE="Arial,Helvetica"> |
22 | <? |
23 | include("../config/config.php3"); |
491b3750 |
24 | include("../functions/imap.php3"); |
25 | include("../functions/strings.php3"); |
26 | include("../functions/date.php3"); |
27 | include("../functions/page_header.php3"); |
28 | include("../functions/array.php3"); |
29 | include("../functions/mailbox.php3"); |
30 | include("../functions/mailbox_display.php3"); |
31 | include("../functions/display_messages.php3"); |
21c3249f |
32 | |
33 | ///////////////////////////////////////////////////////////////////////////////// |
34 | // |
35 | // incoming variables from URL: |
36 | // $sort Direction to sort by date |
37 | // values: 0 - descending order |
38 | // values: 1 - ascending order |
39 | // $startMessage Message to start at |
40 | // $mailbox Full Mailbox name |
41 | // |
42 | // incoming from cookie: |
43 | // $username duh |
44 | // $key pass |
45 | // |
46 | ///////////////////////////////////////////////////////////////////////////////// |
47 | |
48 | |
49 | // open a connection on the imap port (143) |
50 | $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString); |
51 | if (!$imapConnection) { |
52 | echo "Error connecting to IMAP Server.<br>"; |
53 | echo "$errorNumber : $errorString<br>"; |
54 | exit; |
55 | } |
56 | $serverInfo = fgets($imapConnection, 256); |
57 | |
58 | // login |
59 | fputs($imapConnection, "1 login $username $key\n"); |
60 | $read = fgets($imapConnection, 1024); |
61 | if (strpos($read, "NO")) { |
62 | error_username_password_incorrect(); |
63 | exit; |
64 | } |
65 | |
66 | // If the page has been loaded without a specific mailbox, |
67 | // just show a page of general info. |
68 | if (!isset($mailbox)) { |
69 | displayPageHeader("None"); |
70 | general_info($motd, $org_logo, $version, $org_name); |
71 | exit; |
72 | } |
73 | |
74 | |
75 | // switch to the mailbox, and get the number of messages in it. |
76 | selectMailbox($imapConnection, $mailbox, $numMessages); |
77 | |
78 | // make a URL safe $mailbox for use in the links |
79 | $urlMailbox = urlencode($mailbox); |
80 | |
81 | displayPageHeader($mailbox); |
82 | $i = 1; |
83 | while ($i <= $numMessages) { |
84 | getMessageHeaders($imapConnection, $i, $from, $subject, $date); |
85 | |
86 | $messages[$i]["DATE"] = getTimeStamp(explode(" ", trim($date))); |
87 | $messages[$i]["ID"] = $i; |
88 | $messages[$i]["FROM"] = $from; |
89 | $messages[$i]["SUBJECT"] = $subject; |
90 | $i++; |
91 | } |
92 | |
93 | if ($sort == 0) |
94 | $msgs = ary_sort($messages, "DATE", -1); |
95 | else |
96 | $msgs = ary_sort($messages, "DATE", 1); |
97 | |
98 | if ($endMessage > 24) { |
99 | echo "<A HREF=\"right_main.php3?sort=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>   "; |
100 | $endMessage = 24; |
101 | } |
102 | |
103 | /** Display "Next, Previous" on top */ |
104 | |
105 | /** This is the beginning of the message list table. It wraps around all messages */ |
106 | echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>"; |
107 | echo "<TR><TD BGCOLOR=DCDCDC>"; |
108 | echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>"; |
109 | echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">"; |
110 | echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>"; |
111 | echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT></TD>"; |
112 | echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>"; |
113 | if ($sort == 0) |
114 | echo " <A HREF=\"right_main.php3?sort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n"; |
115 | else |
116 | echo " <A HREF=\"right_main.php3?sort=0&startMessage=0&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n"; |
117 | echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT></TD>\n"; |
118 | echo "</TR>"; |
119 | |
120 | // loop through and display the info for each message. |
121 | for ($i = $startMessage;$i <= $endMessage; $i++) { |
122 | printMessageInfo($imapConnection, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE"]); |
123 | } |
124 | |
125 | echo "</TABLE>\n"; |
126 | echo "</TD></TR></TABLE>"; /** End of message-list table */ |
127 | |
128 | /** Display "Next, Previous" on bottom */ |
129 | fclose($imapConnection); |
130 | ?> |
131 | </FONT> |
132 | </BODY> |
133 | </HTML> |