#!/usr/bin/php -q
<?php
// +-------------------------------------------------------------+
// | HiveMail™ version 1.3.1
// +-------------------------------------------------------------+
// | HIVEMAIL™ IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than hivemail or if you have otherwise received
// | this software from someone who is not a representative of
// | this organization you are involved in an illegal activity.
// +-------------------------------------------------------------+
// | $RCSfile: hivemail_process.php,v $ - $Revision: 1.25 $
// | $Date: 2004/08/10 20:16:52 $ - $Author: tubedogg $
// +-------------------------------------------------------------+

/********************************************************************************
* --- R E Q U I R E D   C O N F I G U R A T I O N ---							*
* Change the directive below to use the correct path to your HiveMail™			*
* installation.																	*
*																				*
* The path can be relative, for example:										*
*   $hivemail_path = './public_html/hivemail';									*
*																				*
* Or it can be absolute, for example:											*
*   $hivemail_path = '/home/yoursite/public_html/hivemail';					*
*																				*
* If you do not know what the path is, log on to the HiveMail™ Administrator	*
* Control Panel, and select PHP Info under the main menu. The path should		*
* be in the _SERVER["DOCUMENT_ROOT"] variable, under 'PHP Variables'.			*
********************************************************************************/
$hivemail_path = '../';
/********************************************************************************
* --- O P T I O N A L   C O N F I G U R A T I O N ---							*
* If you wish HiveMail™ to log in an external file the time it takes to			*
* process each message, create a file called hivemail_process.log				*
* in the same directory as this script, and CHMOD it to 0664. Once				*
* the file is in place, change the option below to TRUE.						*
*																				*
* To save space, you may want to prune the log file from time to time. To   	*
* do so, simply delete the file and create it again.							*
********************************************************************************/
$log_process = FALSE;
/********************************************************************************
* Do not edit anything below this line.											*
********************************************************************************/

error_reporting(E_ALL & ~E_NOTICE);
chdir($hivemail_path);

// ############################################################################
// We are outside the admin CP
define('INADMIN', false);

// ############################################################################
// Start database connection
include_once('./includes/init_vars.php');
include_once('./includes/config.php');
include_once('./includes/db_mysql.php');
$DB_site = new DB_MySQL($config);

// ############################################################################
// Get options
$DB_site->setup_options();

// ############################################################################
// Get all common functions
include_once('./includes/functions.php');
include_once('./includes/functions_calendar.php');
include_once('./includes/functions_message.php');
include_once('./includes/functions_file.php');
include_once('./includes/functions_template.php');
include_once('./includes/functions_mime.php');
include_once('./includes/functions_smtp.php');
require_once('./includes/functions_hivepop.php');
include_once('./includes/functions_user.php');
include_once('./includes/init.php');

// ############################################################################
// Get the email from standard input
$fp = fopen('php://stdin', 'r');
for ($message = ''; !feof($fp); $message .= fgets($fp, 4096));
fclose($fp);
$message_size = strlen($message);

// ############################################################################
// Let's rock and roll
$starttime = microtime();
process_mail($message);

// ############################################################################
// Log the time it took to process the email
if ($log_process) {
	$runtime = microdiff($starttime);
	$lfp = fopen(dirname(__FILE__).'/hivemail_process.log', 'a');
	fwrite($lfp, date('M j Y G:i:s').': Processed '.number_format($message_size / 1024, 2).' KB in '.round($runtime, 4).' seconds ('.round(($message_size / 1024) / $runtime, 2)." KB/s)\n");
	fclose($lfp);
}

?>