Свернуть ↑
<?php
/*
* b1gMail7
* (c) 2002-2008 B1G Software
*
* Redistribution of this code without explicit permission
* is forbidden!
*
* $Id: pipe.php,v 1.10 2008/06/02 11:20:03 patrick Exp $
*
*/
chdir(dirname(__FILE__));
define('INTERFACE_MODE', true);
include('../serverlib/init.inc.php');
include(B1GMAIL_DIR . 'serverlib/mailprocessor.class.php');
// request temp file
$tempFileID = RequestTempFile(0);
$tempFileName = TempFileName($tempFileID);
$tempFileFP = fopen($tempFileName, 'wb+');
assert('is_resource($tempFileFP)');
// get mail from stdin
$handle = fopen('php://stdin', 'rb');
while(!feof($handle))
{
$buff = fgets2($handle);
fwrite($tempFileFP, rtrim($buff) . "\r\n");
}
fclose($handle);
$inputSize = ftell($tempFileFP);
fseek($tempFileFP, 0, SEEK_SET);
// empty?
if($inputSize < 3)
{
// yes -> log, do not process
PutLog('Message not processed (input size < 3 bytes)',
PRIO_DEBUG,
__FILE__,
__LINE__);
echo('Message processing aborted (no input)');
exit(-1);
}
// too big?
if($inputSize > $bm_prefs['mailmax'])
{
// yes -> log, do not process
PutLog(sprintf('Message not processed (hard limit; %d > %d bytes)',
$inputSize,
$bm_prefs['mailmax']),
PRIO_NOTE,
__FILE__,
__LINE__);
printf('Message processing aborted (hard limit; %d > %d bytes)',
$inputSize,
$bm_prefs['mailmax']);
exit(-1);
}
// recipients passed?
$recps = array();
$passed_h = false;
$timeout = -1;
foreach($_SERVER['argv'] as $param)
if($param == '--')
$passed_h = true;
else if(substr($param, 0, 10) == '--timeout=')
$timeout = (int)substr($param, 10);
else if($passed_h)
$recps[] = $param;
// set timeout?
if($timeout > -1)
set_time_limit($timeout);
// process mail
$mailProcessor = _new('BMMailProcessor', array($tempFileFP));
if(count($recps) > 0)
$mailProcessor->SetRecipients($recps);
$mailProcessor->ProcessMail();
// clean up
fclose($tempFileFP);
ReleaseTempFile(0, $tempFileID);
?>