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