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