6db6c1a580b7e996149c80db84d7ad864abcc2a5
2 if(!isset($logged_in)) {
3 echo "You must <a href=\"login.php3\">login</a> first.";
6 if(!isset($username) ||
!isset($key)) {
7 echo "You need a valid user and password to access this page!";
12 <BODY TEXT
="#000000" BGCOLOR
="#FFFFFF" LINK
="#0000EE" VLINK
="#0000EE" ALINK
="#0000EE">
13 <FONT FACE
="Arial,Helvetica">
15 include("config/config.php3");
16 include("functions/imap.php3");
17 include("functions/strings.php3");
18 include("functions/date.php3");
19 include("functions/pageheader.php3");
20 include("functions/array.php3");
22 function selectMailbox($imapConnection, $mailbox, &$numberOfMessages) {
24 fputs($imapConnection, "mailboxSelect SELECT \"$mailbox\"\n");
25 $read = fgets($imapConnection, 1024);
26 while ((substr($read, 0, 16) != "mailboxSelect OK") && (substr($read, 0, 17) != "mailboxSelect BAD")) {
27 if (substr(Chop($read), -6) == "EXISTS") {
28 $array = explode(" ", $read);
29 $numberOfMessages = $array[1];
31 $read = fgets($imapConnection, 1024);
35 function getMessageHeaders($imapConnection, $i, &$from, &$subject, &$date) {
36 fputs($imapConnection, "messageFetch FETCH $i:$i RFC822.HEADER.LINES (From Subject Date)\n");
37 $read = fgets($imapConnection, 1024);
38 /* I have to replace <> with [] because HTML uses <> as tags, thus not printing what's in <> */
39 $read = ereg_replace("<", "[", $read);
40 $read = ereg_replace(">", "]", $read);
42 while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
43 if (substr($read, 0, 5) == "From:") {
44 $read = ereg_replace("<", "EMAILSTART--", $read);
45 $read = ereg_replace(">", "--EMAILEND", $read);
46 $from = substr($read, 5, strlen($read) - 6);
48 else if (substr($read, 0, 5) == "Date:") {
49 $read = ereg_replace("<", "[", $read);
50 $read = ereg_replace(">", "]", $read);
51 $date = substr($read, 5, strlen($read) - 6);
53 else if (substr($read, 0, 8) == "Subject:") {
54 $read = ereg_replace("<", "[", $read);
55 $read = ereg_replace(">", "]", $read);
56 $subject = substr($read, 8, strlen($read) - 9);
59 $read = fgets($imapConnection, 1024);
63 function getMessageFlags($imapConnection, $i, &$flags) {
64 /** * 2 FETCH (FLAGS (\Answered \Seen)) */
65 fputs($imapConnection, "messageFetch FETCH $i:$i FLAGS\n");
66 while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
67 if (strpos($read, "FLAGS")) {
68 $read = ereg_replace("\(", "", $read);
69 $read = ereg_replace("\)", "", $read);
70 $read = substr($read, strpos($read, "FLAGS")+
6, strlen($read));
72 $flags = explode(" ", $read);;
74 while ($i < count($flags)) {
75 $flags[$i] = substr($flags[$i], 1, strlen($flags[$i]));
81 $read = fgets($imapConnection, 1024);
85 function getEmailAddr($sender) {
86 if (strpos($sender, "EMAILSTART--") == false)
89 $start = strpos($sender, "EMAILSTART--");
90 $emailAddr = substr($sender, $start, strlen($sender));
95 function getSender($sender) {
96 if (strpos($sender, "EMAILSTART--") == false)
99 $first = substr($sender, 0, strpos($sender, "EMAILSTART--"));
100 $second = substr($sender, strpos($sender, "--EMAILEND") +
10, strlen($sender));
101 return "$first$second";
104 function getSenderName($sender) {
105 $name = getSender($sender);
106 $emailAddr = getEmailAddr($sender);
107 $emailStart = strpos($emailAddr, "EMAILSTART--");
108 $emailEnd = strpos($emailAddr, "--EMAILEND") - 10;
110 if (($emailAddr == "") && ($name == "")) {
113 else if ((strstr($name, "?") != false) ||
(strstr($name, "$") != false) ||
(strstr($name, "%") != false)){
114 $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr);
115 $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr);
118 else if (strlen($name) > 0) {
121 else if (strlen($emailAddr > 0)) {
122 $emailAddr = ereg_replace("EMAILSTART--", "", $emailAddr);
123 $emailAddr = ereg_replace("--EMAILEND", "", $emailAddr);
129 // strip out any quotes if they exist
130 if ((strlen($from) > 0) && ($from[0] == "\"") && ($from[strlen($from) - 1] == "\""))
131 $from = substr($from, 1, strlen($from) - 2);
136 function printMessageInfo($imapConnection, $i, $from, $subject, $date) {
137 getMessageHeaders($imapConnection, $i, $from, $subject, $date);
138 getMessageFlags($imapConnection, $i, $flags);
139 $dateParts = explode(" ", trim($date));
140 $dateString = getDateString($dateParts); // this will reformat the date string into a good format for us.
141 $senderName = getSenderName($from);
142 if (strlen(Chop($subject)) == 0)
143 $subject = "(no subject)";
149 while ($j < count($flags)) {
150 if ($flags[$j] == "Deleted") {
152 } else if ($flags[$j] == "Answered") {
154 } else if ($flags[$j] == "Seen") {
160 if ($deleted == false) {
162 if ($seen == false) {
163 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$i</B></FONT></TD>\n";
164 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
165 echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
166 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$subject</B></FONT></TD>\n";
168 echo " <TD><FONT FACE=\"Arial,Helvetica\">$i</FONT></TD>\n";
169 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
170 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
171 echo " <TD><FONT FACE=\"Arial,Helvetica\">$subject</FONT></TD>\n";
179 /////////////////////////////////////////////////////////////////////////////////
181 // incoming variables from URL:
182 // $sort Direction to sort by date
183 // values: 0 - descending order
184 // values: 1 - ascending order
185 // $startMessage Message to start at
186 // $mailbox Full Mailbox name
188 // incoming from cookie:
192 /////////////////////////////////////////////////////////////////////////////////
195 // open a connection on the imap port (143)
196 $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString);
197 if (!$imapConnection) {
198 echo "Error connecting to IMAP Server.<br>";
199 echo "$errorNumber : $errorString<br>";
202 $serverInfo = fgets($imapConnection, 256);
205 fputs($imapConnection, "1 login $username $key\n");
206 $read = fgets($imapConnection, 1024);
207 if (strpos($read, "NO")) {
209 echo "<TABLE COLS=1 WIDTH=70% NOBORDER BGCOLOR=FFFFFF ALIGN=CENTER>";
211 echo " <TD BGCOLOR=DCDCDC>";
212 echo " <FONT FACE=\"Arial,Helvetica\"><B><CENTER>ERROR</CENTER></B></FONT>";
213 echo " </TD></TR><TR><TD>";
214 echo " <CENTER><FONT FACE=\"Arial,Helvetica\"><BR>Unknown user or password incorrect.<BR><A HREF=\"login.php3\" TARGET=_top>Click here to try again</A>.</FONT></CENTER>";
217 echo "</BODY></HTML>";
222 // If the page has been loaded without a specific mailbox,
223 // just show a page of general info.
224 if (!isset($mailbox)) {
225 displayPageHeader("None");
228 echo "<TABLE COLS=1 WIDTH=70% NOBORDER BGCOLOR=FFFFFF ALIGN=CENTER>";
230 echo " <TD BGCOLOR=DCDCDC>";
231 echo " <FONT FACE=\"Arial,Helvetica\"><B><CENTER>Welcome to $org_name's WebMail system</CENTER></B></FONT>";
232 echo " </TD></TR><TR><TD>";
233 echo " <TR><TD BGCOLOR=FFFFFF>";
234 echo " <FONT FACE=\"Arial,Helvetica\" SIZE=-1><CENTER>Running SquirrelMail version $version (c) 1999 by Nathan and Luke Ehresman.</CENTER></FONT>";
235 echo " </TD></TR><TR><TD>";
236 echo " <TABLE COLS=2 WIDTH=75% NOBORDER align=\"center\">";
238 echo " <TD BGCOLOR=FFFFFF><CENTER>";
239 if (strlen($org_logo) > 3)
240 echo " <IMG SRC=\"$org_logo\">";
242 echo " <B><FONT FACE=\"Arial,Helvetica\">$org_name</FONT></B>";
243 echo " </CENTER></TD></TR><TR>";
244 echo " <TD BGCOLOR=FFFFFF>";
245 echo " <FONT FACE=\"Arial,Helvetica\">$motd</FONT>";
251 echo "</BODY></HTML>";
256 // switch to the mailbox, and get the number of messages in it.
257 selectMailbox($imapConnection, $mailbox, $numMessages);
259 // make a URL safe $mailbox for use in the links
260 $urlMailbox = urlencode($mailbox);
262 displayPageHeader($mailbox);
264 while ($i <= $numMessages) {
265 getMessageHeaders($imapConnection, $i, $from, $subject, $date);
267 $messages[$i]["DATE"] = getTimeStamp(explode(" ", trim($date)));
268 $messages[$i]["ID"] = $i;
269 $messages[$i]["FROM"] = $from;
270 $messages[$i]["SUBJECT"] = $subject;
275 $msgs = ary_sort($messages, "DATE", -1);
277 $msgs = ary_sort($messages, "DATE", 1);
279 if ($endMessage > 24) {
280 echo "<A HREF=\"mailboxMessageList.php3?sort=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>   ";
284 /** Display "Next, Previous" on top */
286 /** This is the beginning of the message list table. It wraps around all messages */
287 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
288 echo "<TR><TD BGCOLOR=DCDCDC>";
289 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>";
290 echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">";
291 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>";
292 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT></TD>";
293 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>";
295 echo " <A HREF=\"mailboxMessageList.php3?sort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"images/up_pointer.gif\" BORDER=0></A></TD>\n";
297 echo " <A HREF=\"mailboxMessageList.php3?sort=0&startMessage=0&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"images/down_pointer.gif\" BORDER=0></A></TD>\n";
298 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT></TD>\n";
301 // loop through and display the info for each message.
302 for ($i = $startMessage;$i <= $endMessage; $i++
) {
303 printMessageInfo($imapConnection, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE"]);
307 echo "</TD></TR></TABLE>"; /** End of message-list table */
309 /** Display "Next, Previous" on bottom */
310 fclose($imapConnection);