", $buffer2); $fd3=fopen($res,"r"); while (!feof($fd3)) { $buffer3 = fgets($fd3, 4096); $data3 = explode("<>", $buffer3); if($data2[0] && $data2[0]==$data3[0]) fputs($fd4, $buffer3); } fclose($fd3); } fclose($fd2); fclose($fd4); copy($tmp,$res); unlink($tmp); # ↑=================================================================↑ // 件数分 for($i=1;$i<=$num;$i++) { $line = _sendcmd("RETR $i");//RETR n -n番目のメッセージ取得(ヘッダ含) while (!ereg("^\.\r\n",$line)) {//EOFの.まで読む $line = fgets($sock,512); $dat[$i].= $line; } $data = _sendcmd("DELE $i");//DELE n n番目のメッセージ削除 } $buf = _sendcmd("QUIT"); //バイバイ fclose($sock); //print_r($dat); //$num=1; //$dat[1] = implode('',file("test00.txt")); //$dat[2] = implode('',file("test01.txt")); $lines = array(); $lines = @file($log); for($j=1;$j<=$num;$j++) { $write = true; $subject = $from = $text = $atta = $part = $attach = ""; list($head, $body) = mime_split($dat[$j]); //echo $body; // 日付の袖しつ eregi("Date:[ \t]*([^\r\n]+)", $head, $datereg); $now = strtotime($datereg[1]); if ($now == -1) $now = time(); $head = ereg_replace("\r\n? ", "", $head); // サブジェクトの抽出 if (eregi("\nSubject:[ \t]*([^\r\n]+)", $head, $subreg)) { $subject = $subreg[1]; while (eregi("(.*)=\?iso-2022-jp\?B\?([^\?]+)\?=(.*)",$subject,$regs)) {//MIME Bデコード $subject = $regs[1].base64_decode($regs[2]).$regs[3]; } while (eregi("(.*)=\?iso-2022-jp\?Q\?([^\?]+)\?=(.*)",$subject,$regs)) {//MIME Bデコード $subject = $regs[1].quoted_printable_decode($regs[2]).$regs[3]; } $subject = htmlspecialchars(convert($subject)); } // 送信者アドレスの抽出 if (eregi("From:[ \t]*([^\r\n]+)", $head, $freg)) { $from = addr_search($freg[1]); } elseif (eregi("Reply-To:[ \t]*([^\r\n]+)", $head, $freg)) { $from = addr_search($freg[1]); } elseif (eregi("Return-Path:[ \t]*([^\r\n]+)", $head, $freg)) { $from = addr_search($freg[1]); } // 拒否アドレス for ($f=0; $f"; // 本文をデコード if (strtolower($main) == "text") { if (eregi("Content-Transfer-Encoding:.*base64", $m_head)) $m_body = base64_decode($m_body); if (eregi("Content-Transfer-Encoding:.*quoted-printable", $m_head)) $m_body = quoted_printable_decode($m_body); $text = convert($m_body); if ($sub == "html") $text = strip_tags($text); $text = str_replace(">",">",$text); $text = str_replace("<","<",$text); # ↓=================================================================↓ # $text = str_replace("\r\n", "\r",$text); $text = str_replace("\r\n", "\n",$text); # ↑=================================================================↑ $text = str_replace("\r", "\n",$text); $text = preg_replace("/\n{2,}/", "\n\n", $text); $text = str_replace("\n", "
", $text); // 電話番号削除 $text = eregi_replace("([[:digit:]]{11})|([[:digit:]\-]{13})", "", $text); // 下線削除 $text = eregi_replace($del_ereg, "", $text); // mac削除 $text = ereg_replace("Content-type: multipart/appledouble;[[:space:]]boundary=(.*)","",$text); // 広告等削除 if (is_array($word)) { foreach ($word as $delstr) $text = str_replace($delstr, "", $text); } if (strlen($text) > $body_limit) $text = substr($text, 0, $body_limit)."..."; } // ファイル名を抽出 if (eregi("name=\"?([^\"\n]+)\"?",$m_head, $filereg)) { $filename = ereg_replace("[\t\r\n]", "", $filereg[1]); if (eregi("(.*)=\?iso-2022-jp\?B\?([^\?]+)\?=(.*)",$filename,$regs)) { $filename = $regs[1].base64_decode($regs[2]).$regs[3]; $filename = convert($filename); } $filename = time() . "-".$filename; } // 添付データをデコードして保存 if (eregi("Content-Transfer-Encoding:.*base64", $m_head) && eregi($subtype, $sub)) { $tmp = base64_decode($m_body); if (!$filename) $filename = time().".$sub"; if (strlen($tmp) < $maxbyte && !eregi($viri, $filename) && $write) { $fp = fopen($tmpdir.$filename, "wb"); fputs($fp, $tmp); fclose($fp); $link = rawurlencode($filename); $attach = $filename; } else { $write = false; } } } if ($imgonly && $attach=="") $write = false; list($old,$otime,$osubj,$ofrom,,) = explode("<>", $lines[0]); // 連即投稿 if ($from == $ofrom && $now - $otime < $wtime) $write = false; $id = $old + 1; # ↓=================================================================↓ # 名前の既定入力 $fd = fopen($log, "r"); while (!feof($fd)) { $buffer = fgets($fd, 4096); $data = explode("<>", $buffer); if (trim($from)==$data[3] && !trim($subject) && $data[2]) $subject=$data[2]; } fclose($fd); # ↑=================================================================↑ if(trim($subject)=="") $subject = $nosubject; $line = "$id<>$now<>$subject<>$from<>$text<>$attach<>\n"; if ($write) array_unshift($lines, $line); } // ログ最大行処理 if (count($lines) > $maxline) { for ($k=count($lines)-1; $k>=$maxline; $k--) { list($id,$tim,$sub,$fro,$tex,$at,) = explode("<>", $lines[$k]); if (file_exists($tmpdir.$at)) @unlink($tmpdir.$at); $lines[$k] = ""; } } // ログに記録 if ($write) { $fp = fopen($log, "w"); flock($fp, LOCK_EX); fputs($fp, implode('', $lines)); fclose($fp); } elseif (file_exists($tmpdir.$filename)) { @unlink($tmpdir.$filename); } /* コマンドー送信!!*/ function _sendcmd($cmd) { global $sock; fputs($sock, $cmd."\r\n"); $buf = fgets($sock, 512); if(substr($buf, 0, 3) == '+OK') { return $buf; } else { die($buf); } return false; } /* ヘッダと本文を分割する */ function mime_split($data) { $part = split("\r\n\r\n", $data, 2); $part[1] = ereg_replace("\r\n[\t ]+", " ", $part[1]); return $part; } /* メールアドレスを抽出する */ function addr_search($addr) { if (eregi("[-!#$%&\'*+\\./0-9A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+", $addr, $fromreg)) { return $fromreg[0]; } else { return false; } } /* 文字コードコンバートauto→SJIS */ function convert($str) { global $bake; if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($str, "SJIS", "auto"); } elseif (function_exists('JcodeConvert')) { if(!$bake) return JcodeConvert($str, 0, 2); else return JcodeConvert($str, 3, 2); } return true; } #--------------------------------------------------------------- # header("Location: $jump"); if($_GET['jump']) $jump=$_GET['jump']; elseif($_POST['jump']) $jump=$_POST['jump']; # else (!$jump) $jump="./joyful.cgi"; header("Location: $jump"); #--------------------------------------------------------------- ?>