01? Php0203 # read all email content from input 04 $ email =; 05 $ fd = fopen (php: // stdin, r); 06 while (! Feof ($ fd) {07 $ email. = fread ($ fd, 1024); 08} 09 fclose ($ fd); 10
- 01
-
- 02
-
- 03 # read all emails from input
-
- 04 $ email = "";
-
- 05 $ fd = fopen ("php: // stdin", "r ");
-
- 06 while (! Feof ($ fd )){
-
- 07 $ email. = fread ($ fd, 1024 );
-
- 08}
-
- 09 fclose ($ fd );
-
- 10
-
- 11 # record all content and test
-
- 12 file_put_contents ("/tmp/mail/". time (), $ email );
-
- 13
-
- 14 # process emails
-
- 15 $ lines = explode ("\ n", $ email );
-
- 16
-
- 17 // empty vars
-
- 18 $ from = "";
-
- 19 $ date = "";
-
- 20 $ subject = "";
-
- 21 $ message = "";
-
- 22 $ splittingheaders = true;
-
- 23
-
- 24 for ($ I = 0; $ I
-
- 25 if ($ splittingheaders ){
-
- 26
-
- 27 // look out for special headers
-
- 28 if (preg_match ("/^ Subject: (. *)/", $ lines [$ I], $ matches )){
-
- 29 $ subject = $ matches [1];
-
- 30}
-
- 31 if (preg_match ("/^ From: (. *)/", $ lines [$ I], $ matches )){
-
- 32 if (strpos ($ lines [$ I], "<")){
-
- 33 // the name exist too in from header
-
- 34 $ data = explode ('<', $ lines [$ I]);
-
- 35 $ from = substr (trim ($ data [1]), 0,-1 );
-
- 36} else {
-
- 37 // only the mail
-
- 38 $ from = $ matches [1];
-
- 39}
-
- 40}
-
- 41 if (preg_match ("/^ Date: (. *)/", $ lines [$ I], $ matches )){
-
- 42 $ date = $ matches [1];
-
- 43}
-
- 44} else {
-
- 45 // not a header, but message
-
- 46 $ message. = $ lines [$ I]. "\ n ";
-
- 47}
-
- 48
-
- 49 if (trim ($ lines [$ I]) = ""){
-
- 50 // empty line, header section has ended
-
- 51 $ splittingheaders = false;
-
- 52}
-
- 53}
-
- 54
-
- 55 $ when = date ("Y-m-d G: I: s ");
-
- 56 $ data = explode ('@', $ from );
-
- 57 $ username = $ data [0];
-
- 58
-
- 59 # Record to database
-
- 60 $ SQL = "insert into mails ('username', 'from', 'subobject', 'date', 'message') values ('$ username ', '$ from',' $ subject ',' $ when', '$ message ')";
-
- 61
-
- 62 # Test
-
- 63 file_put_contents ("/tmp/mail2.log", $ SQL );
-
- 64?>