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