84025faa479aaa0d32904a7883f0e0d27acb24cc
[squirrelmail.git] / functions / mailbox_display.php
1 <?
2
3 /**
4 ** mailbox_display.php
5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
10
11 function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen) {
12 $senderName = getSenderName($from);
13 if (strlen(Chop($subject)) == 0)
14 $subject = "(no subject)";
15
16 echo "<TR>\n";
17 if ($seen == false) {
18 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><B><input type=checkbox name=\"msg[$t]\" value=$i></B></nobr></FONT></TD>\n";
19 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
20 echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
21 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$subject</B></FONT></TD>\n";
22 } else {
23 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><input type=checkbox name=\"msg[$t]\" value=$i></nobr></FONT></TD>\n";
24 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
25 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
26 echo " <TD><FONT FACE=\"Arial,Helvetica\">$subject</FONT></TD>\n";
27 }
28 echo "</TR>\n";
29 }
30
31 /**
32 ** This function loops through a group of messages in the mailbox and shows them
33 **/
34 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort) {
35 include("../config/config.php");
36
37 if (1 <= $numMessages) {
38 getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
39 }
40
41 $j = 0;
42 while ($j < $numMessages) {
43 $messages[$j]["TIME_STAMP"] = getTimeStamp(explode(" ", trim($date[$j])));
44 $messages[$j]["DATE_STRING"] = getDateString(explode(" ", trim($date[$j])));
45 $messages[$j]["ID"] = $j+1;
46 $messages[$j]["FROM"] = $from[$j];
47 $messages[$j]["SUBJECT"] = $subject[$j];
48 $messages[$j]["FLAG_DELETED"] = false;
49 $messages[$j]["FLAG_ANSWERED"] = false;
50 $messages[$j]["FLAG_SEEN"] = false;
51
52 $num = 0;
53 getMessageFlags($imapConnection, $j+1, $flags);
54 while ($num < count($flags)) {
55 if ($flags[$num] == "Deleted") {
56 $messages[$j]["FLAG_DELETED"] = true;
57 }
58 else if ($flags[$num] == "Answered") {
59 $messages[$j]["FLAG_ANSWERED"] = true;
60 }
61 else if ($flags[$num] == "Seen") {
62 $messages[$j]["FLAG_SEEN"] = true;
63 }
64 $num++;
65 }
66 $j++;
67 }
68
69 /** Find and remove the ones that are deleted */
70 $i = 0;
71 $j = 0;
72 while ($j < $numMessages) {
73 if ($messages[$j]["FLAG_DELETED"] == true) {
74 $j++;
75 continue;
76 }
77 $msgs[$i]["TIME_STAMP"] = $messages[$j]["TIME_STAMP"];
78 $msgs[$i]["DATE_STRING"] = $messages[$j]["DATE_STRING"];
79 $msgs[$i]["ID"] = $messages[$j]["ID"];
80 $msgs[$i]["FROM"] = $messages[$j]["FROM"];
81 $msgs[$i]["SUBJECT"] = $messages[$j]["SUBJECT"];
82 $msgs[$i]["FLAG_DELETED"] = $messages[$j]["FLAG_DELETED"];
83 $msgs[$i]["FLAG_ANSWERED"] = $messages[$j]["FLAG_ANSWERED"];
84 $msgs[$i]["FLAG_SEEN"] = $messages[$j]["FLAG_SEEN"];
85 $i++;
86 $j++;
87 }
88
89 $numMessages = $i;
90
91 // There's gotta be messages in the array for it to sort them.
92 if ($numMessages > 0) {
93 if ($sort == 0)
94 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
95 else
96 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
97 }
98
99 if ($startMessage + 24 < $numMessages) {
100 $endMessage = $startMessage + 24;
101 } else {
102 $endMessage = $numMessages;
103 }
104
105 $nextGroup = $startMessage + 25;
106 $prevGroup = $startMessage - 25;
107 $urlMailbox = urlencode($mailbox);
108
109 /** This is the beginning of the message list table. It wraps around all messages */
110 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
111
112 echo "<TR BGCOLOR=FFFFFF><TD>";
113 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing messages <B>$startMessage</B> to <B>$endMessage</B> ($numMessages total)</FONT></CENTER>\n";
114 echo "</TD></TR>\n";
115
116 echo "<TR BGCOLOR=FFFFFF><TD>";
117 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
118 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
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 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
122 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
123 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
124 }
125 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
126 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
127 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
128 }
129 echo "</TD></TR>\n";
130
131 /** The "DELETE" button */
132 echo "<TR><TD BGCOLOR=DCDCDC>";
133 echo "<FORM name=messageList method=post action=\"move_messages.php?mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
134 echo "<NOBR><INPUT TYPE=SUBMIT VALUE=\"Delete Selected\">";
135 if (($move_to_trash == true) && ($mailbox == $trash_folder))
136 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\">Empty Trash</A></NOBR>";
137 echo "</TD></TR>";
138
139 echo "<TR><TD BGCOLOR=DCDCDC>";
140 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>";
141 echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">";
142 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>";
143 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT></TD>";
144 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>";
145 if ($sort == 0)
146 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";
147 else
148 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";
149 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT></TD>\n";
150 echo "</TR>";
151
152 // loop through and display the info for each message.
153 $t = 0; // $t is used for the checkbox number
154 if ($numMessages == 0) { // if there's no messages in this folder
155 echo "<TR><TD BGCOLOR=FFFFFF COLSPAN=4><CENTER><BR><B>THIS FOLDER IS EMPTY</B><BR>&nbsp</CENTER></TD></TR>";
156 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
157 $i = $startMessage - 1;
158 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"]);
159 } else {
160 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
161 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"]);
162 $t++;
163 }
164 }
165 echo "</TABLE>";
166
167 /** The "DELETE" button */
168 echo "<TR><TD BGCOLOR=DCDCDC>";
169 echo "<INPUT TYPE=SUBMIT VALUE=\"Delete Selected\">";
170 if (($move_to_trash == true) && ($mailbox == $trash_folder))
171 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF=\"empty_trash.php\">Empty Trash</A></NOBR>";
172 echo "</TD></TR>";
173
174 echo "</FORM></TABLE>\n";
175 echo "</TD></TR>\n";
176
177 echo "<TR BGCOLOR=FFFFFF><TD>";
178 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
179 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
180 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
181 }
182 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
183 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
184 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
185 }
186 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
187 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
188 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
189 }
190 echo "</TD></TR></TABLE>"; /** End of message-list table */
191 }
192 ?>