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