- <?php
- 02
- #从输入读取到所有的邮件内容
- $email = "";
- $FD = fopen ("Php://stdin", "R");
- !feof ($FD)) {
- $email. = Fread ($FD, 1024);
- 08}
- Fclose ($FD);
- 10
- One #记录所有的内容, test
- File_put_contents ("/tmp/mail/". Time (), $email);
- 13
- #处理邮件
- $lines = explode ("\ n", $email);
- 16
- //Empty VARs
- $from = "";
- $date = "";
- $subject = "";
- $message = "";
- $splittingheaders = true;
- 23
- for ($i =0; $i <count ($lines); $i + +) {
- if ($splittingheaders) {
- 26
- /Look out for special headers
- if (Preg_match ("/^subject: (. *)/", $lines [$i], $matches)) {
- $subject = $matches [1];
- 30}
- if (Preg_match ("/^from: (. *)/", $lines [$i], $matches)) {
- if (Strpos ($lines [$i], "<")) {
- //the name exist too in from header
- $data = Explode (' < ', $lines [$i]);
- $from = substr (Trim ($data [1]), 0,-1);
- }else{
- Notoginseng//only The Mail
- $from = $matches [1];
- 39}
- 40}
- if (Preg_match ("/^date: (. *)/", $lines [$i], $matches)) {
- $date = $matches [1];
- 43}
- {} else {
- A header, but message
- $message. = $lines [$i]. " \ n ";
- 47}
- 48
- if (Trim ($lines [$i]) = = "") {
- Empty line, header section has ended
- Wuyi $splittingheaders = false;
- 52}
- 53}
- 54
- $when = Date ("y-m-d g:i:s");
- $data = explode (' @ ', $from);
- $username = $data [0];
- 58
- #记录到数据库
- $sql = "INSERT INTO mails" (' username ', ' from ', ' subject ', ' Date ', ' message ') VALUES (' $username ', ' $from ', ' $subject ') , ' $when ', ' $message ');
- 61
- #测试
- File_put_contents ("/tmp/mail2.log", $sql);
- ?>