Created
September 22, 2015 00:11
-
-
Save cleverness/4f6ed65a69fc02a8e513 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
/** | |
* | |
* The Sendmail script allows DesktopServer to route low-level email to a file in | |
* a self purging folder that cleans up itself after 48 hours. | |
* | |
* @package DesktopServer | |
* @since 3.8.0 | |
*/ | |
// Write mail to temp/mail folder | |
$mail_folder = "/Applications/MAMP/tmp/mail"; | |
# create a filename for the eml file | |
$i = 1; | |
do { | |
$filename = $mail_folder . '/'. date('Y-m-d_H.m.s-') . '.eml'; | |
}while( is_file($filename) === true ); | |
# write the email contents to the file | |
$email_contents = fopen('php://stdin', 'r'); | |
$fstat = fstat($email_contents); | |
file_put_contents($filename, $email_contents); | |
// Clean up files older than 2 days | |
if (file_exists($mail_folder)) { | |
foreach (new DirectoryIterator($mail_folder) as $fileInfo) { | |
if ($fileInfo->isDot()) { | |
continue; | |
} | |
if (time() - $fileInfo->getCTime() >= 2*24*60*60) { | |
unlink($fileInfo->getRealPath()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment