6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
13 * @package squirrelmail
16 /** The standard includes.. */
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');
21 require_once(SM_PATH
. 'functions/imap_messages.php');
22 require_once(SM_PATH
. 'functions/imap_asearch.php');
23 require_once(SM_PATH
. 'functions/mime.php');
24 require_once(SM_PATH
. 'functions/forms.php');
27 * default value for page_selector_max
29 define('PG_SEL_MAX', 10);
32 * The number of pages to cache msg headers
34 define('SQM_MAX_PAGES_IN_CACHE',5);
37 * Sort constants used for sorting of messages
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);
55 define('SQSORT_THREAD',32);
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);
66 * @param mixed $start UNDOCUMENTED
68 function elapsed($start) {
71 list($start2, $start1) = explode(" ", $start);
72 list($end2, $end1) = explode(" ", $end);
73 $diff1 = $end1 - $start1;
74 $diff2 = $end2 - $start2;
79 return $diff2 +
$diff1;
83 * Displays message header row in messages list
85 * @param array $aMsg contains all message related parameters
89 function printMessageInfo($aMsg) {
90 // FIX ME, remove these globals as well by adding an array as argument for the user settings
91 // specificly meant for header display
94 $default_use_priority,
95 $message_highlight_list,
97 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
99 $show_recipient_instead, /* show recipient name instead of default identity */
100 $use_icons, /* indicates to use icons or text markers */
101 $icon_theme; /* icons theming */
103 $color_string = $color[4];
106 $mailbox = $aMsg['MAILBOX'];
107 $msg = $aMsg['HEADER'];
109 $start_msg = $aMsg['PAGEOFFSET'];
110 $last = $aMsg['LAST'];
111 if (isset($aMsg['SEARCH']) && count($aMsg['SEARCH']) >1 ) {
112 $where = $aMsg['SEARCH'][0];
113 $what = $aMsg['SEARCH'][1];
118 $iIndent = $aMsg['INDENT'];
120 $sSubject = (isset($msg['SUBJECT']) && $msg['SUBJECT'] != '') ?
$msg['SUBJECT'] : _("(no subject)");
121 $sFrom = (isset($msg['FROM'])) ?
$msg['FROM'] : _("Unknown sender");
122 $sTo = (isset($msg['TO'])) ?
$msg['TO'] : _("Unknown recipient");
123 $sCc = (isset($msg['CC'])) ?
$msg['CC'] : '';
124 $aFlags = (isset($msg['FLAGS'])) ?
$msg['FLAGS'] : array();
125 $iPrio = (isset($msg['PRIORITY'])) ?
$msg['PRIORITY'] : 3;
126 $iSize = (isset($msg['SIZE'])) ?
$msg['SIZE'] : 0;
127 $sType0 = (isset($msg['TYPE0'])) ?
$msg['TYPE0'] : 'text';
128 $sType1 = (isset($msg['TYPE1'])) ?
$msg['TYPE1'] : 'plain';
129 if (isset($msg['INTERNALDATE'])) {
130 $sDate = getDateString(getTimeStamp(explode(' ',$msg['INTERNALDATE'])));
132 $sDate = (isset($msg['DATE'])) ?
getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : '';
134 $iId = (isset($msg['UID'])) ?
$msg['UID'] : false;
140 if ($GLOBALS['alt_index_colors']) {
142 if (!isset($color[12])) {
143 $color[12] = '#EAEAEA';
145 $color_string = $color[12];
149 $urlMailbox = urlencode($mailbox);
151 // FIXME, foldertype should be set in right_main.php
152 // in other words, handle as sent is obsoleted from now.
153 // We replace that by providing an array to aMailbox with the to shown headers
154 // that way we are free to show the user different layouts for different folders
155 $bSentFolder = handleAsSent($mailbox);
156 if ((!$bSentFolder) && ($show_recipient_instead)) {
157 // If the From address is the same as $email_address, then handle as Sent
158 $from_array = parseAddress($sFrom, 1);
159 if (!isset($email_address)) {
160 global $datadir, $username;
161 $email_address = getPref($datadir, $username, 'email_address');
163 $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
165 $bHandleAsSent = $bSentFolder;
167 // If this is a Sent message, display To address instead of From
168 if ($bHandleAsSent) {
171 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
172 $sFrom = parseAddress($sFrom/*,1*/);
175 * This is done in case you're looking into Sent folders,
176 * because you can have multiple receivers.
178 $senderNames = $sFrom;
181 if (sizeof($senderNames)){
182 foreach ($senderNames as $senderNames_part) {
183 if ($senderName != '') {
185 $senderAddress .= ', ';
187 $sender_address_part = htmlspecialchars($senderNames_part[0]);
188 $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1]));
189 if ($sender_name_part) {
190 $senderName .= $sender_name_part;
191 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
193 $senderName .= $sender_address_part;
194 $senderAddress .= $sender_address_part;
198 // If Sent, prefix with To: but only if not Sent folder
199 if ($bHandleAsSent ^
$bSentFolder) {
200 $senderName = _("To:") . ' ' . $senderName;
201 $senderAddress = _("To:") . ' ' . $senderAddress;
204 // this is a column property which can apply to multiple columns. Do not use vars for one column
205 // only. instead we should use something like this:
206 // 1ed column $aMailbox['columns']['SUBJECT'] value: aray with properties ...
207 // 2ed column $aMailbox['columns']['FROM'] value: aray with properties ...
208 // NB in case of the sentfolder this could be the TO field
209 // properties array example:
210 // 'truncate' => length (0 is no truncate)
211 // 'prefix => if (x in b then do that )
212 if ($truncate_sender > 0) {
213 $senderName = truncateWithEntities($senderName, $truncate_sender);
216 $flag = $flag_end = $bold = $bold_end = $fontstr = $fontstr_end = $italic = $italic_end = '';
220 foreach ($aFlags as $sFlag => $value) {
224 $flag = "<font color=\"$color[2]\">";
225 $flag_end = '</font>';
236 $fontstr = "<font color=\"$color[9]\">";
237 $fontstr_end = '</font>';
242 if ($bHandleAsSent) {
244 $italic_end = '</i>';
247 if ($where && $what) {
248 $searchstr = '&where='.$where.'&what='.$what;
253 * Message highlight code
255 $matches = array('TO' => 'sTo', 'CC' => 'sCc', 'FROM' => 'sFrom', 'SUBJECT' => 'sSubject');
256 if (is_array($message_highlight_list) && count($message_highlight_list)) {
257 $sTo = parseAddress($sTo);
258 $sCc = parseAddress($sCc);
259 foreach ($message_highlight_list as $message_highlight_list_part) {
260 if (trim($message_highlight_list_part['value']) != '') {
261 $high_val = strtolower($message_highlight_list_part['value']);
262 $match_type = strtoupper($message_highlight_list_part['match_type']);
263 if($match_type == 'TO_CC') {
264 $match = array('TO', 'CC');
266 $match = array($match_type);
268 foreach($match as $match_type) {
269 switch($match_type) {
273 foreach ($
$matches[$match_type] as $address) {
274 $address[0] = decodeHeader($address[0], true, false);
275 $address[1] = decodeHeader($address[1], true, false);
276 if (strstr('^^' . strtolower($address[0]), $high_val) ||
277 strstr('^^' . strtolower($address[1]), $high_val)) {
278 $hlt_color = $message_highlight_list_part['color'];
284 $headertest = strtolower(decodeHeader($
$matches[$match_type], true, false));
285 if (strstr('^^' . $headertest, $high_val)) {
286 $hlt_color = $message_highlight_list_part['color'];
294 } /* end Message highlight code */
296 if (!isset($hlt_color)) {
297 $hlt_color = $color_string;
300 $sSubject = str_replace(' ', ' ', decodeHeader($sSubject));
301 $subject = processSubject($sSubject, $iIndent);
303 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
305 if (sizeof($index_order)) {
306 foreach ($index_order as $index_order_part) {
307 switch ($index_order_part) {
308 case 1: /* checkbox */
310 addCheckBox("msg[$t]", $checkall, $iId),
315 if ($senderAddress != $senderName) {
316 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS
)));
317 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
322 $italic . $bold . $flag . $fontstr . $senderName .
323 $fontstr_end . $flag_end . $bold_end . $italic_end,
325 $hlt_color, $title );
329 $sDate = _("Unknown date");
332 $bold . $flag . $fontstr . $sDate .
333 $fontstr_end . $flag_end . $bold_end,
338 case 4: /* subject */
341 $td_str .= str_repeat(" ",$iIndent);
343 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
344 . '&passed_id='. $iId
345 . '&startMessage='.$start_msg.$searchstr.'"';
346 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
347 if ($subject != $sSubject) {
348 $title = get_html_translation_table(HTML_SPECIALCHARS
);
349 $title = array_flip($title);
350 $title = strtr($sSubject, $title);
351 $title = str_replace('"', "''", $title);
352 $td_str .= " title=\"$title\"";
354 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
355 echo html_tag( 'td', $td_str, 'left', $hlt_color );
359 // icon message markers
361 if ($use_icons && $icon_theme != 'none') {
362 $td_str = "<b><small>";
363 if (isset($aFlags['\\flagged']) && $aFlags['\\flagged'] == true) {
364 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/flagged.png" border="0" height="10" width="10" /> ';
366 if ($default_use_priority) {
367 if ( ($iPrio == 1) ||
($iPrio == 2) ) {
368 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_high.png" border="0" height="10" width="5" /> ';
370 else if ($iPrio == 5) {
371 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/prio_low.png" border="0" height="10" width="5" /> ';
374 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="5" /> ';
377 if ($sType1 == 'mixed') {
378 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/attach.png" border="0" height="10" width="6" />';
380 $td_str .= '<img src="' . SM_PATH
. 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="6" />';
384 if (!isset($aFlags['\\seen']) ||
($aFlags['\\seen']) == false) {
385 $msg_alt = '(' . _("New") . ')';
386 $msg_title = '(' . _("New") . ')';
387 $msg_icon .= SM_PATH
. 'images/themes/' . $icon_theme . '/msg_new';
389 $msg_alt = '(' . _("Read") . ')';
390 $msg_title = '(' . _("Read") . ')';
391 $msg_icon .= SM_PATH
. 'images/themes/' . $icon_theme . '/msg_read';
393 if (isset($aFlags['\\deleted']) && ($aFlags['\\deleted']) == true) {
394 $msg_icon .= '_deleted';
396 if (isset($aFlags['\\answered']) && ($aFlags['\\answered']) == true) {
397 $msg_alt = '(' . _("Answered") . ')';
398 $msg_title = '(' . _("Answered") . ')';
399 $msg_icon .= '_reply';
401 $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />';
402 $td_str .= '</small></b>';
410 // plain text message markers
414 $td_str = "<b><small>";
415 if (isset($aFlags['\\answered']) && $aFlags['\\answered'] == true) {
419 if ($sType1 == 'mixed') {
423 if ($default_use_priority) {
424 if ( ($iPrio == 1) ||
($iPrio == 2) ) {
425 $td_str .= "<font color=\"$color[1]\">!</font>";
429 $td_str .= "<font color=\"$color[8]\">?</font>";
433 if (isset($aFlags['\\deleted']) && $aFlags['\\deleted'] == true) {
434 $td_str .= "<font color=\"$color[1]\">D</font>";
440 $td_str .= '</small></b>';
450 $bold . $fontstr . show_readable_size($iSize) .
451 $fontstr_end . $bold_end,
459 /* html for separationlines between rows */
463 echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
464 $color[0] . '" height="1"></td></tr>' . "\n";
469 function setUserPref($username, $pref, $value) {
471 setPref($data_dir,$username,$pref,$value);
475 * Selects a mailbox for header retrieval.
476 * Cache control for message headers is embedded.
478 * @param resource $imapConnection imap socket handle
479 * @param string $mailbox mailbox to select and retrieve message headers from
480 * @param array $aConfig array with system config settings and incoming vars
481 * @param array $aProps mailbox specific properties
482 * @return array $aMailbox mailbox array with all relevant information
483 * @author Marc Groot Koerkamp
485 function sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aProps) {
487 * NB: retrieve this from the session before accessing this function
488 * and make sure you write it back at the end of the script after
489 * the aMailbox var is added so that the headers are added to the cache
491 global $mailbox_cache;
493 * In case the properties arrays are empty set the defaults.
495 $aDefaultMbxPref = array ();
496 // MBX_PREF_SORT => 0,
497 // MBX_PREF_LIMIT => 15,
498 // MBX_PREF_AUTO_EXPUNGE => 0,
499 // MBX_PREF_INTERNALDATE => 0
501 /* array_merge doesn't work with integers as keys */
502 // foreach ($aDefaultMbxPref as $key => $value) {
503 // if (!isset($aProps[$key])) {
504 // $aProps[$key] = $value;
507 $aDefaultConfigProps = array(
508 // 'allow_thread_sort' => 0,
509 'allow_server_sort' => sqimap_capability($imapConnection,'SORT'),
510 // 'charset' => 'US-ASCII',
511 'user' => false, /* no pref storage if false */
513 // 'search' => 'ALL',
514 'max_cache_size' => SQM_MAX_MBX_IN_CACHE
517 $aConfig = array_merge($aDefaultConfigProps,$aConfig);
518 $iSetIndx = $aConfig['setindex'];
520 $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
522 if ($mailbox_cache) {
523 if (isset($mailbox_cache[$mailbox])) {
524 $aCachedMailbox = $mailbox_cache[$mailbox];
526 $aCachedMailbox = false;
529 if (count($mailbox_cache) > $aConfig['max_cache_size'] -1) {
531 foreach($mailbox_cache as $cachedmailbox => $aVal) {
532 $aTime[$aVal['TIMESTAMP']] = $cachedmailbox;
534 if (ksort($aTime,SORT_NUMERIC
)) {
535 for ($i=0,$iCnt=count($mailbox_cache);$i<($iCnt-$aConfig['max_cache_size']);++
$i) {
536 $sOldestMbx = array_shift($aTime);
538 * Remove only the UIDSET and MSG_HEADERS from cache because those can
539 * contain large amounts of data.
541 if (isset($mailbox_cache[$sOldestMbx]['UIDSET'])) {
542 $mailbox_cache[$sOldestMbx]['UIDSET']= false;
544 if (isset($mailbox_cache[$sOldestMbx]['MSG_HEADERS'])) {
545 $mailbox_cache[$sOldestMbx]['MSG_HEADERS'] = false;
552 $aCachedMailbox = false;
556 * Deal with imap servers that do not return the required UIDNEXT or
557 * UIDVALIDITY response
558 * from a SELECT call (since rfc 3501 it's required).
560 if (!isset($aMbxResponse['UIDNEXT']) ||
!isset($aMbxResponse['UIDVALIDITY'])) {
561 $aStatus = sqimap_status_messages($imapConnection,$mailbox,
562 array('UIDNEXT','UIDVALIDITY'));
563 $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
564 $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
567 $aMailbox['UIDSET'][$iSetIndx] = false;
568 $aMailbox['ID'] = false;
569 $aMailbox['SETINDEX'] = $iSetIndx;
571 if ($aCachedMailbox) {
573 * Validate integrity of cached data
575 if ($aCachedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
576 $aMbxResponse['EXISTS'] &&
577 $aCachedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
578 $aCachedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT'] &&
579 isset($aCachedMailbox['SEARCH'][$iSetIndx]) &&
580 (!isset($aConfig['search']) ||
/* always set search from the searchpage */
581 $aCachedMailbox['SEARCH'][$iSetIndx] == $aConfig['search'])) {
582 if (isset($aCachedMailbox['MSG_HEADERS'])) {
583 $aMailbox['MSG_HEADERS'] = $aCachedMailbox['MSG_HEADERS'];
585 $aMailbox['ID'] = $aCachedMailbox['ID'];
586 if (isset($aCachedMailbox['UIDSET'][$iSetIndx]) && $aCachedMailbox['UIDSET'][$iSetIndx]) {
587 if (isset($aProps[MBX_PREF_SORT
]) && $aProps[MBX_PREF_SORT
] != $aCachedMailbox['SORT'] ) {
588 $newsort = $aProps[MBX_PREF_SORT
];
589 $oldsort = $aCachedMailbox['SORT'];
591 * If it concerns a reverse sort we do not need to invalidate
592 * the cached sorted UIDSET, a reverse is sufficient.
594 if ((($newsort %
2) && ($newsort +
1 == $oldsort)) ||
595 (!($newsort %
2) && ($newsort - 1 == $oldsort))) {
596 $aMailbox['UIDSET'][$iSetIndx] = array_reverse($aCachedMailbox['UIDSET'][$iSetIndx]);
598 $server_sort_array = false;
599 $aMailbox['MSG_HEADERS'] = false;
600 $aMailbox['ID'] = false;
602 // store the new sort value in the mailbox pref
603 if ($aConfig['user']) {
604 // FIXME, in ideal situation, we write back the
605 // prefs at the end of the script
606 setUserPref($aConfig['user'],"pref_$mailbox",serialize($aProps));
609 $aMailbox['UIDSET'][$iSetIndx] = $aCachedMailbox['UIDSET'][$iSetIndx];
615 * Restore the offset in the paginator if no new offset is provided.
617 if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['offset']) && $aCachedMailbox['OFFSET']) {
618 $aMailbox['OFFSET'] = $aCachedMailbox['OFFSET'];
619 $aMailbox['PAGEOFFSET'] = $aCachedMailbox['PAGEOFFSET'];
621 $aMailbox['OFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ?
$aConfig['offset'] -1 : 0;
622 $aMailbox['PAGEOFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ?
$aConfig['offset'] : 1;
626 * Restore the showall value no new showall value is provided.
628 if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['showall']) &&
629 isset($aCachedMailbox['SHOWALL'][$iSetIndx]) && $aCachedMailbox['SHOWALL'][$iSetIndx]) {
630 $aMailbox['SHOWALL'][$iSetIndx] = $aCachedMailbox['SHOWALL'][$iSetIndx];
632 $aMailbox['SHOWALL'][$iSetIndx] = (isset($aConfig['showall']) && $aConfig['showall']) ?
1 : 0;
635 if (!isset($aProps[MBX_PREF_SORT
]) && isset($aCachedMailbox['SORT'])) {
636 $aMailbox['SORT'] = $aCachedMailbox['SORT'];
638 $aMailbox['SORT'] = (isset($aProps[MBX_PREF_SORT
])) ?
$aProps[MBX_PREF_SORT
] : 0;
641 if (!isset($aProps[MBX_PREF_LIMIT
]) && isset($aCachedMailbox['LIMIT'])) {
642 $aMailbox['LIMIT'] = $aCachedMailbox['LIMIT'];
644 $aMailbox['LIMIT'] = (isset($aProps[MBX_PREF_LIMIT
])) ?
$aProps[MBX_PREF_LIMIT
] : 15;
647 if (!isset($aProps[MBX_PREF_INTERNALDATE
]) && isset($aCachedMailbox['INTERNALDATE'])) {
648 $aMailbox['INTERNALDATE'] = $aCachedMailbox['INTERNALDATE'];
650 $aMailbox['INTERNALDATE'] = (isset($aProps[MBX_PREF_INTERNALDATE
])) ?
$aProps[MBX_PREF_INTERNALDATE
] : false;
653 if (!isset($aProps[MBX_PREF_AUTO_EXPUNGE
]) && isset($aCachedMailbox['AUTO_EXPUNGE'])) {
654 $aMailbox['AUTO_EXPUNGE'] = $aCachedMailbox['AUTO_EXPUNGE'];
656 $aMailbox['AUTO_EXPUNGE'] = (isset($aProps[MBX_PREF_AUTO_EXPUNGE
])) ?
$aProps[MBX_PREF_AUTO_EXPUNGE
] : false;
659 if (!isset($aConfig['allow_thread_sort']) && isset($aCachedMailbox['ALLOW_THREAD'])) {
660 $aMailbox['ALLOW_THREAD'] = $aCachedMailbox['ALLOW_THREAD'];
662 $aMailbox['ALLOW_THREAD'] = (isset($aConfig['allow_thread_sort'])) ?
$aConfig['allow_thread_sort'] : false;
665 if (!isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx])) {
666 $aMailbox['SEARCH'][$iSetIndx] = $aCachedMailbox['SEARCH'][$iSetIndx];
668 $aMailbox['SEARCH'][$iSetIndx] = (isset($aConfig['search'])) ?
$aConfig['search'] : 'ALL';
671 if (!isset($aConfig['charset']) && isset($aCachedMailbox['CHARSET'][$iSetIndx])) {
672 $aMailbox['CHARSET'][$iSetIndx] = $aCachedMailbox['CHARSET'][$iSetIndx];
674 $aMailbox['CHARSET'][$iSetIndx] = (isset($aConfig['charset'])) ?
$aConfig['charset'] : 'US-ASCII';
677 $aMailbox['NAME'] = $mailbox;
678 $aMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
679 $aMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ?
$aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
680 $aMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ?
$aMbxResponse['RECENT'] : 0;
681 $aMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
682 $aMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
683 $aMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS'];
684 $aMailbox['RIGHTS'] = $aMbxResponse['RIGHTS'];
688 /* decide if we are thread sorting or not */
689 if (!$aMailbox['ALLOW_THREAD']) {
690 if ($aMailbox['SORT'] & SQSORT_THREAD
) {
691 $aMailbox['SORT'] -= SQSORT_THREAD
;
694 if ($aMailbox['SORT'] & SQSORT_THREAD
) {
695 $aMailbox['SORT_METHOD'] = 'THREAD';
696 $aMailbox['THREAD_INDENT'] = $aCachedMailbox['THREAD_INDENT'];
697 } else if (isset($aConfig['allow_server_sort']) && $aConfig['allow_server_sort']) {
698 $aMailbox['SORT_METHOD'] = 'SERVER';
699 $aMailbox['THREAD_INDENT'] = false;
701 $aMailbox['SORT_METHOD'] = 'SQUIRREL';
702 $aMailbox['THREAD_INDENT'] = false;
705 /* set a timestamp for cachecontrol */
706 $aMailbox['TIMESTAMP'] = time();
713 * Does the $srt $_GET var to field mapping
715 * @param int $srt Field to sort on
716 * @param bool $bServerSort Server sorting is true
717 * @return string $sSortField Field to sort on
719 function getSortField($sort,$bServerSort) {
724 case SQSORT_DATE_ASC
:
725 case SQSORT_DATE_DEC
:
726 $sSortField = 'DATE';
728 case SQSORT_FROM_ASC
:
729 case SQSORT_FROM_DEC
:
730 $sSortField = 'FROM';
732 case SQSORT_SUBJ_ASC
:
733 case SQSORT_SUBJ_DEC
:
734 $sSortField = 'SUBJECT';
736 case SQSORT_SIZE_ASC
:
737 case SQSORT_SIZE_DEC
:
738 $sSortField = ($bServerSort) ?
'SIZE' : 'RFC822.SIZE';
748 case SQSORT_INT_DATE_ASC
:
749 case SQSORT_INT_DATE_DEC
:
750 $sSortField = ($bServerSort) ?
'ARRIVAL' : 'INTERNALDATE';
754 default: $sSortField = 'UID';
761 function get_sorted_msgs_list($imapConnection,&$aMailbox,&$error) {
762 $iSetIndx = (isset($aMailbox['SETINDEX'])) ?
$aMailbox['SETINDEX'] : 0;
763 $bDirection = ($aMailbox['SORT'] %
2);
765 if (!$aMailbox['SEARCH'][$iSetIndx]) {
766 $aMailbox['SEARCH'][$iSetIndx] = 'ALL';
768 switch ($aMailbox['SORT_METHOD']) {
770 $aRes = get_thread_sort($imapConnection,$aMailbox['SEARCH'][$iSetIndx]);
771 if ($aRes === false) {
772 $error = '<b><small><center><font color=red>' .
773 _("Thread sorting is not supported by your IMAP server.") . '<br />' .
774 _("Please report this to the system administrator.") .
775 '</center></small></b>';
776 $aMailbox['SORT'] -= SQSORT_THREAD
;
778 $aMailbox['UIDSET'][$iSetIndx] = $aRes[0];
779 $aMailbox['THREAD_INDENT'][$iSetIndx] = $aRes[1];
783 $sSortField = getSortField($aMailbox['SORT'],true);
784 $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]);
786 $error = '<b><small><center><font color=red>' .
787 _("Server-side sorting is not supported by your IMAP server.") . '<br />' .
788 _("Please report this to the system administrator.") .
789 '</center></small></b>';
791 $aMailbox['UIDSET'][$iSetIndx] = $id;
796 if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') {
797 $id = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
799 $sSortField = getSortField($aMailbox['SORT'],false);
800 $aMailbox['UIDSET'][$iSetIndx] = get_squirrel_sort($imapConnection, $sSortField, $bDirection, $id);
809 function fetchMessageHeaders($imapConnection, &$aMailbox) {
812 * Retrieve the UIDSET.
813 * Setindex is used to be able to store multiple uid sets. That will make it
814 * possible to display the mailbox multiple times in different sort order
815 * or to store serach results separate from normal mailbox view.
817 $iSetIndx = (isset($aMailbox['SETINDEX'])) ?
$aMailbox['SETINDEX'] : 0;
819 $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ?
$aMailbox['EXISTS'] : $aMailbox['LIMIT'];
821 * Adjust the start_msg
823 $start_msg = $aMailbox['PAGEOFFSET'];
824 if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) {
825 $start_msg -= $aMailbox['LIMIT'];
832 if (is_array($aMailbox['UIDSET'])) {
833 $aUid =& $aMailbox['UIDSET'][$iSetIndx];
838 // initialize the fields we want to retrieve:
839 $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Content-Type');
840 $aFetchItems = array('FLAGS', 'RFC822.SIZE');
842 // Are we sorting on internaldate then retrieve the internaldate value as well
843 if ($aMailbox['INTERNALDATE']) {
844 $aFetchItems[] = 'INTERNALDATE';
849 * A uidset with sorted uid's is available. We can use the cache
851 if (($aMailbox['SORT'] != SQSORT_NONE ||
$aMailbox['SEARCH'][$iSetIndx] != 'ALL') &&
852 isset($aUid) && $aUid ) {
854 // limit the cache to SQM_MAX_PAGES_IN_CACHE
855 if (!$aMailbox['SHOWALL'][$iSetIndx]) {
856 $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE
;
857 $iCacheSize = count($aMailbox['MSG_HEADERS']);
858 if ($iCacheSize > $iMaxMsgs) {
859 $iReduce = $iCacheSize - $iMaxMsgs;
860 foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) {
862 unset($aMailbox['MSG_HEADERS'][$iUid]);
871 $id_slice = array_slice($aUid,$start_msg-1,$iLimit);
872 /* do some funky cache checks */
873 $aUidCached = array_keys($aMailbox['MSG_HEADERS']);
874 $aUidNotCached = array_values(array_diff($id_slice,$aUidCached));
876 * $aUidNotCached contains an array with UID's which need to be fetched to
877 * complete the needed message headers.
879 if (count($aUidNotCached)) {
880 $aMsgs = sqimap_get_small_header_list($imapConnection,$aUidNotCached,
881 $aHeaderFields,$aFetchItems);
882 // append the msgs to the existend headers
883 $aMailbox['MSG_HEADERS'] +
= $aMsgs;
888 * Initialize the sorted UID list and fetch the visible message headers
890 if ($aMailbox['SORT'] != SQSORT_NONE ||
$aMailbox['SEARCH'][$iSetIndx] != 'ALL') {// || $aMailbox['SORT_METHOD'] & SQSORT_THREAD 'THREAD') {
893 if ($aMailbox['SEARCH'][$iSetIndx] && $aMailbox['SORT'] == 0) {
894 $aUid = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
896 $error = get_sorted_msgs_list($imapConnection,$aMailbox,$error);
897 $aUid = $aMailbox['UIDSET'][$iSetIndx];
899 if ($error === false) {
900 $id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit);
901 if (count($id_slice)) {
902 $aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice,
903 $aHeaderFields,$aFetchItems);
909 // FIX ME, format message and fallback to squirrel sort
915 // limit the cache to SQM_MAX_PAGES_IN_CACHE
916 if (!$aMailbox['SHOWALL'][$iSetIndx] && isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) {
917 $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE
;
918 $iCacheSize = count($aMailbox['MSG_HEADERS']);
919 if ($iCacheSize > $iMaxMsgs) {
920 $iReduce = $iCacheSize - $iMaxMsgs;
921 foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) {
923 $iId = $aMailbox['MSG_HEADERS'][$iUid]['ID'];
924 unset($aMailbox['MSG_HEADERS'][$iUid]);
925 unset($aMailbox['ID'][$iId]);
935 * retrieve messages by sequence id's and fetch the UID to retrieve
936 * the UID. for sorted lists this is not needed because a UID FETCH
937 * automaticly add the UID value in fetch results
939 $aFetchItems[] = 'UID';
942 $iRangeStart = $aMailbox['EXISTS'] - $aMailbox['OFFSET'];
943 $iRangeEnd = ($iRangeStart > $iLimit) ?
944 ($iRangeStart - $iLimit+
1):1;
946 $id_slice = range($iRangeStart, $iRangeEnd);
948 * Non sorted mailbox with cached message headers
950 if (isset($aMailbox['ID']) && is_array($aMailbox['ID'])) {
951 // the fetched id => uid relation
952 $aId = $aMailbox['ID'];
953 $aIdCached = array();
954 foreach ($aId as $iId => $iUid) {
955 if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
956 if ($iId <= $iRangeStart && $iId >= $iRangeEnd) {
961 $aIdNotCached = array_diff($id_slice,$aIdCached);
963 $aIdNotCached = $id_slice;
966 if (count($aIdNotCached)) {
967 $aMsgs = sqimap_get_small_header_list($imapConnection,$aIdNotCached,
968 $aHeaderFields,$aFetchItems);
969 // append the msgs to the existend headers
970 if (isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) {
971 $aMailbox['MSG_HEADERS'] +
= $aMsgs;
973 $aMailbox['MSG_HEADERS'] = $aMsgs;
975 // update the ID array
976 foreach ($aMsgs as $iUid => $aMsg) {
977 if (isset($aMsg['ID'])) {
978 $aMailbox['ID'][$aMsg['ID']] = $iUid;
984 * In unsorted state we show newest messages first which means
985 * that the UIDSET which represents the order of the messages
986 * should contain a high to low ordered UID list
988 $aSortedUidList = array();
989 foreach ($id_slice as $iId) {
990 if (isset($aMailbox['ID'][$iId])) {
991 $aSortedUidList[] = $aMailbox['ID'][$iId];
994 $aMailbox['UIDSET'][$iSetIndx] = $aSortedUidList;
995 $aMailbox['OFFSET'] = 0;
1002 * This function loops through a group of messages in the mailbox
1003 * and shows them to the user.
1005 * @param mixed $imapConnection
1006 * @param array $aMailbox associative array with mailbox related vars
1008 function showMessagesForMailbox($imapConnection, &$aMailbox) {
1011 // to retrieve the internaldate pref: (I know this is not the right place to do that, move up in front
1012 // and use a properties array as function argument to provide user preferences
1013 global $data_dir, $username;
1015 if (!fetchMessageHeaders($imapConnection, $aMailbox)) {
1018 $iSetIndx = $aMailbox['SETINDEX'];
1019 $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ?
$aMailbox['EXISTS'] : $aMailbox['LIMIT'];
1020 $iEnd = ($aMailbox['PAGEOFFSET'] +
($iLimit - 1) < $aMailbox['EXISTS']) ?
1021 $aMailbox['PAGEOFFSET'] +
$iLimit - 1 : $aMailbox['EXISTS'];
1023 $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'],
1024 $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]);
1026 $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']);
1028 do_hook('mailbox_index_before');
1030 <table border
="0" width
="100%" cellpadding
="0" cellspacing
="0">
1033 <?php
mail_message_listing_beginning($imapConnection, $aMailbox, $msg_cnt_str, $paginator_str); ?
>
1036 <tr
><td height
="5" bgcolor
="<?php echo $color[4]; ?>"></td
></tr
>
1039 <table width
="100%" cellpadding
="1" cellspacing
="0" align
="center" border
="0" bgcolor
="<?php echo $color[9]; ?>">
1042 <table width
="100%" cellpadding
="1" cellspacing
="0" align
="center" border
="0" bgcolor
="<?php echo $color[5]; ?>">
1046 printHeader($aMailbox);
1047 displayMessageArray($imapConnection, $aMailbox);
1056 mail_message_listing_end($aMailbox['EXISTS'], $paginator_str, $msg_cnt_str);
1066 * Function to map an uid list with a msg header array by uid
1067 * The mapped headers are printed with printMessage
1068 * aMailbox parameters contains info about the page we are on, the
1069 * used search criteria, the number of messages to show
1071 * @param resource $imapConnection socket handle to imap
1072 * @param array $aMailbox array with required elements MSG_HEADERS, UIDSET, OFFSET, LIMIT
1075 function displayMessageArray($imapConnection, $aMailbox) {
1076 $iSetIndx = $aMailbox['SETINDEX'];
1077 $aId = $aMailbox['UIDSET'][$iSetIndx];
1078 $aHeaders = $aMailbox['MSG_HEADERS'];
1079 $iOffset = $aMailbox['OFFSET'];
1080 $sort = $aMailbox['SORT'];
1081 $iPageOffset = $aMailbox['PAGEOFFSET'];
1082 $sMailbox = $aMailbox['NAME'];
1083 $sSearch = (isset($aMailbox['SEARCH'][$aMailbox['SETINDEX']])) ?
$aMailbox['SEARCH'][$aMailbox['SETINDEX']] : false;
1084 $aSearch = ($sSearch) ?
array('search.php',$aMailbox['SETINDEX']) : null;
1086 if ($aMailbox['SORT'] & SQSORT_THREAD
) {
1087 $aIndentArray =& $aMailbox['THREAD_INDENT'][$aMailbox['SETINDEX']];
1093 * Loop through and display the info for each message.
1094 * ($t is used for the checkbox number)
1096 $iEnd = ($aMailbox['SHOWALL'][$iSetIndx]) ?
$aMailbox['EXISTS'] : $iOffset +
$aMailbox['LIMIT'];
1097 for ($i=$iOffset,$t=0;$i<$iEnd;++
$i) {
1098 if (isset($aId[$i])) {
1099 $bLast = ((isset($aId[$i+
1]) && isset($aHeaders[$aId[$i+
1]]))
1100 ||
($i == $iEnd )) ?
false : true;
1102 $indent = (isset($aIndentArray[$aId[$i]])) ?
$aIndentArray[$aId[$i]] : 0;
1107 'HEADER' => $aHeaders[$aId[$i]],
1109 'OFFSET' => $iOffset,
1110 'PAGEOFFSET' => $iPageOffset,
1112 'SEARCH' => $aSearch,
1113 'MAILBOX' => $sMailbox,
1114 'INDENT' => $indent,
1117 printMessageInfo($aMsg);
1126 * Displays the standard message list header.
1128 * To finish the table, you need to do a "</table></table>";
1130 * @param resource $imapConnection
1131 * @param array $aMailbox associative array with mailbox related information
1132 * @param string $msg_cnt_str
1133 * @param string $paginator Paginator string
1135 function mail_message_listing_beginning ($imapConnection,
1138 $paginator = ' '
1140 global $color, $show_flag_buttons, $PHP_SELF;
1141 global $lastTargetMailbox, $boxes;
1143 $php_self = $PHP_SELF;
1145 $urlMailbox = urlencode($aMailbox['NAME']);
1147 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
1148 $source_url = $regs[1];
1150 $source_url = $php_self;
1157 $moveFields = addHidden('msg', $msg).
1158 addHidden('mailbox', $aMailbox['NAME']).
1159 addHidden('startMessage', $aMailbox['PAGEOFFSET']);
1161 /* build thread sorting links */
1162 $sort = $aMailbox['SORT'];
1163 if ($aMailbox['ALLOW_THREAD']) {
1164 if ($aMailbox['SORT'] & SQSORT_THREAD
) {
1165 $sort -= SQSORT_THREAD
;
1166 $thread_name = _("Unthread View");
1168 $thread_name = _("Thread View");
1169 $sort = $aMailbox['SORT'] + SQSORT_THREAD
;
1171 $thread_link_str = '<small>[<a href="' . $source_url . '?srt='
1172 . $sort . '&start_messages=1'
1173 . '&mailbox=' . urlencode($aMailbox['NAME']) . '">' . $thread_name
1176 $thread_link_str ='';
1179 * This is the beginning of the message list table.
1180 * It wraps around all messages
1182 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
1183 $form_name = "FormMsgs" . $safe_name;
1185 echo '<form name="' . $form_name . '" method="post" action="'.$php_self.'">' ."\n"
1189 // display flag buttons only if supported
1190 if ($show_flag_buttons &&
1191 in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true) ) {
1192 $button_str .= getButton('SUBMIT', 'markUnflagged', _("Unflag"));
1193 $button_str .= getButton('SUBMIT', 'markFlagged', _("Flag"));
1194 $button_str .= " \n";
1196 if (in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true)) {
1197 $button_str .= getButton('SUBMIT', 'markUnread', _("Unread"));
1198 $button_str .= getButton('SUBMIT', 'markRead', _("Read"));
1199 $button_str .= " \n";
1201 $button_str .= getButton('SUBMIT', 'attache',_("Forward")) .
1203 if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) {
1204 $button_str .= getButton('SUBMIT', 'delete',_("Delete"));
1205 $button_str .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
1206 $button_str .= " \n";
1208 if (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY') {
1209 $button_str .= getButton('SUBMIT', 'expungeButton',_("Expunge")) .' ' . _("mailbox") . "\n";
1210 $button_str .= ' ';
1213 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
1216 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
1218 <?php
echo html_tag('td', '<small>' . $paginator . $thread_link_str . '</small>', 'left') . "\n"; ?
>
1219 <?php
echo html_tag('td', '', 'center') . "\n"; ?
>
1220 <?php
echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right') . "\n"; ?
>
1225 <tr width
="100%" cellpadding
="1" cellspacing
="0" border
="0" bgcolor
="<?php echo $color[0]; ?>">
1227 <table border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
1229 <?php
echo html_tag('td', '', 'left') . "\n"; ?
>
1231 <?php
echo $button_str; ?
>
1232 <?php
do_hook('mailbox_display_buttons'); ?
>
1236 if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) {
1238 <?php
echo html_tag('td', '', 'right'); ?
>
1240 <select name
="targetMailbox">
1241 <?php
echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes); ?
>
1242 </select
></tt
> 
;
1243 <?php
echo getButton('SUBMIT', 'moveButton',_("Move")); ?
>
1255 do_hook('mailbox_form_before');
1259 * Function to add the last row in a message list, it contains the paginator and info about
1260 * the number of messages.
1262 * @param integer $num_msgs number of messages in a mailbox
1263 * @param string $paginator_str Paginator string [Prev | Next] [ 1 2 3 ... 91 92 94 ] [Show all]
1264 * @param string $msg_cnt_str Message count string Viewing Messages: 21 to 1861 (20 total)
1266 function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str) {
1269 /* space between list and footer */
1271 <tr
><td height
="5" bgcolor
="<?php echo $color[4]; ?>" colspan
="1"></td
></tr
>
1274 <table width
="100%" cellpadding
="1" cellspacing
="0" style
="border: 1px solid <?php echo $color[0]; ?>">
1277 <table bgcolor
="<?php echo $color[4]; ?>" border
="0" width
="100%" cellpadding
="1" cellspacing
="0">
1279 <?php
echo html_tag('td', '<small>' . $paginator_str . '</small>', 'left'); ?
>
1280 <?php
echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right'); ?
>
1290 /* End of message-list table */
1292 do_hook('mailbox_index_after');
1297 * Prints the table header for the messages list view
1299 * @param array $aMailbox
1301 function printHeader($aMailbox) {
1302 global $index_order, $internal_date_sort, $color;
1304 if ($aMailbox['SORT_METHOD'] != 'THREAD') {
1310 echo html_tag( 'tr' ,'' , 'center', $color[5] );
1312 /* calculate the width of the subject column based on the
1313 * widths of the other columns */
1314 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
1315 $subjectwidth = 100;
1316 foreach($index_order as $item) {
1317 $subjectwidth -= $widths[$item];
1320 foreach ($index_order as $item) {
1322 case 1: /* checkbox */
1323 echo html_tag( 'td',get_selectall_link($aMailbox) , '', '', 'width="1%"' );
1326 echo html_tag( 'td','' , '', '', 'width="1%"' );
1329 if (handleAsSent($aMailbox['NAME'])) {
1330 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
1331 . '<b>' . _("To") . '</b>';
1333 ShowSortButton($aMailbox, SQSORT_TO_ASC
, SQSORT_TO_DEC
);
1336 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
1337 . '<b>' . _("From") . '</b>';
1339 ShowSortButton($aMailbox, SQSORT_FROM_ASC
, SQSORT_FROM_DEC
);
1345 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
1346 . '<b>' . _("Date") . '</b>';
1348 if ($internal_date_sort) {
1349 ShowSortButton($aMailbox, SQSORT_INT_DATE_ASC
, SQSORT_INT_DATE_DEC
);
1351 ShowSortButton($aMailbox, SQSORT_DATE_ASC
, SQSORT_DATE_DEC
);
1356 case 4: /* subject */
1357 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
1358 . '<b>' . _("Subject") . '</b>';
1360 ShowSortButton($aMailbox, SQSORT_SUBJ_ASC
, SQSORT_SUBJ_DEC
);
1365 echo html_tag( 'td', '', 'center','','width="5%" nowrap')
1366 . '<b>' . _("Size") . '</b>';
1368 ShowSortButton($aMailbox, SQSORT_SIZE_ASC
, SQSORT_SIZE_DEC
);
1379 * This function shows the sort button. Isn't this a good comment?
1381 * @param array $aMailbox
1382 * @param integer $Down
1383 * @param integer $Up
1385 function ShowSortButton($aMailbox, $Down, $Up ) {
1388 /* Figure out which image we want to use. */
1389 if ($aMailbox['SORT'] != $Up && $aMailbox['SORT'] != $Down) {
1390 $img = 'sort_none.png';
1392 } elseif ($aMailbox['SORT'] == $Up) {
1393 $img = 'up_pointer.png';
1396 $img = 'down_pointer.png';
1400 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1401 $source_url = $regs[1];
1403 $source_url = $PHP_SELF;
1406 /* Now that we have everything figured out, show the actual button. */
1407 echo ' <a href="' . $source_url .'?srt=' . $which
1408 . '&startMessage=1&mailbox=' . urlencode($aMailbox['NAME'])
1409 . '"><img src="../images/' . $img
1410 . '" border="0" width="12" height="10" alt="sort" title="'
1411 . _("Click here to change the sorting of the message list") .'" /></a>';
1415 * FIXME: Undocumented function
1417 * @param array $aMailbox
1419 function get_selectall_link($aMailbox) {
1420 global $checkall, $javascript_on;
1424 if ($javascript_on) {
1425 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
1426 $func_name = "CheckAll" . $safe_name;
1427 $form_name = "FormMsgs" . $safe_name;
1428 $result = '<script language="JavaScript" type="text/javascript">'
1430 . "function " . $func_name . "() {\n"
1431 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
1432 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
1433 . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n"
1434 . " document." . $form_name . ".elements[i].checked = "
1435 . " !(document." . $form_name . ".elements[i].checked);\n"
1441 . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />';
1442 // . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
1445 if (strpos($PHP_SELF, "?")) {
1446 $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($aMailbox['NAME'])
1447 . "&startMessage=$aMailbox[PAGEOFFSET]&srt=$aMailbox[SORT]&checkall=";
1449 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
1450 . "&startMessage=$aMailbox[PAGEOFFSET]&srt=$aMailbox[SORT]&checkall=";
1452 if (isset($checkall) && $checkall == '1') {
1458 if (isset($aMailbox['SEARCH']) && $aMailbox['SEARCH'][0]) {
1459 $result .= '&where=' . urlencode($aMailbox['SEARCH'][0])
1460 . '&what=' . urlencode($aMailbox['SEARCH'][1]);
1463 $result .= _("All");
1464 $result .= "</a>\n";
1467 /* Return our final result. */
1472 * This function computes the "Viewing Messages..." string.
1474 * @param integer $start_msg first message number
1475 * @param integer $end_msg last message number
1476 * @param integer $num_msgs total number of message in folder
1479 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
1480 /* Compute the $msg_cnt_str. */
1482 if ($start_msg < $end_msg) {
1483 $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
1484 '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
1485 } else if ($start_msg == $end_msg) {
1486 $result = sprintf(_("Viewing Message: %s (1 total)"), '<b>'.$start_msg.'</b>');
1490 /* Return our result string. */
1495 * Generate a paginator link.
1497 * @param mixed $box Mailbox name
1498 * @param mixed $start_msg Message Offset
1500 * @param string $text text used for paginator link
1503 function get_paginator_link($box, $start_msg, $text) {
1504 sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER
);
1505 $result = "<a href=\"$php_self?startMessage=$start_msg&mailbox=$box\" "
1512 * This function computes the paginator string.
1514 * @param string $box mailbox name
1515 * @param integer $iOffset offset in total number of messages
1516 * @param integer $iTotal total number of messages
1517 * @param integer $iLimit maximum number of messages to show on a page
1518 * @param bool $bShowAll show all messages at once (non paginate mode)
1519 * @return string $result paginate string with links to pages
1521 function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) {
1522 global $username, $data_dir;
1523 sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER
);
1525 /* Initialize paginator string chunks. */
1531 $box = urlencode($box);
1533 /* Create simple strings that will be creating the paginator. */
1534 $spc = ' '; /* This will be used as a space. */
1535 $sep = '|'; /* This will be used as a seperator. */
1537 /* Get some paginator preference values. */
1538 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON
);
1539 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX
);
1541 /* Make sure that our start message number is not too big. */
1542 $iOffset = min($iOffset, $iTotal);
1544 /* Compute the starting message of the previous and next page group. */
1545 $next_grp = $iOffset +
$iLimit;
1546 $prev_grp = $iOffset - $iLimit;
1549 /* Compute the basic previous and next strings. */
1550 if (($next_grp <= $iTotal) && ($prev_grp >= 0)) {
1551 $prv_str = get_paginator_link($box, $prev_grp, _("Previous"));
1552 $nxt_str = get_paginator_link($box, $next_grp, _("Next"));
1553 } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) {
1554 $prv_str = get_paginator_link($box, $prev_grp, _("Previous"));
1555 $nxt_str = _("Next");
1556 } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) {
1557 $prv_str = _("Previous");
1558 $nxt_str = get_paginator_link($box, $next_grp, _("Next"));
1561 /* Page selector block. Following code computes page links. */
1562 if ($iLimit != 0 && $pg_sel && ($iTotal > $iLimit)) {
1563 /* Most importantly, what is the current page!!! */
1564 $cur_pg = intval($iOffset / $iLimit) +
1;
1566 /* Compute total # of pages and # of paginator page links. */
1567 $tot_pgs = ceil($iTotal / $iLimit); /* Total number of Pages */
1568 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1570 /* Compute the size of the four quarters of the page links. */
1572 /* If we can, just show all the pages. */
1573 if (($tot_pgs - 1) <= $pg_max) {
1574 $q1_pgs = $cur_pg - 1;
1575 $q2_pgs = $q3_pgs = 0;
1576 $q4_pgs = $tot_pgs - $cur_pg;
1578 /* Otherwise, compute some magic to choose the four quarters. */
1581 * Compute the magic base values. Added together,
1582 * these values will always equal to the $pag_pgs.
1583 * NOTE: These are DEFAULT values and do not take
1584 * the current page into account. That is below.
1586 $q1_pgs = floor($vis_pgs/4);
1587 $q2_pgs = round($vis_pgs/4, 0);
1588 $q3_pgs = ceil($vis_pgs/4);
1589 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1591 /* Adjust if the first quarter contains the current page. */
1592 if (($cur_pg - $q1_pgs) < 1) {
1593 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) +
$q2_pgs;
1594 $q1_pgs = $cur_pg - 1;
1596 $q3_pgs +
= ceil($extra_pgs / 2);
1597 $q4_pgs +
= floor($extra_pgs / 2);
1599 /* Adjust if the first and second quarters intersect. */
1600 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1601 $extra_pgs = $q2_pgs;
1602 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1603 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1604 $q3_pgs +
= ceil($extra_pgs / 2);
1605 $q4_pgs +
= floor($extra_pgs / 2);
1607 /* Adjust if the fourth quarter contains the current page. */
1608 } else if (($cur_pg +
$q4_pgs) >= $tot_pgs) {
1609 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) +
$q3_pgs;
1611 $q4_pgs = $tot_pgs - $cur_pg;
1612 $q1_pgs +
= floor($extra_pgs / 2);
1613 $q2_pgs +
= ceil($extra_pgs / 2);
1615 /* Adjust if the third and fourth quarter intersect. */
1616 } else if (($cur_pg +
$q3_pgs +
1) >= ($tot_pgs - $q4_pgs +
1)) {
1617 $extra_pgs = $q3_pgs;
1618 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1619 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1620 $q1_pgs +
= floor($extra_pgs / 2);
1621 $q2_pgs +
= ceil($extra_pgs / 2);
1626 * I am leaving this debug code here, commented out, because
1627 * it is a really nice way to see what the above code is doing.
1628 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1629 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />';
1632 /* Print out the page links from the compute page quarters. */
1634 /* Start with the first quarter. */
1635 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1636 $pg_str .= "...$spc";
1638 for ($pg = 1; $pg <= $q1_pgs; ++
$pg) {
1639 $start = (($pg-1) * $iLimit) +
1;
1640 $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
1642 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1643 $pg_str .= "...$spc";
1647 /* Continue with the second quarter. */
1648 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++
$pg) {
1649 $start = (($pg-1) * $iLimit) +
1;
1650 $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
1653 /* Now print the current page. */
1654 $pg_str .= $cur_pg . $spc;
1656 /* Next comes the third quarter. */
1657 for ($pg = $cur_pg +
1; $pg <= $cur_pg +
$q3_pgs; ++
$pg) {
1658 $start = (($pg-1) * $iLimit) +
1;
1659 $pg_str .= get_paginator_link($box, $start, $pg) . $spc;
1662 /* And last, print the forth quarter page links. */
1663 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1664 $pg_str .= "...$spc";
1666 if (($tot_pgs - $q4_pgs) > ($cur_pg +
$q3_pgs)) {
1667 $pg_str .= "...$spc";
1669 for ($pg = $tot_pgs - $q4_pgs +
1; $pg <= $tot_pgs; ++
$pg) {
1670 $start = (($pg-1) * $iLimit) +
1;
1671 $pg_str .= get_paginator_link($box, $start,$pg) . $spc;
1676 $pg_str = "<a href=\"$php_self?showall=0"
1677 . "&startMessage=1&mailbox=$box\" "
1678 . ">" ._("Paginate") . '</a>';
1681 /* Put all the pieces of the paginator string together. */
1683 * Hairy code... But let's leave it like it is since I am not certain
1684 * a different approach would be any easier to read. ;)
1687 if ( $prv_str ||
$nxt_str ) {
1689 /* Compute the 'show all' string. */
1690 $all_str = "<a href=\"$php_self?showall=1"
1691 . "&startMessage=1&mailbox=$box\" "
1692 . ">" . _("Show All") . '</a>';
1694 $result .= ($prv_str != '' ?
$prv_str . $spc . $sep . $spc : '');
1695 $result .= ($nxt_str != '' ?
$nxt_str : '');
1696 $result .= ']' . $spc ;
1700 $result .= ($pg_str != '' ?
$spc . '['.$spc.$pg_str.']' . $spc : '');
1701 $result .= ($all_str != '' ?
$spc . '['.$all_str.']' . $spc . $spc : '');
1703 /* If the resulting string is blank, return a non-breaking space. */
1704 if ($result == '') {
1708 /* Return our final magical paginator string. */
1713 * FIXME: Undocumented function
1715 function truncateWithEntities($subject, $trim_at)
1717 $ent_strlen = strlen($subject);
1718 if (($trim_at <= 0) ||
($ent_strlen <= $trim_at))
1721 global $languages, $squirrelmail_language;
1724 * see if this is entities-encoded string
1725 * If so, Iterate through the whole string, find out
1726 * the real number of characters, and if more
1727 * than $trim_at, substr with an updated trim value.
1729 $trim_val = $trim_at;
1732 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1733 (($ent_loc_end = strpos($subject, ';', $ent_loc+
3)) !== false) ) {
1734 $trim_val +
= ($ent_loc_end-$ent_loc);
1735 $ent_offset = $ent_loc_end+
1;
1737 if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val +
6))) {
1738 $i = strpos($subject,';',$trim_val);
1740 $trim_val = strpos($subject,';',$trim_val);
1743 // only print '...' when we're actually dropping part of the subject
1744 if ($ent_strlen <= $trim_val)
1747 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1748 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1749 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1752 return substr_replace($subject, '...', $trim_val);
1756 * FIXME: Undocumented function
1758 function processSubject($subject, $threadlevel = 0) {
1759 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1760 if ($subject == '') {
1761 return _("(no subject)");
1764 global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
1765 $trim_at = $truncate_subject;
1767 /* if this is threaded, subtract two chars per indentlevel */
1768 if (($threadlevel > 0) && ($threadlevel <= 10))
1769 $trim_at -= (2*$threadlevel);
1771 return truncateWithEntities($subject, $trim_at);
1778 * @deprecated see form functions available in 1.5.1 and 1.4.3.
1779 * @param string $type
1780 * @param string $name
1781 * @param string $value
1783 * @param bool $enabled
1785 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
1786 $disabled = ( $enabled ?
'' : 'disabled ' );
1787 $js = ( $js ?
$js.' ' : '' );
1788 return '<input '.$disabled.$js.
1791 '" value="'.$value .
1792 '" style="padding: 0px; margin: 0px" />';
1796 * Puts string into cell, aligns it and adds <small> tag
1798 * @param string $string string
1799 * @param string $align alignment
1801 function getSmallStringCell($string, $align) {
1802 return html_tag('td',
1803 '<small>' . $string . ': </small>',
1810 * This should go in imap_mailbox.php
1811 * @param string $mailbox
1813 function handleAsSent($mailbox) {
1814 global $handleAsSent_result;
1816 /* First check if this is the sent or draft folder. */
1817 $handleAsSent_result = isSentMailbox($mailbox) ||
isDraftMailbox($mailbox);
1819 /* Then check the result of the handleAsSent hook. */
1820 do_hook('check_handleAsSent_result', $mailbox);
1822 /* And return the result. */
1823 return $handleAsSent_result;
1827 * Process messages list form and handle the cache gracefully. If $sButton and
1828 * $aUid are provided as argument then you can fake a message list submit and
1829 * use it i.e. in read_body.php for del move next and update the cache
1831 * @param resource $imapConnection imap connection
1832 * @param array $aMailbox (reference) cached mailbox
1833 * @param string $sButton fake a submit button
1834 * @param array $aUid fake the $msg array
1835 * @return string $sError error string in case of an error
1836 * @author Marc Groot Koerkamp
1838 function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) {
1840 /* incoming formdata */
1841 $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST
)) ?
'move' : $sButton;
1842 $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST
)) ?
'expunge' : $sButton;
1843 $sButton = (sqgetGlobalVar('attache', $sTmp, SQ_POST
)) ?
'attache' : $sButton;
1844 $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST
)) ?
'setDeleted' : $sButton;
1845 $sButton = (sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST
)) ?
'setDeleted' : $sButton;
1846 $sButton = (sqgetGlobalVar('markRead', $sTmp, SQ_POST
)) ?
'setSeen' : $sButton;
1847 $sButton = (sqgetGlobalVar('markUnread', $sTmp, SQ_POST
)) ?
'unsetSeen' : $sButton;
1848 $sButton = (sqgetGlobalVar('markFlagged', $sTmp, SQ_POST
)) ?
'setFlagged' : $sButton;
1849 $sButton = (sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST
)) ?
'unsetFlagged' : $sButton;
1850 sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST
);
1851 sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST
);
1852 sqgetGlobalVar('msg', $msg, SQ_POST
);
1855 $mailbox = $aMailbox['NAME'];
1857 /* retrieve the check boxes */
1858 $aUid = (isset($msg) && is_array($msg)) ?
array_values($msg) : $aUid;
1860 if (count($aUid) && $sButton != 'expunge') {
1861 $aUpdatedMsgs = false;
1865 // check if id exists in case we come from read_body
1866 if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) &&
1867 !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) {
1870 // What kind of hook is this, can it be removed? Disabled for now because it can invalidate the cache
1871 //if (!boolean_hook_function('move_messages_button_action', NULL, 1)) {
1872 $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash);
1876 case 'unsetDeleted':
1880 case 'unsetFlagged':
1882 $sFlag = (substr($sButton,0,3) == 'set') ?
'\\'.substr($sButton,3) : '\\'.substr($sButton,5);
1883 $bSet = (substr($sButton,0,3) == 'set') ?
true : false;
1884 $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true);
1887 $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox);
1888 sqsession_register($targetMailbox,'lastTargetMailbox');
1892 $aMsgHeaders = array();
1893 foreach ($aUid as $iUid) {
1894 $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid];
1896 if (count($aMsgHeaders)) {
1897 $composesession = attachSelectedMessages($imapConnection,$aMsgHeaders);
1898 // dirty hack, add info to $aMailbox
1899 $aMailbox['FORWARD_SESSION'] = $composesession;
1904 * Updates messages is an array containing the result of the untagged
1905 * fetch responses send by the imap server due to a flag change. That
1906 * response is parsed in a array with msg arrays by the parseFetch function
1908 if ($aUpdatedMsgs) {
1909 // Update the message headers cache
1910 $aDeleted = array();
1911 foreach ($aUpdatedMsgs as $iUid => $aMsg) {
1912 if (isset($aMsg['FLAGS'])) {
1914 * Only update the cached headers if the header is
1917 if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
1918 $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS'];
1921 * Count the messages with the \Delete flag set so we can determine
1922 * if the number of expunged messages equals the number of flagged
1923 * messages for deletion.
1925 if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) {
1926 $aDeleted[] = $iUid;
1930 if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] &&
1931 $iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true))
1933 if (count($aDeleted) != $iExpungedMessages) {
1934 // there are more messages deleted permanently then we expected
1935 // invalidate the cache
1936 $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false;
1937 $aMailbox['MSG_HEADERS'] = false;
1939 // remove expunged messages from cache
1940 $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']];
1941 if (is_array($aUidSet)) {
1942 // create a UID => array index temp array
1943 $aUidSetDummy = array_flip($aUidSet);
1944 foreach ($aDeleted as $iUid) {
1945 // get the id as well in case of SQM_SORT_NONE
1946 if ($aMailbox['SORT'] == SQSORT_NONE
) {
1947 $aMailbox['ID'] = false;
1948 //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID'];
1949 //unset($aMailbox['ID'][$iId]);
1951 // unset the UID and message header
1952 unset($aUidSetDummy[$iUid]);
1953 unset($aMailbox['MSG_HEADERS'][$iUid]);
1955 $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy);
1958 // update EXISTS info
1959 if ($iExpungedMessages) {
1960 $aMailbox['EXISTS'] -= (int) $iExpungedMessages;
1962 // Change the startMessage number if the mailbox was changed
1963 if (($aMailbox['PAGEOFFSET']+
$iExpungedMessages-1) >= $aMailbox['EXISTS']) {
1964 $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ?
1965 $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1;
1970 if ($sButton == 'expunge') {
1972 * on expunge we do not know which messages will be deleted
1973 * so it's useless to try to sync the cache
1975 * Close the mailbox so we do not need to parse the untagged expunge
1976 * responses which do not contain uid info.
1977 * NB: Closing a mailbox is faster then expunge because the imap
1978 * server does not need to generate the untagged expunge responses
1980 sqimap_run_command($imapConnection,'CLOSE',false,$result,$message);
1981 $aMbxResponse = sqimap_mailbox_select($imapConnection,$aMailbox['NAME']);
1982 // update the $aMailbox array
1983 $aMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
1984 $aMailbox['UIDSET'] = false;
1987 $sError = _("No messages were selected.");
1994 function attachSelectedMessages($imapConnection,$aMsgHeaders) {
1995 global $username, $attachment_dir,
1996 $data_dir, $composesession,
1999 if (!isset($compose_messages)) {
2000 $compose_messages = array();
2001 sqsession_register($compose_messages,'compose_messages');
2004 if (!$composesession) {
2005 $composesession = 1;
2006 sqsession_register($composesession,'composesession');
2009 sqsession_register($composesession,'composesession');
2012 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
2014 $composeMessage = new Message();
2015 $rfc822_header = new Rfc822Header();
2016 $composeMessage->rfc822_header
= $rfc822_header;
2017 $composeMessage->reply_rfc822_header
= '';
2019 foreach($aMsgHeaders as $iUid => $aMsgHeader) {
2021 * Retrieve the full message
2023 $body_a = sqimap_run_command($imapConnection, "FETCH $iUid RFC822", true, $response, $readmessage, TRUE);
2025 if ($response == 'OK') {
2026 $subject = (isset($aMsgHeader['SUBJECT'])) ?
$aMsgHeader['SUBJECT'] : $iUid;
2028 array_shift($body_a);
2030 $body = implode('', $body_a);
2033 $localfilename = GenerateRandomString(32, 'FILE', 7);
2034 $full_localfilename = "$hashed_attachment_dir/$localfilename";
2036 $fp = fopen( $full_localfilename, 'wb');
2037 fwrite ($fp, $body);
2039 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
2040 $full_localfilename);
2044 $compose_messages[$composesession] = $composeMessage;
2045 sqsession_register($compose_messages,'compose_messages');
2046 return $composesession;