59177427 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
62f7daa5 |
4 | * mailbox_display.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 The SquirrelMail Project Team |
62f7daa5 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This contains functions that display mailbox information, such as the |
10 | * table row that has sender, date, subject, etc... |
11 | * |
12 | * @version $Id$ |
13 | * @package squirrelmail |
14 | */ |
a4c2cd49 |
15 | |
d6c32258 |
16 | /** The standard includes.. */ |
b68edc75 |
17 | require_once(SM_PATH . 'functions/strings.php'); |
18 | require_once(SM_PATH . 'functions/html.php'); |
19 | require_once(SM_PATH . 'class/html.class.php'); |
20 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
26454147 |
21 | require_once(SM_PATH . 'functions/imap_messages.php'); |
324ac3c5 |
22 | require_once(SM_PATH . 'functions/imap_asearch.php'); |
26454147 |
23 | require_once(SM_PATH . 'functions/mime.php'); |
b531f8ea |
24 | require_once(SM_PATH . 'functions/forms.php'); |
43fdb2a4 |
25 | |
d6c32258 |
26 | /** |
62f7daa5 |
27 | * default value for page_selector_max |
28 | */ |
6c930ade |
29 | define('PG_SEL_MAX', 10); |
30 | |
324ac3c5 |
31 | /** |
62f7daa5 |
32 | * The number of pages to cache msg headers |
33 | */ |
324ac3c5 |
34 | define('SQM_MAX_PAGES_IN_CACHE',5); |
35 | |
8cc8ec79 |
36 | /** |
62f7daa5 |
37 | * Sort constants used for sorting of messages |
38 | */ |
03975a39 |
39 | define('SQSORT_NONE',0); |
40 | define('SQSORT_DATE_ASC',1); |
41 | define('SQSORT_DATE_DEC',2); |
42 | define('SQSORT_FROM_ASC',3); |
43 | define('SQSORT_FROM_DEC',4); |
44 | define('SQSORT_SUBJ_ASC',5); |
45 | define('SQSORT_SUBJ_DEC',6); |
46 | define('SQSORT_SIZE_ASC',7); |
47 | define('SQSORT_SIZE_DEC',8); |
48 | define('SQSORT_TO_ASC',9); |
49 | define('SQSORT_TO_DEC',10); |
50 | define('SQSORT_CC_ASC',11); |
51 | define('SQSORT_CC_DEC',12); |
52 | define('SQSORT_INT_DATE_ASC',13); |
53 | define('SQSORT_INT_DATE_DEC',14); |
324ac3c5 |
54 | |
55 | define('SQSORT_THREAD',32); |
56 | |
57 | |
58 | define('MBX_PREF_SORT',0); |
59 | define('MBX_PREF_LIMIT',1); |
60 | define('MBX_PREF_AUTO_EXPUNGE',2); |
61 | define('MBX_PREF_INTERNALDATE',3); |
62 | define('SQM_MAX_MBX_IN_CACHE',3); |
63 | // define('MBX_PREF_FUTURE',unique integer key); |
64 | |
d6c32258 |
65 | /** |
62f7daa5 |
66 | * @param mixed $start UNDOCUMENTED |
67 | */ |
0fdc2fb6 |
68 | function elapsed($start) { |
69 | |
70 | $end = microtime(); |
71 | list($start2, $start1) = explode(" ", $start); |
72 | list($end2, $end1) = explode(" ", $end); |
73 | $diff1 = $end1 - $start1; |
74 | $diff2 = $end2 - $start2; |
75 | if( $diff2 < 0 ){ |
76 | $diff1 -= 1; |
77 | $diff2 += 1.0; |
78 | } |
79 | return $diff2 + $diff1; |
098ea084 |
80 | } |
81 | |
c7df3f1b |
82 | /** |
62f7daa5 |
83 | * Displays message header row in messages list |
84 | * |
85 | * @param array $aMsg contains all message related parameters |
86 | * @return void |
87 | */ |
0fdc2fb6 |
88 | |
8cc8ec79 |
89 | function printMessageInfo($aMsg) { |
e0e30169 |
90 | // FIX ME, remove these globals as well by adding an array as argument for the user settings |
91 | // specificly meant for header display |
8008456a |
92 | global $checkall, |
e0e30169 |
93 | $color, |
0fdc2fb6 |
94 | $default_use_priority, |
95 | $message_highlight_list, |
96 | $index_order, |
9294e269 |
97 | $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */ |
0fdc2fb6 |
98 | $email_address, |
9294e269 |
99 | $show_recipient_instead, /* show recipient name instead of default identity */ |
100 | $use_icons, /* indicates to use icons or text markers */ |
cc681ac9 |
101 | $icon_theme, /* icons theming */ |
102 | $javascript_on; |
459e3347 |
103 | |
e9e5f0fa |
104 | $color_string = $color[4]; |
8008456a |
105 | |
03975a39 |
106 | // initialisation: |
8cc8ec79 |
107 | $mailbox = $aMsg['MAILBOX']; |
108 | $msg = $aMsg['HEADER']; |
109 | $t = $aMsg['INDX']; |
110 | $start_msg = $aMsg['PAGEOFFSET']; |
111 | $last = $aMsg['LAST']; |
112 | if (isset($aMsg['SEARCH']) && count($aMsg['SEARCH']) >1 ) { |
113 | $where = $aMsg['SEARCH'][0]; |
114 | $what = $aMsg['SEARCH'][1]; |
115 | } else { |
116 | $where = false; |
117 | $what = false; |
118 | } |
e0e30169 |
119 | $iIndent = $aMsg['INDENT']; |
8cc8ec79 |
120 | |
121 | $sSubject = (isset($msg['SUBJECT']) && $msg['SUBJECT'] != '') ? $msg['SUBJECT'] : _("(no subject)"); |
122 | $sFrom = (isset($msg['FROM'])) ? $msg['FROM'] : _("Unknown sender"); |
123 | $sTo = (isset($msg['TO'])) ? $msg['TO'] : _("Unknown recipient"); |
124 | $sCc = (isset($msg['CC'])) ? $msg['CC'] : ''; |
125 | $aFlags = (isset($msg['FLAGS'])) ? $msg['FLAGS'] : array(); |
126 | $iPrio = (isset($msg['PRIORITY'])) ? $msg['PRIORITY'] : 3; |
127 | $iSize = (isset($msg['SIZE'])) ? $msg['SIZE'] : 0; |
8d8da447 |
128 | |
129 | // These don't appear to be used... are they safe to remove |
8cc8ec79 |
130 | $sType0 = (isset($msg['TYPE0'])) ? $msg['TYPE0'] : 'text'; |
131 | $sType1 = (isset($msg['TYPE1'])) ? $msg['TYPE1'] : 'plain'; |
e0e30169 |
132 | if (isset($msg['INTERNALDATE'])) { |
133 | $sDate = getDateString(getTimeStamp(explode(' ',$msg['INTERNALDATE']))); |
134 | } else { |
135 | $sDate = (isset($msg['DATE'])) ? getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : ''; |
136 | } |
324ac3c5 |
137 | $iId = (isset($msg['UID'])) ? $msg['UID'] : false; |
8cc8ec79 |
138 | |
8cc8ec79 |
139 | if (!$iId) { |
140 | return; |
141 | } |
03975a39 |
142 | |
8008456a |
143 | if ($GLOBALS['alt_index_colors']) { |
e0e30169 |
144 | if (!($t % 2)) { |
8008456a |
145 | if (!isset($color[12])) { |
146 | $color[12] = '#EAEAEA'; |
147 | } |
148 | $color_string = $color[12]; |
149 | } |
bdfb67f8 |
150 | } |
8008456a |
151 | |
8008456a |
152 | $urlMailbox = urlencode($mailbox); |
e9e5f0fa |
153 | |
e0e30169 |
154 | // FIXME, foldertype should be set in right_main.php |
155 | // in other words, handle as sent is obsoleted from now. |
156 | // We replace that by providing an array to aMailbox with the to shown headers |
157 | // that way we are free to show the user different layouts for different folders |
53ad5f60 |
158 | $bSentFolder = handleAsSent($mailbox); |
1ae2832e |
159 | if ((!$bSentFolder) && ($show_recipient_instead)) { |
160 | // If the From address is the same as $email_address, then handle as Sent |
03975a39 |
161 | $from_array = parseAddress($sFrom, 1); |
1ae2832e |
162 | if (!isset($email_address)) { |
0bb37159 |
163 | global $data_dir, $username; |
164 | $email_address = getPref($data_dir, $username, 'email_address'); |
1ae2832e |
165 | } |
166 | $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address)); |
8cc8ec79 |
167 | } else { |
1ae2832e |
168 | $bHandleAsSent = $bSentFolder; |
8cc8ec79 |
169 | } |
53ad5f60 |
170 | // If this is a Sent message, display To address instead of From |
03975a39 |
171 | if ($bHandleAsSent) { |
172 | $sFrom = $sTo; |
173 | } |
53ad5f60 |
174 | // Passing 1 below results in only 1 address being parsed, thus defeating the following code |
03975a39 |
175 | $sFrom = parseAddress($sFrom/*,1*/); |
9701e9c8 |
176 | |
0fdc2fb6 |
177 | /* |
e9e5f0fa |
178 | * This is done in case you're looking into Sent folders, |
179 | * because you can have multiple receivers. |
180 | */ |
03975a39 |
181 | $senderNames = $sFrom; |
098ea084 |
182 | $senderName = ''; |
26454147 |
183 | $senderAddress = ''; |
098ea084 |
184 | if (sizeof($senderNames)){ |
185 | foreach ($senderNames as $senderNames_part) { |
e9e5f0fa |
186 | if ($senderName != '') { |
187 | $senderName .= ', '; |
26454147 |
188 | $senderAddress .= ', '; |
e9e5f0fa |
189 | } |
26454147 |
190 | $sender_address_part = htmlspecialchars($senderNames_part[0]); |
53ad5f60 |
191 | $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1])); |
26454147 |
192 | if ($sender_name_part) { |
193 | $senderName .= $sender_name_part; |
194 | $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>'; |
098ea084 |
195 | } else { |
26454147 |
196 | $senderName .= $sender_address_part; |
197 | $senderAddress .= $sender_address_part; |
098ea084 |
198 | } |
199 | } |
937c81fa |
200 | } |
53ad5f60 |
201 | // If Sent, prefix with To: but only if not Sent folder |
202 | if ($bHandleAsSent ^ $bSentFolder) { |
48027e89 |
203 | $senderName = _("To") . ': ' . $senderName; |
204 | $senderAddress = _("To") . ': ' . $senderAddress; |
53ad5f60 |
205 | } |
459e3347 |
206 | |
e0e30169 |
207 | // this is a column property which can apply to multiple columns. Do not use vars for one column |
208 | // only. instead we should use something like this: |
209 | // 1ed column $aMailbox['columns']['SUBJECT'] value: aray with properties ... |
210 | // 2ed column $aMailbox['columns']['FROM'] value: aray with properties ... |
211 | // NB in case of the sentfolder this could be the TO field |
212 | // properties array example: |
213 | // 'truncate' => length (0 is no truncate) |
214 | // 'prefix => if (x in b then do that ) |
8cc8ec79 |
215 | if ($truncate_sender > 0) { |
216 | $senderName = truncateWithEntities($senderName, $truncate_sender); |
bdfb67f8 |
217 | } |
8cc8ec79 |
218 | |
8d8da447 |
219 | $flag = $flag_end = $fontstr = $fontstr_end = $italic = $italic_end = ''; |
8cc8ec79 |
220 | $bold = '<b>'; |
221 | $bold_end = '</b>'; |
222 | |
8cc8ec79 |
223 | foreach ($aFlags as $sFlag => $value) { |
224 | switch ($sFlag) { |
225 | case '\\flagged': |
226 | if ($value) { |
227 | $flag = "<font color=\"$color[2]\">"; |
228 | $flag_end = '</font>'; |
229 | } |
230 | break; |
231 | case '\\seen': |
232 | if ($value) { |
233 | $bold = ''; |
234 | $bold_end = ''; |
235 | } |
236 | break; |
237 | case '\\deleted': |
238 | if ($value) { |
239 | $fontstr = "<font color=\"$color[9]\">"; |
240 | $fontstr_end = '</font>'; |
241 | } |
242 | break; |
243 | } |
bdfb67f8 |
244 | } |
53ad5f60 |
245 | if ($bHandleAsSent) { |
8008456a |
246 | $italic = '<i>'; |
247 | $italic_end = '</i>'; |
8008456a |
248 | } |
249 | |
d215ca7d |
250 | if ($where && $what) { |
251 | $searchstr = '&where='.$where.'&what='.$what; |
252 | } else { |
253 | $searchstr = ''; |
6a622b59 |
254 | } |
8cc8ec79 |
255 | /* |
256 | * Message highlight code |
257 | */ |
3667f469 |
258 | $matches = array('TO' => 'sTo', 'CC' => 'sCc', 'FROM' => 'sFrom', 'SUBJECT' => 'sSubject'); |
937c81fa |
259 | if (is_array($message_highlight_list) && count($message_highlight_list)) { |
03975a39 |
260 | $sTo = parseAddress($sTo); |
261 | $sCc = parseAddress($sCc); |
8008456a |
262 | foreach ($message_highlight_list as $message_highlight_list_part) { |
263 | if (trim($message_highlight_list_part['value']) != '') { |
c0d04f97 |
264 | $high_val = strtolower($message_highlight_list_part['value']); |
265 | $match_type = strtoupper($message_highlight_list_part['match_type']); |
8415b2d3 |
266 | if($match_type == 'TO_CC') { |
267 | $match = array('TO', 'CC'); |
268 | } else { |
269 | $match = array($match_type); |
270 | } |
271 | foreach($match as $match_type) { |
272 | switch($match_type) { |
273 | case('TO'): |
274 | case('CC'): |
275 | case('FROM'): |
3667f469 |
276 | foreach ($$matches[$match_type] as $address) { |
9701e9c8 |
277 | $address[0] = decodeHeader($address[0], true, false); |
278 | $address[1] = decodeHeader($address[1], true, false); |
8415b2d3 |
279 | if (strstr('^^' . strtolower($address[0]), $high_val) || |
280 | strstr('^^' . strtolower($address[1]), $high_val)) { |
281 | $hlt_color = $message_highlight_list_part['color']; |
282 | break 4; |
283 | } |
937c81fa |
284 | } |
937c81fa |
285 | break; |
8415b2d3 |
286 | default: |
3667f469 |
287 | $headertest = strtolower(decodeHeader($$matches[$match_type], true, false)); |
9701e9c8 |
288 | if (strstr('^^' . $headertest, $high_val)) { |
937c81fa |
289 | $hlt_color = $message_highlight_list_part['color']; |
4669e892 |
290 | break 3; |
937c81fa |
291 | } |
8415b2d3 |
292 | break; |
293 | } |
8008456a |
294 | } |
295 | } |
296 | } |
8cc8ec79 |
297 | } /* end Message highlight code */ |
8008456a |
298 | |
299 | if (!isset($hlt_color)) { |
300 | $hlt_color = $color_string; |
301 | } |
5e0efebf |
302 | $col = 0; |
03975a39 |
303 | $sSubject = str_replace(' ', ' ', decodeHeader($sSubject)); |
e0e30169 |
304 | $subject = processSubject($sSubject, $iIndent); |
8cc8ec79 |
305 | |
cc681ac9 |
306 | |
307 | $row_extra = 'valign="top"'; |
308 | |
309 | |
310 | // this stuff does the auto row highlighting on mouseover |
311 | // |
312 | if ($javascript_on) { |
313 | $mouseoverColor = $color[5]; |
314 | $clickedColor = $color[2]; |
315 | $row_extra .= ' onmouseover="setPointer(this, ' . $t . ', \'over\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');" onmouseout="setPointer(this, ' . $t . ', \'out\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');" onmousedown="setPointer(this, ' . $t . ', \'click\', \'' . $hlt_color . '\', \'' . $mouseoverColor . '\', \'' . $clickedColor . '\');"'; |
316 | } |
317 | |
318 | |
319 | echo html_tag( 'tr','','','',$row_extra) . "\n"; |
320 | |
321 | |
322 | // this does the auto-checking of the checkbox no matter |
323 | // where on the row you click |
324 | // |
325 | if ($javascript_on) |
8168dff9 |
326 | $javascript_auto_click = ' onMouseDown="if (document.getElementById(\'msg[' . $t . ']\')) { document.getElementById(\'msg[' . $t . ']\').checked = (document.getElementById(\'msg[' . $t . ']\').checked ? false : true); }"'; |
cc681ac9 |
327 | |
8cc8ec79 |
328 | |
6a622b59 |
329 | if (sizeof($index_order)) { |
b4482518 |
330 | |
331 | // figure out which columns should serve as labels for checkbox: |
332 | // we try to grab the two columns before and after the checkbox, |
333 | // except the subject column, since it is the link that opens |
334 | // the message view |
335 | // |
cc681ac9 |
336 | // if $javascript_on is set, then the highlighting code takes |
337 | // care of this; just skip it |
338 | // |
b4482518 |
339 | $show_label_columns = array(); |
cc681ac9 |
340 | if (!$javascript_on) { |
341 | $get_next_two = 0; |
342 | $last_order_part = 0; |
343 | $last_last_order_part = 0; |
344 | foreach ($index_order as $index_order_part) { |
345 | |
346 | if ($index_order_part == 1) { |
347 | $get_next_two = 1; |
348 | if ($last_last_order_part != 4) |
349 | $show_label_columns[] = $last_last_order_part; |
350 | if ($last_order_part != 4) |
351 | $show_label_columns[] = $last_order_part; |
352 | |
353 | } else if ($get_next_two > 0 && $get_next_two < 3 && $index_order_part != 4) { |
354 | $show_label_columns[] = $index_order_part; |
355 | $get_next_two++; |
356 | } |
357 | $last_last_order_part = $last_order_part; |
358 | $last_order_part = $index_order_part; |
b4482518 |
359 | } |
b4482518 |
360 | } |
361 | |
362 | |
363 | // build the actual columns for display |
364 | // |
365 | foreach ($index_order as $index_order_part) { |
366 | if (in_array($index_order_part, $show_label_columns)) { |
367 | $label_start = '<label for="msg[' . $t . ']">'; |
368 | $label_end = '</label>'; |
369 | } else { |
370 | $label_start = ''; |
371 | $label_end = ''; |
372 | } |
8008456a |
373 | switch ($index_order_part) { |
374 | case 1: /* checkbox */ |
375 | echo html_tag( 'td', |
03975a39 |
376 | addCheckBox("msg[$t]", $checkall, $iId), |
0fdc2fb6 |
377 | 'center', |
378 | $hlt_color ); |
8008456a |
379 | break; |
380 | case 2: /* from */ |
26454147 |
381 | if ($senderAddress != $senderName) { |
382 | $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS))); |
c435f076 |
383 | $title = ' title="' . str_replace(array('"', '<', '>'), array("''", '<', '>'), $senderAddress) . '"'; |
8cc8ec79 |
384 | } else { |
26454147 |
385 | $title = ''; |
8cc8ec79 |
386 | } |
8008456a |
387 | echo html_tag( 'td', |
b4482518 |
388 | $label_start . $italic . $bold . $flag . $fontstr . $senderName . |
389 | $fontstr_end . $flag_end . $bold_end . $italic_end . $label_end, |
0fdc2fb6 |
390 | 'left', |
cc681ac9 |
391 | $hlt_color, $title . $javascript_auto_click); |
8008456a |
392 | break; |
393 | case 3: /* date */ |
03975a39 |
394 | if ($sDate == '') { |
395 | $sDate = _("Unknown date"); |
53d9fbc5 |
396 | } |
8008456a |
397 | echo html_tag( 'td', |
b4482518 |
398 | $label_start . $bold . $flag . $fontstr . $sDate . |
399 | $fontstr_end . $flag_end . $bold_end . $label_end, |
0fdc2fb6 |
400 | 'center', |
401 | $hlt_color, |
cc681ac9 |
402 | 'style="white-space: nowrap;"' . $javascript_auto_click ); |
8008456a |
403 | break; |
404 | case 4: /* subject */ |
405 | $td_str = $bold; |
e0e30169 |
406 | if ($iIndent) { |
407 | $td_str .= str_repeat(" ",$iIndent); |
8008456a |
408 | } |
e9e5f0fa |
409 | $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox |
324ac3c5 |
410 | . '&passed_id='. $iId |
6a622b59 |
411 | . '&startMessage='.$start_msg.$searchstr.'"'; |
158fa340 |
412 | $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr)); |
03975a39 |
413 | if ($subject != $sSubject) { |
8008456a |
414 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
415 | $title = array_flip($title); |
03975a39 |
416 | $title = strtr($sSubject, $title); |
c435f076 |
417 | $title = str_replace(array('"', '<', '>'), array("''", '<', '>'), $title); |
8008456a |
418 | $td_str .= " title=\"$title\""; |
419 | } |
420 | $td_str .= ">$flag$subject$flag_end</a>$bold_end"; |
cc681ac9 |
421 | echo html_tag( 'td', $td_str, 'left', $hlt_color, $javascript_auto_click ); |
8008456a |
422 | break; |
423 | case 5: /* flags */ |
6a622b59 |
424 | |
6395c46d |
425 | // icon message markers |
426 | // |
427 | if ($use_icons && $icon_theme != 'none') { |
428 | $td_str = "<b><small>"; |
03975a39 |
429 | if (isset($aFlags['\\flagged']) && $aFlags['\\flagged'] == true) { |
55103ede |
430 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/flagged.png" border="0" height="10" width="10" /> '; |
6395c46d |
431 | } |
432 | if ($default_use_priority) { |
03975a39 |
433 | if ( ($iPrio == 1) || ($iPrio == 2) ) { |
55103ede |
434 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_high.png" border="0" height="10" width="5" /> '; |
6395c46d |
435 | } |
03975a39 |
436 | else if ($iPrio == 5) { |
55103ede |
437 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_low.png" border="0" height="10" width="5" /> '; |
6395c46d |
438 | } |
0fdc2fb6 |
439 | else { |
55103ede |
440 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="5" /> '; |
6395c46d |
441 | } |
442 | } |
03975a39 |
443 | if ($sType1 == 'mixed') { |
55103ede |
444 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/attach.png" border="0" height="10" width="6" />'; |
0fdc2fb6 |
445 | } else { |
55103ede |
446 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="6" />'; |
6395c46d |
447 | } |
448 | |
449 | $msg_icon = ''; |
03975a39 |
450 | if (!isset($aFlags['\\seen']) || ($aFlags['\\seen']) == false) { |
6395c46d |
451 | $msg_alt = '(' . _("New") . ')'; |
452 | $msg_title = '(' . _("New") . ')'; |
453 | $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_new'; |
0fdc2fb6 |
454 | } else { |
6395c46d |
455 | $msg_alt = '(' . _("Read") . ')'; |
456 | $msg_title = '(' . _("Read") . ')'; |
457 | $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_read'; |
458 | } |
03975a39 |
459 | if (isset($aFlags['\\deleted']) && ($aFlags['\\deleted']) == true) { |
6395c46d |
460 | $msg_icon .= '_deleted'; |
461 | } |
03975a39 |
462 | if (isset($aFlags['\\answered']) && ($aFlags['\\answered']) == true) { |
d3685401 |
463 | $msg_alt = '(' . _("Answered") . ')'; |
464 | $msg_title = '(' . _("Answered") . ')'; |
6395c46d |
465 | $msg_icon .= '_reply'; |
466 | } |
55103ede |
467 | $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />'; |
6395c46d |
468 | $td_str .= '</small></b>'; |
469 | echo html_tag( 'td', |
b4482518 |
470 | $label_start . $td_str . $label_end, |
0fdc2fb6 |
471 | 'right', |
472 | $hlt_color, |
cc681ac9 |
473 | 'style="white-space: nowrap;"' . $javascript_auto_click ); |
8008456a |
474 | } |
6395c46d |
475 | |
6395c46d |
476 | // plain text message markers |
477 | // |
478 | else { |
479 | $stuff = false; |
480 | $td_str = "<b><small>"; |
03975a39 |
481 | if (isset($aFlags['\\answered']) && $aFlags['\\answered'] == true) { |
6395c46d |
482 | $td_str .= _("A"); |
8008456a |
483 | $stuff = true; |
484 | } |
03975a39 |
485 | if ($sType1 == 'mixed') { |
6395c46d |
486 | $td_str .= '+'; |
8008456a |
487 | $stuff = true; |
488 | } |
6395c46d |
489 | if ($default_use_priority) { |
03975a39 |
490 | if ( ($iPrio == 1) || ($iPrio == 2) ) { |
6395c46d |
491 | $td_str .= "<font color=\"$color[1]\">!</font>"; |
492 | $stuff = true; |
493 | } |
03975a39 |
494 | if ($iPrio == 5) { |
6395c46d |
495 | $td_str .= "<font color=\"$color[8]\">?</font>"; |
496 | $stuff = true; |
497 | } |
498 | } |
03975a39 |
499 | if (isset($aFlags['\\deleted']) && $aFlags['\\deleted'] == true) { |
6395c46d |
500 | $td_str .= "<font color=\"$color[1]\">D</font>"; |
501 | $stuff = true; |
502 | } |
503 | if (!$stuff) { |
504 | $td_str .= ' '; |
505 | } |
506 | $td_str .= '</small></b>'; |
507 | echo html_tag( 'td', |
b4482518 |
508 | $label_start . $td_str . $label_end, |
0fdc2fb6 |
509 | 'center', |
510 | $hlt_color, |
cc681ac9 |
511 | 'style="white-space: nowrap;"' . $javascript_auto_click ); |
8008456a |
512 | } |
8008456a |
513 | break; |
514 | case 6: /* size */ |
8008456a |
515 | echo html_tag( 'td', |
b4482518 |
516 | $label_start . $bold . $fontstr . show_readable_size($iSize) . |
517 | $fontstr_end . $bold_end . $label_end, |
0fdc2fb6 |
518 | 'right', |
cc681ac9 |
519 | $hlt_color, $javascript_auto_click ); |
8008456a |
520 | break; |
521 | } |
ed230bc3 |
522 | ++$col; |
8008456a |
523 | } |
bdfb67f8 |
524 | } |
8cc8ec79 |
525 | /* html for separationlines between rows */ |
1c198ef7 |
526 | if ($last) { |
527 | echo '</tr>'."\n"; |
528 | } else { |
55103ede |
529 | echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' . |
0fdc2fb6 |
530 | $color[0] . '" height="1"></td></tr>' . "\n"; |
6a622b59 |
531 | } |
e9e5f0fa |
532 | } |
533 | |
324ac3c5 |
534 | |
535 | function setUserPref($username, $pref, $value) { |
536 | global $data_dir; |
537 | setPref($data_dir,$username,$pref,$value); |
538 | } |
539 | |
540 | /** |
541 | * Selects a mailbox for header retrieval. |
542 | * Cache control for message headers is embedded. |
543 | * |
544 | * @param resource $imapConnection imap socket handle |
545 | * @param string $mailbox mailbox to select and retrieve message headers from |
546 | * @param array $aConfig array with system config settings and incoming vars |
547 | * @param array $aProps mailbox specific properties |
548 | * @return array $aMailbox mailbox array with all relevant information |
549 | * @author Marc Groot Koerkamp |
550 | */ |
551 | function sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aProps) { |
552 | /** |
553 | * NB: retrieve this from the session before accessing this function |
554 | * and make sure you write it back at the end of the script after |
555 | * the aMailbox var is added so that the headers are added to the cache |
556 | */ |
557 | global $mailbox_cache; |
558 | /** |
559 | * In case the properties arrays are empty set the defaults. |
560 | */ |
8d8da447 |
561 | // Doesn't appear to be used... safe to remove? |
324ac3c5 |
562 | $aDefaultMbxPref = array (); |
563 | // MBX_PREF_SORT => 0, |
564 | // MBX_PREF_LIMIT => 15, |
565 | // MBX_PREF_AUTO_EXPUNGE => 0, |
566 | // MBX_PREF_INTERNALDATE => 0 |
567 | // ); |
568 | /* array_merge doesn't work with integers as keys */ |
569 | // foreach ($aDefaultMbxPref as $key => $value) { |
570 | // if (!isset($aProps[$key])) { |
571 | // $aProps[$key] = $value; |
572 | // } |
573 | // } |
574 | $aDefaultConfigProps = array( |
575 | // 'allow_thread_sort' => 0, |
576 | 'allow_server_sort' => sqimap_capability($imapConnection,'SORT'), |
577 | // 'charset' => 'US-ASCII', |
578 | 'user' => false, /* no pref storage if false */ |
579 | 'setindex' => 0, |
580 | // 'search' => 'ALL', |
581 | 'max_cache_size' => SQM_MAX_MBX_IN_CACHE |
582 | ); |
583 | |
584 | $aConfig = array_merge($aDefaultConfigProps,$aConfig); |
585 | $iSetIndx = $aConfig['setindex']; |
586 | |
587 | $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox); |
588 | |
589 | if ($mailbox_cache) { |
590 | if (isset($mailbox_cache[$mailbox])) { |
591 | $aCachedMailbox = $mailbox_cache[$mailbox]; |
592 | } else { |
593 | $aCachedMailbox = false; |
594 | } |
595 | /* cleanup cache */ |
596 | if (count($mailbox_cache) > $aConfig['max_cache_size'] -1) { |
597 | $aTime = array(); |
598 | foreach($mailbox_cache as $cachedmailbox => $aVal) { |
599 | $aTime[$aVal['TIMESTAMP']] = $cachedmailbox; |
600 | } |
601 | if (ksort($aTime,SORT_NUMERIC)) { |
602 | for ($i=0,$iCnt=count($mailbox_cache);$i<($iCnt-$aConfig['max_cache_size']);++$i) { |
603 | $sOldestMbx = array_shift($aTime); |
604 | /** |
605 | * Remove only the UIDSET and MSG_HEADERS from cache because those can |
606 | * contain large amounts of data. |
607 | */ |
608 | if (isset($mailbox_cache[$sOldestMbx]['UIDSET'])) { |
609 | $mailbox_cache[$sOldestMbx]['UIDSET']= false; |
610 | } |
611 | if (isset($mailbox_cache[$sOldestMbx]['MSG_HEADERS'])) { |
612 | $mailbox_cache[$sOldestMbx]['MSG_HEADERS'] = false; |
613 | } |
614 | } |
615 | } |
616 | } |
617 | |
618 | } else { |
619 | $aCachedMailbox = false; |
620 | } |
621 | |
622 | /** |
623 | * Deal with imap servers that do not return the required UIDNEXT or |
624 | * UIDVALIDITY response |
625 | * from a SELECT call (since rfc 3501 it's required). |
626 | */ |
627 | if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) { |
628 | $aStatus = sqimap_status_messages($imapConnection,$mailbox, |
629 | array('UIDNEXT','UIDVALIDITY')); |
630 | $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT']; |
631 | $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY']; |
632 | } |
633 | |
634 | $aMailbox['UIDSET'][$iSetIndx] = false; |
635 | $aMailbox['ID'] = false; |
636 | $aMailbox['SETINDEX'] = $iSetIndx; |
637 | |
638 | if ($aCachedMailbox) { |
639 | /** |
640 | * Validate integrity of cached data |
641 | */ |
642 | if ($aCachedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] && |
643 | $aMbxResponse['EXISTS'] && |
644 | $aCachedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] && |
645 | $aCachedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT'] && |
646 | isset($aCachedMailbox['SEARCH'][$iSetIndx]) && |
647 | (!isset($aConfig['search']) || /* always set search from the searchpage */ |
648 | $aCachedMailbox['SEARCH'][$iSetIndx] == $aConfig['search'])) { |
649 | if (isset($aCachedMailbox['MSG_HEADERS'])) { |
650 | $aMailbox['MSG_HEADERS'] = $aCachedMailbox['MSG_HEADERS']; |
651 | } |
652 | $aMailbox['ID'] = $aCachedMailbox['ID']; |
653 | if (isset($aCachedMailbox['UIDSET'][$iSetIndx]) && $aCachedMailbox['UIDSET'][$iSetIndx]) { |
654 | if (isset($aProps[MBX_PREF_SORT]) && $aProps[MBX_PREF_SORT] != $aCachedMailbox['SORT'] ) { |
655 | $newsort = $aProps[MBX_PREF_SORT]; |
656 | $oldsort = $aCachedMailbox['SORT']; |
657 | /** |
658 | * If it concerns a reverse sort we do not need to invalidate |
659 | * the cached sorted UIDSET, a reverse is sufficient. |
660 | */ |
661 | if ((($newsort % 2) && ($newsort + 1 == $oldsort)) || |
662 | (!($newsort % 2) && ($newsort - 1 == $oldsort))) { |
663 | $aMailbox['UIDSET'][$iSetIndx] = array_reverse($aCachedMailbox['UIDSET'][$iSetIndx]); |
664 | } else { |
324ac3c5 |
665 | $aMailbox['MSG_HEADERS'] = false; |
666 | $aMailbox['ID'] = false; |
667 | } |
668 | // store the new sort value in the mailbox pref |
669 | if ($aConfig['user']) { |
670 | // FIXME, in ideal situation, we write back the |
671 | // prefs at the end of the script |
672 | setUserPref($aConfig['user'],"pref_$mailbox",serialize($aProps)); |
673 | } |
674 | } else { |
675 | $aMailbox['UIDSET'][$iSetIndx] = $aCachedMailbox['UIDSET'][$iSetIndx]; |
676 | } |
677 | } |
678 | } |
679 | } |
680 | /** |
681 | * Restore the offset in the paginator if no new offset is provided. |
682 | */ |
683 | if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['offset']) && $aCachedMailbox['OFFSET']) { |
684 | $aMailbox['OFFSET'] = $aCachedMailbox['OFFSET']; |
685 | $aMailbox['PAGEOFFSET'] = $aCachedMailbox['PAGEOFFSET']; |
686 | } else { |
687 | $aMailbox['OFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] -1 : 0; |
688 | $aMailbox['PAGEOFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] : 1; |
689 | } |
690 | |
691 | /** |
692 | * Restore the showall value no new showall value is provided. |
693 | */ |
694 | if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['showall']) && |
695 | isset($aCachedMailbox['SHOWALL'][$iSetIndx]) && $aCachedMailbox['SHOWALL'][$iSetIndx]) { |
696 | $aMailbox['SHOWALL'][$iSetIndx] = $aCachedMailbox['SHOWALL'][$iSetIndx]; |
697 | } else { |
698 | $aMailbox['SHOWALL'][$iSetIndx] = (isset($aConfig['showall']) && $aConfig['showall']) ? 1 : 0; |
699 | } |
700 | |
701 | if (!isset($aProps[MBX_PREF_SORT]) && isset($aCachedMailbox['SORT'])) { |
702 | $aMailbox['SORT'] = $aCachedMailbox['SORT']; |
703 | } else { |
704 | $aMailbox['SORT'] = (isset($aProps[MBX_PREF_SORT])) ? $aProps[MBX_PREF_SORT] : 0; |
705 | } |
706 | |
707 | if (!isset($aProps[MBX_PREF_LIMIT]) && isset($aCachedMailbox['LIMIT'])) { |
708 | $aMailbox['LIMIT'] = $aCachedMailbox['LIMIT']; |
709 | } else { |
710 | $aMailbox['LIMIT'] = (isset($aProps[MBX_PREF_LIMIT])) ? $aProps[MBX_PREF_LIMIT] : 15; |
711 | } |
712 | |
713 | if (!isset($aProps[MBX_PREF_INTERNALDATE]) && isset($aCachedMailbox['INTERNALDATE'])) { |
714 | $aMailbox['INTERNALDATE'] = $aCachedMailbox['INTERNALDATE']; |
715 | } else { |
716 | $aMailbox['INTERNALDATE'] = (isset($aProps[MBX_PREF_INTERNALDATE])) ? $aProps[MBX_PREF_INTERNALDATE] : false; |
717 | } |
718 | |
719 | if (!isset($aProps[MBX_PREF_AUTO_EXPUNGE]) && isset($aCachedMailbox['AUTO_EXPUNGE'])) { |
720 | $aMailbox['AUTO_EXPUNGE'] = $aCachedMailbox['AUTO_EXPUNGE']; |
721 | } else { |
722 | $aMailbox['AUTO_EXPUNGE'] = (isset($aProps[MBX_PREF_AUTO_EXPUNGE])) ? $aProps[MBX_PREF_AUTO_EXPUNGE] : false; |
723 | } |
724 | |
725 | if (!isset($aConfig['allow_thread_sort']) && isset($aCachedMailbox['ALLOW_THREAD'])) { |
726 | $aMailbox['ALLOW_THREAD'] = $aCachedMailbox['ALLOW_THREAD']; |
727 | } else { |
728 | $aMailbox['ALLOW_THREAD'] = (isset($aConfig['allow_thread_sort'])) ? $aConfig['allow_thread_sort'] : false; |
729 | } |
730 | |
731 | if (!isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx])) { |
732 | $aMailbox['SEARCH'][$iSetIndx] = $aCachedMailbox['SEARCH'][$iSetIndx]; |
733 | } else { |
734 | $aMailbox['SEARCH'][$iSetIndx] = (isset($aConfig['search'])) ? $aConfig['search'] : 'ALL'; |
735 | } |
736 | |
737 | if (!isset($aConfig['charset']) && isset($aCachedMailbox['CHARSET'][$iSetIndx])) { |
738 | $aMailbox['CHARSET'][$iSetIndx] = $aCachedMailbox['CHARSET'][$iSetIndx]; |
739 | } else { |
740 | $aMailbox['CHARSET'][$iSetIndx] = (isset($aConfig['charset'])) ? $aConfig['charset'] : 'US-ASCII'; |
741 | } |
742 | |
743 | $aMailbox['NAME'] = $mailbox; |
744 | $aMailbox['EXISTS'] = $aMbxResponse['EXISTS']; |
745 | $aMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS']; |
746 | $aMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ? $aMbxResponse['RECENT'] : 0; |
747 | $aMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY']; |
748 | $aMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT']; |
749 | $aMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS']; |
750 | $aMailbox['RIGHTS'] = $aMbxResponse['RIGHTS']; |
751 | |
752 | |
753 | |
754 | /* decide if we are thread sorting or not */ |
755 | if (!$aMailbox['ALLOW_THREAD']) { |
756 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
757 | $aMailbox['SORT'] -= SQSORT_THREAD; |
758 | } |
759 | } |
760 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
761 | $aMailbox['SORT_METHOD'] = 'THREAD'; |
762 | $aMailbox['THREAD_INDENT'] = $aCachedMailbox['THREAD_INDENT']; |
763 | } else if (isset($aConfig['allow_server_sort']) && $aConfig['allow_server_sort']) { |
764 | $aMailbox['SORT_METHOD'] = 'SERVER'; |
765 | $aMailbox['THREAD_INDENT'] = false; |
766 | } else { |
767 | $aMailbox['SORT_METHOD'] = 'SQUIRREL'; |
768 | $aMailbox['THREAD_INDENT'] = false; |
769 | } |
770 | |
771 | /* set a timestamp for cachecontrol */ |
772 | $aMailbox['TIMESTAMP'] = time(); |
773 | return $aMailbox; |
774 | } |
775 | |
776 | |
777 | |
c7df3f1b |
778 | /** |
62f7daa5 |
779 | * Does the $srt $_GET var to field mapping |
780 | * |
781 | * @param int $srt Field to sort on |
782 | * @param bool $bServerSort Server sorting is true |
783 | * @return string $sSortField Field to sort on |
784 | */ |
03975a39 |
785 | function getSortField($sort,$bServerSort) { |
786 | switch($sort) { |
787 | case SQSORT_NONE: |
788 | $sSortField = 'UID'; |
789 | break; |
790 | case SQSORT_DATE_ASC: |
791 | case SQSORT_DATE_DEC: |
792 | $sSortField = 'DATE'; |
793 | break; |
794 | case SQSORT_FROM_ASC: |
795 | case SQSORT_FROM_DEC: |
796 | $sSortField = 'FROM'; |
797 | break; |
798 | case SQSORT_SUBJ_ASC: |
799 | case SQSORT_SUBJ_DEC: |
800 | $sSortField = 'SUBJECT'; |
801 | break; |
802 | case SQSORT_SIZE_ASC: |
803 | case SQSORT_SIZE_DEC: |
804 | $sSortField = ($bServerSort) ? 'SIZE' : 'RFC822.SIZE'; |
805 | break; |
806 | case SQSORT_TO_ASC: |
807 | case SQSORT_TO_DEC: |
808 | $sSortField = 'TO'; |
809 | break; |
810 | case SQSORT_CC_ASC: |
811 | case SQSORT_CC_DEC: |
812 | $sSortField = 'CC'; |
813 | break; |
814 | case SQSORT_INT_DATE_ASC: |
815 | case SQSORT_INT_DATE_DEC: |
816 | $sSortField = ($bServerSort) ? 'ARRIVAL' : 'INTERNALDATE'; |
817 | break; |
e0e30169 |
818 | case SQSORT_THREAD: |
03975a39 |
819 | break; |
e0e30169 |
820 | default: $sSortField = 'UID'; |
821 | break; |
822 | |
fe6efa94 |
823 | } |
03975a39 |
824 | return $sSortField; |
e9e5f0fa |
825 | } |
826 | |
324ac3c5 |
827 | function get_sorted_msgs_list($imapConnection,&$aMailbox,&$error) { |
828 | $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0; |
e0e30169 |
829 | $bDirection = ($aMailbox['SORT'] % 2); |
03975a39 |
830 | $error = false; |
324ac3c5 |
831 | if (!$aMailbox['SEARCH'][$iSetIndx]) { |
832 | $aMailbox['SEARCH'][$iSetIndx] = 'ALL'; |
833 | } |
e0e30169 |
834 | switch ($aMailbox['SORT_METHOD']) { |
8cc8ec79 |
835 | case 'THREAD': |
324ac3c5 |
836 | $aRes = get_thread_sort($imapConnection,$aMailbox['SEARCH'][$iSetIndx]); |
837 | if ($aRes === false) { |
03975a39 |
838 | $error = '<b><small><center><font color=red>' . |
ce45831c |
839 | _("Thread sorting is not supported by your IMAP server.") . '<br />' . |
d3b3a524 |
840 | _("Please contact your system administrator and report this error.") . |
ce45831c |
841 | '</center></small></b>'; |
324ac3c5 |
842 | $aMailbox['SORT'] -= SQSORT_THREAD; |
843 | } else { |
844 | $aMailbox['UIDSET'][$iSetIndx] = $aRes[0]; |
845 | $aMailbox['THREAD_INDENT'][$iSetIndx] = $aRes[1]; |
03975a39 |
846 | } |
847 | break; |
8cc8ec79 |
848 | case 'SERVER': |
e0e30169 |
849 | $sSortField = getSortField($aMailbox['SORT'],true); |
324ac3c5 |
850 | $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]); |
03975a39 |
851 | if ($id === false) { |
852 | $error = '<b><small><center><font color=red>' . |
ce45831c |
853 | _("Server-side sorting is not supported by your IMAP server.") . '<br />' . |
d3b3a524 |
854 | _("Please contact your system administrator and report this error.") . |
03975a39 |
855 | '</center></small></b>'; |
324ac3c5 |
856 | } else { |
857 | $aMailbox['UIDSET'][$iSetIndx] = $id; |
83cdc70b |
858 | } |
03975a39 |
859 | break; |
860 | default: |
324ac3c5 |
861 | $id = NULL; |
862 | if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') { |
863 | $id = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]); |
864 | } |
e0e30169 |
865 | $sSortField = getSortField($aMailbox['SORT'],false); |
324ac3c5 |
866 | $aMailbox['UIDSET'][$iSetIndx] = get_squirrel_sort($imapConnection, $sSortField, $bDirection, $id); |
03975a39 |
867 | break; |
e9e5f0fa |
868 | } |
324ac3c5 |
869 | return $error; |
e9e5f0fa |
870 | } |
871 | |
8cc8ec79 |
872 | |
8cc8ec79 |
873 | |
324ac3c5 |
874 | |
875 | function fetchMessageHeaders($imapConnection, &$aMailbox) { |
876 | |
877 | /** |
878 | * Retrieve the UIDSET. |
879 | * Setindex is used to be able to store multiple uid sets. That will make it |
880 | * possible to display the mailbox multiple times in different sort order |
881 | * or to store serach results separate from normal mailbox view. |
882 | */ |
883 | $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0; |
884 | |
885 | $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT']; |
886 | /** |
887 | * Adjust the start_msg |
888 | */ |
889 | $start_msg = $aMailbox['PAGEOFFSET']; |
890 | if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) { |
891 | $start_msg -= $aMailbox['LIMIT']; |
892 | if($start_msg < 1) { |
893 | $start_msg = 1; |
894 | } |
895 | } |
896 | |
897 | |
898 | if (is_array($aMailbox['UIDSET'])) { |
899 | $aUid =& $aMailbox['UIDSET'][$iSetIndx]; |
f6b262a3 |
900 | } else { |
324ac3c5 |
901 | $aUid = false; |
902 | } |
903 | |
904 | // initialize the fields we want to retrieve: |
bddb3448 |
905 | $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Importance', 'Priority', 'Content-Type'); |
324ac3c5 |
906 | $aFetchItems = array('FLAGS', 'RFC822.SIZE'); |
907 | |
908 | // Are we sorting on internaldate then retrieve the internaldate value as well |
909 | if ($aMailbox['INTERNALDATE']) { |
910 | $aFetchItems[] = 'INTERNALDATE'; |
911 | } |
912 | |
913 | |
914 | /** |
915 | * A uidset with sorted uid's is available. We can use the cache |
916 | */ |
917 | if (($aMailbox['SORT'] != SQSORT_NONE || $aMailbox['SEARCH'][$iSetIndx] != 'ALL') && |
918 | isset($aUid) && $aUid ) { |
919 | |
920 | // limit the cache to SQM_MAX_PAGES_IN_CACHE |
921 | if (!$aMailbox['SHOWALL'][$iSetIndx]) { |
922 | $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE; |
923 | $iCacheSize = count($aMailbox['MSG_HEADERS']); |
924 | if ($iCacheSize > $iMaxMsgs) { |
925 | $iReduce = $iCacheSize - $iMaxMsgs; |
926 | foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) { |
927 | if ($iReduce) { |
928 | unset($aMailbox['MSG_HEADERS'][$iUid]); |
929 | } else { |
930 | break; |
931 | } |
932 | --$iReduce; |
933 | } |
6a622b59 |
934 | } |
e9e5f0fa |
935 | } |
324ac3c5 |
936 | |
937 | $id_slice = array_slice($aUid,$start_msg-1,$iLimit); |
938 | /* do some funky cache checks */ |
939 | $aUidCached = array_keys($aMailbox['MSG_HEADERS']); |
940 | $aUidNotCached = array_values(array_diff($id_slice,$aUidCached)); |
941 | /** |
942 | * $aUidNotCached contains an array with UID's which need to be fetched to |
943 | * complete the needed message headers. |
944 | */ |
945 | if (count($aUidNotCached)) { |
946 | $aMsgs = sqimap_get_small_header_list($imapConnection,$aUidNotCached, |
947 | $aHeaderFields,$aFetchItems); |
948 | // append the msgs to the existend headers |
949 | $aMailbox['MSG_HEADERS'] += $aMsgs; |
8cc8ec79 |
950 | } |
6a622b59 |
951 | |
324ac3c5 |
952 | } else { |
953 | /** |
954 | * Initialize the sorted UID list and fetch the visible message headers |
955 | */ |
956 | if ($aMailbox['SORT'] != SQSORT_NONE || $aMailbox['SEARCH'][$iSetIndx] != 'ALL') {// || $aMailbox['SORT_METHOD'] & SQSORT_THREAD 'THREAD') { |
957 | |
958 | $error = false; |
959 | if ($aMailbox['SEARCH'][$iSetIndx] && $aMailbox['SORT'] == 0) { |
960 | $aUid = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]); |
961 | } else { |
962 | $error = get_sorted_msgs_list($imapConnection,$aMailbox,$error); |
963 | $aUid = $aMailbox['UIDSET'][$iSetIndx]; |
03975a39 |
964 | } |
324ac3c5 |
965 | if ($error === false) { |
966 | $id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit); |
967 | if (count($id_slice)) { |
968 | $aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice, |
969 | $aHeaderFields,$aFetchItems); |
970 | } else { |
971 | return false; |
972 | } |
e0e30169 |
973 | |
03975a39 |
974 | } else { |
324ac3c5 |
975 | // FIX ME, format message and fallback to squirrel sort |
976 | if ($error) { |
977 | echo $error; |
978 | } |
03975a39 |
979 | } |
03975a39 |
980 | } else { |
324ac3c5 |
981 | // limit the cache to SQM_MAX_PAGES_IN_CACHE |
982 | if (!$aMailbox['SHOWALL'][$iSetIndx] && isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) { |
983 | $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE; |
984 | $iCacheSize = count($aMailbox['MSG_HEADERS']); |
985 | if ($iCacheSize > $iMaxMsgs) { |
986 | $iReduce = $iCacheSize - $iMaxMsgs; |
987 | foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) { |
988 | if ($iReduce) { |
989 | $iId = $aMailbox['MSG_HEADERS'][$iUid]['ID']; |
990 | unset($aMailbox['MSG_HEADERS'][$iUid]); |
991 | unset($aMailbox['ID'][$iId]); |
992 | } else { |
993 | break; |
994 | } |
995 | --$iReduce; |
996 | } |
997 | } |
03975a39 |
998 | } |
e0e30169 |
999 | |
324ac3c5 |
1000 | /** |
62f7daa5 |
1001 | * retrieve messages by sequence id's and fetch the UID to retrieve |
1002 | * the UID. for sorted lists this is not needed because a UID FETCH |
1003 | * automaticly add the UID value in fetch results |
1004 | **/ |
324ac3c5 |
1005 | $aFetchItems[] = 'UID'; |
1006 | |
1007 | //create id range |
1008 | $iRangeStart = $aMailbox['EXISTS'] - $aMailbox['OFFSET']; |
1009 | $iRangeEnd = ($iRangeStart > $iLimit) ? |
1010 | ($iRangeStart - $iLimit+1):1; |
1011 | |
1012 | $id_slice = range($iRangeStart, $iRangeEnd); |
1013 | /** |
1014 | * Non sorted mailbox with cached message headers |
1015 | */ |
1016 | if (isset($aMailbox['ID']) && is_array($aMailbox['ID'])) { |
1017 | // the fetched id => uid relation |
1018 | $aId = $aMailbox['ID']; |
1019 | $aIdCached = array(); |
1020 | foreach ($aId as $iId => $iUid) { |
1021 | if (isset($aMailbox['MSG_HEADERS'][$iUid])) { |
1022 | if ($iId <= $iRangeStart && $iId >= $iRangeEnd) { |
1023 | $aIdCached[] = $iId; |
1024 | } |
f6b262a3 |
1025 | } |
6a622b59 |
1026 | } |
324ac3c5 |
1027 | $aIdNotCached = array_diff($id_slice,$aIdCached); |
03975a39 |
1028 | } else { |
324ac3c5 |
1029 | $aIdNotCached = $id_slice; |
8cc8ec79 |
1030 | } |
324ac3c5 |
1031 | |
1032 | if (count($aIdNotCached)) { |
1033 | $aMsgs = sqimap_get_small_header_list($imapConnection,$aIdNotCached, |
1034 | $aHeaderFields,$aFetchItems); |
1035 | // append the msgs to the existend headers |
1036 | if (isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) { |
1037 | $aMailbox['MSG_HEADERS'] += $aMsgs; |
1038 | } else { |
1039 | $aMailbox['MSG_HEADERS'] = $aMsgs; |
1040 | } |
1041 | // update the ID array |
1042 | foreach ($aMsgs as $iUid => $aMsg) { |
1043 | if (isset($aMsg['ID'])) { |
1044 | $aMailbox['ID'][$aMsg['ID']] = $iUid; |
1045 | } |
1046 | } |
03975a39 |
1047 | } |
7b73b809 |
1048 | |
324ac3c5 |
1049 | /** |
1050 | * In unsorted state we show newest messages first which means |
1051 | * that the UIDSET which represents the order of the messages |
1052 | * should contain a high to low ordered UID list |
1053 | */ |
1054 | $aSortedUidList = array(); |
1055 | foreach ($id_slice as $iId) { |
1056 | if (isset($aMailbox['ID'][$iId])) { |
1057 | $aSortedUidList[] = $aMailbox['ID'][$iId]; |
1058 | } |
1059 | } |
1060 | $aMailbox['UIDSET'][$iSetIndx] = $aSortedUidList; |
1061 | $aMailbox['OFFSET'] = 0; |
e0e30169 |
1062 | } |
324ac3c5 |
1063 | } |
1064 | return true; |
1065 | } |
6a622b59 |
1066 | |
324ac3c5 |
1067 | /** |
62f7daa5 |
1068 | * This function loops through a group of messages in the mailbox |
1069 | * and shows them to the user. |
1070 | * |
1071 | * @param mixed $imapConnection |
1072 | * @param array $aMailbox associative array with mailbox related vars |
1073 | */ |
324ac3c5 |
1074 | function showMessagesForMailbox($imapConnection, &$aMailbox) { |
0bb37159 |
1075 | global $color, $javascript_on, $compact_paginator; |
324ac3c5 |
1076 | |
1077 | // to retrieve the internaldate pref: (I know this is not the right place to do that, move up in front |
1078 | // and use a properties array as function argument to provide user preferences |
1079 | global $data_dir, $username; |
1080 | |
1081 | if (!fetchMessageHeaders($imapConnection, $aMailbox)) { |
1082 | return false; |
1083 | } |
1084 | $iSetIndx = $aMailbox['SETINDEX']; |
1085 | $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT']; |
1086 | $iEnd = ($aMailbox['PAGEOFFSET'] + ($iLimit - 1) < $aMailbox['EXISTS']) ? |
1087 | $aMailbox['PAGEOFFSET'] + $iLimit - 1 : $aMailbox['EXISTS']; |
6a622b59 |
1088 | |
324ac3c5 |
1089 | $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], |
0bb37159 |
1090 | $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]); |
6a622b59 |
1091 | |
e0e30169 |
1092 | $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']); |
6a622b59 |
1093 | |
1094 | do_hook('mailbox_index_before'); |
0bb37159 |
1095 | |
1096 | if ($javascript_on && $compact_paginator) { |
1097 | // Insert compact paginator javascript |
1098 | echo "\n<!-- start of compact paginator javascript -->\n" |
1099 | . "<script language=\"JavaScript\">\n" |
1100 | . "function SubmitOnSelect(select, URL)\n" |
1101 | . "{\n" |
1102 | . " URL += select.options[select.selectedIndex].value;\n" |
1103 | . " window.location.href = URL;\n" |
1104 | . "}\n" |
1105 | . "</script>\n" |
1106 | . "<!-- end of compact paginator javascript -->\n"; |
c435f076 |
1107 | } |
1108 | mail_message_listing_beginning($imapConnection, $aMailbox, $msg_cnt_str, $paginator_str); |
1109 | ?> |
0fdc2fb6 |
1110 | <tr><td height="5" bgcolor="<?php echo $color[4]; ?>"></td></tr> |
1111 | <tr> |
abafb676 |
1112 | <td> |
0fdc2fb6 |
1113 | <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[9]; ?>"> |
abafb676 |
1114 | <tr> |
0fdc2fb6 |
1115 | <td> |
abafb676 |
1116 | <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[5]; ?>"> |
0fdc2fb6 |
1117 | <?php |
8cc8ec79 |
1118 | printHeader($aMailbox); |
1119 | displayMessageArray($imapConnection, $aMailbox); |
0fdc2fb6 |
1120 | ?> |
abafb676 |
1121 | </table> |
0fdc2fb6 |
1122 | </td> |
abafb676 |
1123 | </tr> |
0fdc2fb6 |
1124 | </table> |
0bb37159 |
1125 | </td> |
1126 | </tr> |
0bb37159 |
1127 | <?php |
1128 | mail_message_listing_end($aMailbox, $paginator_str, $msg_cnt_str); |
1129 | ?> |
c435f076 |
1130 | </table></form> |
abafb676 |
1131 | <?php |
324ac3c5 |
1132 | |
6c930ade |
1133 | } |
bdfb67f8 |
1134 | |
c7df3f1b |
1135 | /** |
62f7daa5 |
1136 | * Function to map an uid list with a msg header array by uid |
1137 | * The mapped headers are printed with printMessage |
1138 | * aMailbox parameters contains info about the page we are on, the |
1139 | * used search criteria, the number of messages to show |
1140 | * |
1141 | * @param resource $imapConnection socket handle to imap |
1142 | * @param array $aMailbox array with required elements MSG_HEADERS, UIDSET, OFFSET, LIMIT |
1143 | * @return void |
1144 | **/ |
8cc8ec79 |
1145 | function displayMessageArray($imapConnection, $aMailbox) { |
324ac3c5 |
1146 | $iSetIndx = $aMailbox['SETINDEX']; |
1147 | $aId = $aMailbox['UIDSET'][$iSetIndx]; |
8cc8ec79 |
1148 | $aHeaders = $aMailbox['MSG_HEADERS']; |
1149 | $iOffset = $aMailbox['OFFSET']; |
1150 | $sort = $aMailbox['SORT']; |
1151 | $iPageOffset = $aMailbox['PAGEOFFSET']; |
1152 | $sMailbox = $aMailbox['NAME']; |
324ac3c5 |
1153 | $sSearch = (isset($aMailbox['SEARCH'][$aMailbox['SETINDEX']])) ? $aMailbox['SEARCH'][$aMailbox['SETINDEX']] : false; |
1154 | $aSearch = ($sSearch) ? array('search.php',$aMailbox['SETINDEX']) : null; |
1155 | |
1156 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
1157 | $aIndentArray =& $aMailbox['THREAD_INDENT'][$aMailbox['SETINDEX']]; |
e0e30169 |
1158 | $bThread = true; |
1159 | } else { |
1160 | $bThread = false; |
1161 | } |
6a622b59 |
1162 | /* |
0fdc2fb6 |
1163 | * Loop through and display the info for each message. |
1164 | * ($t is used for the checkbox number) |
1165 | */ |
324ac3c5 |
1166 | $iEnd = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $iOffset + $aMailbox['LIMIT']; |
8cc8ec79 |
1167 | for ($i=$iOffset,$t=0;$i<$iEnd;++$i) { |
1168 | if (isset($aId[$i])) { |
1169 | $bLast = ((isset($aId[$i+1]) && isset($aHeaders[$aId[$i+1]])) |
1170 | || ($i == $iEnd )) ? false : true; |
e0e30169 |
1171 | if ($bThread) { |
1172 | $indent = (isset($aIndentArray[$aId[$i]])) ? $aIndentArray[$aId[$i]] : 0; |
1173 | } else { |
1174 | $indent = 0; |
1175 | } |
8cc8ec79 |
1176 | $aMsg = array( |
1177 | 'HEADER' => $aHeaders[$aId[$i]], |
1178 | 'INDX' => $t, |
1179 | 'OFFSET' => $iOffset, |
1180 | 'PAGEOFFSET' => $iPageOffset, |
1181 | 'SORT' => $sort, |
1182 | 'SEARCH' => $aSearch, |
1183 | 'MAILBOX' => $sMailbox, |
e0e30169 |
1184 | 'INDENT' => $indent, |
8cc8ec79 |
1185 | 'LAST' => $bLast |
1186 | ); |
324ac3c5 |
1187 | printMessageInfo($aMsg); |
0fdc2fb6 |
1188 | ++$t; |
6a622b59 |
1189 | } else { |
1c198ef7 |
1190 | break; |
6a622b59 |
1191 | } |
94ac35c6 |
1192 | } |
bdfb67f8 |
1193 | } |
1194 | |
c7df3f1b |
1195 | /** |
62f7daa5 |
1196 | * Displays the standard message list header. |
1197 | * |
1198 | * To finish the table, you need to do a "</table></table>"; |
1199 | * |
1200 | * @param resource $imapConnection |
1201 | * @param array $aMailbox associative array with mailbox related information |
1202 | * @param string $msg_cnt_str |
1203 | * @param string $paginator Paginator string |
1204 | */ |
6a622b59 |
1205 | function mail_message_listing_beginning ($imapConnection, |
8cc8ec79 |
1206 | $aMailbox, |
1207 | $msg_cnt_str = '', |
1208 | $paginator = ' ' |
1209 | ) { |
324ac3c5 |
1210 | global $color, $show_flag_buttons, $PHP_SELF; |
1012f961 |
1211 | global $lastTargetMailbox, $boxes; |
6a622b59 |
1212 | |
1213 | $php_self = $PHP_SELF; |
324ac3c5 |
1214 | |
6a622b59 |
1215 | if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) { |
1216 | $source_url = $regs[1]; |
1217 | } else { |
1218 | $source_url = $php_self; |
1219 | } |
c435f076 |
1220 | $php_self = str_replace('&', '&', $php_self); |
6a622b59 |
1221 | |
1222 | if (!isset($msg)) { |
1223 | $msg = ''; |
1224 | } |
abafb676 |
1225 | |
b531f8ea |
1226 | $moveFields = addHidden('msg', $msg). |
8cc8ec79 |
1227 | addHidden('mailbox', $aMailbox['NAME']). |
324ac3c5 |
1228 | addHidden('startMessage', $aMailbox['PAGEOFFSET']); |
8fe969f6 |
1229 | |
5e0539cd |
1230 | /* build thread sorting links */ |
324ac3c5 |
1231 | $sort = $aMailbox['SORT']; |
8cc8ec79 |
1232 | if ($aMailbox['ALLOW_THREAD']) { |
324ac3c5 |
1233 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
1234 | $sort -= SQSORT_THREAD; |
8cc8ec79 |
1235 | $thread_name = _("Unthread View"); |
1236 | } else { |
8cc8ec79 |
1237 | $thread_name = _("Thread View"); |
324ac3c5 |
1238 | $sort = $aMailbox['SORT'] + SQSORT_THREAD; |
8cc8ec79 |
1239 | } |
324ac3c5 |
1240 | $thread_link_str = '<small>[<a href="' . $source_url . '?srt=' |
c435f076 |
1241 | . $sort . '&start_messages=1' |
1242 | . '&mailbox=' . urlencode($aMailbox['NAME']) . '">' . $thread_name |
8cc8ec79 |
1243 | . '</a>]</small>'; |
1244 | } else { |
1245 | $thread_link_str =''; |
1246 | } |
6a622b59 |
1247 | /* |
0fdc2fb6 |
1248 | * This is the beginning of the message list table. |
1249 | * It wraps around all messages |
1250 | */ |
8cc8ec79 |
1251 | $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']); |
3027826a |
1252 | $form_name = "FormMsgs" . $safe_name; |
3da12e67 |
1253 | |
324ac3c5 |
1254 | echo '<form name="' . $form_name . '" method="post" action="'.$php_self.'">' ."\n" |
0fdc2fb6 |
1255 | . $moveFields; |
c435f076 |
1256 | echo '<table border="0" width="100%" cellpadding="0" cellspacing="0"><tr><td>'; |
324ac3c5 |
1257 | |
9294e269 |
1258 | $button_str = ''; |
1259 | // display flag buttons only if supported |
1260 | if ($show_flag_buttons && |
1261 | in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true) ) { |
e1728a7a |
1262 | $button_str .= getButton('submit', 'markUnflagged', _("Unflag")); |
1263 | $button_str .= getButton('submit', 'markFlagged', _("Flag")); |
9294e269 |
1264 | $button_str .= " \n"; |
1265 | } |
1266 | if (in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true)) { |
e1728a7a |
1267 | $button_str .= getButton('submit', 'markUnread', _("Unread")); |
1268 | $button_str .= getButton('submit', 'markRead', _("Read")); |
9294e269 |
1269 | $button_str .= " \n"; |
1270 | } |
e1728a7a |
1271 | $button_str .= getButton('submit', 'attache',_("Forward")) . |
9294e269 |
1272 | " \n"; |
1273 | if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) { |
e1728a7a |
1274 | $button_str .= getButton('submit', 'delete',_("Delete")); |
9294e269 |
1275 | $button_str .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash"); |
1276 | $button_str .= " \n"; |
1277 | } |
1278 | if (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY') { |
e1728a7a |
1279 | $button_str .= getButton('submit', 'expungeButton',_("Expunge")) .' ' . _("mailbox") . "\n"; |
9294e269 |
1280 | $button_str .= ' '; |
1281 | } |
abafb676 |
1282 | ?> |
0fdc2fb6 |
1283 | <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>"> |
abafb676 |
1284 | <tr> |
0fdc2fb6 |
1285 | <td> |
abafb676 |
1286 | <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0"> |
0fdc2fb6 |
1287 | <tr> |
9294e269 |
1288 | <?php echo html_tag('td', '<small>' . $paginator . $thread_link_str . '</small>', 'left') . "\n"; ?> |
c435f076 |
1289 | <?php echo html_tag('td', ' ', 'center') . "\n"; ?> |
9294e269 |
1290 | <?php echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right') . "\n"; ?> |
0fdc2fb6 |
1291 | </tr> |
abafb676 |
1292 | </table> |
0fdc2fb6 |
1293 | </td> |
abafb676 |
1294 | </tr> |
c435f076 |
1295 | <tr bgcolor="<?php echo $color[0]; ?>"> |
0fdc2fb6 |
1296 | <td> |
abafb676 |
1297 | <table border="0" width="100%" cellpadding="1" cellspacing="0"> |
0fdc2fb6 |
1298 | <tr> |
9294e269 |
1299 | <?php echo html_tag('td', '', 'left') . "\n"; ?> |
1300 | <small> |
1301 | <?php echo $button_str; ?> |
1302 | <?php do_hook('mailbox_display_buttons'); ?> |
1303 | </small> |
abafb676 |
1304 | </td> |
4669e892 |
1305 | <?php |
c075fcfe |
1306 | if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) { |
9294e269 |
1307 | ?> |
1308 | <?php echo html_tag('td', '', 'right'); ?> |
1309 | <small> <tt> |
1310 | <select name="targetMailbox"> |
1311 | <?php echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes); ?> |
1312 | </select></tt> |
e1728a7a |
1313 | <?php echo getButton('submit', 'moveButton',_("Move")); ?> |
9294e269 |
1314 | </small> |
1315 | <?php |
4669e892 |
1316 | } |
1317 | ?> |
abafb676 |
1318 | </td> |
0fdc2fb6 |
1319 | </tr> |
abafb676 |
1320 | </table> |
0fdc2fb6 |
1321 | </td> |
abafb676 |
1322 | </tr> |
0fdc2fb6 |
1323 | </table> |
c22c351b |
1324 | </td></tr> |
abafb676 |
1325 | <?php |
1b91be0c |
1326 | do_hook('mailbox_form_before'); |
e9e5f0fa |
1327 | } |
a966982b |
1328 | |
c7df3f1b |
1329 | /** |
62f7daa5 |
1330 | * Function to add the last row in a message list, it contains the paginator and info about |
1331 | * the number of messages. |
1332 | * |
0bb37159 |
1333 | * @param array $aMailbox associative array with mailbox related information |
62f7daa5 |
1334 | * @param string $paginator_str Paginator string [Prev | Next] [ 1 2 3 ... 91 92 94 ] [Show all] |
1335 | * @param string $msg_cnt_str Message count string Viewing Messages: 21 to 1861 (20 total) |
1336 | */ |
0bb37159 |
1337 | function mail_message_listing_end($aMailbox, $paginator_str, $msg_cnt_str) { |
1338 | global $color; |
1339 | |
1340 | if ($aMailbox['EXISTS']) { |
1341 | /* space between list and footer */ |
1342 | |
abafb676 |
1343 | ?> |
0fdc2fb6 |
1344 | <tr><td height="5" bgcolor="<?php echo $color[4]; ?>" colspan="1"></td></tr> |
1345 | <tr> |
abafb676 |
1346 | <td> |
0fdc2fb6 |
1347 | <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>"> |
abafb676 |
1348 | <tr> |
0fdc2fb6 |
1349 | <td> |
abafb676 |
1350 | <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0"> |
0fdc2fb6 |
1351 | <tr> |
c435f076 |
1352 | <?php echo html_tag('td', '<small>' . $paginator_str . '</small>', 'left'); ?> |
1353 | <?php echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right'); ?> |
0fdc2fb6 |
1354 | </tr> |
abafb676 |
1355 | </table> |
0fdc2fb6 |
1356 | </td> |
abafb676 |
1357 | </tr> |
0fdc2fb6 |
1358 | </table> |
abafb676 |
1359 | </td> |
0fdc2fb6 |
1360 | </tr> |
abafb676 |
1361 | <?php |
0fdc2fb6 |
1362 | } |
6a622b59 |
1363 | /* End of message-list table */ |
a966982b |
1364 | |
6a622b59 |
1365 | do_hook('mailbox_index_after'); |
a966982b |
1366 | } |
1367 | |
c7df3f1b |
1368 | /** |
62f7daa5 |
1369 | * Prints the table header for the messages list view |
1370 | * |
1371 | * @param array $aMailbox |
1372 | */ |
8cc8ec79 |
1373 | function printHeader($aMailbox) { |
1374 | global $index_order, $internal_date_sort, $color; |
1375 | |
1376 | if ($aMailbox['SORT_METHOD'] != 'THREAD') { |
1377 | $showsort = true; |
1378 | } else { |
1379 | $showsort = false; |
1380 | } |
1381 | |
1b91be0c |
1382 | echo html_tag( 'tr' ,'' , 'center', $color[5] ); |
e4b5f9d1 |
1383 | |
1384 | /* calculate the width of the subject column based on the |
62f7daa5 |
1385 | * widths of the other columns */ |
e4b5f9d1 |
1386 | $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5); |
1387 | $subjectwidth = 100; |
1388 | foreach($index_order as $item) { |
4669e892 |
1389 | $subjectwidth -= $widths[$item]; |
e4b5f9d1 |
1390 | } |
1391 | |
1392 | foreach ($index_order as $item) { |
1393 | switch ($item) { |
8008456a |
1394 | case 1: /* checkbox */ |
8cc8ec79 |
1395 | echo html_tag( 'td',get_selectall_link($aMailbox) , '', '', 'width="1%"' ); |
abafb676 |
1396 | break; |
8008456a |
1397 | case 5: /* flags */ |
c435f076 |
1398 | echo html_tag( 'td',' ' , '', '', 'width="1%"' ); |
8008456a |
1399 | break; |
1400 | case 2: /* from */ |
8cc8ec79 |
1401 | if (handleAsSent($aMailbox['NAME'])) { |
1b91be0c |
1402 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
0fdc2fb6 |
1403 | . '<b>' . _("To") . '</b>'; |
03975a39 |
1404 | if ($showsort) { |
8cc8ec79 |
1405 | ShowSortButton($aMailbox, SQSORT_TO_ASC, SQSORT_TO_DEC); |
03975a39 |
1406 | } |
8008456a |
1407 | } else { |
1b91be0c |
1408 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
0fdc2fb6 |
1409 | . '<b>' . _("From") . '</b>'; |
03975a39 |
1410 | if ($showsort) { |
8cc8ec79 |
1411 | ShowSortButton($aMailbox, SQSORT_FROM_ASC, SQSORT_FROM_DEC); |
03975a39 |
1412 | } |
8008456a |
1413 | } |
1b91be0c |
1414 | echo "</td>\n"; |
8008456a |
1415 | break; |
1416 | case 3: /* date */ |
c435f076 |
1417 | echo html_tag( 'td' ,'' , 'left', '', 'width="5%" style="white-space: nowrap;"' ) |
0fdc2fb6 |
1418 | . '<b>' . _("Date") . '</b>'; |
a966982b |
1419 | if ($showsort) { |
03975a39 |
1420 | if ($internal_date_sort) { |
8cc8ec79 |
1421 | ShowSortButton($aMailbox, SQSORT_INT_DATE_ASC, SQSORT_INT_DATE_DEC); |
03975a39 |
1422 | } else { |
8cc8ec79 |
1423 | ShowSortButton($aMailbox, SQSORT_DATE_ASC, SQSORT_DATE_DEC); |
03975a39 |
1424 | } |
8008456a |
1425 | } |
1b91be0c |
1426 | echo "</td>\n"; |
8008456a |
1427 | break; |
a966982b |
1428 | case 4: /* subject */ |
e4b5f9d1 |
1429 | echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' ) |
0fdc2fb6 |
1430 | . '<b>' . _("Subject") . '</b>'; |
a966982b |
1431 | if ($showsort) { |
8cc8ec79 |
1432 | ShowSortButton($aMailbox, SQSORT_SUBJ_ASC, SQSORT_SUBJ_DEC); |
8008456a |
1433 | } |
1b91be0c |
1434 | echo "</td>\n"; |
8008456a |
1435 | break; |
1436 | case 6: /* size */ |
c435f076 |
1437 | echo html_tag( 'td', '', 'center','','width="5%" style="white-space: nowrap;"') |
03975a39 |
1438 | . '<b>' . _("Size") . '</b>'; |
1439 | if ($showsort) { |
8cc8ec79 |
1440 | ShowSortButton($aMailbox, SQSORT_SIZE_ASC, SQSORT_SIZE_DEC); |
03975a39 |
1441 | } |
1442 | echo "</td>\n"; |
8008456a |
1443 | break; |
1444 | } |
bdfb67f8 |
1445 | } |
1b91be0c |
1446 | echo "</tr>\n"; |
bdfb67f8 |
1447 | } |
1448 | |
e9e5f0fa |
1449 | |
c7df3f1b |
1450 | /** |
62f7daa5 |
1451 | * This function shows the sort button. Isn't this a good comment? |
1452 | * |
1453 | * @param array $aMailbox |
1454 | * @param integer $Down |
1455 | * @param integer $Up |
1456 | */ |
8cc8ec79 |
1457 | function ShowSortButton($aMailbox, $Down, $Up ) { |
6a622b59 |
1458 | global $PHP_SELF; |
94a4ea53 |
1459 | |
6a622b59 |
1460 | /* Figure out which image we want to use. */ |
8cc8ec79 |
1461 | if ($aMailbox['SORT'] != $Up && $aMailbox['SORT'] != $Down) { |
6a622b59 |
1462 | $img = 'sort_none.png'; |
1463 | $which = $Up; |
8cc8ec79 |
1464 | } elseif ($aMailbox['SORT'] == $Up) { |
6a622b59 |
1465 | $img = 'up_pointer.png'; |
1466 | $which = $Down; |
6c930ade |
1467 | } else { |
6a622b59 |
1468 | $img = 'down_pointer.png'; |
03975a39 |
1469 | $which = 0; |
e35045b7 |
1470 | } |
6a622b59 |
1471 | |
1472 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
1473 | $source_url = $regs[1]; |
e35045b7 |
1474 | } else { |
6a622b59 |
1475 | $source_url = $PHP_SELF; |
6c930ade |
1476 | } |
6a622b59 |
1477 | |
1478 | /* Now that we have everything figured out, show the actual button. */ |
324ac3c5 |
1479 | echo ' <a href="' . $source_url .'?srt=' . $which |
8cc8ec79 |
1480 | . '&startMessage=1&mailbox=' . urlencode($aMailbox['NAME']) |
0fdc2fb6 |
1481 | . '"><img src="../images/' . $img |
1482 | . '" border="0" width="12" height="10" alt="sort" title="' |
494607f5 |
1483 | . _("Click here to change the sorting of the message list") .'" /></a>'; |
6a622b59 |
1484 | } |
1485 | |
c7df3f1b |
1486 | /** |
62f7daa5 |
1487 | * FIXME: Undocumented function |
1488 | * |
1489 | * @param array $aMailbox |
1490 | */ |
8cc8ec79 |
1491 | function get_selectall_link($aMailbox) { |
1492 | global $checkall, $javascript_on; |
324ac3c5 |
1493 | global $PHP_SELF; |
6a622b59 |
1494 | |
1495 | $result = ''; |
1496 | if ($javascript_on) { |
8cc8ec79 |
1497 | $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']); |
3027826a |
1498 | $func_name = "CheckAll" . $safe_name; |
1499 | $form_name = "FormMsgs" . $safe_name; |
6a622b59 |
1500 | $result = '<script language="JavaScript" type="text/javascript">' |
1501 | . "\n<!-- \n" |
3027826a |
1502 | . "function " . $func_name . "() {\n" |
1503 | . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n" |
3962deff |
1504 | . " if(document." . $form_name . ".elements[i].type == 'checkbox' && " |
e0b57c62 |
1505 | . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n" |
3027826a |
1506 | . " document." . $form_name . ".elements[i].checked = " |
1507 | . " !(document." . $form_name . ".elements[i].checked);\n" |
6a622b59 |
1508 | . " }\n" |
1509 | . " }\n" |
1510 | . "}\n" |
1511 | . "//-->\n" |
abafb676 |
1512 | . '</script>' |
c7df3f1b |
1513 | . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />'; |
c435f076 |
1514 | // . <a href="javascript:void(0)" onclick="' . $func_name . '();">' . _("Toggle All") |
abafb676 |
1515 | // . "</a>\n"; |
e35045b7 |
1516 | } else { |
a6d36aa5 |
1517 | $result .= "<a href=\"$PHP_SELF"; |
1518 | // FIXME: why strpos() is used to detect presense of the symbol in the string. |
1519 | // Function returns boolean value only when symbol is not found |
6a622b59 |
1520 | if (strpos($PHP_SELF, "?")) { |
a6d36aa5 |
1521 | $prefix = '&'; |
6a622b59 |
1522 | } else { |
a6d36aa5 |
1523 | $prefix = '?'; |
6a622b59 |
1524 | } |
a6d36aa5 |
1525 | |
1526 | // If variables are part of GET request, they are present in $PHP_SELF |
1527 | // maybe other functions can be used instead of sqgetGlobalVar (like preg_match) |
1528 | if (! sqgetGlobalVar('mailbox',$tmp,SQ_GET)) { |
1529 | $result .= $prefix . 'mailbox=' . urlencode($aMailbox['NAME']); |
1530 | $prefix = '&'; |
1531 | } |
1532 | if (! sqgetGlobalVar('startMessage',$tmp,SQ_GET)) { |
1533 | $result .= $prefix . 'startMessage=' . $aMailbox['PAGEOFFSET']; |
1534 | $prefix = '&'; |
1535 | } |
1536 | if (! sqgetGlobalVar('str',$tmp,SQ_GET)) { |
1537 | $result .= $prefix . 'str=' . $aMailbox['SORT']; |
1538 | $prefix = '&'; |
1539 | } |
1540 | |
6a622b59 |
1541 | if (isset($checkall) && $checkall == '1') { |
a6d36aa5 |
1542 | $checkall_val = '0'; |
1543 | } else { |
1544 | $checkall_val = '1'; |
1545 | } |
1546 | if (! sqgetGlobalVar('checkall',$tmp,SQ_GET) ) { |
1547 | $result .= $prefix . 'checkall=' . $checkall_val; |
1548 | $prefix = '&'; |
6a622b59 |
1549 | } else { |
a6d36aa5 |
1550 | // checkall is already present in php_self. replace it |
1551 | $result = preg_replace("/checkall=(\d)/","checkall=$checkall_val",$result); |
6a622b59 |
1552 | } |
1553 | |
91e0dccc |
1554 | // FIXME: I suspect that search pages use different variables in 1.5.1cvs |
a6d36aa5 |
1555 | // and these variables are present in $PHP_SELF. |
1556 | if (isset($aMailbox['SEARCH']) && isset($aMailbox['SEARCH'][0]) && ! sqgetGlobalVar('where',$tmp,SQ_GET)) { |
1557 | $result .= '&where=' . urlencode($aMailbox['SEARCH'][0]); |
1558 | if (isset($aMailbox['SEARCH'][1]) && ! sqgetGlobalVar('what',$tmp,SQ_GET)) { |
1559 | $result .= '&what=' . urlencode($aMailbox['SEARCH'][1]); |
0bb37159 |
1560 | } |
6a622b59 |
1561 | } |
1562 | $result .= "\">"; |
98a9cc03 |
1563 | $result .= _("All"); |
c7df3f1b |
1564 | $result .= "</a>\n"; |
e35045b7 |
1565 | } |
23d6bd09 |
1566 | |
6a622b59 |
1567 | /* Return our final result. */ |
1568 | return ($result); |
bdfb67f8 |
1569 | } |
1a0e0983 |
1570 | |
c7df3f1b |
1571 | /** |
62f7daa5 |
1572 | * This function computes the "Viewing Messages..." string. |
1573 | * |
1574 | * @param integer $start_msg first message number |
1575 | * @param integer $end_msg last message number |
1576 | * @param integer $num_msgs total number of message in folder |
1577 | * @return string |
1578 | */ |
bdfb67f8 |
1579 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
6a622b59 |
1580 | /* Compute the $msg_cnt_str. */ |
1581 | $result = ''; |
1582 | if ($start_msg < $end_msg) { |
c7df3f1b |
1583 | $result = sprintf(_("Viewing Messages: %s to %s (%s total)"), |
0fdc2fb6 |
1584 | '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs); |
6a622b59 |
1585 | } else if ($start_msg == $end_msg) { |
043f9c14 |
1586 | $result = sprintf(_("Viewing Message: %s (%s total)"), '<b>'.$start_msg.'</b>', $num_msgs); |
6a622b59 |
1587 | } else { |
c7df3f1b |
1588 | $result = '<br />'; |
6a622b59 |
1589 | } |
1590 | /* Return our result string. */ |
1591 | return ($result); |
bdfb67f8 |
1592 | } |
1593 | |
c7df3f1b |
1594 | /** |
62f7daa5 |
1595 | * Generate a paginator link. |
1596 | * |
1597 | * @param mixed $box Mailbox name |
1598 | * @param mixed $start_msg Message Offset |
1599 | * @param mixed $use |
1600 | * @param string $text text used for paginator link |
1601 | * @return string |
1602 | */ |
324ac3c5 |
1603 | function get_paginator_link($box, $start_msg, $text) { |
1604 | sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER); |
1605 | $result = "<a href=\"$php_self?startMessage=$start_msg&mailbox=$box\" " |
c7df3f1b |
1606 | . ">$text</a>"; |
6a622b59 |
1607 | |
6a622b59 |
1608 | return ($result); |
7b294953 |
1609 | } |
1610 | |
c7df3f1b |
1611 | /** |
62f7daa5 |
1612 | * This function computes the paginator string. |
1613 | * |
1614 | * @param string $box mailbox name |
1615 | * @param integer $iOffset offset in total number of messages |
1616 | * @param integer $iTotal total number of messages |
1617 | * @param integer $iLimit maximum number of messages to show on a page |
1618 | * @param bool $bShowAll show all messages at once (non paginate mode) |
1619 | * @return string $result paginate string with links to pages |
1620 | */ |
324ac3c5 |
1621 | function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) { |
0bb37159 |
1622 | global $username, $data_dir, $javascript_on; |
1623 | // page selector globals |
1624 | global $page_selector, $page_selector_max, $compact_paginator; |
324ac3c5 |
1625 | sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER); |
6a622b59 |
1626 | |
1627 | /* Initialize paginator string chunks. */ |
1628 | $prv_str = ''; |
1629 | $nxt_str = ''; |
eac26493 |
1630 | $pg_str = ''; |
6a622b59 |
1631 | $all_str = ''; |
6a622b59 |
1632 | |
1633 | $box = urlencode($box); |
324ac3c5 |
1634 | |
6a622b59 |
1635 | /* Create simple strings that will be creating the paginator. */ |
1636 | $spc = ' '; /* This will be used as a space. */ |
1637 | $sep = '|'; /* This will be used as a seperator. */ |
1638 | |
6a622b59 |
1639 | /* Make sure that our start message number is not too big. */ |
324ac3c5 |
1640 | $iOffset = min($iOffset, $iTotal); |
6a622b59 |
1641 | |
6a622b59 |
1642 | /* Compute the starting message of the previous and next page group. */ |
324ac3c5 |
1643 | $next_grp = $iOffset + $iLimit; |
1644 | $prev_grp = $iOffset - $iLimit; |
1645 | |
1646 | if (!$bShowAll) { |
1647 | /* Compute the basic previous and next strings. */ |
0bb37159 |
1648 | if ($compact_paginator) { |
1649 | if (($next_grp <= $iTotal) && ($prev_grp >= 0)) { |
1650 | $prv_str = get_paginator_link($box, $prev_grp, '<'); |
1651 | $nxt_str = get_paginator_link($box, $next_grp, '>'); |
1652 | } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) { |
1653 | $prv_str = get_paginator_link($box, $prev_grp, '<'); |
1654 | $nxt_str = '>'; |
1655 | } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) { |
1656 | $prv_str = '<'; |
1657 | $nxt_str = get_paginator_link($box, $next_grp, '>'); |
1658 | } |
1659 | } else { |
1660 | if (($next_grp <= $iTotal) && ($prev_grp >= 0)) { |
1661 | $prv_str = get_paginator_link($box, $prev_grp, _("Previous")); |
1662 | $nxt_str = get_paginator_link($box, $next_grp, _("Next")); |
1663 | } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) { |
1664 | $prv_str = get_paginator_link($box, $prev_grp, _("Previous")); |
1665 | $nxt_str = _("Next"); |
1666 | } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) { |
1667 | $prv_str = _("Previous"); |
1668 | $nxt_str = get_paginator_link($box, $next_grp, _("Next")); |
1669 | } |
324ac3c5 |
1670 | } |
6a622b59 |
1671 | |
324ac3c5 |
1672 | /* Page selector block. Following code computes page links. */ |
0bb37159 |
1673 | if ($iLimit != 0 && $page_selector && ($iTotal > $iLimit)) { |
324ac3c5 |
1674 | /* Most importantly, what is the current page!!! */ |
1675 | $cur_pg = intval($iOffset / $iLimit) + 1; |
6a622b59 |
1676 | |
324ac3c5 |
1677 | /* Compute total # of pages and # of paginator page links. */ |
1678 | $tot_pgs = ceil($iTotal / $iLimit); /* Total number of Pages */ |
6a622b59 |
1679 | |
0bb37159 |
1680 | if (!$compact_paginator) { |
1681 | $vis_pgs = min($page_selector_max, $tot_pgs - 1); /* Visible Pages */ |
6a622b59 |
1682 | |
0bb37159 |
1683 | /* Compute the size of the four quarters of the page links. */ |
324ac3c5 |
1684 | |
0bb37159 |
1685 | /* If we can, just show all the pages. */ |
1686 | if (($tot_pgs - 1) <= $page_selector_max) { |
324ac3c5 |
1687 | $q1_pgs = $cur_pg - 1; |
0bb37159 |
1688 | $q2_pgs = $q3_pgs = 0; |
324ac3c5 |
1689 | $q4_pgs = $tot_pgs - $cur_pg; |
0bb37159 |
1690 | |
1691 | /* Otherwise, compute some magic to choose the four quarters. */ |
1692 | } else { |
1693 | /* |
1694 | * Compute the magic base values. Added together, |
1695 | * these values will always equal to the $pag_pgs. |
1696 | * NOTE: These are DEFAULT values and do not take |
1697 | * the current page into account. That is below. |
1698 | */ |
1699 | $q1_pgs = floor($vis_pgs/4); |
1700 | $q2_pgs = round($vis_pgs/4, 0); |
1701 | $q3_pgs = ceil($vis_pgs/4); |
1702 | $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); |
1703 | |
1704 | /* Adjust if the first quarter contains the current page. */ |
1705 | if (($cur_pg - $q1_pgs) < 1) { |
1706 | $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; |
1707 | $q1_pgs = $cur_pg - 1; |
1708 | $q2_pgs = 0; |
1709 | $q3_pgs += ceil($extra_pgs / 2); |
1710 | $q4_pgs += floor($extra_pgs / 2); |
1711 | |
1712 | /* Adjust if the first and second quarters intersect. */ |
1713 | } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { |
1714 | $extra_pgs = $q2_pgs; |
1715 | $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4); |
1716 | $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4); |
1717 | $q3_pgs += ceil($extra_pgs / 2); |
1718 | $q4_pgs += floor($extra_pgs / 2); |
1719 | |
1720 | /* Adjust if the fourth quarter contains the current page. */ |
1721 | } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { |
1722 | $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; |
1723 | $q3_pgs = 0; |
1724 | $q4_pgs = $tot_pgs - $cur_pg; |
1725 | $q1_pgs += floor($extra_pgs / 2); |
1726 | $q2_pgs += ceil($extra_pgs / 2); |
1727 | |
1728 | /* Adjust if the third and fourth quarter intersect. */ |
1729 | } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { |
1730 | $extra_pgs = $q3_pgs; |
1731 | $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4); |
1732 | $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4); |
1733 | $q1_pgs += floor($extra_pgs / 2); |
1734 | $q2_pgs += ceil($extra_pgs / 2); |
1735 | } |
324ac3c5 |
1736 | } |
e35045b7 |
1737 | |
0bb37159 |
1738 | /* |
1739 | * I am leaving this debug code here, commented out, because |
1740 | * it is a really nice way to see what the above code is doing. |
1741 | * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " |
1742 | * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />'; |
1743 | */ |
6a622b59 |
1744 | |
0bb37159 |
1745 | /* Print out the page links from the compute page quarters. */ |
6a622b59 |
1746 | |
0bb37159 |
1747 | /* Start with the first quarter. */ |
1748 | if (($q1_pgs == 0) && ($cur_pg > 1)) { |
324ac3c5 |
1749 | $pg_str .= "...$spc"; |
0bb37159 |
1750 | } else { |
1751 | for ($pg = 1; $pg <= $q1_pgs; ++$pg) { |
1752 | $start = (($pg-1) * $iLimit) + 1; |
1753 | $pg_str .= get_paginator_link($box, $start, $pg) . $spc; |
1754 | } |
1755 | if ($cur_pg - $q2_pgs - $q1_pgs > 1) { |
1756 | $pg_str .= "...$spc"; |
1757 | } |
324ac3c5 |
1758 | } |
6a622b59 |
1759 | |
0bb37159 |
1760 | /* Continue with the second quarter. */ |
1761 | for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { |
1762 | $start = (($pg-1) * $iLimit) + 1; |
1763 | $pg_str .= get_paginator_link($box, $start, $pg) . $spc; |
1764 | } |
6a622b59 |
1765 | |
0bb37159 |
1766 | /* Now print the current page. */ |
1767 | $pg_str .= $cur_pg . $spc; |
6a622b59 |
1768 | |
0bb37159 |
1769 | /* Next comes the third quarter. */ |
1770 | for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { |
1771 | $start = (($pg-1) * $iLimit) + 1; |
1772 | $pg_str .= get_paginator_link($box, $start, $pg) . $spc; |
1773 | } |
6a622b59 |
1774 | |
0bb37159 |
1775 | /* And last, print the forth quarter page links. */ |
1776 | if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { |
324ac3c5 |
1777 | $pg_str .= "...$spc"; |
0bb37159 |
1778 | } else { |
1779 | if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { |
1780 | $pg_str .= "...$spc"; |
1781 | } |
1782 | for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { |
1783 | $start = (($pg-1) * $iLimit) + 1; |
1784 | $pg_str .= get_paginator_link($box, $start,$pg) . $spc; |
1785 | } |
324ac3c5 |
1786 | } |
6a622b59 |
1787 | } |
0bb37159 |
1788 | $last_grp = (($tot_pgs - 1) * $iLimit) + 1; |
6a622b59 |
1789 | } |
324ac3c5 |
1790 | } else { |
1791 | $pg_str = "<a href=\"$php_self?showall=0" |
1792 | . "&startMessage=1&mailbox=$box\" " |
c7df3f1b |
1793 | . ">" ._("Paginate") . '</a>'; |
6a622b59 |
1794 | } |
1795 | |
6a622b59 |
1796 | /* Put all the pieces of the paginator string together. */ |
1797 | /** |
62f7daa5 |
1798 | * Hairy code... But let's leave it like it is since I am not certain |
1799 | * a different approach would be any easier to read. ;) |
1800 | */ |
6a622b59 |
1801 | $result = ''; |
324ac3c5 |
1802 | if ( $prv_str || $nxt_str ) { |
1803 | |
1804 | /* Compute the 'show all' string. */ |
1805 | $all_str = "<a href=\"$php_self?showall=1" |
1806 | . "&startMessage=1&mailbox=$box\" " |
0fdc2fb6 |
1807 | . ">" . _("Show All") . '</a>'; |
abafb676 |
1808 | } |
eac26493 |
1809 | |
0bb37159 |
1810 | if ($compact_paginator) { |
1811 | if ( $prv_str || $nxt_str ) { |
1812 | $result .= '[' . get_paginator_link($box, 1, '<<') . ']'; |
1813 | $result .= '[' . $prv_str . ']'; |
1814 | |
1815 | $pg_url = $php_self . '?mailbox=' . $box; |
6a622b59 |
1816 | |
0bb37159 |
1817 | $result .= '[' . $nxt_str . ']'; |
1818 | $result .= '[' . get_paginator_link($box, $last_grp, '>>') . ']'; |
1819 | |
1820 | if ($page_selector) { |
1821 | $result .= $spc . '<select name="startMessage"'; |
1822 | if ($javascript_on) { |
1823 | $result .= ' onchange="JavaScript:SubmitOnSelect' |
c435f076 |
1824 | . '(this, \'' . $pg_url . '&startMessage=\')"'; |
0bb37159 |
1825 | } |
1826 | $result .='>'; |
1827 | |
1828 | for ($p = 0; $p < $tot_pgs; $p++) { |
1829 | $result .= '<option '; |
1830 | if (($p+1) == $cur_pg) $result .= 'selected '; |
1831 | $result .= 'value="' . (($p*$iLimit)+1) . '">' |
1832 | . ($p+1) . "/$tot_pgs" . '</option>'; |
1833 | } |
1834 | |
1835 | $result .= '</select>'; |
1836 | |
1837 | if ($javascript_on) { |
1838 | $result .= '<noscript language="JavaScript">' |
1839 | . addSubmit(_("Go")) |
1840 | . '</noscript>'; |
1841 | } else { |
1842 | $result .= addSubmit(_("Go")); |
1843 | } |
1844 | } |
1845 | } |
1846 | |
1847 | $result .= ($pg_str != '' ? '['.$pg_str.']' . $spc : ''); |
1848 | $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : ''); |
1849 | } else { |
1850 | if ( $prv_str || $nxt_str ) { |
1851 | $result .= '['; |
1852 | $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); |
1853 | $result .= ($nxt_str != '' ? $nxt_str : ''); |
1854 | $result .= ']' . $spc ; |
1855 | } |
1856 | |
1857 | $result .= ($pg_str != '' ? $spc . '['.$spc.$pg_str.']' . $spc : ''); |
1858 | $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : ''); |
1859 | } |
6a622b59 |
1860 | /* If the resulting string is blank, return a non-breaking space. */ |
1861 | if ($result == '') { |
1862 | $result = ' '; |
1863 | } |
6a622b59 |
1864 | /* Return our final magical paginator string. */ |
1865 | return ($result); |
bdfb67f8 |
1866 | } |
1867 | |
c7df3f1b |
1868 | /** |
62f7daa5 |
1869 | * FIXME: Undocumented function |
1870 | */ |
eaa4f45f |
1871 | function truncateWithEntities($subject, $trim_at) |
1872 | { |
341aa42f |
1873 | $ent_strlen = strlen($subject); |
1874 | if (($trim_at <= 0) || ($ent_strlen <= $trim_at)) |
6a622b59 |
1875 | return $subject; |
eaa4f45f |
1876 | |
1877 | global $languages, $squirrelmail_language; |
6a622b59 |
1878 | |
6a622b59 |
1879 | /* |
62f7daa5 |
1880 | * see if this is entities-encoded string |
1881 | * If so, Iterate through the whole string, find out |
1882 | * the real number of characters, and if more |
1883 | * than $trim_at, substr with an updated trim value. |
1884 | */ |
341aa42f |
1885 | $trim_val = $trim_at; |
1886 | $ent_offset = 0; |
1887 | $ent_loc = 0; |
a1440f89 |
1888 | while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) && |
1889 | (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) { |
1890 | $trim_val += ($ent_loc_end-$ent_loc); |
6a622b59 |
1891 | $ent_offset = $ent_loc_end+1; |
1892 | } |
341aa42f |
1893 | if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val + 6))) { |
a1440f89 |
1894 | $i = strpos($subject,';',$trim_val); |
1895 | if ($i) { |
1896 | $trim_val = strpos($subject,';',$trim_val); |
1897 | } |
46a49f65 |
1898 | } |
341aa42f |
1899 | // only print '...' when we're actually dropping part of the subject |
1900 | if ($ent_strlen <= $trim_val) |
6a622b59 |
1901 | return $subject; |
6a622b59 |
1902 | |
1903 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
b3e4bf71 |
1904 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth')) { |
1905 | return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth', $subject, $trim_val); |
6a622b59 |
1906 | } |
ecaf6352 |
1907 | |
c435f076 |
1908 | return substr_replace($subject, '...', $trim_val + 1); |
bdfb67f8 |
1909 | } |
f93c93b9 |
1910 | |
c7df3f1b |
1911 | /** |
62f7daa5 |
1912 | * FIXME: Undocumented function |
1913 | */ |
eaa4f45f |
1914 | function processSubject($subject, $threadlevel = 0) { |
1915 | /* Shouldn't ever happen -- caught too many times in the IMAP functions */ |
1916 | if ($subject == '') { |
1917 | return _("(no subject)"); |
1918 | } |
1919 | |
3fc1a95f |
1920 | global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */ |
1921 | $trim_at = $truncate_subject; |
eaa4f45f |
1922 | |
1923 | /* if this is threaded, subtract two chars per indentlevel */ |
1924 | if (($threadlevel > 0) && ($threadlevel <= 10)) |
1925 | $trim_at -= (2*$threadlevel); |
1926 | |
1927 | return truncateWithEntities($subject, $trim_at); |
1928 | } |
1929 | |
e9e5f0fa |
1930 | |
c7df3f1b |
1931 | /** |
62f7daa5 |
1932 | * Creates button |
1933 | * |
1934 | * @deprecated see form functions available in 1.5.1 and 1.4.3. |
1935 | * @param string $type |
1936 | * @param string $name |
1937 | * @param string $value |
1938 | * @param string $js |
1939 | * @param bool $enabled |
1940 | */ |
1a531551 |
1941 | function getButton($type, $name, $value, $js = '', $enabled = TRUE) { |
98a9cc03 |
1942 | $disabled = ( $enabled ? '' : 'disabled ' ); |
1a531551 |
1943 | $js = ( $js ? $js.' ' : '' ); |
c7df3f1b |
1944 | return '<input '.$disabled.$js. |
0fdc2fb6 |
1945 | 'type="'.$type. |
1946 | '" name="'.$name. |
c7df3f1b |
1947 | '" value="'.$value . |
1948 | '" style="padding: 0px; margin: 0px" />'; |
e9e5f0fa |
1949 | } |
1950 | |
c7df3f1b |
1951 | /** |
62f7daa5 |
1952 | * Puts string into cell, aligns it and adds <small> tag |
1953 | * |
1954 | * @param string $string string |
1955 | * @param string $align alignment |
1956 | */ |
e9e5f0fa |
1957 | function getSmallStringCell($string, $align) { |
6a622b59 |
1958 | return html_tag('td', |
1959 | '<small>' . $string . ': </small>', |
1960 | $align, |
1961 | '', |
c435f076 |
1962 | 'style="white-space: nowrap;"' ); |
e9e5f0fa |
1963 | } |
1964 | |
c7df3f1b |
1965 | /** |
62f7daa5 |
1966 | * This should go in imap_mailbox.php |
1967 | * @param string $mailbox |
1968 | */ |
a3439b27 |
1969 | function handleAsSent($mailbox) { |
6a8e7cae |
1970 | global $handleAsSent_result; |
4669e892 |
1971 | |
6a622b59 |
1972 | /* First check if this is the sent or draft folder. */ |
6a8e7cae |
1973 | $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox); |
a3439b27 |
1974 | |
6a622b59 |
1975 | /* Then check the result of the handleAsSent hook. */ |
1976 | do_hook('check_handleAsSent_result', $mailbox); |
a3439b27 |
1977 | |
6a622b59 |
1978 | /* And return the result. */ |
6a8e7cae |
1979 | return $handleAsSent_result; |
6a622b59 |
1980 | } |
e842b215 |
1981 | |
324ac3c5 |
1982 | /** |
1983 | * Process messages list form and handle the cache gracefully. If $sButton and |
1984 | * $aUid are provided as argument then you can fake a message list submit and |
1985 | * use it i.e. in read_body.php for del move next and update the cache |
1986 | * |
1987 | * @param resource $imapConnection imap connection |
1988 | * @param array $aMailbox (reference) cached mailbox |
1989 | * @param string $sButton fake a submit button |
1990 | * @param array $aUid fake the $msg array |
1991 | * @return string $sError error string in case of an error |
1992 | * @author Marc Groot Koerkamp |
1993 | */ |
1994 | function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) { |
1995 | |
1996 | /* incoming formdata */ |
1997 | $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST)) ? 'move' : $sButton; |
1998 | $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST)) ? 'expunge' : $sButton; |
1999 | $sButton = (sqgetGlobalVar('attache', $sTmp, SQ_POST)) ? 'attache' : $sButton; |
2000 | $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton; |
2001 | $sButton = (sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton; |
2002 | $sButton = (sqgetGlobalVar('markRead', $sTmp, SQ_POST)) ? 'setSeen' : $sButton; |
2003 | $sButton = (sqgetGlobalVar('markUnread', $sTmp, SQ_POST)) ? 'unsetSeen' : $sButton; |
2004 | $sButton = (sqgetGlobalVar('markFlagged', $sTmp, SQ_POST)) ? 'setFlagged' : $sButton; |
2005 | $sButton = (sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST)) ? 'unsetFlagged' : $sButton; |
2006 | sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST); |
2007 | sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST); |
2008 | sqgetGlobalVar('msg', $msg, SQ_POST); |
2009 | |
2010 | $sError = ''; |
2011 | $mailbox = $aMailbox['NAME']; |
2012 | |
2013 | /* retrieve the check boxes */ |
2014 | $aUid = (isset($msg) && is_array($msg)) ? array_values($msg) : $aUid; |
2015 | |
2016 | if (count($aUid) && $sButton != 'expunge') { |
2017 | $aUpdatedMsgs = false; |
2018 | $bExpunge = false; |
2019 | switch ($sButton) { |
2020 | case 'setDeleted': |
2021 | // check if id exists in case we come from read_body |
2022 | if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) && |
2023 | !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) { |
2024 | break; |
2025 | } |
7c788b1c |
2026 | $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash); |
2027 | $bExpunge = true; |
324ac3c5 |
2028 | break; |
2029 | case 'unsetDeleted': |
2030 | case 'setSeen': |
2031 | case 'unsetSeen': |
2032 | case 'setFlagged': |
2033 | case 'unsetFlagged': |
2034 | // get flag |
2035 | $sFlag = (substr($sButton,0,3) == 'set') ? '\\'.substr($sButton,3) : '\\'.substr($sButton,5); |
2036 | $bSet = (substr($sButton,0,3) == 'set') ? true : false; |
2037 | $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true); |
2038 | break; |
2039 | case 'move': |
2040 | $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox); |
2041 | sqsession_register($targetMailbox,'lastTargetMailbox'); |
2042 | $bExpunge = true; |
2043 | break; |
2044 | case 'attache': |
2045 | $aMsgHeaders = array(); |
2046 | foreach ($aUid as $iUid) { |
2047 | $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid]; |
2048 | } |
2049 | if (count($aMsgHeaders)) { |
2050 | $composesession = attachSelectedMessages($imapConnection,$aMsgHeaders); |
2051 | // dirty hack, add info to $aMailbox |
2052 | $aMailbox['FORWARD_SESSION'] = $composesession; |
2053 | } |
2054 | break; |
7c788b1c |
2055 | default: |
2056 | // Hook for plugin buttons |
2057 | do_hook_function('mailbox_display_button_action', $aUid); |
2058 | break; |
324ac3c5 |
2059 | } |
2060 | /** |
2061 | * Updates messages is an array containing the result of the untagged |
2062 | * fetch responses send by the imap server due to a flag change. That |
2063 | * response is parsed in a array with msg arrays by the parseFetch function |
2064 | */ |
2065 | if ($aUpdatedMsgs) { |
2066 | // Update the message headers cache |
2067 | $aDeleted = array(); |
2068 | foreach ($aUpdatedMsgs as $iUid => $aMsg) { |
2069 | if (isset($aMsg['FLAGS'])) { |
fd28fa79 |
2070 | /** |
ddd209f2 |
2071 | * Only update the cached headers if the header is |
fd28fa79 |
2072 | * cached. |
2073 | */ |
2074 | if (isset($aMailbox['MSG_HEADERS'][$iUid])) { |
2075 | $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS']; |
2076 | } |
324ac3c5 |
2077 | /** |
2078 | * Count the messages with the \Delete flag set so we can determine |
2079 | * if the number of expunged messages equals the number of flagged |
2080 | * messages for deletion. |
2081 | */ |
2082 | if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) { |
2083 | $aDeleted[] = $iUid; |
2084 | } |
2085 | } |
2086 | } |
2087 | if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] && |
2088 | $iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true)) |
2089 | { |
2090 | if (count($aDeleted) != $iExpungedMessages) { |
2091 | // there are more messages deleted permanently then we expected |
2092 | // invalidate the cache |
2093 | $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false; |
2094 | $aMailbox['MSG_HEADERS'] = false; |
2095 | } else { |
2096 | // remove expunged messages from cache |
2097 | $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']]; |
2098 | if (is_array($aUidSet)) { |
2099 | // create a UID => array index temp array |
2100 | $aUidSetDummy = array_flip($aUidSet); |
2101 | foreach ($aDeleted as $iUid) { |
2102 | // get the id as well in case of SQM_SORT_NONE |
2103 | if ($aMailbox['SORT'] == SQSORT_NONE) { |
2104 | $aMailbox['ID'] = false; |
2105 | //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID']; |
2106 | //unset($aMailbox['ID'][$iId]); |
2107 | } |
2108 | // unset the UID and message header |
2109 | unset($aUidSetDummy[$iUid]); |
2110 | unset($aMailbox['MSG_HEADERS'][$iUid]); |
2111 | } |
2112 | $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy); |
324ac3c5 |
2113 | } |
2114 | } |
ddd209f2 |
2115 | // update EXISTS info |
2116 | if ($iExpungedMessages) { |
2117 | $aMailbox['EXISTS'] -= (int) $iExpungedMessages; |
2118 | } |
324ac3c5 |
2119 | // Change the startMessage number if the mailbox was changed |
4c284a74 |
2120 | if (($aMailbox['PAGEOFFSET']-1) >= $aMailbox['EXISTS']) { |
324ac3c5 |
2121 | $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ? |
2122 | $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1; |
91e0dccc |
2123 | $aMailbox['OFFSET'] = $aMailbox['PAGEOFFSET'] - 1 ; |
324ac3c5 |
2124 | } |
2125 | } |
2126 | } |
2127 | } else { |
2128 | if ($sButton == 'expunge') { |
2129 | /** |
2130 | * on expunge we do not know which messages will be deleted |
2131 | * so it's useless to try to sync the cache |
2132 | |
2133 | * Close the mailbox so we do not need to parse the untagged expunge |
2134 | * responses which do not contain uid info. |
2135 | * NB: Closing a mailbox is faster then expunge because the imap |
2136 | * server does not need to generate the untagged expunge responses |
2137 | */ |
2138 | sqimap_run_command($imapConnection,'CLOSE',false,$result,$message); |
2139 | $aMbxResponse = sqimap_mailbox_select($imapConnection,$aMailbox['NAME']); |
2140 | // update the $aMailbox array |
2141 | $aMailbox['EXISTS'] = $aMbxResponse['EXISTS']; |
2142 | $aMailbox['UIDSET'] = false; |
2143 | } else { |
2144 | if ($sButton) { |
2145 | $sError = _("No messages were selected."); |
2146 | } |
2147 | } |
2148 | } |
2149 | return $sError; |
2150 | } |
2151 | |
2152 | function attachSelectedMessages($imapConnection,$aMsgHeaders) { |
2153 | global $username, $attachment_dir, |
2154 | $data_dir, $composesession, |
2155 | $compose_messages; |
2156 | |
2157 | if (!isset($compose_messages)) { |
2158 | $compose_messages = array(); |
2159 | sqsession_register($compose_messages,'compose_messages'); |
2160 | } |
2161 | |
2162 | if (!$composesession) { |
2163 | $composesession = 1; |
2164 | sqsession_register($composesession,'composesession'); |
2165 | } else { |
2166 | $composesession++; |
2167 | sqsession_register($composesession,'composesession'); |
2168 | } |
2169 | |
2170 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
2171 | |
2172 | $composeMessage = new Message(); |
2173 | $rfc822_header = new Rfc822Header(); |
2174 | $composeMessage->rfc822_header = $rfc822_header; |
2175 | $composeMessage->reply_rfc822_header = ''; |
2176 | |
2177 | foreach($aMsgHeaders as $iUid => $aMsgHeader) { |
2178 | /** |
2179 | * Retrieve the full message |
2180 | */ |
2181 | $body_a = sqimap_run_command($imapConnection, "FETCH $iUid RFC822", true, $response, $readmessage, TRUE); |
2182 | |
2183 | if ($response == 'OK') { |
2184 | $subject = (isset($aMsgHeader['SUBJECT'])) ? $aMsgHeader['SUBJECT'] : $iUid; |
2185 | |
2186 | array_shift($body_a); |
2187 | array_pop($body_a); |
2188 | $body = implode('', $body_a); |
2189 | $body .= "\r\n"; |
2190 | |
2191 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
2192 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
2193 | |
2194 | $fp = fopen( $full_localfilename, 'wb'); |
2195 | fwrite ($fp, $body); |
2196 | fclose($fp); |
2197 | $composeMessage->initAttachment('message/rfc822',$subject.'.msg', |
2198 | $full_localfilename); |
2199 | } |
2200 | } |
2201 | |
2202 | $compose_messages[$composesession] = $composeMessage; |
2203 | sqsession_register($compose_messages,'compose_messages'); |
2204 | return $composesession; |
2205 | } |
2206 | |
043f9c14 |
2207 | // vim: et ts=4 |
b4482518 |
2208 | ?> |