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