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