<?
require_once('include/global.php');
require_once("include/file.php");
require_once('conf.inc.php');



// debug only
	if (!$_POST['q']) $_POST['q'] = $_GET['q'];		 #echo '<xmp>';


// get
	$mail_file_table = $AUTH[auth_m_mf_table];

	$_names = array();
	if ($_POST['q'] != '')
	{
		$_ex = explode('|', $_POST['q']);
		for ($e=0; $e<sizeof($_ex); $e++)
		{
			$mf_no = $_ex[$e];
			if (is_numeric($mf_no))
			{
				$sql = "
					SELECT
						mf_no, mf_arrival_date, mf_subject, mf_from, mf_to, mb_id, mf_filesize
					FROM
						$mail_file_table
					WHERE
						mf_no='" . $mf_no . "'
						AND m_no='" . $AUTH['auth_m_no'] . "'
						AND mb_id='". $_POST['mb_id']. "'
					";
				$row = db_get_row($sql);

				if ($row)
				{
					for ($j=0; $j<9999999; $j++)
					{
						if ($j > 0)
						{
							$_name = get_mail_box_backup_filename($row['mf_arrival_date'], $row['mf_subject'], $row['mf_from'], $row['mf_to'], $row['mb_id']).' ('.$j.').eml';
						} else 
						{
							$_name = get_mail_box_backup_filename($row['mf_arrival_date'], $row['mf_subject'], $row['mf_from'], $row['mf_to'], $row['mb_id']).'.eml';
						}	// if()
						if (!in_array($_name, $_names))
							break;							
					}	// for()
					$_names[] = $_name;

					echo $row['mf_no'].'|'.$_name.'|'.$row['mf_filesize'];
					echo "|!|";
				}	// if()

			}	// if()
		}	// for()
	}	// if()


//require_once('include/global_end.php');
?>