59177427 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
4 | * mailbox_display.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 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 | |
b68edc75 |
15 | require_once(SM_PATH . 'functions/strings.php'); |
16 | require_once(SM_PATH . 'functions/html.php'); |
17 | require_once(SM_PATH . 'class/html.class.php'); |
18 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
43fdb2a4 |
19 | |
6dc5eca4 |
20 | /* Constants: |
21 | * PG_SEL_MAX: default value for page_selector_max |
22 | * SUBJ_TRIM_AT: the length at which we trim off subjects |
23 | */ |
6c930ade |
24 | define('PG_SEL_MAX', 10); |
6dc5eca4 |
25 | define('SUBJ_TRIM_AT', 55); |
6c930ade |
26 | |
098ea084 |
27 | function elapsed($start) |
28 | { |
29 | $end = microtime(); |
30 | list($start2, $start1) = explode(" ", $start); |
31 | list($end2, $end1) = explode(" ", $end); |
32 | $diff1 = $end1 - $start1; |
33 | $diff2 = $end2 - $start2; |
34 | if( $diff2 < 0 ){ |
35 | $diff1 -= 1; |
36 | $diff2 += 1.0; |
37 | } |
38 | return $diff2 + $diff1; |
39 | } |
40 | |
7b887886 |
41 | function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox, |
d215ca7d |
42 | $start_msg, $where, $what) { |
8008456a |
43 | global $checkall, |
5bba30b5 |
44 | $color, $msgs, $msort, $td_str, $msg, |
c1c17724 |
45 | $default_use_priority, |
46 | $message_highlight_list, |
47 | $index_order, |
459e3347 |
48 | $indent_array, /* indent subject by */ |
49 | $pos, /* Search postion (if any) */ |
c1c17724 |
50 | $thread_sort_messages, /* thread sorting on/off */ |
459e3347 |
51 | $server_sort_order, /* sort value when using server-sorting */ |
c1c17724 |
52 | $row_count, |
459e3347 |
53 | $allow_server_sort, /* enable/disable server-side sorting */ |
54 | $truncate_sender; /* number of characters for From/To field (<= 0 for unchanged) */ |
55 | |
e9e5f0fa |
56 | $color_string = $color[4]; |
8008456a |
57 | |
58 | if ($GLOBALS['alt_index_colors']) { |
59 | if (!isset($row_count)) { |
60 | $row_count = 0; |
61 | } |
62 | $row_count++; |
63 | if ($row_count % 2) { |
64 | if (!isset($color[12])) { |
65 | $color[12] = '#EAEAEA'; |
66 | } |
67 | $color_string = $color[12]; |
68 | } |
bdfb67f8 |
69 | } |
8008456a |
70 | $msg = $msgs[$key]; |
71 | |
6a622b59 |
72 | if($mailbox == 'None') { |
73 | $boxes = sqimap_mailbox_list($imapConnection); |
8008456a |
74 | $mailbox = $boxes[0]['unformatted']; |
6a622b59 |
75 | unset($boxes); |
bdfb67f8 |
76 | } |
8008456a |
77 | $urlMailbox = urlencode($mailbox); |
e9e5f0fa |
78 | |
79 | if (handleAsSent($mailbox)) { |
80 | $msg['FROM'] = $msg['TO']; |
098ea084 |
81 | } |
267b2e40 |
82 | $msg['FROM'] = parseAddress($msg['FROM'],1); |
9701e9c8 |
83 | |
e9e5f0fa |
84 | /* |
85 | * This is done in case you're looking into Sent folders, |
86 | * because you can have multiple receivers. |
87 | */ |
937c81fa |
88 | |
098ea084 |
89 | $senderNames = $msg['FROM']; |
90 | $senderName = ''; |
91 | if (sizeof($senderNames)){ |
92 | foreach ($senderNames as $senderNames_part) { |
e9e5f0fa |
93 | if ($senderName != '') { |
94 | $senderName .= ', '; |
95 | } |
098ea084 |
96 | if ($senderNames_part[1]) { |
97 | $senderName .= decodeHeader($senderNames_part[1]); |
98 | } else { |
99 | $senderName .= htmlspecialchars($senderNames_part[0]); |
100 | } |
101 | } |
937c81fa |
102 | } |
3027826a |
103 | $senderName = str_replace(' ',' ',$senderName); |
459e3347 |
104 | |
105 | if ( $truncate_sender > 0 && strlen($senderName) > $truncate_sender ) { |
106 | $senderName = substr_replace($senderName, '... ', $truncate_sender); |
107 | } |
108 | |
5786ef5a |
109 | echo html_tag( 'tr','','','','VALIGN="top"') . "\n"; |
8008456a |
110 | |
111 | if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) { |
112 | $flag = "<font color=\"$color[2]\">"; |
113 | $flag_end = '</font>'; |
114 | } else { |
115 | $flag = ''; |
116 | $flag_end = ''; |
bdfb67f8 |
117 | } |
8008456a |
118 | if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) { |
119 | $bold = '<b>'; |
120 | $bold_end = '</b>'; |
121 | } else { |
122 | $bold = ''; |
123 | $bold_end = ''; |
bdfb67f8 |
124 | } |
8008456a |
125 | if (handleAsSent($mailbox)) { |
126 | $italic = '<i>'; |
127 | $italic_end = '</i>'; |
128 | } else { |
129 | $italic = ''; |
130 | $italic_end = ''; |
131 | } |
132 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
133 | $fontstr = "<font color=\"$color[9]\">"; |
134 | $fontstr_end = '</font>'; |
135 | } else { |
136 | $fontstr = ''; |
137 | $fontstr_end = ''; |
138 | } |
139 | |
d215ca7d |
140 | if ($where && $what) { |
141 | $searchstr = '&where='.$where.'&what='.$what; |
142 | } else { |
143 | $searchstr = ''; |
6a622b59 |
144 | } |
9701e9c8 |
145 | |
937c81fa |
146 | if (is_array($message_highlight_list) && count($message_highlight_list)) { |
8415b2d3 |
147 | $msg['TO'] = parseAddress($msg['TO']); |
148 | $msg['CC'] = parseAddress($msg['CC']); |
8008456a |
149 | foreach ($message_highlight_list as $message_highlight_list_part) { |
150 | if (trim($message_highlight_list_part['value']) != '') { |
c0d04f97 |
151 | $high_val = strtolower($message_highlight_list_part['value']); |
152 | $match_type = strtoupper($message_highlight_list_part['match_type']); |
8415b2d3 |
153 | if($match_type == 'TO_CC') { |
154 | $match = array('TO', 'CC'); |
155 | } else { |
156 | $match = array($match_type); |
157 | } |
158 | foreach($match as $match_type) { |
159 | switch($match_type) { |
160 | case('TO'): |
161 | case('CC'): |
162 | case('FROM'): |
163 | foreach ($msg[$match_type] as $address) { |
9701e9c8 |
164 | $address[0] = decodeHeader($address[0], true, false); |
165 | $address[1] = decodeHeader($address[1], true, false); |
8415b2d3 |
166 | if (strstr('^^' . strtolower($address[0]), $high_val) || |
167 | strstr('^^' . strtolower($address[1]), $high_val)) { |
168 | $hlt_color = $message_highlight_list_part['color']; |
169 | break 4; |
170 | } |
937c81fa |
171 | } |
937c81fa |
172 | break; |
8415b2d3 |
173 | default: |
9701e9c8 |
174 | $headertest = strtolower(decodeHeader($msg[$match_type], true, false)); |
175 | if (strstr('^^' . $headertest, $high_val)) { |
937c81fa |
176 | $hlt_color = $message_highlight_list_part['color']; |
8415b2d3 |
177 | break 3; |
937c81fa |
178 | } |
8415b2d3 |
179 | break; |
180 | } |
8008456a |
181 | } |
182 | } |
183 | } |
184 | } |
185 | |
186 | if (!isset($hlt_color)) { |
187 | $hlt_color = $color_string; |
188 | } |
59352d08 |
189 | $checked = ($checkall == 1) ? ' CHECKED' : ''; |
5e0efebf |
190 | $col = 0; |
9701e9c8 |
191 | $msg['SUBJECT'] = decodeHeader($msg['SUBJECT']); |
192 | $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]); |
193 | $subject = str_replace(' ',' ',$subject); |
6a622b59 |
194 | if (sizeof($index_order)) { |
8008456a |
195 | foreach ($index_order as $index_order_part) { |
196 | switch ($index_order_part) { |
197 | case 1: /* checkbox */ |
198 | echo html_tag( 'td', |
199 | "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>", |
6a622b59 |
200 | 'center', |
8008456a |
201 | $hlt_color ); |
202 | break; |
203 | case 2: /* from */ |
204 | echo html_tag( 'td', |
098ea084 |
205 | $italic . $bold . $flag . $fontstr . $senderName . |
8008456a |
206 | $fontstr_end . $flag_end . $bold_end . $italic_end, |
c1c17724 |
207 | 'left', |
8008456a |
208 | $hlt_color ); |
209 | break; |
210 | case 3: /* date */ |
53d9fbc5 |
211 | $date_string = $msg['DATE_STRING'] . ''; |
212 | if ($date_string == '') { |
213 | $date_string = _("Unknown date"); |
214 | } |
8008456a |
215 | echo html_tag( 'td', |
53d9fbc5 |
216 | $bold . $flag . $fontstr . $date_string . |
8008456a |
217 | $fontstr_end . $flag_end . $bold_end, |
218 | 'center', |
219 | $hlt_color, |
220 | 'nowrap' ); |
221 | break; |
222 | case 4: /* subject */ |
223 | $td_str = $bold; |
224 | if ($thread_sort_messages == 1) { |
6903c7bd |
225 | if (isset($indent_array[$msg['ID']])) { |
8008456a |
226 | $td_str .= str_repeat(" ",$indent_array[$msg['ID']]); |
227 | } |
228 | } |
e9e5f0fa |
229 | $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox |
6a622b59 |
230 | . '&passed_id='. $msg["ID"] |
231 | . '&startMessage='.$start_msg.$searchstr.'"'; |
158fa340 |
232 | $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr)); |
306b6393 |
233 | if ($subject != $msg['SUBJECT']) { |
8008456a |
234 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
235 | $title = array_flip($title); |
306b6393 |
236 | $title = strtr($msg['SUBJECT'], $title); |
8008456a |
237 | $title = str_replace('"', "''", $title); |
238 | $td_str .= " title=\"$title\""; |
239 | } |
240 | $td_str .= ">$flag$subject$flag_end</a>$bold_end"; |
c1c17724 |
241 | echo html_tag( 'td', $td_str, 'left', $hlt_color ); |
8008456a |
242 | break; |
243 | case 5: /* flags */ |
244 | $stuff = false; |
245 | $td_str = "<b><small>"; |
6a622b59 |
246 | |
8008456a |
247 | if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) { |
248 | $td_str .= _("A"); |
249 | $stuff = true; |
250 | } |
251 | if ($msg['TYPE0'] == 'multipart') { |
252 | $td_str .= '+'; |
253 | $stuff = true; |
254 | } |
255 | if ($default_use_priority) { |
256 | if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) { |
257 | $td_str .= "<font color=\"$color[1]\">!</font>"; |
258 | $stuff = true; |
259 | } |
260 | if ($msg['PRIORITY'] == 5) { |
261 | $td_str .= "<font color=\"$color[8]\">?</font>"; |
262 | $stuff = true; |
263 | } |
264 | } |
265 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) { |
266 | $td_str .= "<font color=\"$color[1]\">D</font>"; |
267 | $stuff = true; |
268 | } |
269 | if (!$stuff) { |
270 | $td_str .= ' '; |
271 | } |
2bd00b7b |
272 | do_hook("msg_envelope"); |
8008456a |
273 | $td_str .= '</small></b>'; |
274 | echo html_tag( 'td', |
275 | $td_str, |
276 | 'center', |
277 | $hlt_color, |
278 | 'nowrap' ); |
279 | break; |
280 | case 6: /* size */ |
8008456a |
281 | echo html_tag( 'td', |
6a622b59 |
282 | $bold . $fontstr . show_readable_size($msg['SIZE']) . |
8008456a |
283 | $fontstr_end . $bold_end, |
284 | 'right', |
285 | $hlt_color ); |
286 | break; |
287 | } |
ed230bc3 |
288 | ++$col; |
8008456a |
289 | } |
bdfb67f8 |
290 | } |
7b887886 |
291 | if ($not_last) { |
ed230bc3 |
292 | echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' . |
293 | $color[0] . '" HEIGHT="1"></td></tr>' . "\n"; |
6a622b59 |
294 | } else { |
7b887886 |
295 | echo '</tr>'."\n"; |
6a622b59 |
296 | } |
e9e5f0fa |
297 | } |
298 | |
ed230bc3 |
299 | function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) { |
300 | if ($id != 'no') { |
098ea084 |
301 | $id = array_slice($id, ($start_msg-1), $show_num); |
ed230bc3 |
302 | $end = $start_msg + $show_num - 1; |
303 | if ($num_msgs < $show_num) { |
304 | $end_loop = $num_msgs; |
305 | } else if ($end > $num_msgs) { |
306 | $end_loop = $num_msgs - $start_msg + 1; |
307 | } else { |
308 | $end_loop = $show_num; |
83cdc70b |
309 | } |
310 | return fillMessageArray($imapConnection,$id,$end_loop,$show_num); |
ed230bc3 |
311 | } else { |
312 | return false; |
313 | } |
314 | } |
315 | |
316 | function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) { |
317 | $id = get_thread_sort($imapConnection); |
318 | return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
319 | } |
320 | |
6a622b59 |
321 | function getServerSortMessages($imapConnection, $start_msg, $show_num, |
ed230bc3 |
322 | $num_msgs, $server_sort_order, $mbxresponse) { |
323 | $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse); |
324 | return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
e9e5f0fa |
325 | } |
326 | |
6a622b59 |
327 | function getSelfSortMessages($imapConnection, $start_msg, $show_num, |
e9e5f0fa |
328 | $num_msgs, $sort, $mbxresponse) { |
ed230bc3 |
329 | $msgs = array(); |
330 | if ($num_msgs >= 1) { |
331 | $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse); |
332 | if ($sort < 6 ) { |
333 | $end = $num_msgs; |
334 | $end_loop = $end; |
7b73b809 |
335 | /* set shownum to 999999 to fool sqimap_get_small_header_list |
336 | and rebuild the msgs_str to 1:* */ |
337 | $show_num = 999999; |
ed230bc3 |
338 | } else { |
339 | /* if it's not sorted */ |
340 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
341 | $end_msg = $start_msg + ($show_num - 1); |
342 | } else { |
343 | $end_msg = $num_msgs; |
344 | } |
345 | if ($end_msg < $start_msg) { |
346 | $start_msg = $start_msg - $show_num; |
347 | if ($start_msg < 1) { |
348 | $start_msg = 1; |
349 | } |
350 | } |
098ea084 |
351 | $id = array_slice(array_reverse($id), ($start_msg-1), $show_num); |
ed230bc3 |
352 | $end = $start_msg + $show_num - 1; |
353 | if ($num_msgs < $show_num) { |
354 | $end_loop = $num_msgs; |
355 | } else if ($end > $num_msgs) { |
356 | $end_loop = $num_msgs - $start_msg + 1; |
357 | } else { |
358 | $end_loop = $show_num; |
359 | } |
83cdc70b |
360 | } |
361 | $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num); |
e9e5f0fa |
362 | } |
ed230bc3 |
363 | return $msgs; |
e9e5f0fa |
364 | } |
365 | |
366 | |
367 | |
6c930ade |
368 | /* |
e35045b7 |
369 | * This function loops through a group of messages in the mailbox |
370 | * and shows them to the user. |
371 | */ |
6a622b59 |
372 | function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, |
373 | $start_msg, $sort, $color, $show_num, |
374 | $use_cache, $mode='') { |
fcba142a |
375 | global $msgs, $msort, $auto_expunge, $thread_sort_messages, |
6a622b59 |
376 | $allow_server_sort, $server_sort_order; |
377 | |
167d7428 |
378 | /* |
379 | * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc |
380 | * so setting it to an empty array beforehand seems to clean up the issue, and stopping the |
381 | * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error |
382 | */ |
383 | |
384 | if (!isset($msort)) { |
385 | $msort = array(); |
386 | } |
387 | |
49ae9d34 |
388 | if (!isset($msgs)) { |
389 | $msgs = array(); |
390 | } |
391 | |
8415b2d3 |
392 | //$start = microtime(); |
6a622b59 |
393 | /* If autoexpunge is turned on, then do it now. */ |
394 | $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox); |
395 | $srt = $sort; |
396 | /* If autoexpunge is turned on, then do it now. */ |
397 | if ($auto_expunge == true) { |
398 | $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, ''); |
399 | $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt; |
400 | $num_msgs = $mbxresponse['EXISTS']; |
401 | } |
e35045b7 |
402 | |
6a622b59 |
403 | if ($mbxresponse['EXISTS'] > 0) { |
404 | /* if $start_msg is lower than $num_msgs, we probably deleted all messages |
405 | * in the last page. We need to re-adjust the start_msg |
406 | */ |
aa0da530 |
407 | |
6a622b59 |
408 | if($start_msg > $num_msgs) { |
409 | $start_msg -= $show_num; |
410 | if($start_msg < 1) { |
411 | $start_msg = 1; |
412 | } |
e9e5f0fa |
413 | } |
4e9f35e4 |
414 | |
6a622b59 |
415 | /* This code and the next if() block check for |
416 | * server-side sorting methods. The $id array is |
417 | * formatted and $sort is set to 6 to disable |
418 | * SM internal sorting |
419 | */ |
420 | |
421 | if ($thread_sort_messages == 1) { |
422 | $mode = 'thread'; |
423 | } elseif ($allow_server_sort == 1) { |
424 | $mode = 'serversort'; |
425 | } else { |
426 | $mode = ''; |
427 | } |
8008456a |
428 | |
7b73b809 |
429 | if ($use_cache) { |
430 | sqgetGlobalVar('msgs', $msgs, SQ_SESSION); |
431 | sqgetGlobalVar('msort', $msort, SQ_SESSION); |
432 | } else { |
433 | sqsession_unregister('msort'); |
d3714d3a |
434 | sqsession_unregister('msgs'); } |
6a622b59 |
435 | switch ($mode) { |
436 | case 'thread': |
ed230bc3 |
437 | $id = get_thread_sort($imapConnection); |
438 | $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
6a622b59 |
439 | if ($msgs === false) { |
440 | echo '<b><small><center><font color=red>' . |
441 | _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator."). |
442 | '</center></small></b>'; |
443 | $thread_sort_messages = 0; |
444 | $msort = $msgs = array(); |
6a622b59 |
445 | } else { |
446 | $msort= $msgs; |
447 | $sort = 6; |
6a622b59 |
448 | } |
449 | break; |
450 | case 'serversort': |
ed230bc3 |
451 | $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse); |
452 | $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
6a622b59 |
453 | if ($msgs === false) { |
454 | echo '<b><small><center><font color=red>' . |
455 | _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator."). |
456 | '</center></small></b>'; |
457 | $sort = $server_sort_order; |
458 | $allow_server_sort = FALSE; |
459 | $msort = $msgs = array(); |
6a622b59 |
460 | $id = array(); |
461 | } else { |
6a622b59 |
462 | $msort = $msgs; |
ed230bc3 |
463 | $sort = 6; |
6a622b59 |
464 | } |
465 | break; |
466 | default: |
467 | if (!$use_cache) { |
6a622b59 |
468 | $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num, |
469 | $num_msgs, $sort, $mbxresponse); |
470 | $msort = calc_msort($msgs, $sort); |
6a622b59 |
471 | } /* !use cache */ |
472 | break; |
473 | } // switch |
ed230bc3 |
474 | sqsession_register($msort, 'msort'); |
475 | sqsession_register($msgs, 'msgs'); |
7b73b809 |
476 | |
6a622b59 |
477 | } /* if exists > 0 */ |
478 | |
479 | $res = getEndMessage($start_msg, $show_num, $num_msgs); |
480 | $start_msg = $res[0]; |
481 | $end_msg = $res[1]; |
482 | |
483 | $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg, |
484 | $num_msgs, $show_num, $sort); |
485 | |
486 | $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); |
487 | |
488 | do_hook('mailbox_index_before'); |
fcba142a |
489 | echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">'; |
22642690 |
490 | echo '<tr><td>'; |
491 | |
492 | mail_message_listing_beginning($imapConnection, $mailbox, $sort, |
493 | $msg_cnt_str, $paginator_str, $start_msg); |
494 | echo '</td></tr>'; |
495 | /* line between the button area and the list */ |
496 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
497 | |
498 | echo '<tr><td>'; |
499 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
500 | echo ' <tr><td>'; |
501 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">'; |
502 | echo '<tr><td>'; |
6a622b59 |
503 | printHeader($mailbox, $srt, $color, !$thread_sort_messages); |
504 | |
22642690 |
505 | displayMessageArray($imapConnection, $num_msgs, $start_msg, |
506 | $msort, $mailbox, $sort, $color, $show_num,0,0); |
507 | echo '</td></tr></table></td></tr></table>'; |
6a622b59 |
508 | |
22642690 |
509 | mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color); |
6a622b59 |
510 | echo '</td></tr></table>'; |
8415b2d3 |
511 | //$t = elapsed($start); |
46a49f65 |
512 | //echo("elapsed time = $t seconds\n"); |
6c930ade |
513 | } |
bdfb67f8 |
514 | |
e9e5f0fa |
515 | function calc_msort($msgs, $sort) { |
8008456a |
516 | |
e35045b7 |
517 | /* |
518 | * 0 = Date (up) |
519 | * 1 = Date (dn) |
520 | * 2 = Name (up) |
521 | * 3 = Name (dn) |
522 | * 4 = Subject (up) |
523 | * 5 = Subject (dn) |
524 | */ |
625c8b78 |
525 | |
6a622b59 |
526 | if (($sort == 0) || ($sort == 1)) { |
625c8b78 |
527 | foreach ($msgs as $item) { |
528 | $msort[] = $item['TIME_STAMP']; |
529 | } |
6a622b59 |
530 | } elseif (($sort == 2) || ($sort == 3)) { |
625c8b78 |
531 | foreach ($msgs as $item) { |
532 | $msort[] = $item['FROM-SORT']; |
533 | } |
6a622b59 |
534 | } elseif (($sort == 4) || ($sort == 5)) { |
625c8b78 |
535 | foreach ($msgs as $item) { |
536 | $msort[] = $item['SUBJECT-SORT']; |
537 | } |
6a622b59 |
538 | } else { |
539 | $msort = $msgs; |
540 | } |
541 | if ($sort < 6) { |
542 | if ($sort % 2) { |
543 | asort($msort); |
544 | } else { |
545 | arsort($msort); |
546 | } |
547 | } |
548 | return $msort; |
549 | } |
550 | |
fc60dc76 |
551 | function fillMessageArray($imapConnection, $id, $count, $show_num=false) { |
a18594b2 |
552 | return sqimap_get_small_header_list($imapConnection, $id, $show_num); |
e35045b7 |
553 | } |
8008456a |
554 | |
e9e5f0fa |
555 | |
e35045b7 |
556 | /* Generic function to convert the msgs array into an HTML table. */ |
6a622b59 |
557 | function displayMessageArray($imapConnection, $num_msgs, $start_msg, |
558 | $msort, $mailbox, $sort, $color, |
559 | $show_num, $where=0, $what=0) { |
59352d08 |
560 | global $imapServerAddress, $use_mailbox_cache, $index_order, |
6a622b59 |
561 | $indent_array, $thread_sort_messages, $allow_server_sort, |
562 | $server_sort_order, $PHP_SELF; |
563 | |
564 | $res = getEndMessage($start_msg, $show_num, $num_msgs); |
565 | $start_msg = $res[0]; |
566 | $end_msg = $res[1]; |
a966982b |
567 | |
6a622b59 |
568 | $urlMailbox = urlencode($mailbox); |
e9e5f0fa |
569 | |
6a622b59 |
570 | /* get indent level for subject display */ |
540c4435 |
571 | if ($thread_sort_messages == 1 && $num_msgs) { |
6a622b59 |
572 | $indent_array = get_parent_level($imapConnection); |
94ac35c6 |
573 | } |
a966982b |
574 | |
6a622b59 |
575 | $real_startMessage = $start_msg; |
576 | if ($sort == 6) { |
577 | if ($end_msg - $start_msg < $show_num - 1) { |
578 | $end_msg = $end_msg - $start_msg + 1; |
579 | $start_msg = 1; |
580 | } else if ($start_msg > $show_num) { |
581 | $end_msg = $show_num; |
582 | $start_msg = 1; |
583 | } |
584 | } |
585 | $endVar = $end_msg + 1; |
586 | |
587 | /* |
588 | * Loop through and display the info for each message. |
589 | * ($t is used for the checkbox number) |
590 | */ |
591 | $t = 0; |
592 | |
593 | /* messages display */ |
594 | |
540c4435 |
595 | if (!$num_msgs) { |
e35045b7 |
596 | /* if there's no messages in this folder */ |
8008456a |
597 | echo html_tag( 'tr', |
13cf639b |
598 | html_tag( 'td', |
6b4bd11f |
599 | "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ", |
13cf639b |
600 | 'center', |
601 | $color[4], |
602 | 'COLSPAN="' . count($index_order) . '"' |
603 | ) |
6a622b59 |
604 | ); |
605 | } elseif ($start_msg == $end_msg) { |
e35045b7 |
606 | /* if there's only one message in the box, handle it differently. */ |
6a622b59 |
607 | if ($sort != 6) { |
608 | $i = $start_msg; |
609 | } else { |
610 | $i = 1; |
611 | } |
612 | reset($msort); |
613 | $k = 0; |
614 | do { |
615 | $key = key($msort); |
616 | next($msort); |
617 | $k++; |
618 | } while (isset ($key) && ($k < $i)); |
7b887886 |
619 | printMessageInfo($imapConnection, $t, true, $key, $mailbox, |
ed230bc3 |
620 | $real_startMessage, $where, $what); |
94ac35c6 |
621 | } else { |
6a622b59 |
622 | $i = $start_msg; |
623 | reset($msort); |
624 | $k = 0; |
625 | do { |
626 | $key = key($msort); |
627 | next($msort); |
628 | $k++; |
629 | } while (isset ($key) && ($k < $i)); |
ed230bc3 |
630 | $not_last = true; |
6a622b59 |
631 | do { |
ed230bc3 |
632 | if (!$i || $i == $endVar-1) $not_last = false; |
633 | printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox, |
634 | $real_startMessage, $where, $what); |
6a622b59 |
635 | $key = key($msort); |
636 | $t++; |
637 | $i++; |
638 | next($msort); |
639 | } while ($i && $i < $endVar); |
94ac35c6 |
640 | } |
bdfb67f8 |
641 | } |
642 | |
6c930ade |
643 | /* |
e35045b7 |
644 | * Displays the standard message list header. To finish the table, |
645 | * you need to do a "</table></table>"; |
646 | * |
647 | * $moveURL is the URL to submit the delete/move form to |
648 | * $mailbox is the current mailbox |
649 | * $sort is the current sorting method (-1 for no sorting available [searches]) |
650 | * $Message is a message that is centered on top of the list |
651 | * $More is a second line that is left aligned |
652 | */ |
e35045b7 |
653 | |
6a622b59 |
654 | function mail_message_listing_beginning ($imapConnection, |
655 | $mailbox = '', $sort = -1, |
656 | $msg_cnt_str = '', |
657 | $paginator = ' ', |
658 | $start_msg = 1) { |
659 | global $color, $auto_expunge, $base_uri, $thread_sort_messages, |
660 | $allow_thread_sort, $allow_server_sort, $server_sort_order, |
661 | $PHP_SELF; |
662 | |
663 | $php_self = $PHP_SELF; |
664 | /* fix for incorrect $PHP_SELF */ |
665 | if (strpos($php_self, 'move_messages.php')) { |
666 | $php_self = str_replace('move_messages.php', 'right_main.php', $php_self); |
667 | } |
668 | $urlMailbox = urlencode($mailbox); |
e35045b7 |
669 | |
6a622b59 |
670 | if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) { |
671 | $source_url = $regs[1]; |
672 | } else { |
673 | $source_url = $php_self; |
674 | } |
675 | |
676 | if (!isset($msg)) { |
677 | $msg = ''; |
678 | } |
8fe969f6 |
679 | $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' . |
680 | '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' . |
681 | '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">'; |
682 | |
683 | // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox" |
684 | // . "&startMessage=$start_msg"; |
6a622b59 |
685 | /* |
686 | * This is the beginning of the message list table. |
687 | * It wraps around all messages |
688 | */ |
3027826a |
689 | $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox); |
690 | $form_name = "FormMsgs" . $safe_name; |
691 | echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n" |
8fe969f6 |
692 | . $moveFields |
22642690 |
693 | . html_tag( 'table' , |
c1c17724 |
694 | html_tag( 'tr', |
695 | html_tag( 'td' , |
696 | html_tag( 'table' , |
697 | html_tag( 'tr', |
698 | html_tag( 'td', $paginator, 'left' ) . |
22642690 |
699 | html_tag( 'td', $msg_cnt_str, 'right' ) |
c1c17724 |
700 | ) |
22642690 |
701 | , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) |
c1c17724 |
702 | , 'left', '', '' ) |
703 | , '', $color[0] ) |
22642690 |
704 | , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ); |
4b920601 |
705 | /* line between header and button area */ |
22642690 |
706 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
22642690 |
707 | |
4b920601 |
708 | echo '<tr><td>'; |
22642690 |
709 | echo html_tag( 'tr' ) . "\n" |
710 | . html_tag( 'td' ,'' , 'left', '', '' ) |
711 | . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) |
712 | . '<tr><td>' |
713 | . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) |
c1c17724 |
714 | . html_tag( 'tr', |
22642690 |
715 | getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') . |
716 | getSmallStringCell(_("Transform Selected Messages"), 'right') |
c1c17724 |
717 | ) |
e9e5f0fa |
718 | . html_tag( 'tr' ) ."\n" |
719 | . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' ); |
22642690 |
720 | getMbxList($imapConnection); |
721 | echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n"; |
722 | echo getButton('SUBMIT', 'attache',_("Forward")) . "\n"; |
6c930ade |
723 | |
22642690 |
724 | echo " </TD>\n" |
6a622b59 |
725 | . html_tag( 'td', '', 'right', '', 'nowrap' ); |
e35045b7 |
726 | |
22642690 |
727 | |
728 | |
6a622b59 |
729 | if (!$auto_expunge) { |
730 | echo getButton('SUBMIT', 'expungeButton',_("Expunge")) |
731 | .' ' . _("mailbox") . "\n"; |
732 | } |
d3714d3a |
733 | do_hook('mailbox_display_buttons'); |
6a622b59 |
734 | echo getButton('SUBMIT', 'markRead',_("Read")); |
735 | echo getButton('SUBMIT', 'markUnread',_("Unread")); |
8e724112 |
736 | echo getButton('SUBMIT', 'delete',_("Delete")) ." \n"; |
6a622b59 |
737 | if (!strpos($php_self,'mailbox')) { |
738 | $location = $php_self.'?mailbox=INBOX&startMessage=1'; |
739 | } else { |
740 | $location = $php_self; |
8008456a |
741 | } |
6a622b59 |
742 | echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">'; |
743 | echo "</TD>\n" |
744 | . " </TR>\n"; |
745 | |
746 | /* draws thread sorting links */ |
747 | if ($allow_thread_sort == TRUE) { |
748 | if ($thread_sort_messages == 1 ) { |
749 | $set_thread = 2; |
750 | $thread_name = _("Unthread View"); |
751 | } elseif ($thread_sort_messages == 0) { |
752 | $set_thread = 1; |
753 | $thread_name = _("Thread View"); |
754 | } |
c1c17724 |
755 | echo html_tag( 'tr' , |
756 | html_tag( 'td' , |
e35045b7 |
757 | ' <a href=' . $source_url . '?sort=' |
c1c17724 |
758 | . "$sort" . '&start_messages=1&set_thread=' . "$set_thread" |
759 | . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name |
760 | . '</a></small> ' |
761 | , '', '', '' ) |
762 | , '', '', '' ); |
6a622b59 |
763 | } |
a966982b |
764 | |
22642690 |
765 | echo "</TABLE></td></tr></table></td></tr>\n"; |
a966982b |
766 | |
1b91be0c |
767 | do_hook('mailbox_form_before'); |
6c766fd5 |
768 | |
8008456a |
769 | /* if using server sort we highjack the |
6a622b59 |
770 | * the $sort var and use $server_sort_order |
771 | * instead. but here we reset sort for a bit |
772 | * since its easy |
773 | */ |
8008456a |
774 | if ($allow_server_sort == TRUE) { |
775 | $sort = $server_sort_order; |
776 | } |
e9e5f0fa |
777 | } |
a966982b |
778 | |
e9e5f0fa |
779 | function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) { |
22642690 |
780 | if ($num_msgs) { |
4b920601 |
781 | /* space between list and footer */ |
22642690 |
782 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">'; |
4b920601 |
783 | |
22642690 |
784 | echo '</td></tr><tr><td>'; |
785 | echo html_tag( 'table', |
e9e5f0fa |
786 | html_tag( 'tr', |
787 | html_tag( 'td', |
788 | html_tag( 'table', |
789 | html_tag( 'tr', |
790 | html_tag( 'td', $paginator_str ) . |
791 | html_tag( 'td', $msg_cnt_str, 'right' ) |
792 | ) |
22642690 |
793 | , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' ) |
e9e5f0fa |
794 | ) |
22642690 |
795 | ) |
796 | , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' ); |
797 | echo '</td></tr>'; |
798 | } |
6a622b59 |
799 | /* End of message-list table */ |
a966982b |
800 | |
6a622b59 |
801 | do_hook('mailbox_index_after'); |
802 | echo "</FORM>\n"; |
a966982b |
803 | } |
804 | |
e9e5f0fa |
805 | function printHeader($mailbox, $sort, $color, $showsort=true) { |
6a622b59 |
806 | global $index_order; |
1b91be0c |
807 | echo html_tag( 'tr' ,'' , 'center', $color[5] ); |
e4b5f9d1 |
808 | |
809 | /* calculate the width of the subject column based on the |
810 | * widths of the other columns */ |
811 | $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5); |
812 | $subjectwidth = 100; |
813 | foreach($index_order as $item) { |
814 | $subjectwidth -= $widths[$item]; |
815 | } |
816 | |
817 | foreach ($index_order as $item) { |
818 | switch ($item) { |
8008456a |
819 | case 1: /* checkbox */ |
820 | case 5: /* flags */ |
1b91be0c |
821 | echo html_tag( 'td' ,' ' , '', '', 'width="1%"' ); |
8008456a |
822 | break; |
823 | case 2: /* from */ |
824 | if (handleAsSent($mailbox)) { |
1b91be0c |
825 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
6a622b59 |
826 | . '<b>' . _("To") . '</b>'; |
8008456a |
827 | } else { |
1b91be0c |
828 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
6a622b59 |
829 | . '<b>' . _("From") . '</b>'; |
8008456a |
830 | } |
a966982b |
831 | if ($showsort) { |
1b91be0c |
832 | ShowSortButton($sort, $mailbox, 2, 3); |
8008456a |
833 | } |
1b91be0c |
834 | echo "</td>\n"; |
8008456a |
835 | break; |
836 | case 3: /* date */ |
1b91be0c |
837 | echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' ) |
6a622b59 |
838 | . '<b>' . _("Date") . '</b>'; |
a966982b |
839 | if ($showsort) { |
1b91be0c |
840 | ShowSortButton($sort, $mailbox, 0, 1); |
8008456a |
841 | } |
1b91be0c |
842 | echo "</td>\n"; |
8008456a |
843 | break; |
a966982b |
844 | case 4: /* subject */ |
e4b5f9d1 |
845 | echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' ) |
6a622b59 |
846 | . '<b>' . _("Subject") . '</b>'; |
a966982b |
847 | if ($showsort) { |
1b91be0c |
848 | ShowSortButton($sort, $mailbox, 4, 5); |
8008456a |
849 | } |
1b91be0c |
850 | echo "</td>\n"; |
8008456a |
851 | break; |
852 | case 6: /* size */ |
e842b215 |
853 | echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' ); |
8008456a |
854 | break; |
855 | } |
bdfb67f8 |
856 | } |
1b91be0c |
857 | echo "</tr>\n"; |
bdfb67f8 |
858 | } |
859 | |
e9e5f0fa |
860 | |
bdfb67f8 |
861 | /* |
e35045b7 |
862 | * This function shows the sort button. Isn't this a good comment? |
863 | */ |
864 | function ShowSortButton($sort, $mailbox, $Up, $Down ) { |
6a622b59 |
865 | global $PHP_SELF; |
866 | /* Figure out which image we want to use. */ |
867 | if ($sort != $Up && $sort != $Down) { |
868 | $img = 'sort_none.png'; |
869 | $which = $Up; |
870 | } elseif ($sort == $Up) { |
871 | $img = 'up_pointer.png'; |
872 | $which = $Down; |
6c930ade |
873 | } else { |
6a622b59 |
874 | $img = 'down_pointer.png'; |
875 | $which = 6; |
e35045b7 |
876 | } |
6a622b59 |
877 | |
878 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
879 | $source_url = $regs[1]; |
e35045b7 |
880 | } else { |
6a622b59 |
881 | $source_url = $PHP_SELF; |
6c930ade |
882 | } |
6a622b59 |
883 | |
884 | /* Now that we have everything figured out, show the actual button. */ |
885 | echo ' <a href="' . $source_url .'?newsort=' . $which |
886 | . '&startMessage=1&mailbox=' . urlencode($mailbox) |
da9a8410 |
887 | . '"><img src="../images/' . $img |
888 | . '" border="0" width="12" height="10" alt="sort" title="' |
889 | . _("Click here to change the sorting of the message list") .'"></a>'; |
6a622b59 |
890 | } |
891 | |
892 | function get_selectall_link($start_msg, $sort) { |
893 | global $checkall, $what, $where, $mailbox, $javascript_on; |
894 | global $PHP_SELF, $PG_SHOWNUM; |
895 | |
896 | $result = ''; |
897 | if ($javascript_on) { |
3027826a |
898 | $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox); |
899 | $func_name = "CheckAll" . $safe_name; |
900 | $form_name = "FormMsgs" . $safe_name; |
6a622b59 |
901 | $result = '<script language="JavaScript" type="text/javascript">' |
902 | . "\n<!-- \n" |
3027826a |
903 | . "function " . $func_name . "() {\n" |
904 | . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n" |
905 | . " if(document." . $form_name . ".elements[i].type == 'checkbox'){\n" |
906 | . " document." . $form_name . ".elements[i].checked = " |
907 | . " !(document." . $form_name . ".elements[i].checked);\n" |
6a622b59 |
908 | . " }\n" |
909 | . " }\n" |
910 | . "}\n" |
911 | . "//-->\n" |
3027826a |
912 | . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All") |
913 | /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/ |
6a622b59 |
914 | . "</a>\n"; |
e35045b7 |
915 | } else { |
6a622b59 |
916 | if (strpos($PHP_SELF, "?")) { |
917 | $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox) |
918 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
919 | } else { |
920 | $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) |
921 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
922 | } |
923 | if (isset($checkall) && $checkall == '1') { |
924 | $result .= '0'; |
925 | } else { |
926 | $result .= '1'; |
927 | } |
928 | |
929 | if (isset($where) && isset($what)) { |
930 | $result .= '&where=' . urlencode($where) |
931 | . '&what=' . urlencode($what); |
932 | } |
933 | $result .= "\">"; |
934 | |
935 | if (isset($checkall) && ($checkall == '1')) { |
936 | $result .= _("Unselect All"); |
937 | } else { |
938 | $result .= _("Select All"); |
939 | } |
940 | $result .= "</A>\n"; |
e35045b7 |
941 | } |
23d6bd09 |
942 | |
6a622b59 |
943 | /* Return our final result. */ |
944 | return ($result); |
bdfb67f8 |
945 | } |
1a0e0983 |
946 | |
6c930ade |
947 | /* |
e35045b7 |
948 | * This function computes the "Viewing Messages..." string. |
949 | */ |
bdfb67f8 |
950 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
6a622b59 |
951 | /* Compute the $msg_cnt_str. */ |
952 | $result = ''; |
953 | if ($start_msg < $end_msg) { |
954 | $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), |
955 | $start_msg, $end_msg, $num_msgs); |
956 | } else if ($start_msg == $end_msg) { |
957 | $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg); |
958 | } else { |
959 | $result = '<br>'; |
960 | } |
961 | /* Return our result string. */ |
962 | return ($result); |
bdfb67f8 |
963 | } |
964 | |
6c930ade |
965 | /* |
e35045b7 |
966 | * Generate a paginator link. |
967 | */ |
6c930ade |
968 | function get_paginator_link($box, $start_msg, $use, $text) { |
6a622b59 |
969 | global $PHP_SELF; |
e35045b7 |
970 | |
6a622b59 |
971 | $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use" |
972 | . "&startMessage=$start_msg&mailbox=$box\" " |
973 | . "TARGET=\"right\">$text</A>"; |
974 | return ($result); |
756d0680 |
975 | /* |
6a622b59 |
976 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
977 | $source_url = $regs[1]; |
978 | } else { |
979 | $source_url = $PHP_SELF; |
980 | } |
981 | |
982 | $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use" |
983 | . "&startMessage=$start_msg&mailbox=$box\" " |
984 | . "TARGET=\"right\">$text</A>"; |
985 | return ($result); |
986 | */ |
7b294953 |
987 | } |
988 | |
6c930ade |
989 | /* |
e35045b7 |
990 | * This function computes the paginator string. |
991 | */ |
6a622b59 |
992 | function get_paginator_str($box, $start_msg, $end_msg, $num_msgs, |
993 | $show_num, $sort) { |
994 | global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM; |
995 | |
996 | /* Initialize paginator string chunks. */ |
997 | $prv_str = ''; |
998 | $nxt_str = ''; |
999 | $pg_str = ''; |
1000 | $all_str = ''; |
1001 | $tgl_str = ''; |
1002 | |
1003 | $box = urlencode($box); |
1004 | |
1005 | /* Create simple strings that will be creating the paginator. */ |
1006 | $spc = ' '; /* This will be used as a space. */ |
1007 | $sep = '|'; /* This will be used as a seperator. */ |
1008 | |
1009 | /* Get some paginator preference values. */ |
1010 | $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON); |
1011 | $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX); |
1012 | |
1013 | /* Make sure that our start message number is not too big. */ |
1014 | $start_msg = min($start_msg, $num_msgs); |
1015 | |
1016 | /* Decide whether or not we will use the mailbox cache. */ |
1017 | /* Not sure why $use_mailbox_cache is even passed in. */ |
1018 | if ($sort == 6) { |
1019 | $use = 0; |
1020 | } else { |
1021 | $use = 1; |
1022 | } |
1023 | |
1024 | /* Compute the starting message of the previous and next page group. */ |
1025 | $next_grp = $start_msg + $show_num; |
1026 | $prev_grp = $start_msg - $show_num; |
1027 | |
1028 | /* Compute the basic previous and next strings. */ |
1029 | if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) { |
1030 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
1031 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
1032 | } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) { |
1033 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
1034 | $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n"; |
1035 | } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) { |
1036 | $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>'; |
1037 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
1038 | } |
1039 | |
1040 | /* Page selector block. Following code computes page links. */ |
1041 | if ($pg_sel && ($num_msgs > $show_num)) { |
1042 | /* Most importantly, what is the current page!!! */ |
1043 | $cur_pg = intval($start_msg / $show_num) + 1; |
1044 | |
1045 | /* Compute total # of pages and # of paginator page links. */ |
1046 | $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */ |
1047 | $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */ |
1048 | |
1049 | /* Compute the size of the four quarters of the page links. */ |
1050 | |
1051 | /* If we can, just show all the pages. */ |
1052 | if (($tot_pgs - 1) <= $pg_max) { |
1053 | $q1_pgs = $cur_pg - 1; |
1054 | $q2_pgs = $q3_pgs = 0; |
1055 | $q4_pgs = $tot_pgs - $cur_pg; |
1056 | |
e35045b7 |
1057 | /* Otherwise, compute some magic to choose the four quarters. */ |
6a622b59 |
1058 | } else { |
1059 | /* |
1060 | * Compute the magic base values. Added together, |
1061 | * these values will always equal to the $pag_pgs. |
1062 | * NOTE: These are DEFAULT values and do not take |
1063 | * the current page into account. That is below. |
1064 | */ |
1065 | $q1_pgs = floor($vis_pgs/4); |
1066 | $q2_pgs = round($vis_pgs/4, 0); |
1067 | $q3_pgs = ceil($vis_pgs/4); |
1068 | $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); |
1069 | |
1070 | /* Adjust if the first quarter contains the current page. */ |
1071 | if (($cur_pg - $q1_pgs) < 1) { |
1072 | $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; |
1073 | $q1_pgs = $cur_pg - 1; |
1074 | $q2_pgs = 0; |
1075 | $q3_pgs += ceil($extra_pgs / 2); |
1076 | $q4_pgs += floor($extra_pgs / 2); |
1077 | |
1078 | /* Adjust if the first and second quarters intersect. */ |
1079 | } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { |
1080 | $extra_pgs = $q2_pgs; |
1081 | $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
1082 | $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
1083 | $q3_pgs += ceil($extra_pgs / 2); |
1084 | $q4_pgs += floor($extra_pgs / 2); |
1085 | |
1086 | /* Adjust if the fourth quarter contains the current page. */ |
1087 | } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { |
1088 | $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; |
1089 | $q3_pgs = 0; |
1090 | $q4_pgs = $tot_pgs - $cur_pg; |
1091 | $q1_pgs += floor($extra_pgs / 2); |
1092 | $q2_pgs += ceil($extra_pgs / 2); |
1093 | |
1094 | /* Adjust if the third and fourth quarter intersect. */ |
1095 | } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { |
1096 | $extra_pgs = $q3_pgs; |
1097 | $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
1098 | $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
1099 | $q1_pgs += floor($extra_pgs / 2); |
1100 | $q2_pgs += ceil($extra_pgs / 2); |
1101 | } |
1102 | } |
e35045b7 |
1103 | |
6a622b59 |
1104 | /* |
1105 | * I am leaving this debug code here, commented out, because |
1106 | * it is a really nice way to see what the above code is doing. |
1107 | * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " |
1108 | * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; |
1109 | */ |
1110 | |
1111 | /* Print out the page links from the compute page quarters. */ |
1112 | |
1113 | /* Start with the first quarter. */ |
1114 | if (($q1_pgs == 0) && ($cur_pg > 1)) { |
1115 | $pg_str .= "...$spc"; |
1116 | } else { |
1117 | for ($pg = 1; $pg <= $q1_pgs; ++$pg) { |
1118 | $start = (($pg-1) * $show_num) + 1; |
1119 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1120 | } |
1121 | if ($cur_pg - $q2_pgs - $q1_pgs > 1) { |
1122 | $pg_str .= "...$spc"; |
1123 | } |
1124 | } |
1125 | |
1126 | /* Continue with the second quarter. */ |
1127 | for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { |
1128 | $start = (($pg-1) * $show_num) + 1; |
1129 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1130 | } |
1131 | |
1132 | /* Now print the current page. */ |
1133 | $pg_str .= $cur_pg . $spc; |
1134 | |
1135 | /* Next comes the third quarter. */ |
1136 | for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { |
1137 | $start = (($pg-1) * $show_num) + 1; |
1138 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1139 | } |
1140 | |
1141 | /* And last, print the forth quarter page links. */ |
1142 | if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { |
1143 | $pg_str .= "...$spc"; |
1144 | } else { |
1145 | if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { |
1146 | $pg_str .= "...$spc"; |
1147 | } |
1148 | for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { |
1149 | $start = (($pg-1) * $show_num) + 1; |
1150 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1151 | } |
1152 | } |
1153 | } else if ($PG_SHOWNUM == 999999) { |
1154 | $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0" |
1155 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
1156 | . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc; |
1157 | } |
1158 | |
1159 | /* If necessary, compute the 'show all' string. */ |
1160 | if (($prv_str != '') || ($nxt_str != '')) { |
1161 | $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1" |
1162 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
1163 | . "TARGET=\"right\">" . _("Show All") . '</A>'; |
1164 | } |
1165 | |
1166 | /* Last but not least, get the value for the toggle all link. */ |
1167 | $tgl_str = get_selectall_link($start_msg, $sort); |
1168 | |
1169 | /* Put all the pieces of the paginator string together. */ |
1170 | /** |
1171 | * Hairy code... But let's leave it like it is since I am not certain |
1172 | * a different approach would be any easier to read. ;) |
1173 | */ |
1174 | $result = ''; |
1175 | $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); |
1176 | $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : ''); |
1177 | $result .= ($pg_str != '' ? $pg_str : ''); |
1178 | $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : ''); |
1179 | $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str); |
1180 | |
1181 | /* If the resulting string is blank, return a non-breaking space. */ |
1182 | if ($result == '') { |
1183 | $result = ' '; |
1184 | } |
e35045b7 |
1185 | |
6a622b59 |
1186 | /* Return our final magical paginator string. */ |
1187 | return ($result); |
bdfb67f8 |
1188 | } |
1189 | |
6903c7bd |
1190 | function processSubject($subject, $threadlevel = 0) { |
6fbd125b |
1191 | global $languages, $squirrelmail_language; |
6a622b59 |
1192 | /* Shouldn't ever happen -- caught too many times in the IMAP functions */ |
6dc5eca4 |
1193 | if ($subject == '') { |
6a622b59 |
1194 | return _("(no subject)"); |
6dc5eca4 |
1195 | } |
e35045b7 |
1196 | |
6dc5eca4 |
1197 | $trim_at = SUBJ_TRIM_AT; |
6903c7bd |
1198 | |
c2f88417 |
1199 | /* if this is threaded, subtract two chars per indentlevel */ |
6dc5eca4 |
1200 | if($threadlevel > 0 && $threadlevel <= 10) { |
6903c7bd |
1201 | $trim_at -= (2*$threadlevel); |
6dc5eca4 |
1202 | } |
6903c7bd |
1203 | |
6dc5eca4 |
1204 | if (strlen($subject) <= $trim_at) { |
6a622b59 |
1205 | return $subject; |
6dc5eca4 |
1206 | } |
6a622b59 |
1207 | |
46a49f65 |
1208 | $ent_strlen = $orig_len = strlen($subject); |
6903c7bd |
1209 | $trim_val = $trim_at - 5; |
1210 | $ent_offset = 0; |
6a622b59 |
1211 | /* |
1212 | * see if this is entities-encoded string |
1213 | * If so, Iterate through the whole string, find out |
1214 | * the real number of characters, and if more |
46a49f65 |
1215 | * than 55, substr with an updated trim value. |
6a622b59 |
1216 | */ |
a1440f89 |
1217 | $step = $ent_loc = 0; |
1218 | while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) && |
1219 | (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) { |
1220 | $trim_val += ($ent_loc_end-$ent_loc); |
6a622b59 |
1221 | $ent_offset = $ent_loc_end+1; |
a1440f89 |
1222 | ++$step; |
6a622b59 |
1223 | } |
a1440f89 |
1224 | |
1225 | if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +6))) { |
1226 | $i = strpos($subject,';',$trim_val); |
1227 | if ($i) { |
1228 | $trim_val = strpos($subject,';',$trim_val); |
1229 | } |
46a49f65 |
1230 | } |
6903c7bd |
1231 | if ($ent_strlen <= $trim_at){ |
6a622b59 |
1232 | return $subject; |
1233 | } |
1234 | |
1235 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
1236 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
1237 | return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val); |
1238 | } |
ecaf6352 |
1239 | |
1240 | // only print '...' when we're actually dropping part of the subject |
6dc5eca4 |
1241 | if(strlen($subject) <= $trim_val) { |
ecaf6352 |
1242 | return $subject; |
1243 | } else { |
1244 | return substr($subject, 0, $trim_val) . '...'; |
1245 | } |
bdfb67f8 |
1246 | } |
f93c93b9 |
1247 | |
6a622b59 |
1248 | function getMbxList($imapConnection) { |
1249 | global $lastTargetMailbox; |
1250 | echo ' <small> <tt><select name="targetMailbox">'; |
be2d5495 |
1251 | echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) ); |
6a622b59 |
1252 | echo ' </SELECT></TT> '; |
e9e5f0fa |
1253 | } |
1254 | |
1255 | function getButton($type, $name, $value) { |
6a622b59 |
1256 | return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">'; |
e9e5f0fa |
1257 | } |
1258 | |
1259 | function getSmallStringCell($string, $align) { |
6a622b59 |
1260 | return html_tag('td', |
1261 | '<small>' . $string . ': </small>', |
1262 | $align, |
1263 | '', |
1264 | 'nowrap' ); |
e9e5f0fa |
1265 | } |
1266 | |
1267 | function getEndMessage($start_msg, $show_num, $num_msgs) { |
6a622b59 |
1268 | if ($start_msg + ($show_num - 1) < $num_msgs){ |
1269 | $end_msg = $start_msg + ($show_num - 1); |
1270 | } else { |
1271 | $end_msg = $num_msgs; |
1272 | } |
e9e5f0fa |
1273 | |
6a622b59 |
1274 | if ($end_msg < $start_msg) { |
1275 | $start_msg = $start_msg - $show_num; |
1276 | if ($start_msg < 1) { |
1277 | $start_msg = 1; |
1278 | } |
e9e5f0fa |
1279 | } |
6a622b59 |
1280 | return (array($start_msg,$end_msg)); |
e9e5f0fa |
1281 | } |
1282 | |
a3439b27 |
1283 | function handleAsSent($mailbox) { |
6a8e7cae |
1284 | global $handleAsSent_result; |
1285 | |
6a622b59 |
1286 | /* First check if this is the sent or draft folder. */ |
6a8e7cae |
1287 | $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox); |
a3439b27 |
1288 | |
6a622b59 |
1289 | /* Then check the result of the handleAsSent hook. */ |
1290 | do_hook('check_handleAsSent_result', $mailbox); |
a3439b27 |
1291 | |
6a622b59 |
1292 | /* And return the result. */ |
6a8e7cae |
1293 | return $handleAsSent_result; |
6a622b59 |
1294 | } |
e842b215 |
1295 | |
937c81fa |
1296 | ?> |