This file is indexed.

/usr/share/IlohaMail/source/main.php is in ilohamail 0.8.14-0rc3sid6.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
<?php
/////////////////////////////////////////////////////////
//	
//	source/main.php
//
//	(C)Copyright 2000-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
//
//		This file is part of IlohaMail.
//		IlohaMail is free software released under the GPL 
//		license.  See enclosed file COPYING for details,
//		or see http://www.fsf.org/copyleft/gpl.html
//
/////////////////////////////////////////////////////////

/********************************************************

	AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
	FILE: source/main.php
	PURPOSE:
		1.  List specified number of messages in specified order from given folder.
		2.  Provide interface to read messages (link subjects to source/read_message.php)
		3.  Provide interface to send messasge to senders (link "From" field to source/compose.php)
		4.  Provide interface to move or delete messages
		5.  Provide interface to view messages not currently listed.
		6.  Provide functionality to move, delete messages and expunge folders.
	PRE-CONDITIONS:
		$user - Session ID
		$folder - Folder name
		[$sort_field] - Field to sort by {"subject", "from", "to", "size", "date"}
		[$sort_order] - Order, "ASC" or "DESC"
		[$start] - Show specified number of messages starting with this index

********************************************************/

$exec_start_time = microtime();

include("../include/stopwatch.inc");
$clock = new stopwatch(true);

$clock->register("start");

include("../include/super2global.inc");
$clock->register("pre-header");
include("../include/header_main.inc");
$clock->register("post-header");
include("../include/ryosdates.inc");
include("../include/icl.inc");
include("../include/main.inc");
include("../include/cache.inc");
$clock->register("includes done");

	if (!isset($folder)){
		echo "Error: folder not specified";
		exit;
	}
	include("../lang/".$my_prefs["lang"]."defaultFolders.inc");
	include("../lang/".$my_prefs["lang"]."main.inc");
	include("../lang/".$my_prefs["lang"]."dates.inc");

	//initialize some vars
	if (!isset($hideseen)) $hideseen=0;
	if (!isset($showdeleted)) $showdeleted=0;
	if (strcmp($folder, $my_prefs["trash_name"])==0) $showdeleted=1;
	if (empty($my_prefs["main_cols"])) $my_prefs["main_cols"]="camfsdz";
	
	$clock->register("pre-connect");
	
	//connect to mail server
	$conn = iil_Connect($host, $loginID, $password, $AUTH_MODE);
	if (!$conn){
		echo "Connection failed: $iil_error <br> ";
		exit;
	}
	
	$clock->register("post-connect");
		
	echo "\n<!-- ICLMessages:\n".$conn->message."-->\n";
	
	//move columns
	//$MOVE_FIELDS = 1;
	if ($MOVE_FIELDS){
		$report = $mainErrors[8];
		if ($move_col && $move_direction){
			//echo "Moving fields <br>\n";
			$col_pos = strpos($my_prefs["main_cols"], $move_col);
			if ($col_pos !== false){
				if ($move_direction=="right") $move_direction = 1;
				else if ($move_direction=="left") $move_direction = -1;
				$partner_col = $my_prefs["main_cols"][$col_pos+$move_direction];
				//echo "Shift is $move_direction switching with $partner_col <br>\n";
				if ($partner_col){
					$my_prefs["main_cols"][$col_pos+$move_direction] = $move_col;
					$my_prefs["main_cols"][$col_pos] = $partner_col;
					include("../include/save_prefs.inc");
				}
			}
		}
	}
	

	//default names for toolbar input fields, used in main_tools.inc as well
	$main_tool_fields = array("expunge", "empty_trash", "delete_selected",
								"mark_read", "mark_unread", "moveto", "move_selected");

	//if toolbar displayed at top & bottom, bottom fields will have '_2' appened
	//at the end of field name.  we deal with that here
	reset($main_tool_fields); 
	while ( list($k,$tool_field)=each($main_tool_fields) ){
		$tool_var_name = $tool_field."_2";
		$tool_var_val = $$tool_var_name;
		if (!empty($tool_var_val)) $$tool_field = $tool_var_val;
	}										
	
	//actions (flagging, deleting, moving, etc)
	if ($move_selected) $submit = "File";
	if ($delete_selected) $submit = "Delete";
	if ($empty_trash) $submit = "Expunge";
	if ($mark_read) $submit = "Read";
	if ($mark_unread) $submit = "Unread";
	
	if (isset($submit)){
		$messages="";
		
		/* compose an IMAP message list string including all checked items */
		if ((is_array($uids)) && (implode("",$uids)!="")){
			$checkboxes = iil_C_Search($conn, $folder, "UID ".implode(",", $uids));
		}
		if (is_array($checkboxes)){
               $messages = implode(",", $checkboxes);
               $num_checked = count($checkboxes);
		}
		
		/* "Move to trash" is same as "Delete" */
		if (($submit=="File") && $moveto && (strcmp($moveto, $my_prefs["trash_name"])==0)) $submit="Delete";
           
		/*  delete all */
		if ($delete_all == 2 ){
			$messages .= "1:".$delete_all_num;
		}
					
		/* delete items */
		$delete_success = false;
		if (($submit=="Delete")||(strcmp($submit,$mainStrings[10])==0)){
			//if folders and trash specified, move to trash
			if ($ICL_CAPABILITY["folders"]){
				if (strcmp($folder, $my_prefs["trash_name"])!=0){
					if (!empty($my_prefs["trash_name"])){
						if (iil_C_Move($conn, $messages, $folder, $my_prefs["trash_name"]) >= 0){
							$delete_success = true;
						}else{
							$report = $mainErrors[2].":".$messages;
						}
					}
				}else{
					$report = $mainErrors[3].":".$messages;
				}
			}

			//otherwise, just mark as deleted
			if (!$delete_success){
				if (iil_C_Delete($conn, $folder, $messages) > 0) $delete_success = true;
			}
			
			//if deleted, format success report
			if ($delete_success){
				$report =  str_replace("%n", $num_checked, $mainMessages["delete"]);
			}
		}
		
		/*  move items */
		if (($submit=="File")||(strcmp($submit,$mainStrings[12])==0)){
			if (strcasecmp($folder, $my_prefs["trash_name"])==0){
				iil_C_Undelete($conn, $folder, $messages);
			}
			if (iil_C_Move($conn, $messages, $folder, $moveto) >= 0){
				$report = str_replace("%n", $num_checked, $mainMessages["move"]);
				$report = str_replace("%f", $moveto, $report);
				if (strcasecmp($folder, $my_prefs["trash_name"])==0){
					iil_C_Delete($conn, $folder, $messages);
				}
			}else{
				$report = $mainErrors[4];
			}
		}
			
			
		/* empty trash  command */
		if (($submit=="Expunge") && ($expunge==1)){
			if ($folder==$my_prefs["trash_name"]){
				if (!iil_C_ClearFolder($conn, $folder)){
					echo $mainErrors[6]." (".$conn->error.")<br>\n";
				}
			}else{
				$error .= "Folder $folder is not trash (trash is ".$my_prefs["trash_name"].")<br>\n";
			}
		}
		
		/* expunge non-trash folders automatically */
		if (strcasecmp($folder,$my_prefs["trash_name"])!=0){
			iil_C_Expunge($conn, $folder);
		}
		
		/* mark as unread */
		if ($submit=="Unread"){
			iil_C_Unseen($conn, $folder, $messages);
			$reload_folders = true;
			$selected_boxes = $checkboxes;
		}
		
		/* mark as read */
		if ($submit=="Read"){
			iil_C_Flag($conn, $folder, $messages, "SEEN");
			$reload_folders = true;
			$selected_boxes = $checkboxes;
		}
	} //end if submit
		
		
	/* If search results were moved or deleted, stop execution here. */
	if (isset($search_done)){
		echo "<p>Request completed.\n";
		echo "</body></html>";
		exit;
	}
	
	/* initialize sort field and sort order 
		(set to default prefernce values if not specified */
	
	if (empty($sort_field)) $sort_field=$my_prefs["sort_field"];
	if (empty($sort_order)) $sort_order=$my_prefs["sort_order"];

	
	/* figure out which/how many messages to fetch */
	if ((empty($start)) || (!isset($start))) $start = 0;
	$num_show=$my_prefs["view_max"];
	if ($num_show==0) $num_show=50;
	$next_start=$start+$num_show;
	$prev_start=$start-$num_show;
	if ($prev_start<0) $prev_start=0;
	//echo "<p>Start: $start";
	
	/* flush, so the browser can't start renderin and user sees some feedback */
	flush();
	
	$clock->register("pre-count");

	/* retreive message list (search, or list all in folder) */
	if ((!empty($search)) || (!empty($search_criteria))){
		include("../lang/".$my_prefs["lang"]."search_errors.inc");
		$criteria="";
		$error="";
		$date = $month."/".$day."/".$year;
		if (empty($search_criteria)){
			// check criteria
			if ($date_operand=="ignore"){
				if ($field=="-"){
					$error=$searchErrors["field"];
				}
				if (empty($string)){
					$error=$searchErrors["empty"];
				}
			}else if ((empty($date))||($date=="mm/dd/yyyy")){
				$error=$searchErrors["date"];
			}
			if (!empty($date)){
				$date_a=explode("/", $date);
				$date=iil_FormatSearchDate($date_a[0], $date_a[1], $date_a[2]);
			}
		}
		if ($error==""){
			// format search string
			if (empty($search_criteria)){
				$criteria="ALL";
				if ($field!="-") $criteria.=" $field \"$string\"";
				if ($date_operand!="ignore") $criteria.=" $date_operand $date";
				$search_criteria = $criteria;
			}else{
				$search_criteria = stripslashes($search_criteria);
				$criteria = $search_criteria;
			}
			
			echo "Searching \"$criteria\" in $folder<br>\n"; flush();
			
			// search
			$messages_a=iil_C_Search($conn, $folder, $criteria);
			if ($messages_a!==false){
				$total_num=count($messages_a);
				if (is_array($messages_a)) $messages_str=implode(",", $messages_a);
				else $messages_str="";
				echo "found: {".$messages_str."} <br>\n"; flush();
			}else{
				echo "Error: ".$conn->error."<br>\n"; flush();
			}
		}else{
			$headers=false;
		}
	}else{
		$total_num=iil_C_CountMessages($conn, $folder);
		if ($total_num > 0) $messages_str="1:".$total_num;
		else $messages_str="";
		$index_failed = false;		
	}
	
	$clock->register("post count");
	
	echo "<!-- Total num: $total_num //-->\n"; flush();
		
		
	/* if there are more messages than will be displayed,
	 		create an index array, sort, 
	 		then figure out which messages to fetch 
	*/
	if (($total_num - $num_show) > 0){
		//attempt ot read from cache
		$read_cache = false;
		if (file_exists(realpath($CACHE_DIR))){
			$cache_path = $CACHE_DIR.ereg_replace("[\\/]", "", $loginID.".".$host);
			$index_a = main_ReadCache($cache_path, $folder, $messages_str, $sort_field, $read_cache);
		}
		//if there are "recent" messages, ignore cache
	    if ($ICL_CAPABILITY["radar"]){
			$recent=iil_C_CheckForRecent($conn, $folder);
			if ($recent > 0) $read_cache = false;
		}
		
		//if not read from cache, go to server
		if (!$read_cache){
			$index_a=iil_C_FetchHeaderIndex($conn, $folder, $messages_str, $sort_field);
			$clock->register("post index: no cache");
		}else{
			$clock->register("post index: cache");
		}
		
		if ($index_a===false){
			//echo "iil_C_FetchHeaderIndex failed<br>\n";
            if (strcasecmp($sort_field,"date")==0){
                if (strcasecmp($sort_order, "ASC")==0){
                    $messages_str = $start.":".($start + $num_show);
                }else{
                    $messages_str = ($total_num - $start - $num_show).":".($total_num - $start);
                }
                //echo $messages_str; flush();
                $index_failed = false;
            }else{
                $index_failed = true;
            }
		}else{
			if ((!$read_cache) && (file_exists(realpath($CACHE_DIR))))
				main_WriteCache($cache_path, $folder, $sort_field, $index_a, $messages_str);

			if (strcasecmp($sort_order, "ASC")==0) asort($index_a);
			else if (strcasecmp($sort_order, "DESC")==0) arsort($index_a);
			
			reset($index_a);
			$i=0;
			while (list($key, $val) = each ($index_a)){
				if (($i >= $start) && ($i < $next_start)) $id_a[$i]=$key;
				$i++;
			}
			if (is_array($id_a)) $messages_str=implode(",", $id_a);

		}
		
		
		echo "<!-- Indexed: $index_a //-->"; flush();
	}
	
	$clock->register("post index");

	/* fetch headers */
	if ($messages_str!=""){
		//echo "Messages: $messages_str <br>\n";
		$headers=iil_C_FetchHeaders($conn, $folder, $messages_str);
		$headers=iil_SortHeaders($headers, $sort_field, $sort_order);  //if not from index array
	}else{
		$headers=false;
	}
	
	$clock->register("post headers");
	echo "<!-- Headers fetched: $headers //-->\n"; flush();
	
	/* if indexing failed, we need to get messages within range */
	if ($index_failed){
		$i = 0;
		$new_header_a=array();
		reset($headers);
		while ( list($k, $h) = each($headers) ){
			if (($i >= $start) && ($i < $next_start)){
				$new_header_a[$k] = $headers[$k];
				//echo "<br>Showing $i : ".$h->id;
			}
			$i++;
		}
		$headers = $new_header_a;
	}
		
	/*  start form */
	echo "\n<form name=\"messages\" method=\"POST\" action=\"main.php\">\n";			

	/* Show folder name, num messages, page selection pop-up */
	
	if ($headers==false) $headers=array();
	echo "<table width=\"100%\" cellpadding=2 cellspacing=0><tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
	echo "<td align=left valign=bottom>\n";
		$disp_folderName = $defaults[$folder];
		if (empty($disp_folderName)){
			$disp_folderName = $folder;
			if (iil_StartsWith($disp_folderName, $my_prefs["rootdir"])){
				$disp_folderName = substr($disp_folderName, strlen($my_prefs["rootdir"])+1);
			}
		}
		if (empty($search)){
			echo "<span class=\"bigTitle\">";
			echo iil_utf7_decode($disp_folderName);
			echo "</span>\n";
		}
		echo "<span class=\"mainHeadingSmall\">\n";
		if (strcasecmp("INBOX", $folder)==0)
			echo "[<a href=\"main.php?user=$user&folder=$folder\" class=\"mainHeadingSmall\">".$mainStrings[17]."</a>]";
        if (strcmp($folder,$my_prefs["trash_name"])!=0)
			echo "[<a href=\"main.php?user=$user&folder=$folder&delete_all=1\" class=\"mainHeadingSmall\">".$mainStrings[18]."</a>]";
		echo "</span>\n";
	echo "</td>\n";
	echo "<td align=\"right\" valign=\"bottom\" class=\"mainHeadingSmall\">";
		//show quota
		if ($my_prefs["show_quota"]=="m"){
			$quota = iil_C_GetQuota($conn);
			include("../lang/".$my_prefs["lang"]."quota.inc");
			if ($quota) echo $quotaStr["label"].LangInsertStringsFromAK($quotaStr["full"], $quota);
			else echo $quotaStr["label"].$quotaStr["unknown"];
		}
	echo "</td>\n";
	echo "</tr></table>";
	
	/* Confirm "delete all" request */
	if ($delete_all==1){
		echo "<p>".str_replace("%f", $folder, $mainErrors[7]);
		echo "<span class=\"small\">[<a href=\"main.php?user=$user&folder=$folder&delete_all=2&delete_all_num=$total_num&submit=Delete\">";
			echo $mainStrings[18]."</a>]</span>";
		echo "<span class=\"small\">[<a href=\"main.php?user=$user&folder=$folder\">".$mainStrings[19]."</a>]</span>";
	}
	
	
	/* Show error messages, and reports */
	if (!empty($error)) echo "<p><center><span style=\"color: red\">$error</span></center>";
	//if ((empty($error)) && (empty($report))) echo "<p>";


	$c_date["day"]=GetCurrentDay();
	$c_date["month"]=GetCurrentMonth();
	$c_date["year"]=GetCurrentYear();

	if (count($headers)>0) {
		if (!isset($start)) $start=0;
		$i=0;

		if (sizeof($headers)>0){			
			/*  show "To" field or "From" field? */
			if ($folder==$my_prefs["sent_box_name"]){
				$showto=true;
				$fromheading=$mainStrings[7];
			}else{
				$fromheading=$mainStrings[8];
			}			


			/*  show num msgs and any notices */
			echo "<table width=\"100%\"><tr>";
			echo "<td valign=bottom align=\"left\"><span class=\"mainLightSmall\">";

			echo str_replace("%p", ($num_show>$total_num?$total_num:$num_show), str_replace("%n", $total_num, $mainStrings[0]))."&nbsp;";
			
			echo "</span</td>";
			echo "<td align=center><span class=\"mainLightSmall\">";
			if (!empty($report)) echo $report;
			echo "</span></td>\n";
			echo "<td valign=bottom align=right class=\"mainLightSmall\">";
			//page controls
			$num_items=$total_num;
			if ($num_items > $num_show){
				if ($prev_start < $start){
					$args = "&sort_field=$sort_field&sort_order=$sort_order&start=$prev_start";
					if (!empty($search_criteria)) $args .= "&search_criteria=".urlencode($search_criteria);
					echo "[<a href=\"main.php?user=$sid&folder=".urlencode($folder).$args."\" class=\"mainLightSmall\">";
					echo $mainStrings[2]." $num_show".$mainStrings[3]."</a>]";
				}

				if ($next_start<$num_items){
					$num_next_str = $num_show;
					if (($num_items - $next_start) < $num_show) $num_next_str = $num_items - $next_start;
					$args = "&sort_field=$sort_field&sort_order=$sort_order&start=$next_start";
					if (!empty($search_criteria)) $args .= "&search_criteria=".urlencode($search_criteria);
					echo "[<a href=\"main.php?user=$sid&folder=".urlencode($folder).$args."\" class=\"mainLightSmall\">";
					echo $mainStrings[4]." $num_next_str".$mainStrings[5]."</a>]";
				}

				echo "<select name=start class=\"small\">\n";
					$c=0;
					while ($c < $total_num){
						$c2=($c + $num_show);
						if ($c2 > $total_num) $c2=$total_num;
						echo "<option value=".$c.($c==$start?" SELECTED":"").">".($c+1)."-".$c2."\n";
						$c = $c + $num_show;
					}
				echo "</select>";
				echo "<input type=submit value=\"".$mainStrings[16]."\">";
				
			}
			echo "</td>\n";
			echo "</tr></table>\n";

			$clock->register("pre list");

			/***
			Show tool bar
			***/
			if (strpos($my_prefs["main_toolbar"], "t")!==false){
				include("../include/main_tools.inc");
			}

			/* main list */
			$num_cols = strlen($my_prefs["main_cols"]);
			echo "\n<!-- MAIN LIST //-->\n";
			echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"".$my_colors["main_hilite"]."\">\n";
			echo "<tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
				$check_link="<SCRIPT type=\"text/javascript\" language=JavaScript1.2><!-- Make old browsers think this is a comment.\n";
				$check_link.="document.write(\"<a href=javascript:SelectAllMessages(true) class='tblheader'><b>+</b></a><span class=tblheader>|</span><a href=javascript:SelectAllMessages(false) class=tblheader><b>-</b></a>\")";
				$check_link.="\n--></SCRIPT><NOSCRIPT>";
				$check_link.="<a href=\"main.php?folder=".urlencode($folder)."&start=$start&user=$user&sort_field=$sort_field&sort_order=$sort_order&check_all=1\"><b>+</b></a>|";
 				$check_link.="<a href=\"main.php?folder=".urlencode($folder)."&start=$start&user=$user&sort_field=$sort_field&sort_order=$sort_order&uncheck_all=1\"><b>-</b></a>";
				$check_link.="</NOSCRIPT>";
				$tbl_header["c"] = "\n<td>$check_link</td>";
				$tbl_header["s"] = "\n<td>".FormFieldHeader("subject", $mainStrings[6])."</td>";
				if ($showto)
					$tbl_header["f"] = "\n<td>".FormFieldHeader("to", $fromheading)."</td>";
				else
					$tbl_header["f"] = "\n<td>".FormFieldHeader("from", $fromheading)."</td>";
				$tbl_header["d"] = "\n<td>".FormFieldHeader("date", $mainStrings[9])."</td>";
				$tbl_header["z"] = "\n<td>".FormFieldHeader("size", $mainStrings[14])."</td>";
				$tbl_header["a"] = "<td><img src=\"themes/".$my_prefs["theme"]."/images/att.gif\"></td>";
				$tbl_header["m"] = "<td><img src=\"themes/".$my_prefs["theme"]."/images/reply.gif\"></td>";
				for ($i=0;$i<$num_cols;$i++) echo $tbl_header[$my_prefs["main_cols"][$i]];
			echo "\n</tr>\n";
			if ($MOVE_FIELDS){
				echo "<tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
				$base_url = "main.php?folder=".urlencode($folder)."&start=$start&user=$user&sort_field=$sort_field&sort_order=$sort_order";
				$base_url.= "&MOVE_FIELDS=1";
				for ($i=0;$i<$num_cols;$i++) echo ShowFieldControls($my_prefs["main_cols"][$i], $base_url, $i, $num_cols);
				echo "</tr>\n";
			}
			$display_i=0;
			$prev_id = "";
			while (list ($key,$val) = each ($headers)) {
				//$next_id = $headers[key($headers)]->id;
				$header = $headers[$key];
				$id = $header->id;
				$seen = ($header->seen?"Y":"N");
				$deleted = ($header->deleted?"D":"");
				if (($id>0) && (($showdeleted==0)&&($deleted!="D")) || ($showdeleted)){
					if (($hideseen==0)||($seen=="N")){
						$display_i++;
						//echo "\n<tr ".(($i % 2)==0?"bgcolor=\"$bgc\"":"").">\n";
						
						echo "\n<tr bgcolor=\"".$my_colors["main_bg"]."\">\n";
						
						//show checkbox
						$row["c"] = "<td><input type=\"checkbox\" name=\"checkboxes[]\" value=\"$id\" ";
						$row["c"].= (isset($check_all)?"CHECKED":"");
						if (!isset($uncheck_all)) $row["c"].=(($spam) && (isSpam($header->Subject)>0) ? "CHECKED":"");
						if (is_array($selected_boxes) && in_array($id, $selected_boxes)) $row["c"].="CHECKED";
						$row["c"].= "></td>\n";
						//echo $row["c"];
						
						//show subject
						$subject=trim(chop($header->subject));
						if (empty($subject)) $subject=$mainStrings[15];
						$args = "user=$user&folder=".urlencode($folder)."&id=$id&uid=".$header->uid."&start=$start";
						$args.= "&num_msgs=$total_num&sort_field=$sort_field&sort_order=$sort_order";
						$row["s"] = "<td><a href=\"read_message.php?".$args."\" ";
						$row["s"].= ($my_prefs["view_inside"]!=1?"target=\"scr".$user.urlencode($folder).$id."\"":"").">".($seen=="N"?"<B>":"");
						$row["s"].= encodeUTFSafeHTML(LangDecodeSubject($subject, $my_prefs["charset"])).($seen=="N"?"</B>":"")."</a></td>\n";
						//echo $row["s"];
						
						//show sender||recipient
						if ($showto) $row["f"] = "<td>".LangDecodeAddressList($header->to, $my_prefs["charset"], $user)."</td>\n";						
						else $row["f"] = "<td>".LangDecodeAddressList($header->from, $my_prefs["charset"], $user)."</td>\n";
						//echo $row["f"];

						//show date/time
						$timestamp = $header->timestamp;
						$timestamp = $timestamp + ((int)$my_prefs["timezone"] * 3600);
						$row["d"] = "<td><nobr>".ShowShortDate($timestamp, $lang_datetime)."&nbsp;</nobr></td>\n";
						//echo $row["d"];

						//show size
						$row["z"] = "<td><nobr>".ShowBytes($header->size)."</nobr></td>\n";

						//attachments?
						$row["a"] = "<td>";
						if (preg_match("/multipart\/m/i", $header->ctype)==TRUE){
							$row["a"].= "<img src=\"themes/".$my_prefs["theme"]."/images/att.gif\">";
						}
						$row["a"].= "</td>\n";
						//echo $row["a"];

						//show flags
						$row["m"] = "<td>".($header->deleted?"D":"").($header->answered?"<img src=\"themes/".$my_prefs["theme"]."/images/reply.gif\">":"&nbsp;")."</td>\n";
						//echo $row["a"];
						
						for ($i=0;$i<$num_cols;$i++) echo $row[$my_prefs["main_cols"][$i]];
						
						echo "</tr>\n";
						flush();
					}
				}
				$i++;
			}
			echo "</table>";

			flush();
			
			$clock->register("post list: $i");
			
			echo "<input type=\"hidden\" name=\"user\" value=\"$user\">\n";
			echo "<input type=\"hidden\" name=\"folder\" value=\"$folder\">\n";
			echo "<input type=hidden name=\"sort_field\" value=\"".$sort_field."\">\n";
			echo "<input type=hidden name=\"sort_order\" value=\"".$sort_order."\">\n";
			if (isset($search)) echo "<input type=hidden name=search_done value=1>\n";
			echo "<input type=\"hidden\" name=\"max_messages\" value=\"".$display_i."\">\n";
			
			/***
			Show tool bar
			***/
			if (strpos($my_prefs["main_toolbar"], "b")!==false){
				$clock->register("pre tools include");
				include("../include/main_tools.inc");
				$clock->register("post tools include");
			}
			
			echo "</form>\n";
			
			if (($folder=="INBOX")&&($ICL_CAPABILITY["radar"])){
				/*** THIS JavaScript code does NOT run reliably!! ***/
				echo "\n<script language=\"JavaScript\">\n";
				echo "if (parent.radar)";
				echo "  parent.radar.location=\"radar.php?user=".$user."\";\n";
				echo "</script>\n";
			}
			if (($ICL_CAPABILITY["folders"]) && ($my_prefs["list_folders"]) && ($my_prefs["showNumUnread"]) && ($reload_folders)){
				echo "\n<script language=\"JavaScript\">\n";
				echo "parent.list1.location=\"folders.php?user=".$user."\";\n";
				echo "</script>\n";
			}
		}else{
			if (!empty($search)) echo "<p><center>".$mainErrors[0]."</center>";
			else echo "<p><center><span class=mainLight>".$mainErrors[1]."</span></center>";
		}
	}else{
		if (!empty($search)) echo "<p><center><span class=mainLight>".$mainErrors[0]."</span></center>";
		else echo "<p><center><span class=mainLight>".$mainErrors[1]."</span></center>";
	}
	
	iil_Close($conn);

$clock->register("done");
$exec_finish_time = microtime();
echo '<!-- execution time: '.$exec_start_time.' ~ '.$exec_finish_time.' -->';
echo "\n<!--\n";
$clock->dump();
echo "\n//-->\n";
?>
</BODY></HTML>