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