Added MUCH better composing
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
3302d0d4 1<?
7c1b84d9 2
3302d0d4 3 /**
a09387f4 4 ** mailbox_display.php
3302d0d4 5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 **/
10
8467bf00 11 function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
3302d0d4 12 $senderName = getSenderName($from);
05207a68 13 $urlMailbox = urlencode($mailbox);
926da13e 14 echo "<TR>\n";
15 if ($seen == false) {
4c2d69ac 16 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><B><input type=checkbox name=\"msg[$t]\" value=$i></B></nobr></FONT></TD>\n";
926da13e 17 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
18 echo " <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
b8ea4ed6 19 echo " <TD><FONT FACE=\"Arial,Helvetica\"><B><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i&sort=$sort&startMessage=$startMessage\">$subject</A></B></FONT></TD>\n";
926da13e 20 } else {
4c2d69ac 21 echo " <TD><FONT FACE=\"Arial,Helvetica\"><nobr><input type=checkbox name=\"msg[$t]\" value=$i></nobr></FONT></TD>\n";
926da13e 22 echo " <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
23 echo " <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
8467bf00 24 echo " <TD><FONT FACE=\"Arial,Helvetica\"><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i&sort=$sort&startMessage=$startMessage\">$subject</A></FONT></TD>\n";
926da13e 25 }
26 echo "</TR>\n";
27 }
28
29 /**
30 ** This function loops through a group of messages in the mailbox and shows them
31 **/
32 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort) {
61a4ac35 33 include("../config/config.php");
34
3e054c43 35 if (1 <= $numMessages) {
36 getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
37 }
38
39 $j = 0;
40 while ($j < $numMessages) {
e550d551 41// echo "$numMessages -- $j -- $subject[$j]<BR>";
0e919368 42 $date[$j] = ereg_replace(" ", " ", $date[$j]);
43 $tmpdate = explode(" ", trim($date[$j]));
44
45 $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate);
46 $messages[$j]["DATE_STRING"] = getDateString($tmpdate);
3e054c43 47 $messages[$j]["ID"] = $j+1;
0e919368 48 $messages[$j]["FROM"] = getSenderName($from[$j]);
3e054c43 49 $messages[$j]["SUBJECT"] = $subject[$j];
5b10f02a 50 $messages[$j]["FLAG_DELETED"] = false;
51 $messages[$j]["FLAG_ANSWERED"] = false;
52 $messages[$j]["FLAG_SEEN"] = false;
926da13e 53
3e054c43 54 $num = 0;
55 getMessageFlags($imapConnection, $j+1, $flags);
56 while ($num < count($flags)) {
57 if ($flags[$num] == "Deleted") {
5b10f02a 58 $messages[$j]["FLAG_DELETED"] = true;
59 }
3e054c43 60 else if ($flags[$num] == "Answered") {
5b10f02a 61 $messages[$j]["FLAG_ANSWERED"] = true;
62 }
3e054c43 63 else if ($flags[$num] == "Seen") {
5b10f02a 64 $messages[$j]["FLAG_SEEN"] = true;
65 }
3e054c43 66 $num++;
3302d0d4 67 }
5b10f02a 68 $j++;
69 }
70
71 /** Find and remove the ones that are deleted */
3e054c43 72 $i = 0;
73 $j = 0;
74 while ($j < $numMessages) {
5b10f02a 75 if ($messages[$j]["FLAG_DELETED"] == true) {
76 $j++;
77 continue;
78 }
79 $msgs[$i]["TIME_STAMP"] = $messages[$j]["TIME_STAMP"];
80 $msgs[$i]["DATE_STRING"] = $messages[$j]["DATE_STRING"];
81 $msgs[$i]["ID"] = $messages[$j]["ID"];
82 $msgs[$i]["FROM"] = $messages[$j]["FROM"];
83 $msgs[$i]["SUBJECT"] = $messages[$j]["SUBJECT"];
84 $msgs[$i]["FLAG_DELETED"] = $messages[$j]["FLAG_DELETED"];
85 $msgs[$i]["FLAG_ANSWERED"] = $messages[$j]["FLAG_ANSWERED"];
86 $msgs[$i]["FLAG_SEEN"] = $messages[$j]["FLAG_SEEN"];
e550d551 87
5b10f02a 88 $i++;
3302d0d4 89 $j++;
90 }
91
3e054c43 92 $numMessages = $i;
926da13e 93
4c2d69ac 94 // There's gotta be messages in the array for it to sort them.
95 if ($numMessages > 0) {
0e919368 96 /** 0 = Date (up) 4 = Subject (up)
97 ** 1 = Date (dn) 5 = Subject (dn)
98 ** 2 = Name (up)
99 ** 3 = Name (dn)
100 **/
4c2d69ac 101 if ($sort == 0)
102 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
0e919368 103 else if ($sort == 1)
4c2d69ac 104 $msgs = ary_sort($msgs, "TIME_STAMP", 1);
0e919368 105 else {
106 $original = $msgs;
107 $i = 0;
108 while ($i < count($msgs)) {
109 $msgs[$i]["FROM"] = strtolower($msgs[$i]["FROM"]);
110 $msgs[$i]["SUBJECT"] = strtolower($msgs[$i]["SUBJECT"]);
111 $i++;
112 }
113
114 if ($sort == 2)
115 $msgs = ary_sort($msgs, "FROM", -1);
116 else if ($sort == 3)
117 $msgs = ary_sort($msgs, "FROM", 1);
118 else if ($sort == 4)
119 $msgs = ary_sort($msgs, "SUBJECT", -1);
120 else if ($sort == 5)
121 $msgs = ary_sort($msgs, "SUBJECT", 1);
122 else
123 $msgs = ary_sort($msgs, "TIME_STAMP", -1);
124
125 $i = 0;
126 while ($i < count($msgs)) {
127 $j = 0;
128 while ($j < count($original)) {
129 if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
130 $msgs[$i]["FROM"] = $original[$j]["FROM"];
131 $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
132 }
133 $j++;
134 }
135 $i++;
136 }
137 }
4c2d69ac 138 }
926da13e 139
e550d551 140// $j = 0;
141// while ($j < $numMessages) {
142// $sub = $msgs[$j]["SUBJECT"];
143// $id = $msgs[$j]["ID"];
144// echo "$id -- $sub<BR>";
145// $j++;
146// }
147//exit;
148
926da13e 149 if ($startMessage + 24 < $numMessages) {
926da13e 150 $endMessage = $startMessage + 24;
151 } else {
926da13e 152 $endMessage = $numMessages;
153 }
154
5b10f02a 155 $nextGroup = $startMessage + 25;
926da13e 156 $prevGroup = $startMessage - 25;
20db5033 157 $urlMailbox = urlencode($mailbox);
926da13e 158
e550d551 159
20db5033 160 /** This is the beginning of the message list table. It wraps around all messages */
161 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
926da13e 162
0d1b4832 163 if ($startMessage < $endMessage) {
164 echo "<TR BGCOLOR=FFFFFF><TD>";
165 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing messages <B>$startMessage</B> to <B>$endMessage</B> ($numMessages total)</FONT></CENTER>\n";
166 echo "</TD></TR>\n";
167 } else if ($startMessage == $endMessage) {
168 echo "<TR BGCOLOR=FFFFFF><TD>";
169 echo "<CENTER><FONT FACE=\"Arial,Helvetica\">Viewing message <B>$startMessage</B> ($numMessages total)</FONT></CENTER>\n";
170 echo "</TD></TR>\n";
171 }
26b6c99c 172
20db5033 173 echo "<TR BGCOLOR=FFFFFF><TD>";
5b10f02a 174 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
a09387f4 175 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
176 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
926da13e 177 }
5b10f02a 178 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
a09387f4 179 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
aa4c3749 180 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
3302d0d4 181 }
5b10f02a 182 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
aa4c3749 183 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
a09387f4 184 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
926da13e 185 }
20db5033 186 echo "</TD></TR>\n";
926da13e 187
68347a84 188 /** The delete and move options */
faf8f4a2 189 echo "<TR><TD BGCOLOR=$color_lgray>";
05207a68 190 echo "<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
68347a84 191 echo "<SELECT NAME=move_or_delete><OPTION>Delete selected messages<OPTION>Move selected messages</SELECT>";
192 echo "<NOBR><INPUT TYPE=SUBMIT VALUE=\"Go\">";
61a4ac35 193 if (($move_to_trash == true) && ($mailbox == $trash_folder))
194 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>";
aa4c3749 195 echo "</TD></TR>";
196
faf8f4a2 197 echo "<TR><TD BGCOLOR=$color_lgray>";
926da13e 198 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=FFFFFF>";
199 echo "<TR BGCOLOR=FFFFCC ALIGN=\"center\">";
200 echo " <TD WIDTH=5%><FONT FACE=\"Arial,Helvetica\"><B>Num</B></FONT></TD>";
0e919368 201 /** FROM HEADER **/
202 echo " <TD WIDTH=25%><FONT FACE=\"Arial,Helvetica\"><B>From</B></FONT>";
203 if ($sort == 2)
204 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
205 else if ($sort == 3)
206 echo " <A HREF=\"right_main.php?sort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
207 else
208 echo " <A HREF=\"right_main.php?sort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
209 /** DATE HEADER **/
926da13e 210 echo " <TD WIDTH=15%><FONT FACE=\"Arial,Helvetica\"><B>Date</B></FONT>";
211 if ($sort == 0)
a09387f4 212 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";
0e919368 213 else if ($sort == 1)
a09387f4 214 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";
0e919368 215 else
216 echo " <A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
217 /** SUBJECT HEADER **/
218 echo " <TD WIDTH=*><FONT FACE=\"Arial,Helvetica\"><B>Subject</B></FONT>\n";
219 if ($sort == 4)
220 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
221 else if ($sort == 5)
222 echo " <A HREF=\"right_main.php?sort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
223 else
224 echo " <A HREF=\"right_main.php?sort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
926da13e 225 echo "</TR>";
226
227 // loop through and display the info for each message.
aa4c3749 228 $t = 0; // $t is used for the checkbox number
4c2d69ac 229 if ($numMessages == 0) { // if there's no messages in this folder
230 echo "<TR><TD BGCOLOR=FFFFFF COLSPAN=4><CENTER><BR><B>THIS FOLDER IS EMPTY</B><BR>&nbsp</CENTER></TD></TR>";
231 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
3e054c43 232 $i = $startMessage - 1;
8467bf00 233 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
4c2d69ac 234 } else {
235 for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
8467bf00 236 printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox, $sort, $startMessage);
4c2d69ac 237 $t++;
238 }
926da13e 239 }
68347a84 240 echo "</FORM></TABLE>";
aa4c3749 241
68347a84 242 echo "</TABLE>\n";
4c2d69ac 243 echo "</TD></TR>\n";
244
20db5033 245 echo "<TR BGCOLOR=FFFFFF><TD>";
246 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
a09387f4 247 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
248 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
20db5033 249 }
250 else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
a09387f4 251 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Previous</FONT></A>\n";
aa4c3749 252 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Next</FONT>\n";
20db5033 253 }
254 else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
aa4c3749 255 echo "<FONT FACE=\"Arial,Helvetica\" COLOR=ACACAC>Previous</FONT>\n";
a09387f4 256 echo "<A HREF=\"right_main.php?sort=$sort&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\"><FONT FACE=\"Arial,Helvetica\">Next</FONT></A>\n";
20db5033 257 }
926da13e 258 echo "</TD></TR></TABLE>"; /** End of message-list table */
3302d0d4 259 }
26b6c99c 260?>