MIL001_m.php 19.3 KB
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
<?php 
//*****************************************************************************
//* 
//* プログラム名:Webメール(携帯電話)
//* プログラムID:MIL001_m.php
//* 機能        :
//* 作成者      :
//* 
//*****************************************************************************

	header("Content-type: text/html; charset=Shift_JIS");

	//*** 共通処理 ***//
	include("include_m/CommonProcess.inc");

	$syain_cd = $PHP_SYAIN_CD;

//	require_once "include_m/MIL001_m.inc";
//	require_once "include_m/MIL002_m.inc";

	//*** 関数表示 ***//
	require_once "include_m/jcode.phps";
	require_once "include_m/MIL001.inc";
	require_once "include_m/MIL002.inc";

	/* ヘッダと本文を分割する */
	function mime_split($data) {
		$part = split("\r\n\r\n", $data, 2);
		$maxbyte = 10000000; //10MB
		return $part;
	}

	/* 文字コードコンバートJIS→SJIS */
	function convert($str) {
		if (function_exists('mb_convert_encoding')) {
			return mb_convert_encoding($str, "SJIS", "JIS,SJIS");
		}elseif (function_exists('JcodeConvert')) {
			return JcodeConvert($str, 0, 2);
		}
		return true;
	}

	$strSQLIns="";
	$objRecIns="null";
	$strSQLseq="";
	$objRecseq="null";
	$strSQLup="";
	$objRecup="null";
	$strSQL="";
	$objRec="null";

	$strSQLseq="Select syain_cd,mail_add,smtp_add,pop3_add,mail_name,mail_pass ".
				" from mail_TBL Where syain_cd='".$syain_cd."'";
	$objRecseq = pg_exec($strSQLseq);
	if($objRecseq==false){
			echo("SQL実行に失敗しました(SELECT)");
			exit;
	}
	if (pg_numrows($objRecseq) > 0){
			$objmail = pg_fetch_object($objRecseq, 0);
			$strMailAdd=$objmail->mail_add;
			$intSrvadd=$objmail->pop3_add;
			$strUserName=$objmail->mail_name;
			$strPASSWORD=$objmail->mail_pass;
			
			// 登録サーバー名取得
			$strSQLseq="Select * from mailAdmin_TBL Where srv_id=".$intSrvadd." and srv_flg=2";
			$objRecseq = pg_exec($strSQLseq);
			if($objRecseq==false){
					echo("SQL実行に失敗しました(SELECT)");
					exit;
			}
			if (pg_numrows($objRecseq) > 0){
				 $objmail = pg_fetch_object($objRecseq, 0);
				 $strSrvName=$objmail->srv_add;
			}else{
					$sock=-1;
			}
			$p = new pop3($strSrvName, $strUserName, $strPASSWORD);
			if (!$p->open()) {
				 $sock=-2;
			}
	}else{
			$sock=-1;
	}
	
	if($edit_flg==1){
			$sock=-1;
	}

	 if($sock==-1 || $sock==-2 ){
?>
	 <html>
	 <body>
<?php  //メニュー 
	 if($sock==-2){
					echo "<br> アカウントの設定がされていません<br>";
	 }
?>	<HR width="100%">
	 </body>
	 </html>
<?php 
	 }else{
			//*** 新規メール取得 ***//
			$strSQLseq="Select syain_cd,mail_add,smtp_add,pop3_add,mail_name,mail_pass from mail_TBL Where syain_cd='".$PHP_SYAIN_CD."'";
			$objRecseq = pg_exec($strSQLseq);
			if ($objRecseq==false){
					echo("SQL実行に失敗しました(SELECT)");
					exit;
			}
			if (pg_numrows($objRecseq) > 0){
					$objmail = pg_fetch_object($objRecseq, 0);
					$strMailAdd=$objmail->mail_add;
					$intSrvadd=$objmail->pop3_add;
					$strUserName=$objmail->mail_name;
					$strPASSWORD=$objmail->mail_pass;

					// 登録サーバー名取得
					$strSQLseq="Select * from mailAdmin_TBL Where srv_id=".$intSrvadd." and srv_flg=2";
					$objRecseq = pg_exec($strSQLseq);
					if ($objRecseq==false){
							echo("SQL実行に失敗しました(SELECT)");
							exit;
					}
					if (pg_numrows($objRecseq) > 0){
							$objmail = pg_fetch_object($objRecseq, 0);
							$strSrvName=$objmail->srv_add;
					}else{
							$sock=-1;
					}
		   }

			// Create pop3 object
			$p = new pop3($strSrvName, $strUserName, $strPASSWORD);
			$p->apop = $use_apop;

			// Connect to pop3 server
			if (!$p->open()) {
				html_exit('<BR><span class="largefont">サーバーにログイン出来ませんでした</span><BR>');
			}

			list($total_num, $total_size) = $p->get_stat();
			$list = $p->get_list();
			$uid  = $p->get_uidl();

			//$tmpdir = "../../".$PHP_FOLDER."/temp/mail/";
			$tmpdir  = "../temp/".$PHP_FOLDER."/mail/";

			//サーバ内の全メール取得
			$init_num = $total_num;

			//文字化け対策
			if (function_exists("mb_internal_encoding")) {
				mb_internal_encoding("EUC");
			}

			$strMILSQL="Select send_flg8,send_flg9 from sendinfo_tbl Where syain_cd='$PHP_SYAIN_CD'";
			$objMILData = pg_exec($strMILSQL);
			if($objMILData==false){
				echo("SQL実行に失敗しました(SELECT)");
				exit;
			}
			$delmail_flg=0;
			if (pg_numrows($objMILData) > 0){
				$objchkMail = pg_fetch_object($objMILData, 0);
				$delmail_flg  = $objchkMail->send_flg9;
				$dispmail_flg = $objchkMail->send_flg8;
				if (($dispmail_flg=="NULL") || ($dispmail_flg=="0")){
					$dispmail_flg=10;
				}
			}else{
				$delmail_flg=0;
				$dispmail_flg=10;
			}
			//メールサーバからDBにインサート
			for ($num = $init_num; $num > 0; --$num) {
					$header = $p->head($num);
					if (!$header) {
						continue;
					}

					$header_list = parse_header($header);
					$mail_size = $list[$num];
					//DBに既に存在するか確認
					$strSQLchk="Select mail_id,del_flg from mail_get_tbl Where mail_id ='".addslashes($uid[$num])."' and syain_cd='$PHP_SYAIN_CD'";
					$objRecchk = pg_exec($strSQLchk);
					if($objRecchk==false){
						echo("SQL実行に失敗しました(SELECT)");
						exit;
					}

					if (pg_numrows($objRecchk) == 0 ){
							$temp_flg=0;
							//fromチェック
							if (isset($header_list['from'])) {
								//$from=decode_mimeheader(get_name($header_list['from']), 1);
								$str_From=decode_mimeheader(get_name($header_list['from']), 1);
								$str_From=ereg_replace("[\'\"\;]", "", $str_From);
								$str_Addr=decode_mimeheader($header_list['from'], 1);
								$str_Addr=ereg_replace("[\'\"\;]", "", $str_Addr);
								$str_Addr= str_replace("\"","",$str_Addr);
								$intpoint = strlen($str_From);            
								$str_Addr = trim(substr($str_Addr,$intpoint));            
								if (substr($str_Addr,0,1)=="@"){
									$str_Addr = htmlspecialchars(decode_mimeheader($header_list['from'], 1), ENT_QUOTES);
								}
							} else {
								$str_From= '(Unknown)';
								$str_Addr = "";
							}
							if (isset($header_list['cc'])) {
								$to=decode_mimeheader(get_name($header_list['to']), 1);
							} else {
								$to= '(Unknown)';
							}
							if (isset($header_list['subject'])) {
								$subject = decode_mimeheader($header_list['subject'], 1);
								if(trim($subject)==""){
									$subject='(no subject)';
								}
							}
							$date=format_date2($header_list['date']);
							$u_id=$uid[$num];

							if ($num < 1) {
								echo 'メッセージは見つかりませんでした。';
								return;
							}

							$data = $p->retr($num);
							if (!$data) {
								echo 'メッセージを見つけることができませんでした。';
								//return;
							}
							list($raw_header, $body) = split("\r?\n\r?\n", $data, 2);    
							$sbody = $body;

							$strheader=$raw_header;

							$header_list = parse_header($raw_header);
							$header_list_html = parse_header($raw_header);
							if (!isset($header_list['content-type'])) {
							}
							$ctype = parse_ctype($header_list['content-type']);

							if (strtolower($ctype['type']) == 'multipart') {

									$boundary = $ctype['param']['boundary'];
									if($boundary==""){
										$mbody[0]="";
										$mbody[1]="";
										$mbody[2]=$data;
									}else{
										$mbody= split("--".$boundary,$body);
									}

									//BODY部情報取得
									list($chk_header_html, $chk_body_html) = split("\r?\n\r?\n", $mbody[2], 2);
									$chk_header_list = parse_header($chk_header_html);
									$chk_ctype_html = parse_ctype($chk_header_list['content-type']);

									$nomiFlg=0;
									if ($chk_ctype_html['type']=="html" || $chk_ctype_html['subtype']=="html"){
										list($raw_header_html, $body_html) = split("\r?\n\r?\n", $mbody[2], 2);
										$header_list_html = parse_header($raw_header_html);
										$body=$body_html;
										$nomiFlg=1;

									}else{
										//添付付メール
										list($tmp_raw_header_html, $tmp_body_html) = split("\r?\n\r?\n", $mbody[1], 2);
										$tmp_header_list_html = parse_header($tmp_raw_header_html);
										$tmp_ctype_html = parse_ctype($tmp_header_list_html['content-type']);

										$tmp_boundary = $tmp_ctype_html['param']['boundary'];
										$tmp_body= split("--".$tmp_boundary,$tmp_body_html);

										list($tmp1_raw_header_html, $tmp1_body_html) = split("\r?\n\r?\n", $tmp_body[1], 2);
										$tmp1_header_list_html = parse_header($tmp1_raw_header_html);
										$tmp1_ctype_html = parse_ctype($tmp1_header_list_html['content-type']);
										$tmp1_boundary = $tmp1_ctype_html['param']['boundary'];
										$tmp3_body= split("--".$tmp1_boundary,$tmp1_body_html);

										list($tmp2_raw_header_html, $tmp2_body_html) = split("\r?\n\r?\n", $tmp_body[2], 2);
										$tmp2_header_list_html = parse_header($tmp2_raw_header_html);
										$tmp2_ctype_html = parse_ctype($tmp2_header_list_html['content-type']);

										list($tmp3_raw_header_html, $tmp3_body_html) = split("\r?\n\r?\n", $tmp3_body[2], 2);
										$tmp3_header_list_html = parse_header($tmp3_raw_header_html);
										$tmp3_ctype_html = parse_ctype($tmp3_header_list_html['content-type']);

										if ($tmp1_ctype_html['type']=="html" || $tmp1_ctype_html['subtype']=="html"){
											$header_list_html = parse_header($tmp1_raw_header_html);
											$body=$tmp1_body_html;
										}else if ($tmp2_ctype_html['type']=="html" || $tmp2_ctype_html['subtype']=="html"){
											$header_list_html = parse_header($tmp2_raw_header_html);
											$body=$tmp2_body_html;
										}else if ($tmp3_ctype_html['type']=="html" || $tmp3_ctype_html['subtype']=="html"){
											$header_list_html = parse_header($tmp3_raw_header_html);
											$body=$tmp3_body_html;
										}else{
											$body=$tmp_body_html;
											$header_list_html = parse_header($tmp_raw_header_html);
										}
									}

									if ($nomiFlg!=1){
										//本文設定
										if($mail_size<10000000){
											//添付ファイル設定
											for($j=2;$j < (count($mbody)-1);++$j){
												list($m_head, $m_body) = mime_split($mbody[$j]);
												$m_body = ereg_replace("\r\n\.\r\n$", "", $m_body) ;
												$m_head = ereg_replace("[[:space:]]", "", $m_head) ;  
												if (!eregi("Content-Location:", $m_head)) {
													if (!eregi("Content-type: *([^;\n]+)", $m_head, $type)) continue;
															list($main, $sub) = explode("/", $type[1]);
															// ファイル名を抽出
															if (eregi("name=\"?([^\"\n]+)\"?",$m_head, $filereg)) {
																	$tempname[$j] =  ereg_replace("[\t\r\n]", "", $filereg[1]);
																	//echo $tempname[$j];
																	$tempname_temp =$tempname[$j];
																	while (eregi("(.*)=\?iso-2022-jp\?B\?([^\?]+)\?=(.*)",$tempname[$j],$regs)) {
																		$tempname[$j] = $regs[1].base64_decode($regs[2]).$regs[3];
																	}
																	$tempname[$j] = convert($tempname[$j]);
																	if ($temp_flg==0){
																		if (trim($tempname[$j]) != ""){
																			$temp_flg=1;
																		}
																	}
																	if (!$original) $tempname[$j] = $tempname[$j];
															}
															// 添付データをデコードして保存
															$maxbyte = 10000000; //1MB
															// 保存しないファイル(正規表現)
															//$tmpdir  = "../../".$PHP_FOLDER."/temp/mail/";
															$tmpdir  = "../temp/".$PHP_FOLDER."/mail/";
															//echo "<textarea>".$mbody[$j]."<textarea>";
															if (eregi("Content-Transfer-Encoding:.*base64", $m_head)) {
																	$tmp = base64_decode($m_body);
																	$mail_id=$_GET['view_uid'];
																	$strSQLseq="Select * from mail_temp_tbl Where syain_cd='$PHP_SYAIN_CD' and mail_id='".addslashes($u_id)."' and temp_index=".($j-1);
																	$objRecseq = pg_exec($strSQLseq);
																	if (pg_numrows($objRecseq) == 0){
																		$strSQLseq="Insert Into mail_temp_tbl values('$PHP_SYAIN_CD','$u_id',".($j-1).",'".addslashes(JCodeConvert($tempname[$j], 2, 1))."')";
																		//メール添付取得
																		$objRecseq = pg_exec($strSQLseq);
																	}
																	$fp = fopen($tmpdir.$PHP_SYAIN_CD."-".($j-1)."-".$u_id, "w");
																	fputs($fp, $tmp);
																	fclose($fp);
																	$ByteOver[$j]=0;

															}else if(eregi("Content-Transfer-Encoding:.*7bit", $m_head)){
																	$tmp = $m_body;
																	$mail_id=$_GET['view_uid'];
																	$strSQLseq="Select * from mail_temp_tbl Where syain_cd='$PHP_SYAIN_CD' and mail_id='".addslashes($u_id)."' and temp_index=".($j-1);
																	$objRecseq = pg_exec($strSQLseq);
																	if (pg_numrows($objRecseq) == 0){
																		$strSQLseq="Insert Into mail_temp_tbl values('$PHP_SYAIN_CD','$u_id',".($j-1).",'".addslashes(JCodeConvert($tempname[$j], 2, 1))."')";
																		//メール添付取得
																		$objRecseq = pg_exec($strSQLseq);
																	}
																	$fp = fopen($tmpdir.$PHP_SYAIN_CD."-".($j-1)."-".$u_id, "w");
																	fputs($fp, $tmp);
																	fclose($fp);
																	$ByteOver[$j]=0;

															}else if(eregi("Content-Transfer-Encoding:.*quoted-printable", $m_head)){
																	$tmp = $m_body;
																	$mail_id=$_GET['view_uid'];
																	$strSQLseq="Select * from mail_temp_tbl Where syain_cd='$PHP_SYAIN_CD' and mail_id='".addslashes($u_id)."' and temp_index=".($j-1);
																	$objRecseq = pg_exec($strSQLseq);
																	if (pg_numrows($objRecseq) == 0){
																		$strSQLseq="Insert Into mail_temp_tbl values('$PHP_SYAIN_CD','$u_id',".($j-1).",'".addslashes(JCodeConvert($tempname[$j], 2, 1))."')";
																		//メール添付取得
																		$objRecseq = pg_exec($strSQLseq);
																	}
																	$fp = fopen($tmpdir.$PHP_SYAIN_CD."-".($j-1)."-".$u_id, "w");
																	fputs($fp, $tmp);
																	fclose($fp);
																	$ByteOver[$j]=0;
															}
												}
									}
							}else{
									//サイズオーバー
									$mail_id=$_GET['view_uid'];
									$strSQLseq="Select * from mail_temp_tbl Where syain_cd='$PHP_SYAIN_CD' and mail_id='".addslashes($u_id)."' and temp_index=1";
									$objRecseq = pg_exec($strSQLseq);
									if (pg_numrows($objRecseq) == 0){
										//20110513 修正
										$msg = mb_convert_encoding("※10MB以上の添付ファイルは受信できません", "EUC-JP", "SJIS");
										$strSQLseq="Insert Into mail_temp_tbl values('$PHP_SYAIN_CD','$u_id',1,'$msg')";
										//$strSQLseq="Insert Into mail_temp_tbl values('$PHP_SYAIN_CD','$u_id',1,'※10MB以上の添付ファイルは受信できません')";
										//メール添付取得
										$objRecseq = pg_exec($strSQLseq);
										if($objRecseq==false){
											echo("SQL実行に失敗しました(SELECT)");
											exit;
										}
									}
							}
						}
						$nomiFlg=0;
						$mail_size = 0;
					}else{
						//echo $subject;
						//echo "<textarea>".$raw_header."</textarea>";
						//echo "<textarea>".$body."</textarea>";
						$j=1;
						$m_head = $raw_header; $m_body = $body;
						$body = $sbody;
						if ($ctype['type']!="html" && $ctype['subtype']!="html"){
							$body=$body;
						}
						//echo "<textarea>".$body."</textarea>";
						$m_body = ereg_replace("\r\n\.\r\n$", "", $m_body) ;
						$m_head = ereg_replace("[[:space:]]", "", $m_head) ;  
						if (!eregi("Content-type: *([^;\n]+)", $m_head, $type)){
							list($main, $sub) = explode("/", $type[1]);
							// ファイル名を抽出
							if (eregi("name=\"?([^\"\n]+)\"?",$m_head, $filereg)) {
								$tempname[$j] =  ereg_replace("[\t\r\n]", "", $filereg[1]);
								while (eregi("(.*)=\?iso-2022-jp\?B\?([^\?]+)\?=(.*)",$tempname[$j],$regs)) {
									$tempname[$j] = $regs[1].base64_decode($regs[2]).$regs[3];
								}
								$tempname[$j] = convert($tempname[$j]);

								if ($temp_flg==0){
									if (trim($tempname[$j]) != ""){
										$temp_flg=1;
									}
								}
							if (!$original) $tempname[$j] = $tempname[$j];
							}
							// 添付データをデコードして保存
							$maxbyte = 10000000; //1MB
							//$tmpdir  = "../../".$PHP_FOLDER."/temp/mail/";
							$tmpdir  = "../temp/".$PHP_FOLDER."/mail/";
							if (eregi("Content-Transfer-Encoding:.*base64", $m_head)) {
								$tmp = base64_decode($m_body);
								$mail_id=$_GET['view_uid'];
								$strSQLseq="Select * from mail_temp_tbl Where syain_cd='$PHP_SYAIN_CD' and mail_id='".addslashes($u_id)."' and temp_index=".($j);
								$objRecseq = pg_exec($strSQLseq);
								if (pg_numrows($objRecseq) == 0){
									$strSQLseq="Insert Into mail_temp_tbl values('$PHP_SYAIN_CD','$u_id',".($j).",'".addslashes(JCodeConvert($tempname[$j], 2, 1))."')";
									//メール添付取得
									$objRecseq = @pg_exec($strSQLseq);
									if($objRecseq==false){
										//echo("SQL実行に失敗しました(SELECT)");
										//exit;
									}
								}
								$fp = fopen($tmpdir.$PHP_SYAIN_CD."-".($j)."-".$u_id, "w");
								fputs($fp, $tmp);
								fclose($fp);
								$ByteOver[$j]=0;
							}else if(eregi("Content-Transfer-Encoding:.*quoted-printable", $m_head)){
								$tmp = $m_body;
								$mail_id=$_GET['view_uid'];
								$strSQLseq="Select * from mail_temp_tbl Where syain_cd='$PHP_SYAIN_CD' and mail_id='".addslashes($u_id)."' and temp_index=".($j-1);
								$objRecseq = pg_exec($strSQLseq);
								if (pg_numrows($objRecseq) == 0){
									$strSQLseq="Insert Into mail_temp_tbl values('$PHP_SYAIN_CD','$u_id',".($j-1).",'".addslashes(JCodeConvert($tempname[$j], 2, 1))."')";
									//メール添付取得
									$objRecseq = pg_exec($strSQLseq);
									if($objRecseq==false){
										//echo("SQL実行に失敗しました(SELECT)");
										//exit;
									}
								}
								$fp = fopen($tmpdir.$PHP_SYAIN_CD."-".($j-1)."-".$u_id, "w");
								fputs($fp, $tmp);
								fclose($fp);
								$ByteOver[$j]=0;
							}
						}
					}
					// Check charset
					if (isset($ctype['param']['charset'])) {
						$jc_from = check_jcode_encoding($ctype['param']['charset']);
					} else {
						$jc_from = 0;
					}

					// Check encoding and decode body
					if (isset($header_list_html['content-transfer-encoding'])) {
						$body = decode_body($body, $header_list_html['content-transfer-encoding']);
					}

					$body=addslashes(JCodeConvert($body, $jc_from, 1));
					$subject=addslashes(JCodeConvert($subject, $jc_from, 1));
					$strheader=addslashes(JCodeConvert($strheader, $jc_from, 1));
					
					//サイズ
					$strsize=$list[$num];
					$strSQLIns = "Insert Into mail_get_tbl".
							"(mail_id,get_date,syain_cd,header,subject,comment,mail_size,kind_flg,temp_flg,del_flg,from_name,from_addr) ".
							"values (".
									"'".addslashes($u_id)."','$date','$PHP_SYAIN_CD','$strheader','$subject','$body','$strsize',0,$temp_flg,0,'".$str_From."','".$str_Addr."')";
					$objRecIns = @pg_exec($strSQLIns);
				}
				if ($delmail_flg==1){
						$p->dele($num);
				}
			}
			
			$p->close();

			//*** メールサーバ検索 ***//
			for ($num = $init_num; $num > 0; --$num) {
				//DBから削除するための条件作成
				if (trim($strJoken)==""){
					$strJoken="mail_id <> "."'".addslashes($uid[$num])."'";
				}else{
					$strJoken=$strJoken." and mail_id <> "."'".addslashes($uid[$num])."'";
				}
			}

			//*** 受信メールテーブル削除 ***//
			if (trim($strJoken != "")){	
				$strSQLdel= "delete from mail_get_tbl where syain_cd='".$PHP_SYAIN_CD."' and del_flg=1 and (".$strJoken.")";
			}else{
				$strSQLdel= "delete from mail_get_tbl where syain_cd='".$PHP_SYAIN_CD."' and del_flg=1";
			}
			//echo $strSQLdel;
			$objRecdel = pg_exec($strSQLdel);
			if($objRecdel==false){
				echo("SQL実行に失敗しました(delete)");
				exit;
			}

			header("Location: ./MIL003_m.php?$PHP_Argument");
	 }

?>