Last active
November 4, 2017 14:29
-
-
Save ytorbyk/9868298c8671a493737a53184854f0b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/php | |
| <?php | |
| # create a filename for the emlx file | |
| date_default_timezone_set("Europe/Kiev"); | |
| list($ms, $time) = explode(' ', microtime()); | |
| $filename = dirname(__FILE__) . '/' . date('Y-m-d H.i.s.', $time) . substr($ms, 2, 3) . '.eml'; | |
| # write the email contents to the file | |
| $email_contents = fopen('php://stdin', 'r'); | |
| $fstat = fstat($email_contents); | |
| $sEmail = ""; | |
| while (!feof($email_contents)) { | |
| $sEmail .= fread($email_contents, 1024); | |
| } | |
| fclose($email_contents); | |
| $lines = explode("\n", $sEmail); | |
| // empty vars | |
| $from = ""; | |
| $subject = ""; | |
| $headers = ""; | |
| $message = ""; | |
| $splittingheaders = true; | |
| for ($i=0; $i < count($lines); $i++) { | |
| if ($splittingheaders) { | |
| // this is a header | |
| $headers .= $lines[$i]."\n"; | |
| // look out for special headers | |
| if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { | |
| $subject = $matches[1]; | |
| } | |
| if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { | |
| $from = $matches[1]; | |
| } | |
| if (preg_match("/^To: (.*)/", $lines[$i], $matches)) { | |
| $to = $matches[1]; | |
| } | |
| } else { | |
| // not a header, but message | |
| $message .= $lines[$i]."\n"; | |
| } | |
| if (trim($lines[$i])=="") { | |
| // empty line, header section has ended | |
| $splittingheaders = false; | |
| } | |
| } | |
| $filename = dirname(__FILE__) . '/mail/' | |
| . date('Y.m.d-H.i\'s', $time) | |
| . '[' . substr($ms, 2, 3) . '].eml'; | |
| file_put_contents($filename, $fstat['size']."\n"); | |
| file_put_contents($filename, $sEmail, FILE_APPEND); | |
| # open up the emlx file (using Apple Mail) | |
| #exec('open '.escapeshellarg($filename)); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install
Configure php.ini
sendmail_path = /Users/<your-user>/Support/smtp_catcher.phpAll emails will be stored in
/Users/<your-user>/Support/mailfolder