- $indent_array[$parent] = 0;
-
- /* now the children, checking each thread portion for
- ),(, and space, adjusting the level and space values
- to get the indent level
- */
- $level = 0;
- $spaces = array();
- $spaces_total = 0;
- $indent = 0;
- $fake = FALSE;
- for ($k=1;$k<(count($thread_new[$i]))-1;$k++) {
- $chars = count_chars($thread_new[$i][$k], 1);
- if (isset($chars['40'])) { /* testing for ( */
- $level = $level + $chars['40'];
- }
- if (isset($chars['41'])) { /* testing for ) */
- $level = $level - $chars['41'];
- $spaces[$level] = 0;
- /* if we were faking lets stop, this portion
- of the thread is over
- */
- if ($level == $cutoff) {
- $fake = FALSE;
- }
- }
- if (isset($chars['32'])) { /* testing for space */
- if (!isset($spaces[$level])) {
- $spaces[$level] = 0;
- }
- $spaces[$level] = $spaces[$level] + $chars['32'];
- }
- for ($x=0;$x<=$level;$x++) {
- if (isset($spaces[$x])) {
- $spaces_total = $spaces_total + $spaces[$x];
- }
- }
- $indent = $level + $spaces_total;
- /* must have run into a message that broke the thread
- so we are adjusting for that portion
- */
- if ($fake == TRUE) {
- $indent = $indent +1;
- }
- if (preg_match("/(\d+)/", $thread_new[$i][$k], $regs)) {
- $child = $regs[1];
- }
- /* the thread must be broken if $indent == 0
- so indent the message once and start faking it
- */
- if ($indent == 0) {
- $indent = 1;
- $fake = TRUE;
- $cutoff = $level;
- }
- /* dont need abs but if indent was negative
- errors would occur
- */
- $indent_array[$child] = abs($indent);
- $spaces_total = 0;
+ // nobreak
+ case 'SUBJECT':
+ if(!$walk) {
+ array_walk($msgs, create_function('&$v,&$k,$f',
+ '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $v[$f] = strtolower(decodeHeader(trim($v[$f]), true, false));
+ $v[$f] = (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\[\w\]):\s*)*\s*(.*)$/si", $v[$f], $matches)) ?
+ $matches[1] : $v[$f];'),$sSortField);
+ $walk = true;
+ }
+ foreach ($msgs as $item) {
+ $aUid[$item['UID']] = $item[$sSortField];
+ }
+ natcasesort($aUid);
+ $aUid = array_keys($aUid);
+ if ($reverse) {
+ $aUid = array_reverse($aUid);
+ }
+ break;
+ // \natcasesort section
+ // sort_numeric section
+ case 'DATE':
+ case 'INTERNALDATE':
+ if(!$walk) {
+ array_walk($msgs, create_function('&$v,$k,$f',
+ '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $v[$f] = getTimeStamp(explode(" ",$v[$f]));'),$sSortField);
+ $walk = true;
+ }
+ // nobreak;
+ case 'RFC822.SIZE':
+ if(!$walk) {
+ // redefine $sSortField to maintain the same namespace between
+ // server-side sorting and SquirrelMail sorting
+ $sSortField = 'SIZE';
+ }
+ foreach ($msgs as $item) {
+ $aUid[$item['UID']] = (isset($item[$sSortField])) ? $item[$sSortField] : 0;
+ }
+ if ($reverse) {
+ arsort($aUid,SORT_NUMERIC);
+ } else {
+ asort($aUid, SORT_NUMERIC);