- Fix URL for Read Receipts being incorrect in some cases (#1177518).
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 3/**
4b4abf93 4 * mailbox_display.php
5 *
6 * This contains functions that display mailbox information, such as the
7 * table row that has sender, date, subject, etc...
8 *
47ccfad4 9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 */
a4c2cd49 14
324ac3c5 15
16/**
17 * Selects a mailbox for header retrieval.
18 * Cache control for message headers is embedded.
19 *
20 * @param resource $imapConnection imap socket handle
21 * @param string $mailbox mailbox to select and retrieve message headers from
22 * @param array $aConfig array with system config settings and incoming vars
23 * @param array $aProps mailbox specific properties
24 * @return array $aMailbox mailbox array with all relevant information
4955562f 25 * @since 1.5.1
324ac3c5 26 * @author Marc Groot Koerkamp
27 */
91c27aee 28function sqm_api_mailbox_select($imapConnection,$account,$mailbox,$aConfig,$aProps) {
29
324ac3c5 30 /**
31 * NB: retrieve this from the session before accessing this function
32 * and make sure you write it back at the end of the script after
33 * the aMailbox var is added so that the headers are added to the cache
34 */
35 global $mailbox_cache;
91c27aee 36
324ac3c5 37 $aDefaultConfigProps = array(
324ac3c5 38// 'charset' => 'US-ASCII',
39 'user' => false, /* no pref storage if false */
40 'setindex' => 0,
41// 'search' => 'ALL',
42 'max_cache_size' => SQM_MAX_MBX_IN_CACHE
43 );
44
45 $aConfig = array_merge($aDefaultConfigProps,$aConfig);
91c27aee 46
324ac3c5 47 $iSetIndx = $aConfig['setindex'];
48
49 $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
50
51 if ($mailbox_cache) {
91c27aee 52 if (isset($mailbox_cache[$account.'_'.$mailbox])) {
53 $aCachedMailbox = $mailbox_cache[$account.'_'.$mailbox];
324ac3c5 54 } else {
55 $aCachedMailbox = false;
56 }
57 /* cleanup cache */
58 if (count($mailbox_cache) > $aConfig['max_cache_size'] -1) {
59 $aTime = array();
60 foreach($mailbox_cache as $cachedmailbox => $aVal) {
61 $aTime[$aVal['TIMESTAMP']] = $cachedmailbox;
62 }
63 if (ksort($aTime,SORT_NUMERIC)) {
64 for ($i=0,$iCnt=count($mailbox_cache);$i<($iCnt-$aConfig['max_cache_size']);++$i) {
65 $sOldestMbx = array_shift($aTime);
66 /**
67 * Remove only the UIDSET and MSG_HEADERS from cache because those can
68 * contain large amounts of data.
69 */
70 if (isset($mailbox_cache[$sOldestMbx]['UIDSET'])) {
71 $mailbox_cache[$sOldestMbx]['UIDSET']= false;
72 }
73 if (isset($mailbox_cache[$sOldestMbx]['MSG_HEADERS'])) {
74 $mailbox_cache[$sOldestMbx]['MSG_HEADERS'] = false;
75 }
76 }
77 }
78 }
79
80 } else {
81 $aCachedMailbox = false;
82 }
83
84 /**
85 * Deal with imap servers that do not return the required UIDNEXT or
86 * UIDVALIDITY response
87 * from a SELECT call (since rfc 3501 it's required).
88 */
89 if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) {
90 $aStatus = sqimap_status_messages($imapConnection,$mailbox,
91 array('UIDNEXT','UIDVALIDITY'));
92 $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
93 $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
94 }
95
91c27aee 96 $aMailbox['ACCOUNT'] = $account;
324ac3c5 97 $aMailbox['UIDSET'][$iSetIndx] = false;
98 $aMailbox['ID'] = false;
99 $aMailbox['SETINDEX'] = $iSetIndx;
c3731db5 100 $aMailbox['MSG_HEADERS'] = false;
324ac3c5 101
102 if ($aCachedMailbox) {
103 /**
104 * Validate integrity of cached data
105 */
106 if ($aCachedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
107 $aMbxResponse['EXISTS'] &&
108 $aCachedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
109 $aCachedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT'] &&
110 isset($aCachedMailbox['SEARCH'][$iSetIndx]) &&
111 (!isset($aConfig['search']) || /* always set search from the searchpage */
112 $aCachedMailbox['SEARCH'][$iSetIndx] == $aConfig['search'])) {
113 if (isset($aCachedMailbox['MSG_HEADERS'])) {
114 $aMailbox['MSG_HEADERS'] = $aCachedMailbox['MSG_HEADERS'];
115 }
116 $aMailbox['ID'] = $aCachedMailbox['ID'];
117 if (isset($aCachedMailbox['UIDSET'][$iSetIndx]) && $aCachedMailbox['UIDSET'][$iSetIndx]) {
118 if (isset($aProps[MBX_PREF_SORT]) && $aProps[MBX_PREF_SORT] != $aCachedMailbox['SORT'] ) {
119 $newsort = $aProps[MBX_PREF_SORT];
120 $oldsort = $aCachedMailbox['SORT'];
121 /**
122 * If it concerns a reverse sort we do not need to invalidate
123 * the cached sorted UIDSET, a reverse is sufficient.
124 */
125 if ((($newsort % 2) && ($newsort + 1 == $oldsort)) ||
126 (!($newsort % 2) && ($newsort - 1 == $oldsort))) {
127 $aMailbox['UIDSET'][$iSetIndx] = array_reverse($aCachedMailbox['UIDSET'][$iSetIndx]);
128 } else {
91c27aee 129 $server_sort_array = false;
324ac3c5 130 $aMailbox['MSG_HEADERS'] = false;
131 $aMailbox['ID'] = false;
132 }
133 // store the new sort value in the mailbox pref
134 if ($aConfig['user']) {
135 // FIXME, in ideal situation, we write back the
136 // prefs at the end of the script
91c27aee 137 setUserPref($aConfig['user'],'pref_'.$account.'_'.$mailbox,serialize($aProps));
324ac3c5 138 }
139 } else {
140 $aMailbox['UIDSET'][$iSetIndx] = $aCachedMailbox['UIDSET'][$iSetIndx];
141 }
142 }
143 }
144 }
145 /**
146 * Restore the offset in the paginator if no new offset is provided.
147 */
148 if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['offset']) && $aCachedMailbox['OFFSET']) {
149 $aMailbox['OFFSET'] = $aCachedMailbox['OFFSET'];
150 $aMailbox['PAGEOFFSET'] = $aCachedMailbox['PAGEOFFSET'];
151 } else {
152 $aMailbox['OFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] -1 : 0;
153 $aMailbox['PAGEOFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] : 1;
154 }
91c27aee 155 /**
156 * Restore the number of messages in the result set
157 */
158 if (isset($aCachedMailbox['TOTAL'][$iSetIndx]) && $aCachedMailbox['TOTAL'][$iSetIndx]) {
159 $aMailbox['TOTAL'][$iSetIndx] = $aCachedMailbox['TOTAL'][$iSetIndx];
160 }
324ac3c5 161
162 /**
163 * Restore the showall value no new showall value is provided.
164 */
165 if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['showall']) &&
166 isset($aCachedMailbox['SHOWALL'][$iSetIndx]) && $aCachedMailbox['SHOWALL'][$iSetIndx]) {
167 $aMailbox['SHOWALL'][$iSetIndx] = $aCachedMailbox['SHOWALL'][$iSetIndx];
168 } else {
169 $aMailbox['SHOWALL'][$iSetIndx] = (isset($aConfig['showall']) && $aConfig['showall']) ? 1 : 0;
170 }
171
91c27aee 172 /**
173 * Restore the sort order if no new sort order is provided.
174 */
324ac3c5 175 if (!isset($aProps[MBX_PREF_SORT]) && isset($aCachedMailbox['SORT'])) {
176 $aMailbox['SORT'] = $aCachedMailbox['SORT'];
177 } else {
178 $aMailbox['SORT'] = (isset($aProps[MBX_PREF_SORT])) ? $aProps[MBX_PREF_SORT] : 0;
179 }
180
91c27aee 181 /**
182 * Restore the number of message to show per page when no new limit is provided
183 */
324ac3c5 184 if (!isset($aProps[MBX_PREF_LIMIT]) && isset($aCachedMailbox['LIMIT'])) {
185 $aMailbox['LIMIT'] = $aCachedMailbox['LIMIT'];
186 } else {
187 $aMailbox['LIMIT'] = (isset($aProps[MBX_PREF_LIMIT])) ? $aProps[MBX_PREF_LIMIT] : 15;
188 }
189
91c27aee 190 /**
191 * Restore the ordered columns to show when no new ordered columns are provided
192 */
193 if (!isset($aProps[MBX_PREF_COLUMNS]) && isset($aCachedMailbox['COLUMNS'])) {
194 $aMailbox['COLUMNS'] = $aCachedMailbox['COLUMNS'];
324ac3c5 195 } else {
91c27aee 196 $aMailbox['COLUMNS'] = (isset($aProps[MBX_PREF_COLUMNS])) ? $aProps[MBX_PREF_COLUMNS] :
197 array(SQM_COL_FLAGS,SQM_COL_FROM, SQM_COL_SUBJ, SQM_COL_FLAGS);
324ac3c5 198 }
199
d0b119a5 200 /**
201 * Restore the headers we fetch the last time. Saves intitialisation stuff in read_body.
202 */
203 $aMailbox['FETCHHEADERS'] = (isset($aCachedMailbox['FETCHHEADERS'])) ? $aCachedMailbox['FETCHHEADERS'] : null;
204
324ac3c5 205 if (!isset($aProps[MBX_PREF_AUTO_EXPUNGE]) && isset($aCachedMailbox['AUTO_EXPUNGE'])) {
206 $aMailbox['AUTO_EXPUNGE'] = $aCachedMailbox['AUTO_EXPUNGE'];
207 } else {
208 $aMailbox['AUTO_EXPUNGE'] = (isset($aProps[MBX_PREF_AUTO_EXPUNGE])) ? $aProps[MBX_PREF_AUTO_EXPUNGE] : false;
209 }
324ac3c5 210 if (!isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx])) {
211 $aMailbox['SEARCH'][$iSetIndx] = $aCachedMailbox['SEARCH'][$iSetIndx];
7762b03c 212 } else if (isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx]) &&
213 $aConfig['search'] != $aCachedMailbox['SEARCH'][$iSetIndx]) {
214 // reset the pageindex
215 $aMailbox['SEARCH'][$iSetIndx] = $aConfig['search'];
216 $aMailbox['OFFSET'] = 0;
217 $aMailbox['PAGEOFFSET'] = 1;
324ac3c5 218 } else {
219 $aMailbox['SEARCH'][$iSetIndx] = (isset($aConfig['search'])) ? $aConfig['search'] : 'ALL';
220 }
324ac3c5 221 if (!isset($aConfig['charset']) && isset($aCachedMailbox['CHARSET'][$iSetIndx])) {
222 $aMailbox['CHARSET'][$iSetIndx] = $aCachedMailbox['CHARSET'][$iSetIndx];
223 } else {
224 $aMailbox['CHARSET'][$iSetIndx] = (isset($aConfig['charset'])) ? $aConfig['charset'] : 'US-ASCII';
225 }
226
227 $aMailbox['NAME'] = $mailbox;
228 $aMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
229 $aMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
230 $aMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ? $aMbxResponse['RECENT'] : 0;
231 $aMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
232 $aMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
233 $aMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS'];
234 $aMailbox['RIGHTS'] = $aMbxResponse['RIGHTS'];
235
324ac3c5 236 /* decide if we are thread sorting or not */
324ac3c5 237 if ($aMailbox['SORT'] & SQSORT_THREAD) {
91c27aee 238 if (!sqimap_capability($imapConnection,'THREAD')) {
239 $aMailbox['SORT'] ^= SQSORT_THREAD;
240 } else {
241 $aMailbox['THREAD_INDENT'] = $aCachedMailbox['THREAD_INDENT'];
242 }
324ac3c5 243 } else {
324ac3c5 244 $aMailbox['THREAD_INDENT'] = false;
245 }
246
247 /* set a timestamp for cachecontrol */
248 $aMailbox['TIMESTAMP'] = time();
249 return $aMailbox;
250}
251
c7df3f1b 252/**
91c27aee 253 * Fetch the message headers for a mailbox. Settings are part of the aMailbox
4955562f 254 * array. Dependent of the mailbox settings it deals with sort, thread and search
255 * If server sort is supported then SORT is also used for retrieving sorted search results
62f7daa5 256 *
91c27aee 257 * @param resource $imapConnection imap socket handle
258 * @param array $aMailbox (reference) mailbox retrieved from sqm_api_mailbox_select
259 * @return error $error error number
4955562f 260 * @since 1.5.1
91c27aee 261 * @author Marc Groot Koerkamp
62f7daa5 262 */
d0b119a5 263function fetchMessageHeaders($imapConnection, &$aMailbox) {
e0e30169 264
91c27aee 265 /* FIX ME, this function is kind of big, maybe we can split it up in
266 a couple of functions. Make sure the functions are private and starts with _
267 Also make sure that the error codes are propagated */
324ac3c5 268
269 /**
270 * Retrieve the UIDSET.
271 * Setindex is used to be able to store multiple uid sets. That will make it
272 * possible to display the mailbox multiple times in different sort order
273 * or to store serach results separate from normal mailbox view.
274 */
275 $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0;
276
277 $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
278 /**
279 * Adjust the start_msg
280 */
281 $start_msg = $aMailbox['PAGEOFFSET'];
282 if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) {
283 $start_msg -= $aMailbox['LIMIT'];
284 if($start_msg < 1) {
285 $start_msg = 1;
286 }
287 }
d0b119a5 288
324ac3c5 289 if (is_array($aMailbox['UIDSET'])) {
290 $aUid =& $aMailbox['UIDSET'][$iSetIndx];
f6b262a3 291 } else {
324ac3c5 292 $aUid = false;
293 }
d0b119a5 294 $aFetchHeaders = $aMailbox['FETCHHEADERS'];
324ac3c5 295
91c27aee 296 $iError = 0;
297 $aFetchItems = $aHeaderItems = array();
324ac3c5 298 // initialize the fields we want to retrieve:
b4246036 299 $aHeaderFields = array();
91c27aee 300 foreach ($aFetchHeaders as $v) {
301 switch ($v) {
302 case SQM_COL_DATE: $aHeaderFields[] = 'Date'; break;
303 case SQM_COL_TO: $aHeaderFields[] = 'To'; break;
304 case SQM_COL_CC: $aHeaderFields[] = 'Cc'; break;
305 case SQM_COL_FROM: $aHeaderFields[] = 'From'; break;
306 case SQM_COL_SUBJ: $aHeaderFields[] = 'Subject'; break;
307 case SQM_COL_PRIO: $aHeaderFields[] = 'X-Priority'; break;
308 case SQM_COL_ATTACHMENT: $aHeaderFields[] = 'Content-Type'; break;
309 case SQM_COL_INT_DATE: $aFetchItems[] = 'INTERNALDATE'; break;
310 case SQM_COL_FLAGS: $aFetchItems[] = 'FLAGS'; break;
311 case SQM_COL_SIZE: $aFetchItems[] = 'RFC822.SIZE'; break;
312 default: break;
313 }
324ac3c5 314 }
315
324ac3c5 316 /**
317 * A uidset with sorted uid's is available. We can use the cache
318 */
91c27aee 319 if (isset($aUid) && $aUid ) {
324ac3c5 320 // limit the cache to SQM_MAX_PAGES_IN_CACHE
91c27aee 321 if (!$aMailbox['SHOWALL'][$iSetIndx] && isset($aMailbox['MSG_HEADERS'])) {
324ac3c5 322 $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE;
323 $iCacheSize = count($aMailbox['MSG_HEADERS']);
324 if ($iCacheSize > $iMaxMsgs) {
325 $iReduce = $iCacheSize - $iMaxMsgs;
326 foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) {
327 if ($iReduce) {
328 unset($aMailbox['MSG_HEADERS'][$iUid]);
329 } else {
330 break;
331 }
332 --$iReduce;
333 }
6a622b59 334 }
e9e5f0fa 335 }
324ac3c5 336
337 $id_slice = array_slice($aUid,$start_msg-1,$iLimit);
338 /* do some funky cache checks */
6ab20f61 339 if (isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) {
fe1521ef 340 // temp code, read_body del / next links fo not update fields.
341 foreach ($aMailbox['MSG_HEADERS'] as $iUid => $aValue) {
342 if (!isset($aValue['UID'])) {
343 unset($aMailbox['MSG_HEADERS'][$iUid]);
344 }
345 }
91c27aee 346 $aUidCached = array_keys($aMailbox['MSG_HEADERS']);
347 } else {
348 $aMailbox['MSG_HEADERS'] = array();
349 $aUidCached = array();
350 }
324ac3c5 351 $aUidNotCached = array_values(array_diff($id_slice,$aUidCached));
91c27aee 352
324ac3c5 353 /**
354 * $aUidNotCached contains an array with UID's which need to be fetched to
355 * complete the needed message headers.
356 */
357 if (count($aUidNotCached)) {
358 $aMsgs = sqimap_get_small_header_list($imapConnection,$aUidNotCached,
359 $aHeaderFields,$aFetchItems);
360 // append the msgs to the existend headers
361 $aMailbox['MSG_HEADERS'] += $aMsgs;
8cc8ec79 362 }
324ac3c5 363 } else {
364 /**
91c27aee 365 * Initialize the sorted UID list or initiate a UID list with search
366 * results and fetch the visible message headers
324ac3c5 367 */
324ac3c5 368
91c27aee 369 if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') { // in case of a search request
370
324ac3c5 371 if ($aMailbox['SEARCH'][$iSetIndx] && $aMailbox['SORT'] == 0) {
372 $aUid = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
373 } else {
91c27aee 374
375 $iError = 0;
376 $iError = _get_sorted_msgs_list($imapConnection,$aMailbox,$iError);
324ac3c5 377 $aUid = $aMailbox['UIDSET'][$iSetIndx];
03975a39 378 }
91c27aee 379 if (!$iError) {
380 /**
381 * Number of messages is the resultset
382 */
383 $aMailbox['TOTAL'][$iSetIndx] = count($aUid);
324ac3c5 384 $id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit);
385 if (count($id_slice)) {
386 $aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice,
387 $aHeaderFields,$aFetchItems);
388 } else {
91c27aee 389 $iError = 1; // FIX ME, define an error code
324ac3c5 390 }
03975a39 391 }
91c27aee 392 } else { //
393 $iError = 0;
394 $iError = _get_sorted_msgs_list($imapConnection,$aMailbox,$iError);
395 $aUid = $aMailbox['UIDSET'][$iSetIndx];
396
397 if (!$iError) {
398 /**
399 * Number of messages is the resultset
400 */
401 $aMailbox['TOTAL'][$iSetIndx] = count($aUid);
402 $id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit);
403 if (count($id_slice)) {
404 $aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice,
405 $aHeaderFields,$aFetchItems);
324ac3c5 406 } else {
91c27aee 407 $iError = 1; // FIX ME, define an error code
324ac3c5 408 }
409 }
8cc8ec79 410 }
8cc8ec79 411 }
91c27aee 412 return $iError;
0fdc2fb6 413}
a966982b 414
4955562f 415/**
416 * Prepares the message headers for display inside a template. The links are calculated,
417 * color for row highlighting is calculated and optionally the strings are truncated.
418 *
419 * @param array $aMailbox (reference) mailbox retrieved from sqm_api_mailbox_select
420 * @param array $aProps properties
421 * @return array $aFormattedMessages array with message headers and format info
422 * @since 1.5.1
423 * @author Marc Groot Koerkamp
424 */
91c27aee 425function prepareMessageList(&$aMailbox, $aProps) {
84bb1d31 426
427 /* Globalize link attributes so plugins can share in modifying them */
428 global $link, $title, $target, $onclick, $link_extra;
429
91c27aee 430 /* retrieve the properties */
431 $my_email_address = (isset($aProps['email'])) ? $aProps['email'] : false;
432 $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false;
433 $aColumnDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false;
434 $aExtraColumns = (isset($aProps['extra_columns'])) ? $aProps['extra_columns'] : array();
435 $iAccount = (isset($aProps['account'])) ? (int) $aProps['account'] : 0;
436 $sMailbox = (isset($aProps['mailbox'])) ? $aProps['mailbox'] : false;
437 $sTargetModule = (isset($aProps['module'])) ? $aProps['module'] : 'read_body';
a966982b 438
91c27aee 439 /*
440 * TODO 1, retrieve array with identity email addresses in order to match against to,cc and set a flag
441 * $aFormattedMessages[$iUid]['match_identity'] = true
442 * The template can show some image if there is a match.
443 * TODO 2, makes sure the matching is done fast by doing a strpos call on the returned $value
444 */
8cc8ec79 445
91c27aee 446 /**
447 * Only retrieve values for displayable columns
448 */
449 foreach ($aColumnDesc as $k => $v) {
450 switch ($k) {
451 case SQM_COL_FROM: $aCol[SQM_COL_FROM] = 'from'; break;
452 case SQM_COL_DATE: $aCol[SQM_COL_DATE] = 'date'; break;
453 case SQM_COL_SUBJ: $aCol[SQM_COL_SUBJ] = 'subject'; break;
454 case SQM_COL_FLAGS: $aCol[SQM_COL_FLAGS] = 'FLAGS'; break;
455 case SQM_COL_SIZE: $aCol[SQM_COL_SIZE] = 'SIZE'; break;
456 case SQM_COL_PRIO: $aCol[SQM_COL_PRIO] = 'x-priority'; break;
457 case SQM_COL_ATTACHMENT: $aCol[SQM_COL_ATTACHMENT] = 'content-type'; break;
458 case SQM_COL_INT_DATE: $aCol[SQM_COL_INT_DATE] = 'INTERNALDATE'; break;
459 case SQM_COL_TO: $aCol[SQM_COL_TO] = 'to'; break;
460 case SQM_COL_CC: $aCol[SQM_COL_CC] = 'cc'; break;
461 case SQM_COL_BCC: $aCol[SQM_COL_BCC] = 'bcc'; break;
462 default: break;
463 }
464 }
83eb12fc 465 $aExtraHighLightColumns = array();
466 foreach ($aExtraColumns as $v) {
467 switch ($v) {
468 case SQM_COL_FROM: $aExtraHighLightColumns[] = 'from'; break;
469 case SQM_COL_SUBJ: $aExtraHighLightColumns[] = 'subject'; break;
470 case SQM_COL_TO: $aExtraHighLightColumns[] = 'to'; break;
471 case SQM_COL_CC: $aExtraHighLightColumns[] = 'cc'; break;
472 case SQM_COL_BCC: $aExtraHighLightColumns[] = 'bcc'; break;
23541351 473 default: break;
474 }
475 }
91c27aee 476 $aFormattedMessages = array();
477
478
479 $iSetIndx = $aMailbox['SETINDEX'];
480 $aId = $aMailbox['UIDSET'][$iSetIndx];
481 $aHeaders =& $aMailbox['MSG_HEADERS']; /* use a reference to avoid a copy.
482 MSG_HEADERS can contain large amounts of data */
483 $iOffset = $aMailbox['OFFSET'];
484 $sort = $aMailbox['SORT'];
485 $iPageOffset = $aMailbox['PAGEOFFSET'];
486 $sMailbox = $aMailbox['NAME'];
487 $sSearch = (isset($aMailbox['SEARCH'][$aMailbox['SETINDEX']]) &&
488 $aMailbox['SEARCH'][$aMailbox['SETINDEX']] != 'ALL') ? $aMailbox['SEARCH'][$aMailbox['SETINDEX']] : false;
489 $aSearch = ($sSearch) ? array('search.php',$aMailbox['SETINDEX']) : null;
490 /* avoid improper usage */
491 if ($sMailbox && isset($iAccount) && $sTargetModule) {
492 $aInitQuery = array("account=$iAccount",'mailbox='.urlencode($sMailbox));
8cc8ec79 493 } else {
91c27aee 494 $aInitQuery = false;
8cc8ec79 495 }
496
91c27aee 497 if ($aMailbox['SORT'] & SQSORT_THREAD) {
498 $aIndentArray =& $aMailbox['THREAD_INDENT'][$aMailbox['SETINDEX']];
499 $bThread = true;
500 } else {
501 $bThread = false;
502 }
503 /*
504 * Retrieve value for checkbox column
505 */
506 if (!sqgetGlobalVar('checkall',$checkall,SQ_GET)) {
507 $checkall = false;
e4b5f9d1 508 }
509
91c27aee 510 /*
511 * Loop through and display the info for each message.
512 */
513 $iEnd = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $iOffset + $aMailbox['LIMIT'];
514 for ($i=$iOffset,$t=0;$i<$iEnd;++$i) {
515 if (isset($aId[$i])) {
516
517 $bHighLight = false;
02e830bd 518 $value = $title = $link = $target = $onclick = $link_extra = '';
91c27aee 519 $aQuery = ($aInitQuery !== false) ? $aInitQuery : false;
520 $aMsg = $aHeaders[$aId[$i]];
521 if (isset($aSearch) && count($aSearch) > 1 && $aQuery) {
522 $aQuery[] = "where=". $aSearch[0];
523 $aQuery[] = "what=" . $aSearch[1];
8008456a 524 }
91c27aee 525 $iUid = (isset($aMsg['UID'])) ? $aMsg['UID'] : $aId[$i];
526 if ($aQuery) {
527 $aQuery[] = "passed_id=$aId[$i]";
528 $aQuery[] = "startMessage=$iPageOffset";
8008456a 529 }
91c27aee 530
531 foreach ($aCol as $k => $v) {
02e830bd 532 $title = $link = $target = $onclick = $link_extra = '';
91c27aee 533 $aColumns[$k] = array();
534 $value = (isset($aMsg[$v])) ? $aMsg[$v] : '';
535 $sUnknown = _("Unknown recipient");
536 switch ($k) {
537 case SQM_COL_FROM:
538 $sUnknown = _("Unknown sender");
539 case SQM_COL_TO:
540 case SQM_COL_CC:
541 case SQM_COL_BCC:
542 $sTmp = false;
543 if ($value) {
544 if ($highlight_list && !$bHighLight) {
545 $bHighLight = highlightMessage($aCol[$k], $value, $highlight_list,$aFormattedMessages[$iUid]);
546 }
582bbe27 547 $aAddressList = parseRFC822Address($value);
548 $sTmp = getAddressString($aAddressList,array('best' => true));
549 $title = $title_maybe = '';
550 foreach ($aAddressList as $aAddr) {
551 $sPersonal = (isset($aAddr[SQM_ADDR_PERSONAL])) ? $aAddr[SQM_ADDR_PERSONAL] : '';
552 $sMailbox = (isset($aAddr[SQM_ADDR_MAILBOX])) ? $aAddr[SQM_ADDR_MAILBOX] : '';
553 $sHost = (isset($aAddr[SQM_ADDR_HOST])) ? $aAddr[SQM_ADDR_HOST] : '';
554 if ($sPersonal) {
555 $title .= htmlspecialchars($sMailbox.'@'.$sHost).', ';
556 } else {
557 // if $value gets truncated we need to add the addresses with no
558 // personal name as well
559 $title_maybe .= htmlspecialchars($sMailbox.'@'.$sHost).', ';
560 }
561 }
562 if ($title) {
563 $title = substr($title,0,-2); // strip ', ';
564 }
86ef259b 565 $sTmp = decodeHeader($sTmp);
91c27aee 566 if (isset($aColumnDesc[$k]['truncate']) && $aColumnDesc[$k]['truncate']) {
567 $sTrunc = truncateWithEntities($sTmp, $aColumnDesc[$k]['truncate']);
582bbe27 568 if ($sTrunc != $sTmp) {
569 if (!$title) {
570 $title = htmlspecialchars($sTmp);
571 } else if ($title_maybe) {
572 $title = $title .', '.$title_maybe;
573 $title = substr($title,0,-2); // strip ', ';
574 }
575 }
91c27aee 576 $sTmp = $sTrunc;
577 }
578 }
86ef259b 579 $value = ($sTmp) ? $sTmp : $sUnknown;
91c27aee 580 break;
581 case SQM_COL_SUBJ:
d0b119a5 582 // subject is mime encoded, decode it.
129c22ed 583 // value is sanitized in decoding function.
86ef259b 584 // TODO, verify if it should be done before or after the highlighting
129c22ed 585 $value=decodeHeader($value);
91c27aee 586 if ($highlight_list && !$bHighLight) {
587 $bHighLight = highlightMessage('SUBJECT', $value, $highlight_list, $aFormattedMessages[$iUid]);
588 }
589 $iIndent = (isset($aIndentArray[$aId[$i]])) ? $aIndentArray[$aId[$i]] : 0;
129c22ed 590 // FIXME: don't break 8bit symbols and html entities during truncation
91c27aee 591 if (isset($aColumnDesc[$k]['truncate']) && $aColumnDesc[$k]['truncate']) {
592 $sTmp = truncateWithEntities($value, $aColumnDesc[$k]['truncate']-$iIndent);
887f7f28 593 // drop any double spaces since these will be displayed in the title
594 $title = ($sTmp != $value) ? preg_replace('/\s{2,}/', ' ', $value) : '';
91c27aee 595 $value = $sTmp;
596 }
597 /* generate the link to the message */
598 if ($aQuery) {
599 // TODO, $sTargetModule should be a query parameter so that we can use a single entrypoint
600 $link = $sTargetModule.'.php?' . implode('&amp;',$aQuery);
02e830bd 601
84bb1d31 602 // see top of this function for which attributes are available
202bcbcc 603 // in the global scope for plugin use (like $link, $target,
84bb1d31 604 // $onclick, $link_extra, $title, and so forth)
202bcbcc 605 // plugins are responsible for sharing nicely (such as for
84bb1d31 606 // setting the target, etc)
02e830bd 607 do_hook('subject_link', array($iPageOffset, $sSearch, $aSearch));
91c27aee 608 }
91c27aee 609 $value = (trim($value)) ? $value : _("(no subject)");
610 /* add thread indentation */
611 $aColumns[$k]['indent'] = $iIndent;
91c27aee 612 break;
613 case SQM_COL_SIZE:
614 $value = show_readable_size($value);
615 break;
616 case SQM_COL_DATE:
617 case SQM_COL_INT_DATE:
3b64ced2 618 $value = getDateString(getTimeStamp(explode(' ',trim($value))));
91c27aee 619 break;
620 case SQM_COL_FLAGS:
621 $aFlagColumn = array('seen' => false,
622 'deleted'=>false,
623 'answered'=>false,
624 'flagged' => false,
625 'draft' => false);
c3731db5 626
627 if(!is_array($value)) $value = array();
91c27aee 628 foreach ($value as $sFlag => $value) {
629 switch ($sFlag) {
630 case '\\seen' : $aFlagColumn['seen'] = true; break;
631 case '\\deleted' : $aFlagColumn['deleted'] = true; break;
632 case '\\answered': $aFlagColumn['answered'] = true; break;
633 case '\\flagged' : $aFlagColumn['flagged'] = true; break;
634 case '\\draft' : $aFlagColumn['draft'] = true; break;
635 default: break;
636 }
637 }
638 $value = $aFlagColumn;
639 break;
640 case SQM_COL_PRIO:
641 $value = ($value) ? (int) $value : 3;
642 break;
643 case SQM_COL_ATTACHMENT:
644 $value = (is_array($value) && $value[0] == 'multipart' && $value[1] == 'mixed') ? true : false;
645 break;
646 case SQM_COL_CHECK:
647 $value = $checkall;
648 break;
649 default : break;
650 }
02e830bd 651 if ($title) { $aColumns[$k]['title'] = $title; }
652 if ($link) { $aColumns[$k]['link'] = $link; }
653 if ($link_extra) { $aColumns[$k]['link_extra'] = $link_extra; }
654 if ($onclick) { $aColumns[$k]['onclick'] = $onclick; }
655 if ($target) { $aColumns[$k]['target'] = $target; }
91c27aee 656 $aColumns[$k]['value'] = $value;
8008456a 657 }
91c27aee 658 /* columns which will not be displayed but should be inspected
659 because the highlight list contains rules with those columns */
83eb12fc 660 foreach ($aExtraHighLightColumns as $v) {
661 if ($highlight_list && !$bHighLight && isset($aMsg[$v])) {
662 $bHighLight = highlightMessage($v, $aMsg[$v], $highlight_list,$aFormattedMessages[$iUid]);
91c27aee 663 }
03975a39 664 }
91c27aee 665 $aFormattedMessages[$iUid]['columns'] = $aColumns;
666
667 } else {
8008456a 668 break;
669 }
bdfb67f8 670 }
91c27aee 671 return $aFormattedMessages;
bdfb67f8 672}
673
e9e5f0fa 674
4955562f 675/**
676 * Sets the row color if the provided column value pair matches a hightlight rule
677 *
678 * @param string $sCol column name
679 * @param string $sVal column value
680 * @param array $highlight_list highlight rules
681 * @param array $aFormat (reference) array where row color info is stored
682 * @return bool match found
683 * @since 1.5.1
684 * @author Marc Groot Koerkamp
685 */
91c27aee 686function highlightMessage($sCol, $sVal, $highlight_list, &$aFormat) {
91c27aee 687 if (!is_array($highlight_list) && count($highlight_list) == 0) {
688 return false;
689 }
690 $hlt_color = false;
691 $sCol = strtoupper($sCol);
83eb12fc 692
91c27aee 693 foreach ($highlight_list as $highlight_list_part) {
694 if (trim($highlight_list_part['value'])) {
695 $high_val = strtolower($highlight_list_part['value']);
696 $match_type = strtoupper($highlight_list_part['match_type']);
697 if($match_type == 'TO_CC') {
698 if ($sCol == 'TO' || $sCol == 'CC') {
699 $match_type = $sCol;
700 } else {
701 continue;
702 }
703 } else {
704 if ($match_type != $sCol) {
705 continue;
706 }
707 }
708 if (strpos(strtolower($sVal),$high_val) !== false) {
709 $hlt_color = $highlight_list_part['color'];
710 break;
711 }
712 }
713 }
714 if ($hlt_color) {
d0b119a5 715 // Bug in highlight color???
f3a1e5fa 716 if ($hlt_color{0} != '#') {
717 $hlt_color = '#'. $hlt_color;
718 }
91c27aee 719 $aFormat['row']['color'] = $hlt_color;
720 return true;
e35045b7 721 } else {
91c27aee 722 return false;
6c930ade 723 }
91c27aee 724}
6a622b59 725
91c27aee 726function setUserPref($username, $pref, $value) {
727 global $data_dir;
728 setPref($data_dir,$username,$pref,$value);
6a622b59 729}
730
c7df3f1b 731/**
4b4abf93 732 * Execute the sorting for a mailbox
733 *
734 * @param resource $imapConnection Imap connection
735 * @param array $aMailbox (reference) Mailbox retrieved with sqm_api_mailbox_select
736 * @return int $error (reference) Error number
737 * @private
4955562f 738 * @since 1.5.1
4b4abf93 739 * @author Marc Groot Koerkamp
740 */
91c27aee 741function _get_sorted_msgs_list($imapConnection,&$aMailbox) {
742 $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0;
49719da8 743 $bDirection = !($aMailbox['SORT'] % 2);
91c27aee 744 $error = 0;
745 if (!$aMailbox['SEARCH'][$iSetIndx]) {
746 $aMailbox['SEARCH'][$iSetIndx] = 'ALL';
747 }
748 if (($aMailbox['SORT'] & SQSORT_THREAD) && sqimap_capability($imapConnection,'THREAD')) {
749 $aRes = get_thread_sort($imapConnection,$aMailbox['SEARCH'][$iSetIndx]);
750 if ($aRes === false) {
751 $aMailbox['SORT'] -= SQSORT_THREAD;
752 $error = 1; // fix me, define an error code;
6a622b59 753 } else {
91c27aee 754 $aMailbox['UIDSET'][$iSetIndx] = $aRes[0];
755 $aMailbox['THREAD_INDENT'][$iSetIndx] = $aRes[1];
a6d36aa5 756 }
91c27aee 757 } else if ($aMailbox['SORT'] === SQSORT_NONE) {
758 $id = sqimap_run_search($imapConnection, 'ALL' , '');
759 if ($id === false) {
760 $error = 1; // fix me, define an error code
a6d36aa5 761 } else {
91c27aee 762 $aMailbox['UIDSET'][$iSetIndx] = array_reverse($id);
763 $aMailbox['TOTAL'][$iSetIndx] = $aMailbox['EXISTS'];
a6d36aa5 764 }
91c27aee 765 } else {
766 if (sqimap_capability($imapConnection,'SORT')) {
767 $sSortField = _getSortField($aMailbox['SORT'],true);
768 $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]);
769 if ($id === false) {
770 $error = 1; // fix me, define an error code
771 } else {
772 $aMailbox['UIDSET'][$iSetIndx] = $id;
773 }
6a622b59 774 } else {
91c27aee 775 $id = NULL;
776 if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') {
777 $id = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
778 }
779 $sSortField = _getSortField($aMailbox['SORT'],false);
780 $aMailbox['UIDSET'][$iSetIndx] = get_squirrel_sort($imapConnection, $sSortField, $bDirection, $id);
6a622b59 781 }
e35045b7 782 }
91c27aee 783 return $error;
bdfb67f8 784}
1a0e0983 785
c7df3f1b 786/**
4b4abf93 787 * Does the $srt $_GET var to field mapping
788 *
789 * @param int $srt Field to sort on
790 * @param bool $bServerSort Server sorting is true
791 * @return string $sSortField Field to sort on
4955562f 792 * @since 1.5.1
4b4abf93 793 * @private
794 */
91c27aee 795function _getSortField($sort,$bServerSort) {
796 switch($sort) {
797 case SQSORT_NONE:
798 $sSortField = 'UID';
799 break;
800 case SQSORT_DATE_ASC:
801 case SQSORT_DATE_DESC:
802 $sSortField = 'DATE';
803 break;
804 case SQSORT_FROM_ASC:
805 case SQSORT_FROM_DESC:
806 $sSortField = 'FROM';
807 break;
808 case SQSORT_SUBJ_ASC:
809 case SQSORT_SUBJ_DESC:
810 $sSortField = 'SUBJECT';
811 break;
812 case SQSORT_SIZE_ASC:
813 case SQSORT_SIZE_DESC:
814 $sSortField = ($bServerSort) ? 'SIZE' : 'RFC822.SIZE';
815 break;
816 case SQSORT_TO_ASC:
817 case SQSORT_TO_DESC:
818 $sSortField = 'TO';
819 break;
820 case SQSORT_CC_ASC:
821 case SQSORT_CC_DESC:
822 $sSortField = 'CC';
823 break;
824 case SQSORT_INT_DATE_ASC:
825 case SQSORT_INT_DATE_DESC:
826 $sSortField = ($bServerSort) ? 'ARRIVAL' : 'INTERNALDATE';
827 break;
828 case SQSORT_THREAD:
829 break;
830 default: $sSortField = 'UID';
831 break;
832
6a622b59 833 }
91c27aee 834 return $sSortField;
bdfb67f8 835}
836
4955562f 837/**
838 * This function is a utility function for setting which headers should be
839 * fetched. It takes into account the highlight list which requires extra
840 * headers to be fetch in order to make those rules work. It's called before
841 * the headers are fetched which happens in showMessagesForMailbox and when
842 * the next and prev links in read_body.php are used.
843 *
844 * @param array $aMailbox associative array with mailbox related vars
845 * @param array $aProps
846 * @return void
847 * @since 1.5.1
848 */
849
c3731db5 850function calcFetchColumns(&$aMailbox, &$aProps) {
851
852 $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false;
853 $aColumnsDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false;
854
855 $aFetchColumns = $aColumnsDesc;
856 if (isset($aFetchColumns[SQM_COL_CHECK])) {
857 unset($aFetchColumns[SQM_COL_CHECK]);
858 }
859
860 /*
861 * Before we fetch the message headers, check if we need to fetch extra columns
862 * to make the message highlighting work
863 */
864 if (is_array($highlight_list) && count($highlight_list)) {
865 $aHighlightColumns = array();
866 foreach ($highlight_list as $highlight_list_part) {
867 if (trim($highlight_list_part['value'])) {
868 $match_type = strtoupper($highlight_list_part['match_type']);
869 switch ($match_type) {
870 case 'TO_CC':
871 $aHighlightColumns[SQM_COL_TO] = true;
872 $aHighlightColumns[SQM_COL_CC] = true;
873 break;
874 case 'TO': $aHighlightColumns[SQM_COL_TO] = true; break;
875 case 'CC': $aHighlightColumns[SQM_COL_CC] = true; break;
876 case 'FROM': $aHighlightColumns[SQM_COL_FROM] = true; break;
877 case 'SUBJECT':$aHighlightColumns[SQM_COL_SUBJ] = true; break;
878 }
879 }
880 }
881 $aExtraColumns = array();
882 foreach ($aHighlightColumns as $k => $v) {
883 if (!isset($aFetchColumns[$k])) {
884 $aExtraColumns[] = $k;
885 $aFetchColumns[$k] = true;
886 }
887 }
888 if (count($aExtraColumns)) {
889 $aProps['extra_columns'] = $aExtraColumns;
890 }
891 }
892 $aMailbox['FETCHHEADERS'] = array_keys($aFetchColumns);
c3731db5 893}
6a622b59 894
6a622b59 895
91c27aee 896/**
4b4abf93 897 * This function loops through a group of messages in the mailbox
898 * and shows them to the user.
899 *
900 * @param resource $imapConnection
901 * @param array $aMailbox associative array with mailbox related vars
902 * @param array $aProps
903 * @param int $iError error code, 0 is no error
904 */
91c27aee 905function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) {
906 global $PHP_SELF;
24bb7e49 907 global $boxes, $show_copy_buttons;
91c27aee 908
909 $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false;
910 $fancy_index_highlite = (isset($aProps['config']['fancy_index_highlite'])) ? $aProps['config']['fancy_index_highlite'] : true;
911 $aColumnsDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false;
912 $iAccount = (isset($aProps['account'])) ? (int) $aProps['account'] : 0;
913 $sMailbox = (isset($aProps['mailbox'])) ? $aProps['mailbox'] : false;
914 $sTargetModule = (isset($aProps['module'])) ? $aProps['module'] : 'read_body';
915 $show_flag_buttons = (isset($aProps['config']['show_flag_buttons'])) ? $aProps['config']['show_flag_buttons'] : true;
24bb7e49 916
917 /* allows to control copy button in function call. If array key is not set, code follows user preferences */
918 if (isset($aProps['config']['show_copy_buttons']))
919 $show_copy_buttons = $aProps['config']['show_copy_buttons'];
920
91c27aee 921 $lastTargetMailbox = (isset($aProps['config']['lastTargetMailbox'])) ? $aProps['config']['lastTargetMailbox'] : '';
922 $aOrder = array_keys($aProps['columns']);
923 $trash_folder = (isset($aProps['config']['trash_folder']) && $aProps['config']['trash_folder'])
924 ? $aProps['config']['trash_folder'] : false;
925 $sent_folder = (isset($aProps['config']['sent_folder']) && $aProps['config']['sent_folder'])
926 ? $aProps['config']['sent_folder'] : false;
927 $draft_folder = (isset($aProps['config']['draft_folder']) && $aProps['config']['draft_folder'])
928 ? $aProps['config']['draft_folder'] : false;
929 $page_selector = (isset($aProps['config']['page_selector'])) ? $aProps['config']['page_selector'] : false;
930 $page_selector_max = (isset($aProps['config']['page_selector_max'])) ? $aProps['config']['page_selector_max'] : 10;
931 $color = $aProps['config']['color'];
6a622b59 932
6a622b59 933
91c27aee 934 /*
935 * Form ID
936 */
937 static $iFormId;
324ac3c5 938
91c27aee 939 if (!isset($iFormId)) {
940 $iFormId=1;
941 } else {
942 ++$iFormId;
943 }
d0b119a5 944 // store the columns to fetch so we can pick them up in read_body
91c27aee 945 // where we validate the cache.
c3731db5 946 calcFetchColumns($aMailbox ,$aProps);
e35045b7 947
d0b119a5 948 $iError = fetchMessageHeaders($imapConnection, $aMailbox);
91c27aee 949 if ($iError) {
950 return array();
951 } else {
952 $aMessages = prepareMessageList($aMailbox, $aProps);
953 }
6a622b59 954
91c27aee 955 $iSetIndx = $aMailbox['SETINDEX'];
956 $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
957 $iEnd = ($aMailbox['PAGEOFFSET'] + ($iLimit - 1) < $aMailbox['EXISTS']) ?
958 $aMailbox['PAGEOFFSET'] + $iLimit - 1 : $aMailbox['EXISTS'];
6a622b59 959
91c27aee 960 $iNumberOfMessages = $aMailbox['TOTAL'][$iSetIndx];
aa2e9274 961 $iEnd = min ( $iEnd, $iNumberOfMessages );
6a622b59 962
91c27aee 963 $php_self = $PHP_SELF;
6a622b59 964
91c27aee 965 $urlMailbox = urlencode($aMailbox['NAME']);
6a622b59 966
91c27aee 967 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
968 $source_url = $regs[1];
969 } else {
970 $source_url = $php_self;
971 }
6a622b59 972
91c27aee 973 $baseurl = $source_url.'?mailbox=' . urlencode($aMailbox['NAME']) .'&amp;account='.$aMailbox['ACCOUNT'];
974 $where = urlencode($aMailbox['SEARCH'][$iSetIndx][0]);
975 $what = urlencode($aMailbox['SEARCH'][$iSetIndx][1]);
976 $baseurl .= '&amp;where=' . $where . '&amp;what=' . $what;
977
978 /* build thread sorting links */
979 $newsort = $aMailbox['SORT'];
980 if (sqimap_capability($imapConnection,'THREAD')) {
981 if ($aMailbox['SORT'] & SQSORT_THREAD) {
982 $newsort -= SQSORT_THREAD;
983 $thread_name = _("Unthread View");
984 } else {
985 $thread_name = _("Thread View");
986 $newsort = $aMailbox['SORT'] + SQSORT_THREAD;
6a622b59 987 }
91c27aee 988 $thread_link_str = '<small>[<a href="' . $baseurl . '&amp;srt='
989 . $newsort . '&amp;startMessage=1">' . $thread_name
990 . '</a>]</small>';
324ac3c5 991 } else {
91c27aee 992 $thread_link_str ='';
6a622b59 993 }
91c27aee 994 $sort = $aMailbox['SORT'];
6a622b59 995
91c27aee 996 /* FIX ME ADD CHECKBOX CONTROL. No checkbox => no buttons */
997
998
999
1000 /* future admin control over displayable buttons */
91c27aee 1001 $aAdminControl = array(
1002 'markUnflagged' => 1,
1003 'markFlagged' => 1,
1004 'markRead' => 1,
1005 'markUnread' => 1,
a5d40e74 1006 'forward' => 1,
91c27aee 1007 'delete' => 1,
1008 'undeleteButton'=> 1,
1009 'bypass_trash' => 1,
1010 'expungeButton' => 1,
24bb7e49 1011 'moveButton' => 1,
1012 'copyButton' => 1
91c27aee 1013 );
24bb7e49 1014
91c27aee 1015 /* user prefs control */
1016 $aUserControl = array (
a5d40e74 1017
91c27aee 1018 'markUnflagged' => $show_flag_buttons,
1019 'markFlagged' => $show_flag_buttons,
1020 'markRead' => 1,
1021 'markUnread' => 1,
a5d40e74 1022 'forward' => 1,
91c27aee 1023 'delete' => 1,
1024 'undeleteButton'=> 1,
1025 'bypass_trash' => 1,
1026 'expungeButton' => 1,
24bb7e49 1027 'moveButton' => 1,
1028 'copyButton' => $show_copy_buttons
a5d40e74 1029
91c27aee 1030 );
1031
1032 $showDelete = ($aMailbox['RIGHTS'] != 'READ-ONLY' &&
1033 in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) ? true : false;
a5d40e74 1034 $showByPassTrash = (($aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' &&
91c27aee 1035 in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) &&
a5d40e74 1036 $trash_folder) ? true : false; //
1037
91c27aee 1038 $showUndelete = (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' &&
1039 in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true) && !$trash_folder) ? true : false;
1040 $showMove = ($aMailbox['RIGHTS'] != 'READ-ONLY') ? true : false;
1041 $showExpunge = (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' &&
1042 in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) ? true : false;
24bb7e49 1043
1044 /* Button options that depend on IMAP server and selected folder */
91c27aee 1045 $aImapControl = array (
1046 'markUnflagged' => in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true),
1047 'markFlagged' => in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true),
1048 'markRead' => in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true),
1049 'markUnread' => in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true),
a5d40e74 1050 'forward' => 1,
91c27aee 1051 'delete' => $showDelete,
1052 'undeleteButton'=> $showUndelete,
1053 'bypass_trash' => $showByPassTrash,
1054 'expungeButton' => $showExpunge,
24bb7e49 1055 'moveButton' => $showMove,
1056 'copyButton' => 1
91c27aee 1057 );
24bb7e49 1058 /* Button strings */
91c27aee 1059 $aButtonStrings = array(
1060 'markUnflagged' => _("Unflag"),
1061 'markFlagged' => _("Flag"),
1062 'markRead' => _("Read"),
1063 'markUnread' => _("Unread"),
a5d40e74 1064 'forward' => _("Forward"),
91c27aee 1065 'delete' => _("Delete"),
1066 'undeleteButton' => _("Undelete"),
1067 'bypass_trash' => _("Bypass Trash"),
1068 'expungeButton' => _("Expunge"),
24bb7e49 1069 'moveButton' => _("Move"),
1070 'copyButton' => _("Copy")
91c27aee 1071 );
a5d40e74 1072
1073
6a622b59 1074 /**
91c27aee 1075 * Register buttons in order to an array
1076 * The key is the "name", the first element of the value array is the "value", second argument is the type.
62f7daa5 1077 */
91c27aee 1078 $aFormElements = array();
1079 foreach($aAdminControl as $k => $v) {
1080 if ($v & $aUserControl[$k] & $aImapControl[$k]) {
1081 switch ($k) {
1082 case 'markUnflagged':
1083 case 'markFlagged':
1084 case 'markRead':
1085 case 'markUnread':
1086 case 'delete':
1087 case 'undeleteButton':
1088 case 'expungeButton':
1089 case 'forward':
1090 $aFormElements[$k] = array($aButtonStrings[$k],'submit');
1091 break;
1092 case 'bypass_trash':
1093 $aFormElements[$k] = array($aButtonStrings[$k],'checkbox');
1094 break;
1095 case 'moveButton':
24bb7e49 1096 case 'copyButton':
91c27aee 1097 $aFormElements['targetMailbox'] =
1098 array(sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes),'select');
1099 $aFormElements['mailbox'] = array($aMailbox['NAME'],'hidden');
1100 $aFormElements['startMessage'] = array($aMailbox['PAGEOFFSET'],'hidden');
1101 $aFormElements[$k] = array($aButtonStrings[$k],'submit');
1102 break;
0bb37159 1103 }
1104 }
91c27aee 1105 $aFormElements['account'] = array($iAccount,'hidden');
1106 }
0bb37159 1107
91c27aee 1108 /*
4b4abf93 1109 * This is the beginning of the message list table.
1110 * It wraps around all messages
1111 */
91c27aee 1112 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
1113 $form_name = "FormMsgs" . $safe_name;
0bb37159 1114
91c27aee 1115 //if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
1116 $align = array('left' => 'left', 'right' => 'right');
1117 //}
1118 //sm_print_r($align);
1119
1120 /* finally set the template vars */
1121
1122 // FIX ME, before we support multiple templates we must review the names of the vars
1123
1124
91c27aee 1125 $aTemplate['color'] = $color;
1126 $aTemplate['form_name'] = "FormMsgs" . $safe_name;
1127 $aTemplate['form_id'] = 'mbx_'.$iFormId;
1128 $aTemplate['page_selector'] = $page_selector;
1129 $aTemplate['page_selector_max'] = $page_selector_max;
1130 $aTemplate['messagesPerPage'] = $aMailbox['LIMIT'];
1131 $aTemplate['showall'] = $aMailbox['SHOWALL'][$iSetIndx];
1132 $aTemplate['end_msg'] = $iEnd;
1133 $aTemplate['align'] = $align;
1134 $aTemplate['iNumberOfMessages'] = $iNumberOfMessages;
1135 $aTemplate['aOrder'] = $aOrder;
1136 $aTemplate['aFormElements'] = $aFormElements;
1137 $aTemplate['sort'] = $sort;
1138 $aTemplate['pageOffset'] = $aMailbox['PAGEOFFSET'];
1139 $aTemplate['baseurl'] = $baseurl;
1140 $aTemplate['aMessages'] =& $aMessages;
1141 $aTemplate['trash_folder'] = $trash_folder;
1142 $aTemplate['sent_folder'] = $sent_folder;
1143 $aTemplate['draft_folder'] = $draft_folder;
1144 $aTemplate['thread_link_str'] = $thread_link_str;
1145 $aTemplate['php_self'] = str_replace('&','&amp;',$php_self);
1146 $aTemplate['mailbox'] = $sMailbox;
1147 $aTemplate['javascript_on'] = (isset($aProps['config']['javascript_on'])) ? $aProps['config']['javascript_on'] : false;
1148 $aTemplate['enablesort'] = (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false;
1149 $aTemplate['icon_theme'] = (isset($aProps['config']['icon_theme'])) ? $aProps['config']['icon_theme'] : false;
1150 $aTemplate['use_icons'] = (isset($aProps['config']['use_icons'])) ? $aProps['config']['use_icons'] : false;
1151 $aTemplate['alt_index_colors'] = (isset($aProps['config']['alt_index_colors'])) ? $aProps['config']['alt_index_colors'] : false;
1152 $aTemplate['fancy_index_highlite'] = $fancy_index_highlite;
1153
49719da8 1154
91c27aee 1155 return $aTemplate;
bdfb67f8 1156}
1157
91c27aee 1158
c7df3f1b 1159/**
4b4abf93 1160 * Truncates a string and take care of html encoded characters
1161 *
1162 * @param string $s string to truncate
1163 * @param int $iTrimAt Trim at nn characters
1164 * @return string Trimmed string
1165 */
d7112bcb 1166function truncateWithEntities($s, $iTrimAt) {
eaa4f45f 1167 global $languages, $squirrelmail_language;
6a622b59 1168
d7112bcb 1169 $ent_strlen = strlen($s);
1170 if (($iTrimAt <= 0) || ($ent_strlen <= $iTrimAt))
1171 return $s;
6a622b59 1172
1173 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
b3e4bf71 1174 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth')) {
d7112bcb 1175 return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth', $s, $iTrimAt);
1176 } else {
1177 /*
4b4abf93 1178 * see if this is entities-encoded string
1179 * If so, Iterate through the whole string, find out
1180 * the real number of characters, and if more
1181 * than $iTrimAt, substr with an updated trim value.
1182 */
d7112bcb 1183 $trim_val = $iTrimAt;
1184 $ent_offset = 0;
1185 $ent_loc = 0;
1186 while ( $ent_loc < $trim_val && (($ent_loc = strpos($s, '&', $ent_offset)) !== false) &&
1187 (($ent_loc_end = strpos($s, ';', $ent_loc+3)) !== false) ) {
1188 $trim_val += ($ent_loc_end-$ent_loc);
1189 $ent_offset = $ent_loc_end+1;
1190 }
ecaf6352 1191
d7112bcb 1192 if (($trim_val > $iTrimAt) && ($ent_strlen > $trim_val) && (strpos($s,';',$trim_val) < ($trim_val + 6))) {
1193 $i = strpos($s,';',$trim_val);
1194 if ($i !== false) {
1195 $trim_val = strpos($s,';',$trim_val)+1;
1196 }
1197 }
1198 // only print '...' when we're actually dropping part of the subject
1199 if ($ent_strlen <= $trim_val)
1200 return $s;
1201 }
1202 return substr_replace($s, '...', $trim_val);
e9e5f0fa 1203}
1204
d7112bcb 1205
c7df3f1b 1206/**
4b4abf93 1207 * This should go in imap_mailbox.php
1208 * @param string $mailbox
1209 */
a3439b27 1210function handleAsSent($mailbox) {
6a8e7cae 1211 global $handleAsSent_result;
4669e892 1212
6a622b59 1213 /* First check if this is the sent or draft folder. */
6a8e7cae 1214 $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
a3439b27 1215
6a622b59 1216 /* Then check the result of the handleAsSent hook. */
1217 do_hook('check_handleAsSent_result', $mailbox);
a3439b27 1218
6a622b59 1219 /* And return the result. */
6a8e7cae 1220 return $handleAsSent_result;
6a622b59 1221}
e842b215 1222
324ac3c5 1223/**
1224 * Process messages list form and handle the cache gracefully. If $sButton and
1225 * $aUid are provided as argument then you can fake a message list submit and
1226 * use it i.e. in read_body.php for del move next and update the cache
1227 *
1228 * @param resource $imapConnection imap connection
1229 * @param array $aMailbox (reference) cached mailbox
1230 * @param string $sButton fake a submit button
1231 * @param array $aUid fake the $msg array
1232 * @return string $sError error string in case of an error
4955562f 1233 * @since 1.5.1
324ac3c5 1234 * @author Marc Groot Koerkamp
1235 */
1236function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) {
324ac3c5 1237 /* incoming formdata */
1238 $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST)) ? 'move' : $sButton;
24bb7e49 1239 $sButton = (sqgetGlobalVar('copyButton', $sTmp, SQ_POST)) ? 'copy' : $sButton;
324ac3c5 1240 $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST)) ? 'expunge' : $sButton;
91c27aee 1241 $sButton = (sqgetGlobalVar('forward', $sTmp, SQ_POST)) ? 'forward' : $sButton;
324ac3c5 1242 $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton;
91c27aee 1243 $sButton = (sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST)) ? 'unsetDeleted' : $sButton;
324ac3c5 1244 $sButton = (sqgetGlobalVar('markRead', $sTmp, SQ_POST)) ? 'setSeen' : $sButton;
1245 $sButton = (sqgetGlobalVar('markUnread', $sTmp, SQ_POST)) ? 'unsetSeen' : $sButton;
1246 $sButton = (sqgetGlobalVar('markFlagged', $sTmp, SQ_POST)) ? 'setFlagged' : $sButton;
1247 $sButton = (sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST)) ? 'unsetFlagged' : $sButton;
1248 sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST);
1249 sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST);
1250 sqgetGlobalVar('msg', $msg, SQ_POST);
91c27aee 1251 if (sqgetGlobalVar('account', $iAccount, SQ_POST) === false) {
1252 $iAccount = 0;
1253 }
324ac3c5 1254 $sError = '';
1255 $mailbox = $aMailbox['NAME'];
1256
1257 /* retrieve the check boxes */
1258 $aUid = (isset($msg) && is_array($msg)) ? array_values($msg) : $aUid;
324ac3c5 1259 if (count($aUid) && $sButton != 'expunge') {
1260 $aUpdatedMsgs = false;
1261 $bExpunge = false;
1262 switch ($sButton) {
1263 case 'setDeleted':
1264 // check if id exists in case we come from read_body
1265 if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) &&
1266 !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) {
1267 break;
1268 }
7c788b1c 1269 $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash);
1270 $bExpunge = true;
91c27aee 1271 //}
324ac3c5 1272 break;
1273 case 'unsetDeleted':
1274 case 'setSeen':
1275 case 'unsetSeen':
1276 case 'setFlagged':
1277 case 'unsetFlagged':
1278 // get flag
1279 $sFlag = (substr($sButton,0,3) == 'set') ? '\\'.substr($sButton,3) : '\\'.substr($sButton,5);
1280 $bSet = (substr($sButton,0,3) == 'set') ? true : false;
1281 $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true);
1282 break;
1283 case 'move':
821651ff 1284 $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox,true,$mailbox);
324ac3c5 1285 sqsession_register($targetMailbox,'lastTargetMailbox');
1286 $bExpunge = true;
1287 break;
24bb7e49 1288 case 'copy':
b400dda3 1289 // sqimap_msgs_list_copy returns true or false.
1290 // If error happens - fourth argument handles it inside function.
1291 sqimap_msgs_list_copy($imapConnection,$aUid,$targetMailbox,true);
24bb7e49 1292 sqsession_register($targetMailbox,'lastTargetMailbox');
1293 break;
91c27aee 1294 case 'forward':
324ac3c5 1295 $aMsgHeaders = array();
1296 foreach ($aUid as $iUid) {
1297 $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid];
1298 }
1299 if (count($aMsgHeaders)) {
1300 $composesession = attachSelectedMessages($imapConnection,$aMsgHeaders);
1301 // dirty hack, add info to $aMailbox
1302 $aMailbox['FORWARD_SESSION'] = $composesession;
1303 }
1304 break;
7c788b1c 1305 default:
91c27aee 1306 // Hook for plugin buttons
1307 do_hook_function('mailbox_display_button_action', $aUid);
1308 break;
324ac3c5 1309 }
1310 /**
1311 * Updates messages is an array containing the result of the untagged
1312 * fetch responses send by the imap server due to a flag change. That
1313 * response is parsed in a array with msg arrays by the parseFetch function
1314 */
1315 if ($aUpdatedMsgs) {
1316 // Update the message headers cache
1317 $aDeleted = array();
1318 foreach ($aUpdatedMsgs as $iUid => $aMsg) {
1319 if (isset($aMsg['FLAGS'])) {
fd28fa79 1320 /**
ddd209f2 1321 * Only update the cached headers if the header is
fd28fa79 1322 * cached.
1323 */
1324 if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
1325 $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS'];
1326 }
324ac3c5 1327 /**
1328 * Count the messages with the \Delete flag set so we can determine
1329 * if the number of expunged messages equals the number of flagged
1330 * messages for deletion.
1331 */
1332 if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) {
1333 $aDeleted[] = $iUid;
1334 }
1335 }
1336 }
1337 if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] &&
1338 $iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true))
1339 {
1340 if (count($aDeleted) != $iExpungedMessages) {
1341 // there are more messages deleted permanently then we expected
1342 // invalidate the cache
1343 $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false;
1344 $aMailbox['MSG_HEADERS'] = false;
1345 } else {
1346 // remove expunged messages from cache
1347 $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']];
1348 if (is_array($aUidSet)) {
1349 // create a UID => array index temp array
1350 $aUidSetDummy = array_flip($aUidSet);
1351 foreach ($aDeleted as $iUid) {
1352 // get the id as well in case of SQM_SORT_NONE
1353 if ($aMailbox['SORT'] == SQSORT_NONE) {
1354 $aMailbox['ID'] = false;
1355 //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID'];
1356 //unset($aMailbox['ID'][$iId]);
1357 }
1358 // unset the UID and message header
1359 unset($aUidSetDummy[$iUid]);
1360 unset($aMailbox['MSG_HEADERS'][$iUid]);
1361 }
1362 $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy);
324ac3c5 1363 }
1364 }
ddd209f2 1365 // update EXISTS info
1366 if ($iExpungedMessages) {
1367 $aMailbox['EXISTS'] -= (int) $iExpungedMessages;
91c27aee 1368 $aMailbox['TOTAL'][$aMailbox['SETINDEX']] -= (int) $iExpungedMessages;
ddd209f2 1369 }
4c284a74 1370 if (($aMailbox['PAGEOFFSET']-1) >= $aMailbox['EXISTS']) {
324ac3c5 1371 $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ?
1372 $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1;
91c27aee 1373 $aMailbox['OFFSET'] = $aMailbox['PAGEOFFSET'] - 1 ;
324ac3c5 1374 }
1375 }
1376 }
1377 } else {
1378 if ($sButton == 'expunge') {
1379 /**
1380 * on expunge we do not know which messages will be deleted
1381 * so it's useless to try to sync the cache
4b4abf93 1382 *
324ac3c5 1383 * Close the mailbox so we do not need to parse the untagged expunge
1384 * responses which do not contain uid info.
1385 * NB: Closing a mailbox is faster then expunge because the imap
1386 * server does not need to generate the untagged expunge responses
1387 */
1388 sqimap_run_command($imapConnection,'CLOSE',false,$result,$message);
91c27aee 1389 $aMailbox = sqm_api_mailbox_select($imapConnection,$iAccount, $aMailbox['NAME'],array(),array());
324ac3c5 1390 } else {
1391 if ($sButton) {
1392 $sError = _("No messages were selected.");
1393 }
1394 }
1395 }
1396 return $sError;
1397}
1398
4955562f 1399/**
1400 * Attach messages to a compose session
1401 *
1402 * @param resource $imapConnection imap connection
1403 * @param array $aMsgHeaders
1404 * @return int $composesession unique compose_session_id where the attached messages belong to
1405 * @author Marc Groot Koerkamp
1406 */
324ac3c5 1407function attachSelectedMessages($imapConnection,$aMsgHeaders) {
1408 global $username, $attachment_dir,
91c27aee 1409 $data_dir;
1410
324ac3c5 1411
91c27aee 1412 sqgetGlobalVar('composesession', $composesession, SQ_SESSION);
1413 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
1414 if (!isset($compose_messages)|| is_null($compose_messages)) {
324ac3c5 1415 $compose_messages = array();
1416 sqsession_register($compose_messages,'compose_messages');
1417 }
1418
1419 if (!$composesession) {
1420 $composesession = 1;
1421 sqsession_register($composesession,'composesession');
1422 } else {
1423 $composesession++;
1424 sqsession_register($composesession,'composesession');
1425 }
1426
1427 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1428
1429 $composeMessage = new Message();
1430 $rfc822_header = new Rfc822Header();
1431 $composeMessage->rfc822_header = $rfc822_header;
1432 $composeMessage->reply_rfc822_header = '';
1433
1434 foreach($aMsgHeaders as $iUid => $aMsgHeader) {
1435 /**
1436 * Retrieve the full message
1437 */
1438 $body_a = sqimap_run_command($imapConnection, "FETCH $iUid RFC822", true, $response, $readmessage, TRUE);
324ac3c5 1439 if ($response == 'OK') {
91c27aee 1440
1441 $subject = (isset($aMsgHeader['subject'])) ? $aMsgHeader['subject'] : $iUid;
324ac3c5 1442
1443 array_shift($body_a);
1444 array_pop($body_a);
1445 $body = implode('', $body_a);
1446 $body .= "\r\n";
1447
1448 $localfilename = GenerateRandomString(32, 'FILE', 7);
1449 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1450
1451 $fp = fopen( $full_localfilename, 'wb');
1452 fwrite ($fp, $body);
1453 fclose($fp);
1454 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
1455 $full_localfilename);
1456 }
1457 }
1458
1459 $compose_messages[$composesession] = $composeMessage;
1460 sqsession_register($compose_messages,'compose_messages');
1461 return $composesession;
1462}
1463
02e830bd 1464?>