среда, 11 сентября 2013 г.

Catch-all STMP в php

Catch-all STMP в php


#!/usr/bin/php
<?php
date_default_timezone_set('Europe/Moscow');
$dir='/var/www/system/htdocs/mail/list/';
$input = file_get_contents('php://stdin');
preg_match('|^To: (.*)|', $input, $matches);
if ($matches[1]){
$d=preg_replace('/[^a-z\d@\.-]+/','',$matches[1]);
$d=str_replace('@','_',$d);
} else $d='undef';
if (!is_dir($dir.$d)){
  mkdir($dir.$d,0770);
}
$input=explode("\n\n",$input,2);
$input[0].="\nX-SaaS-Origin:".getenv('PWD');
$input=implode("\n\n",$input);

$fn=date('Y-m-d.His_').'rand'.rand(1111,9999).'.txt';

file_put_contents($dir.$d.'/'.$fn, $input);

Комментариев нет:

Отправить комментарий