59177427 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
4 | * mailbox_display.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This contains functions that display mailbox information, such as the |
10 | * table row that has sender, date, subject, etc... |
11 | * |
12 | * $Id$ |
13 | */ |
a4c2cd49 |
14 | |
46d38f78 |
15 | require_once('../functions/strings.php'); |
43fdb2a4 |
16 | |
35586184 |
17 | define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */ |
18 | |
19 | function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) { |
5e7f6ef6 |
20 | global $checkall, |
21 | $color, $msgs, $msort, |
22 | $sent_folder, $draft_folder, |
23 | $default_use_priority, |
24 | $message_highlight_list, |
25 | $index_order, |
26 | $pos; /* Search postion (if any) */ |
bdfb67f8 |
27 | |
28 | $color_string = $color[4]; |
29 | if ($GLOBALS['alt_index_colors']) { |
88cb1b4d |
30 | if (!isset($GLOBALS['row_count'])) { |
31 | $GLOBALS['row_count'] = 0; |
bdfb67f8 |
32 | } |
5e7f6ef6 |
33 | $GLOBALS['row_count']++; |
88cb1b4d |
34 | if ($GLOBALS['row_count'] % 2) { |
35 | if (!isset($color[12])) { |
36 | $color[12] = '#EAEAEA'; |
37 | } |
ac53fb56 |
38 | $color_string = $color[12]; |
bdfb67f8 |
39 | } |
40 | } |
41 | $msg = $msgs[$key]; |
42 | |
e14ded6e |
43 | /** |
44 | * This is done in case you're looking into Sent folders, |
45 | * because you can have multi receiver. |
46 | */ |
47 | $sendersName = split(',', $msg['FROM']); |
5dd6c4d7 |
48 | $senderName = ''; |
ca6e7f05 |
49 | for ($index = 0 ; $index < count($sendersName) ; $index++) { |
5dd6c4d7 |
50 | if ($senderName != '') { |
e14ded6e |
51 | $senderName .= ', '; |
e14ded6e |
52 | } |
ca6e7f05 |
53 | $senderName .= sqimap_find_displayable_name($sendersName[$index]); |
54 | } |
e14ded6e |
55 | |
bdfb67f8 |
56 | if( $mailbox == 'None' ) { |
57 | // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
58 | $boxes = sqimap_mailbox_list($imapConnection); |
59 | // sqimap_logout($imapConnection); |
60 | $mailbox = $boxes[0]['unformatted']; |
61 | unset( $boxes ); |
62 | } |
63 | $urlMailbox = urlencode($mailbox); |
64 | $subject = processSubject($msg['SUBJECT']); |
65 | echo "<TR>\n"; |
66 | |
67 | if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) { |
bd9bbfef |
68 | $flag = "<font color=\"$color[2]\">"; |
bdfb67f8 |
69 | $flag_end = '</font>'; |
70 | } else { |
71 | $flag = ''; |
72 | $flag_end = ''; |
73 | } |
74 | if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) { |
75 | $bold = '<b>'; |
76 | $bold_end = '</b>'; |
77 | } else { |
78 | $bold = ''; |
79 | $bold_end = ''; |
80 | } |
81 | |
a3439b27 |
82 | if (handleAsSent($mailbox)) { |
bdfb67f8 |
83 | $italic = '<i>'; |
84 | $italic_end = '</i>'; |
85 | } else { |
86 | $italic = ''; |
87 | $italic_end = ''; |
88 | } |
89 | |
90 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
91 | $fontstr = "<font color=\"$color[9]\">"; |
92 | $fontstr_end = '</font>'; |
93 | } else { |
94 | $fontstr = ''; |
95 | $fontstr_end = ''; |
96 | } |
97 | |
98 | for ($i=0; $i < count($message_highlight_list); $i++) { |
99 | if (trim($message_highlight_list[$i]['value']) != '') { |
90bc0b93 |
100 | if ($message_highlight_list[$i]['match_type'] == 'to_cc') { |
bdfb67f8 |
101 | if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) { |
102 | $hlt_color = $message_highlight_list[$i]['color']; |
103 | continue; |
104 | } |
90bc0b93 |
105 | } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) { |
bdfb67f8 |
106 | $hlt_color = $message_highlight_list[$i]['color']; |
107 | continue; |
b60b58f9 |
108 | } |
bdfb67f8 |
109 | } |
110 | } |
111 | |
112 | if (!isset($hlt_color)) { |
113 | $hlt_color = $color_string; |
114 | } |
115 | |
116 | if ($where && $what) { |
a5ee5ac2 |
117 | if( !isset( $pos ) || $pos == '' ) { |
118 | $pos = '0'; |
119 | } |
120 | $search_stuff = "&pos=" . urlencode( $pos ) . "&where=".urlencode($where).'&what='.urlencode($what); |
bdfb67f8 |
121 | } |
122 | |
123 | $checked = ($checkall == 1 ?' checked' : ''); |
124 | |
125 | for ($i=1; $i <= count($index_order); $i++) { |
126 | switch ($index_order[$i]) { |
127 | case 1: /* checkbox */ |
bd9bbfef |
128 | echo " <td bgcolor=\"$hlt_color\" align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n"; |
bdfb67f8 |
129 | break; |
130 | case 2: /* from */ |
bd9bbfef |
131 | echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n"; |
bdfb67f8 |
132 | break; |
133 | case 3: /* date */ |
bd9bbfef |
134 | echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n"; |
bdfb67f8 |
135 | break; |
136 | case 4: /* subject */ |
bd9bbfef |
137 | echo " <td bgcolor=\"$hlt_color\">$bold"; |
bdfb67f8 |
138 | if (! isset($search_stuff)) { $search_stuff = ''; } |
139 | echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\""; |
140 | do_hook("subject_link"); |
141 | |
142 | if ($subject != $msg['SUBJECT']) { |
143 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
144 | $title = array_flip($title); |
145 | $title = strtr($msg['SUBJECT'], $title); |
146 | $title = str_replace('"', "''", $title); |
147 | echo " title=\"$title\""; |
148 | } |
149 | echo ">$flag$subject$flag_end</a>$bold_end</td>\n"; |
150 | break; |
151 | case 5: /* flags */ |
152 | $stuff = false; |
bd9bbfef |
153 | echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n"; |
bdfb67f8 |
154 | if (isset($msg['FLAG_ANSWERED']) && |
155 | $msg['FLAG_ANSWERED'] == true) { |
e26c5580 |
156 | echo _("A") . "\n"; |
bdfb67f8 |
157 | $stuff = true; |
158 | } |
159 | if ($msg['TYPE0'] == 'multipart') { |
160 | echo "+\n"; |
161 | $stuff = true; |
162 | } |
163 | if ($default_use_priority) { |
164 | if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) { |
bd9bbfef |
165 | echo "<font color=\"$color[1]\">!</font>\n"; |
bdfb67f8 |
166 | $stuff = true; |
167 | } |
168 | if (ereg('(5)',substr($msg['PRIORITY'],0,1))) { |
bd9bbfef |
169 | echo "<font color=\"$color[8]\">?</font>\n"; |
bdfb67f8 |
170 | $stuff = true; |
171 | } |
172 | } |
173 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
174 | echo "<font color=\"$color[1]\">D</font>\n"; |
175 | $stuff = true; |
176 | } |
177 | |
178 | if (!$stuff) { |
179 | echo " \n"; |
180 | } |
181 | echo "</small></b></td>\n"; |
182 | break; |
183 | case 6: /* size */ |
bd9bbfef |
184 | echo " <td bgcolor=\"$hlt_color\">$bold$fontstr" . |
bdfb67f8 |
185 | show_readable_size($msg['SIZE']) . |
186 | "$fontstr_end$bold_end</td>\n"; |
187 | break; |
188 | } |
189 | } |
190 | echo "</tr>\n"; |
191 | } |
192 | |
193 | /** |
194 | * This function loops through a group of messages in the mailbox |
195 | * and shows them to the user. |
196 | */ |
197 | function showMessagesForMailbox |
f506bb2c |
198 | ($imapConnection, $mailbox, $num_msgs, $start_msg, $sort, |
199 | $color, $show_num, $use_cache) { |
bdfb67f8 |
200 | global $msgs, $msort; |
201 | global $sent_folder, $draft_folder; |
202 | global $message_highlight_list; |
203 | global $auto_expunge; |
204 | |
205 | /* If autoexpunge is turned on, then do it now. */ |
206 | if ($auto_expunge == true) { |
207 | sqimap_mailbox_expunge($imapConnection, $mailbox, false); |
208 | } |
209 | sqimap_mailbox_select($imapConnection, $mailbox); |
210 | |
a3439b27 |
211 | $issent = handleAsSent($mailbox); |
bdfb67f8 |
212 | if (!$use_cache) { |
213 | /* If it is sorted... */ |
214 | if ($num_msgs >= 1) { |
0d455368 |
215 | if ($sort < 6) { |
bdfb67f8 |
216 | $id = range(1, $num_msgs); |
0d455368 |
217 | } else { |
bdfb67f8 |
218 | // if it's not sorted |
219 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
220 | $end_msg = $start_msg + ($show_num-1); |
221 | } else { |
222 | $end_msg = $num_msgs; |
223 | } |
224 | |
225 | if ($end_msg < $start_msg) { |
226 | $start_msg = $start_msg - $show_num; |
227 | if ($start_msg < 1) { |
228 | $start_msg = 1; |
229 | } |
230 | } |
231 | |
232 | $real_startMessage = $num_msgs - $start_msg + 1; |
233 | $real_endMessage = $num_msgs - $start_msg - $show_num + 2; |
234 | if ($real_endMessage <= 0) { |
235 | $real_endMessage = 1; |
236 | } |
237 | $id = array_reverse(range($real_endMessage, $real_startMessage)); |
91f68e94 |
238 | } |
b60b58f9 |
239 | |
91f68e94 |
240 | $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent); |
241 | $flags = sqimap_get_flags_list($imapConnection, $id, $issent); |
242 | foreach ($msgs_list as $hdr) { |
bdfb67f8 |
243 | $from[] = $hdr->from; |
244 | $date[] = $hdr->date; |
245 | $subject[] = $hdr->subject; |
246 | $to[] = $hdr->to; |
247 | $priority[] = $hdr->priority; |
248 | $cc[] = $hdr->cc; |
249 | $size[] = $hdr->size; |
250 | $type[] = $hdr->type0; |
251 | } |
252 | } |
253 | |
254 | $j = 0; |
255 | if ($sort == 6) { |
256 | $end = $start_msg + $show_num - 1; |
257 | if ($num_msgs < $show_num) { |
258 | $end_loop = $num_msgs; |
259 | } else if ($end > $num_msgs) { |
260 | $end_loop = $num_msgs - $start_msg + 1; |
261 | } else { |
262 | $end_loop = $show_num; |
b60b58f9 |
263 | } |
bdfb67f8 |
264 | } else { |
23d6bd09 |
265 | $end = $num_msgs; |
cd928157 |
266 | $end_loop = $end; |
bdfb67f8 |
267 | } |
f7b1b3b1 |
268 | |
bdfb67f8 |
269 | while ($j < $end_loop) { |
cd928157 |
270 | if (isset($date[$j])) { |
0f8a1ce9 |
271 | $date[$j] = str_replace(' ', ' ', $date[$j]); |
cd928157 |
272 | $tmpdate = explode(' ', trim($date[$j])); |
273 | } else { |
bdfb67f8 |
274 | $tmpdate = $date = array('', '', '', '', '', ''); |
cd928157 |
275 | } |
90bc0b93 |
276 | |
277 | $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate); |
278 | $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']); |
279 | $messages[$j]['ID'] = $id[$j]; |
280 | $messages[$j]['FROM'] = decodeHeader($from[$j]); |
281 | $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j]))); |
282 | $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]); |
283 | $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j])); |
284 | $messages[$j]['TO'] = decodeHeader($to[$j]); |
285 | $messages[$j]['PRIORITY'] = $priority[$j]; |
286 | $messages[$j]['CC'] = $cc[$j]; |
287 | $messages[$j]['SIZE'] = $size[$j]; |
288 | $messages[$j]['TYPE0'] = $type[$j]; |
e9f8ea4e |
289 | |
290 | # fix SUBJECT-SORT to remove Re: |
bdfb67f8 |
291 | $re_abbr = /* Add more here! */ |
292 | 'vedr|sv|' . /* Danish */ |
293 | 're|aw'; /* English */ |
f1e6f580 |
294 | |
bdfb67f8 |
295 | if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) { |
296 | $messages[$j]['SUBJECT-SORT'] = $regs[2]; |
297 | } |
b60b58f9 |
298 | |
5b6ae78a |
299 | $num = 0; |
300 | while ($num < count($flags[$j])) { |
bdfb67f8 |
301 | if ($flags[$j][$num] == 'Deleted') { |
302 | $messages[$j]['FLAG_DELETED'] = true; |
303 | } else if ($flags[$j][$num] == 'Answered') { |
304 | $messages[$j]['FLAG_ANSWERED'] = true; |
305 | } else if ($flags[$j][$num] == 'Seen') { |
306 | $messages[$j]['FLAG_SEEN'] = true; |
307 | } else if ($flags[$j][$num] == 'Flagged') { |
308 | $messages[$j]['FLAG_FLAGGED'] = true; |
309 | } |
310 | $num++; |
7151188f |
311 | } |
5b6ae78a |
312 | $j++; |
bdfb67f8 |
313 | } |
f9b3e5d9 |
314 | |
bdfb67f8 |
315 | /* Only ignore messages flagged as deleted if we are using a |
316 | * trash folder or auto_expunge */ |
317 | if (((isset($move_to_trash) && $move_to_trash) |
318 | || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) { |
f7b1b3b1 |
319 | |
f9b3e5d9 |
320 | /** Find and remove the ones that are deleted */ |
321 | $i = 0; |
322 | $j = 0; |
f7b1b3b1 |
323 | |
23d6bd09 |
324 | while ($j < $num_msgs) { |
bdfb67f8 |
325 | if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) { |
326 | $j++; |
327 | continue; |
328 | } |
329 | $msgs[$i] = $messages[$j]; |
330 | |
331 | $i++; |
332 | $j++; |
5b6ae78a |
333 | } |
23d6bd09 |
334 | $num_msgs = $i; |
bdfb67f8 |
335 | } else { |
336 | if (!isset($messages)) { |
337 | $messages = array(); |
338 | } |
339 | $msgs = $messages; |
340 | } |
341 | } |
342 | |
343 | // There's gotta be messages in the array for it to sort them. |
344 | if ($num_msgs > 0 && ! $use_cache) { |
345 | /** 0 = Date (up) 4 = Subject (up) |
346 | ** 1 = Date (dn) 5 = Subject (dn) |
347 | ** 2 = Name (up) |
348 | ** 3 = Name (dn) |
349 | **/ |
350 | session_unregister("msgs"); |
351 | if (($sort == 0) || ($sort == 1)) |
90bc0b93 |
352 | $msort = array_cleave ($msgs, 'TIME_STAMP'); |
bdfb67f8 |
353 | elseif (($sort == 2) || ($sort == 3)) |
90bc0b93 |
354 | $msort = array_cleave ($msgs, 'FROM-SORT'); |
bdfb67f8 |
355 | elseif (($sort == 4) || ($sort == 5)) |
90bc0b93 |
356 | $msort = array_cleave ($msgs, 'SUBJECT-SORT'); |
bdfb67f8 |
357 | else // ($sort == 6) |
0d455368 |
358 | $msort = $msgs; |
359 | |
bdfb67f8 |
360 | if ($sort < 6) { |
9b0f85eb |
361 | if ($sort % 2) { |
bdfb67f8 |
362 | asort($msort); |
0d455368 |
363 | } else { |
bdfb67f8 |
364 | arsort($msort); |
0d455368 |
365 | } |
bdfb67f8 |
366 | } |
367 | session_register('msort'); |
368 | } |
369 | displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num); |
370 | session_register('msgs'); |
371 | } |
372 | |
373 | /** |
374 | * Generic function to convert the msgs array into an HTML table. |
375 | */ |
376 | function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) { |
377 | global $folder_prefix, $sent_folder; |
378 | global $imapServerAddress, $data_dir, $username, $use_mailbox_cache; |
379 | global $index_order, $real_endMessage, $real_startMessage, $checkall; |
380 | |
381 | /* If cache isn't already set, do it now. */ |
382 | if (!session_is_registered('msgs')) { session_register('msgs'); } |
383 | if (!session_is_registered('msort')) { session_register('msort'); } |
384 | |
385 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
386 | $end_msg = $start_msg + ($show_num-1); |
387 | } else { |
388 | $end_msg = $num_msgs; |
389 | } |
390 | |
391 | if ($end_msg < $start_msg) { |
392 | $start_msg = $start_msg - $show_num; |
393 | if ($start_msg < 1) { $start_msg = 1; } |
394 | } |
395 | |
396 | $urlMailbox = urlencode($mailbox); |
397 | |
398 | do_hook('mailbox_index_before'); |
399 | |
400 | $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); |
7b294953 |
401 | $paginator_str = get_paginator_str |
402 | ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort); |
bdfb67f8 |
403 | |
404 | if (! isset($msg)) { |
405 | $msg = ''; |
406 | } |
407 | |
29eb5486 |
408 | mail_message_listing_beginning( $imapConnection, |
bdfb67f8 |
409 | "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg", |
410 | $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg); |
411 | |
412 | $groupNum = $start_msg % ($show_num - 1); |
413 | $real_startMessage = $start_msg; |
414 | if ($sort == 6) { |
415 | if ($end_msg - $start_msg < $show_num - 1) { |
23d6bd09 |
416 | $end_msg = $end_msg - $start_msg + 1; |
417 | $start_msg = 1; |
bdfb67f8 |
418 | } else if ($start_msg > $show_num) { |
23d6bd09 |
419 | $end_msg = $show_num; |
420 | $start_msg = 1; |
bdfb67f8 |
421 | } |
422 | } |
423 | $endVar = $end_msg + 1; |
424 | |
425 | /* Loop through and display the info for each message. */ |
426 | $t = 0; // $t is used for the checkbox number |
427 | if ($num_msgs == 0) { // if there's no messages in this folder |
428 | echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n". |
429 | " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n". |
430 | "</TD></TR>"; |
431 | } elseif ($start_msg == $end_msg) { |
432 | /* If there's only one message in the box, handle it differently. */ |
433 | if ($sort != 6) { |
434 | $i = $start_msg; |
435 | } else { |
436 | $i = 1; |
437 | } |
438 | |
439 | reset($msort); |
440 | $k = 0; |
441 | do { |
442 | $key = key($msort); |
443 | next($msort); |
444 | $k++; |
445 | } while (isset ($key) && ($k < $i)); |
446 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0); |
447 | } else { |
448 | $i = $start_msg; |
449 | |
450 | reset($msort); |
451 | $k = 0; |
452 | do { |
453 | $key = key($msort); |
454 | next($msort); |
455 | $k++; |
456 | } while (isset ($key) && ($k < $i)); |
457 | |
458 | do { |
459 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0); |
460 | $key = key($msort); |
461 | $t++; |
462 | $i++; |
463 | next($msort); |
464 | } while ($i && $i < $endVar); |
465 | } |
466 | |
467 | echo '</table>'. |
bd9bbfef |
468 | "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1>" . |
469 | "<tr BGCOLOR=\"$color[4]\"><td>" . |
470 | "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>". |
bdfb67f8 |
471 | "<td align=right>$msg_cnt_str</td></tr></table>". |
bd9bbfef |
472 | "</td></tr>". |
bdfb67f8 |
473 | "</table>"; |
474 | /** End of message-list table */ |
475 | |
476 | do_hook('mailbox_index_after'); |
477 | echo "</TABLE></FORM>\n"; |
478 | } |
479 | |
480 | /** |
481 | * Displays the standard message list header. To finish the table, |
482 | * you need to do a "</table></table>"; |
483 | * |
484 | * $moveURL is the URL to submit the delete/move form to |
485 | * $mailbox is the current mailbox |
486 | * $sort is the current sorting method (-1 for no sorting available [searches]) |
487 | * $Message is a message that is centered on top of the list |
488 | * $More is a second line that is left aligned |
489 | */ |
490 | function mail_message_listing_beginning |
f7b1b3b1 |
491 | ($imapConnection, $moveURL, $mailbox = '', $sort = -1, |
bdfb67f8 |
492 | $msg_cnt_str = '', $paginator = ' ', $start_msg = 1) { |
493 | global $color, $index_order, $auto_expunge, $move_to_trash; |
494 | global $checkall, $sent_folder, $draft_folder; |
495 | $urlMailbox = urlencode($mailbox); |
496 | |
497 | /* |
498 | * This is the beginning of the message list table. |
499 | * It wraps around all messages |
500 | */ |
bd9bbfef |
501 | echo "<FORM name=messageList method=post action=\"$moveURL\">\n" |
502 | . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n" |
7b294953 |
503 | . "<TR BGCOLOR=\"$color[0]\"><TD>" |
504 | . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n" |
505 | . " <TD ALIGN=LEFT>$paginator</TD>\n" |
506 | . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n" |
507 | . " </TR></TABLE>\n" |
508 | . '</TD></TR>' |
509 | . "<TR><TD BGCOLOR=\"$color[0]\">\n" |
7b294953 |
510 | . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n" |
511 | . " <TR>\n" |
bd9bbfef |
512 | . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n" |
b4b83736 |
513 | . ' <SMALL> ' . _("Move Selected To:") . "</SMALL>\n" |
7b294953 |
514 | . " </TD>\n" |
515 | . " <TD ALIGN=RIGHT NOWRAP>\n" |
516 | . ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n" |
517 | . " </TD>\n" |
518 | . " </TR>\n" |
519 | . " <TR>\n" |
bd9bbfef |
520 | . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n" |
7b294953 |
521 | . ' <SMALL> <TT><SELECT NAME="targetMailbox">'; |
bdfb67f8 |
522 | |
523 | $boxes = sqimap_mailbox_list($imapConnection); |
524 | for ($i = 0; $i < count($boxes); $i++) { |
3b7d68e6 |
525 | if (!in_array('noselect', $boxes[$i]['flags'])) { |
90bc0b93 |
526 | $box = $boxes[$i]['unformatted']; |
3b7e638f |
527 | $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']); |
3b7d68e6 |
528 | if( $box2 == 'INBOX' ) { |
529 | $box2 = _("INBOX"); |
530 | } |
14eb705c |
531 | echo " <OPTION VALUE=\"$box\">$box2</option>\n"; |
bdfb67f8 |
532 | } |
533 | } |
ac208bba |
534 | echo ' </SELECT></TT> '. |
535 | "<INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n". |
bdfb67f8 |
536 | " </TD>\n". |
537 | " <TD ALIGN=RIGHT NOWRAP> \n"; |
538 | if (!$auto_expunge) { |
539 | echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n"; |
540 | } |
541 | echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n". |
542 | " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n". |
543 | " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n". |
544 | " </TD>\n". |
545 | " </TR>\n". |
546 | "</TABLE>\n"; |
547 | do_hook('mailbox_form_before'); |
548 | echo '</TD></TR>'. |
549 | |
550 | "<TR><TD BGCOLOR=\"$color[0]\">". |
bd9bbfef |
551 | "<TABLE WIDTH=\"100%\" BORDER=0 CELLPADDING=2 CELLSPACING="; |
bdfb67f8 |
552 | if ($GLOBALS['alt_index_colors']) { |
ac53fb56 |
553 | echo "0"; |
bdfb67f8 |
554 | } else { |
ac53fb56 |
555 | echo "1"; |
bdfb67f8 |
556 | } |
557 | echo " BGCOLOR=\"$color[0]\">". |
558 | "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">"; |
559 | |
560 | /* Print the headers. */ |
561 | for ($i=1; $i <= count($index_order); $i++) { |
562 | switch ($index_order[$i]) { |
563 | case 1: /* checkbox */ |
564 | case 5: /* flags */ |
565 | echo ' <TD WIDTH="1%"><B> </B></TD>'; |
566 | break; |
567 | |
568 | case 2: /* from */ |
a3439b27 |
569 | if (handleAsSent($mailbox)) { |
bdfb67f8 |
570 | echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>'; |
571 | } else { |
572 | echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>'; |
573 | } |
574 | |
575 | ShowSortButton($sort, $mailbox, 2, 3); |
576 | echo "</TD>\n"; |
577 | break; |
578 | |
579 | case 3: /* date */ |
580 | echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>'; |
581 | ShowSortButton($sort, $mailbox, 0, 1); |
582 | echo "</TD>\n"; |
583 | break; |
584 | |
585 | case 4: /* subject */ |
586 | echo ' <TD><B>'. _("Subject") .'</B> '; |
587 | ShowSortButton($sort, $mailbox, 4, 5); |
588 | echo "</TD>\n"; |
589 | break; |
590 | |
591 | case 6: /* size */ |
592 | echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n"; |
593 | break; |
594 | } |
595 | } |
596 | echo "</TR>\n"; |
597 | } |
598 | |
599 | /* |
600 | * This function shows the sort button. Isn't this a good comment? |
601 | */ |
602 | function ShowSortButton($sort, $mailbox, $Up, $Down) { |
603 | /* Figure out which image we want to use. */ |
604 | if ($sort != $Up && $sort != $Down) { |
001befaf |
605 | $img = 'sort_none.png'; |
bdfb67f8 |
606 | $which = $Up; |
607 | } elseif ($sort == $Up) { |
001befaf |
608 | $img = 'up_pointer.png'; |
bdfb67f8 |
609 | $which = $Down; |
610 | } else { |
001befaf |
611 | $img = 'down_pointer.png'; |
bdfb67f8 |
612 | $which = 6; |
613 | } |
614 | |
615 | /* Now that we have everything figured out, show the actual button. */ |
616 | echo ' <a href="right_main.php?newsort=' . $which . |
617 | '&startMessage=1&mailbox=' . urlencode($mailbox) . |
618 | '"><IMG SRC="../images/' . $img . |
619 | '" BORDER=0 WIDTH=12 HEIGHT=10></a>'; |
620 | } |
621 | |
622 | function get_selectall_link($start_msg, $sort) { |
f506bb2c |
623 | global $checkall, $what, $where, $mailbox, $javascript_on; |
624 | global $PHP_SELF, $PG_SHOWNUM; |
bdfb67f8 |
625 | |
626 | if ($javascript_on) { |
627 | $result = |
628 | '<script language="JavaScript">' . |
629 | "\n<!-- \n" . |
630 | "function CheckAll() {\n" . |
631 | " for (var i = 0; i < document.messageList.elements.length; i++) {\n" . |
632 | " if( document.messageList.elements[i].type == 'checkbox' ) {\n" . |
633 | " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n". |
634 | " }\n" . |
635 | " }\n" . |
636 | "}\n" . |
637 | "//-->\n" . |
7c0060c9 |
638 | '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n"; |
bdfb67f8 |
639 | } else { |
0954af91 |
640 | if (strpos($PHP_SELF, "?")) { |
641 | $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox) |
c57b0888 |
642 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
0954af91 |
643 | } |
644 | else { |
645 | $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) |
646 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
647 | } |
bdfb67f8 |
648 | if (isset($checkall) && $checkall == '1') { |
649 | $result .= '0'; |
650 | } else { |
651 | $result .= '1'; |
652 | } |
653 | |
654 | if (isset($where) && isset($what)) { |
655 | $result .= '&where=' . urlencode($where) |
656 | . '&what=' . urlencode($what); |
657 | } |
658 | |
f506bb2c |
659 | if ($PG_SHOWNUM == 999999) { |
660 | $result .= '&PG_SHOWNUM=999999'; |
661 | } |
662 | |
bdfb67f8 |
663 | $result .= "\">"; |
664 | |
665 | if (isset($checkall) && ($checkall == '1')) { |
666 | $result .= _("Unselect All"); |
23d6bd09 |
667 | } else { |
bdfb67f8 |
668 | $result .= _("Select All"); |
23d6bd09 |
669 | } |
670 | |
bdfb67f8 |
671 | $result .= "</A>\n"; |
23d6bd09 |
672 | } |
673 | |
bdfb67f8 |
674 | /* Return our final result. */ |
675 | return ($result); |
676 | } |
1a0e0983 |
677 | |
bdfb67f8 |
678 | /** |
679 | * This function computes the "Viewing Messages..." string. |
680 | */ |
681 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
682 | /* Compute the $msg_cnt_str. */ |
683 | $result = ''; |
684 | if ($start_msg < $end_msg) { |
685 | $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs); |
686 | } else if ($start_msg == $end_msg) { |
687 | $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg); |
688 | } else { |
689 | $result = '<br>'; |
690 | } |
23d6bd09 |
691 | |
bdfb67f8 |
692 | /* Return our result string. */ |
693 | return ($result); |
694 | } |
695 | |
696 | /** |
7b294953 |
697 | * Generate a paginator link. |
698 | */ |
699 | function get_paginator_link |
700 | ($box, $start_msg, $use, $text) { |
701 | $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use" |
702 | . "&startMessage=$start_msg&mailbox=$box\" " |
703 | . "TARGET=\"right\">$text</A>"; |
704 | return ($result); |
705 | } |
706 | |
707 | /** |
708 | * This function computes the paginator string. |
709 | */ |
bdfb67f8 |
710 | function get_paginator_str |
7b294953 |
711 | ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) { |
f506bb2c |
712 | global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM; |
bdfb67f8 |
713 | |
7b294953 |
714 | /* Initialize paginator string chunks. */ |
715 | $prv_str = ''; |
716 | $nxt_str = ''; |
717 | $pg_str = ''; |
718 | $all_str = ''; |
719 | $tgl_str = ''; |
720 | |
721 | /* Create simple strings that will be creating the paginator. */ |
722 | $spc = ' '; /* This will be used as a space. */ |
723 | $sep = '|'; /* This will be used as a seperator. */ |
bdfb67f8 |
724 | |
7b294953 |
725 | /* Get some paginator preference values. */ |
311339a0 |
726 | $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON); |
7b294953 |
727 | $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX); |
728 | |
729 | /* Make sure that our start message number is not too big. */ |
730 | $start_msg = min($start_msg, $num_msgs); |
731 | |
732 | /* Decide whether or not we will use the mailbox cache. */ |
733 | /* Not sure why $use_mailbox_cache is even passed in. */ |
bdfb67f8 |
734 | if ($sort == 6) { |
735 | $use = 0; |
736 | } else { |
737 | $use = 1; |
738 | } |
7b294953 |
739 | |
740 | /* Compute the starting message of the previous and next page group. */ |
741 | $next_grp = $start_msg + $show_num; |
742 | $prev_grp = $start_msg - $show_num; |
743 | |
744 | /* Compute the basic previous and next strings. */ |
745 | if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) { |
746 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
747 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
748 | } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) { |
749 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
750 | $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n"; |
751 | } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) { |
752 | $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>'; |
753 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
bdfb67f8 |
754 | } |
7b294953 |
755 | |
bdfb67f8 |
756 | /* Page selector block. Following code computes page links. */ |
7b294953 |
757 | if ($pg_sel && ($num_msgs > $show_num)) { |
758 | /* Most importantly, what is the current page!!! */ |
759 | $cur_pg = intval($start_msg / $show_num) + 1; |
760 | |
761 | /* Compute total # of pages and # of paginator page links. */ |
762 | $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */ |
763 | $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */ |
764 | |
765 | /************************************************************/ |
766 | /* Compute the size of the four quarters of the page links. */ |
767 | /************************************************************/ |
768 | |
769 | /* If we can, just show all the pages. */ |
770 | if (($tot_pgs - 1) <= $pg_max) { |
771 | $q1_pgs = $cur_pg - 1; |
772 | $q2_pgs = $q3_pgs = 0; |
773 | $q4_pgs = $tot_pgs - $cur_pg; |
774 | |
775 | /* Otherwise, compute some magic to choose the four quarters. */ |
776 | } else { |
777 | /* Compute the magic base values. Added together, */ |
778 | /* these values will always equal to the $pag_pgs. */ |
779 | /* NOTE: These are DEFAULT values and do not take */ |
780 | /* the current page into account. That is below. */ |
781 | $q1_pgs = floor($vis_pgs/4); |
782 | $q2_pgs = round($vis_pgs/4, 0); |
783 | $q3_pgs = ceil($vis_pgs/4); |
784 | $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); |
785 | |
786 | /* Adjust if the first quarter contains the current page. */ |
787 | if (($cur_pg - $q1_pgs) < 1) { |
788 | $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; |
789 | $q1_pgs = $cur_pg - 1; |
790 | $q2_pgs = 0; |
791 | $q3_pgs += ceil($extra_pgs / 2); |
792 | $q4_pgs += floor($extra_pgs / 2); |
793 | |
794 | /* Adjust if the first and second quarters intersect. */ |
795 | } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { |
796 | $extra_pgs = $q2_pgs; |
797 | $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
798 | $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
799 | $q3_pgs += ceil($extra_pgs / 2); |
800 | $q4_pgs += floor($extra_pgs / 2); |
801 | |
802 | /* Adjust if the fourth quarter contains the current page. */ |
803 | } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { |
804 | $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; |
805 | $q3_pgs = 0; |
806 | $q4_pgs = $tot_pgs - $cur_pg; |
807 | $q1_pgs += floor($extra_pgs / 2); |
808 | $q2_pgs += ceil($extra_pgs / 2); |
809 | |
810 | /* Adjust if the third and fourth quarter intersect. */ |
811 | } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { |
812 | $extra_pgs = $q3_pgs; |
813 | $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
814 | $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
815 | $q1_pgs += floor($extra_pgs / 2); |
816 | $q2_pgs += ceil($extra_pgs / 2); |
817 | } |
23d6bd09 |
818 | } |
7b294953 |
819 | |
820 | /* I am leaving this debug code here, commented out, because */ |
821 | /* it is a really nice way to see what the above code is doing. */ |
822 | /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */ |
823 | /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */ |
824 | |
825 | /************************************************************/ |
826 | /* Print out the page links from the compute page quarters. */ |
827 | /************************************************************/ |
828 | |
829 | /* Start with the first quarter. */ |
830 | if (($q1_pgs == 0) && ($cur_pg > 1)) { |
831 | $pg_str .= "...$spc"; |
832 | } else { |
833 | for ($pg = 1; $pg <= $q1_pgs; ++$pg) { |
834 | $start = (($pg-1) * $show_num) + 1; |
835 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
836 | } |
837 | if ($cur_pg - $q2_pgs - $q1_pgs > 1) { |
838 | $pg_str .= "...$spc"; |
839 | } |
23d6bd09 |
840 | } |
7b294953 |
841 | |
842 | /* Continue with the second quarter. */ |
843 | for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { |
844 | $start = (($pg-1) * $show_num) + 1; |
845 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
23d6bd09 |
846 | } |
7b294953 |
847 | |
848 | /* Now print the current page. */ |
849 | $pg_str .= $cur_pg . $spc; |
850 | |
851 | /* Next comes the third quarter. */ |
852 | for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { |
853 | $start = (($pg-1) * $show_num) + 1; |
854 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
855 | } |
856 | |
857 | /* And last, print the forth quarter page links. */ |
858 | if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { |
859 | $pg_str .= "...$spc"; |
860 | } else { |
861 | if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { |
862 | $pg_str .= "...$spc"; |
863 | } |
864 | for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { |
865 | $start = (($pg-1) * $show_num) + 1; |
866 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
867 | } |
868 | } |
f506bb2c |
869 | } else if ($PG_SHOWNUM == 999999) { |
870 | $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use" |
871 | . "&startMessage=1&mailbox=$box\" TARGET=\"right\">" |
d72204a2 |
872 | . _("Paginate") . '</A>' . $spc; |
7b294953 |
873 | } |
874 | |
875 | /* If necessary, compute the 'show all' string. */ |
876 | if (($prv_str != '') || ($nxt_str != '')) { |
f506bb2c |
877 | $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999" |
7b294953 |
878 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
879 | . "TARGET=\"right\">" . _("Show All") . '</A>'; |
bdfb67f8 |
880 | } |
23d6bd09 |
881 | |
7b294953 |
882 | /* Last but not least, get the value for the toggle all link. */ |
883 | $tgl_str = get_selectall_link($start_msg, $sort); |
884 | |
885 | /* Put all the pieces of the paginator string together. */ |
886 | $result = ''; |
7b294953 |
887 | $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); |
dbf3883b |
888 | $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : ''); |
889 | $result .= ($pg_str != '' ? $pg_str : ''); |
f506bb2c |
890 | $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : ''); |
dbf3883b |
891 | $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str); |
7b294953 |
892 | |
893 | /* If the resulting string is blank, return a non-breaking space. */ |
894 | if ($result == '') { |
895 | $result = ' '; |
bdfb67f8 |
896 | } |
7b294953 |
897 | |
898 | /* Return our final magical paginator string. */ |
899 | return ($result); |
bdfb67f8 |
900 | } |
901 | |
902 | function processSubject($subject) { |
903 | // Shouldn't ever happen -- caught too many times in the IMAP functions |
904 | if ($subject == '') |
905 | return _("(no subject)"); |
906 | |
907 | if (strlen($subject) <= 55) |
908 | return $subject; |
909 | |
910 | $ent_strlen=strlen($subject); |
911 | $trim_val=50; |
912 | $ent_offset=0; |
913 | // see if this is entities-encoded string |
914 | // If so, Iterate through the whole string, find out |
915 | // the real number of characters, and if more |
916 | // than 55, substr with an updated trim value. |
917 | while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false && |
918 | ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) |
919 | { |
920 | $trim_val += ($ent_loc_end-$ent_loc)+1; |
921 | $ent_strlen -= $ent_loc_end-$ent_loc; |
922 | $ent_offset = $ent_loc_end+1; |
923 | } |
23d6bd09 |
924 | |
bdfb67f8 |
925 | if ($ent_strlen <= 55) |
926 | return $subject; |
927 | |
928 | return substr($subject, 0, $trim_val) . '...'; |
929 | } |
f93c93b9 |
930 | |
a3439b27 |
931 | function handleAsSent($mailbox) { |
932 | global $sent_folder, $draft_folder; |
933 | global $handleAsSent_result; |
934 | |
935 | /* First check if this is the sent or draft folder. */ |
936 | $handleAsSent_result = (($mailbox == $sent_folder) |
937 | || ($mailbox == $draft_folder)); |
938 | |
939 | /* Then check the result of the handleAsSent hook. */ |
940 | do_hook('check_handleAsSent_result', $mailbox); |
941 | |
942 | /* And return the result. */ |
943 | return ($handleAsSent_result); |
944 | } |
945 | |
e14ded6e |
946 | ?> |