437cfb821ff7def98c2be8fae27880b68c12e96f
[squirrelmail.git] / functions / mailbox_display.php
1 <?
2 /**
3 ** mailbox_display.php
4 **
5 ** This contains functions that display mailbox information, such as the
6 ** table row that has sender, date, subject, etc...
7 **
8 **/
9
10 function printMessageInfo($imapConnection, $i, $from, $subject, $dateString, $answered, $seen) {
11 $senderName = getSenderName($from);
12 if (strlen(Chop($subject)) == 0)
13 $subject = "(no subject)";
14
15 echo "<TR>\n";
16 if ($seen == false) {
17 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$i</B></FONT></TD>\n";
18 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
19 echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
20 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$subject</B></FONT></TD>\n";
21 } else {
22 echo " <TD><FONT FACE=\"Arial,Helvetica\">$i</FONT></TD>\n";
23 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
24 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
25 echo " <TD><FONT FACE=\"Arial,Helvetica\">$subject</FONT></TD>\n";
26 }
27 echo "</TR>\n";
28 }
29
30 /**
31 ** This function loops through a group of messages in the mailbox and shows them
32 **/
33 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort) {
34 $j = 1;
35 while ($j <= $numMessages) {
36 $q = 0;
37 getMessageHeaders($imapConnection, $j, $from, $subject, $date);
38 getMessageFlags($imapConnection, $j, $flags);
39
40 $messages[$j]["TIME_STAMP"] = getTimeStamp(explode(" ", trim($date)));
41 $messages[$j]["DATE_STRING"] = getDateString(explode(" ", trim($date)));
42 $messages[$j]["ID"] = $j;
43 $messages[$j]["FROM"] = $from;
44 $messages[$j]["SUBJECT"] = $subject;
45 $messages[$j]["FLAG_DELETED"] = false;
46 $messages[$j]["FLAG_ANSWERED"] = false;
47 $messages[$j]["FLAG_SEEN"] = false;
48
49 while ($q < count($flags)) {
50 if ($flags[$q] == "Deleted") {
51 $messages[$j]["FLAG_DELETED"] = true;
52 }
53 else if ($flags[$q] == "Answered") {
54 $messages[$j]["FLAG_ANSWERED"] = true;
55 }
56 else if ($flags[$q] == "Seen") {
57 $messages[$j]["FLAG_SEEN"] = true;
58 }
59 $q++;
60 }
61
62 $j++;
63 }
64
65 /** Find and remove the ones that are deleted */
66 $i = 1;
67 $j = 1;
68 while ($j <= $numMessages) {
69 if ($messages[$j]["FLAG_DELETED"] == true) {
70 $j++;
71 continue;
72 }
73 $msgs[$i]["TIME_STAMP"] = $messages[$j]["TIME_STAMP"];
74 $msgs[$i]["DATE_STRING"] = $messages[$j]["DATE_STRING"];
75 $msgs[$i]["ID"] = $messages[$j]["ID"];
76 $msgs[$i]["FROM"] = $messages[$j]["FROM"];
77 $msgs[$i]["SUBJECT"] = $messages[$j]["SUBJECT"];
78 $msgs[$i]["FLAG_DELETED"] = $messages[$j]["FLAG_DELETED"];
79 $msgs[$i]["FLAG_ANSWERED"] = $messages[$j]["FLAG_ANSWERED"];
80 $msgs[$i]["FLAG_SEEN"] = $messages[$j]["FLAG_SEEN"];
81 $i++;
82 $j++;
83 }
84
85 $numMessagesOld = $numMessages;
86 $numMessages = $i - 1;
87
88 if ($sort == 0)
89 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
90 else
91 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
92
93 if ($startMessage + 24 < $numMessages) {
94 $endMessage = $startMessage + 24;
95 } else {
96 $endMessage = $numMessages;
97 }
98
99 $nextGroup = $startMessage + 25;
100 $prevGroup = $startMessage - 25;
101 $urlMailbox = urlencode($mailbox);
102
103 /** This is the beginning of the message list table. It wraps around all messages */
104 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
105
106 echo "<TR BGCOLOR=FFFFFF><TD>";
107 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing messages <B>$startMessage</B> to <B>$endMessage</B> ($numMessages total)</FONT></CENTER>\n";
108 echo "</TD></TR>\n";
109
110 echo "<TR BGCOLOR=FFFFFF><TD>";
111 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
112 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
113 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
114 }
115 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
116 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
117 }
118 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
119 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
120 }
121 echo "</TD></TR>\n";
122
123 echo "<TR><TD BGCOLOR=DCDCDC>";
124 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>";
125 echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">";
126 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>";
127 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT></TD>";
128 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>";
129 if ($sort == 0)
130 echo " <A HREF=\"right_main.php?sort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
131 else
132 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
133 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT></TD>\n";
134 echo "</TR>";
135
136 // loop through and display the info for each message.
137 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
138 printMessageInfo($imapConnection, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"]);
139 }
140 echo "</TABLE>\n";
141
142 echo "</TD></TR>\n";
143 echo "<TR BGCOLOR=FFFFFF><TD>";
144 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
145 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
146 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
147 }
148 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
149 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
150 }
151 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
152 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
153 }
154 echo "</TD></TR></TABLE>"; /** End of message-list table */
155 }
156 ?>