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