/**
* Register function that will be called when the script terminates abruptly.
* Get code, test and id from URL.
* Retrieve mailing (subject, body, attachments, etc) that will be sent.
*
* @param array $args.- Configuration overwrites
*/
function Pommo_Mta($args = array())
{
$defaults = array('queueSize' => 100, 'maxRunTime' => 80, 'skipSecurity' => false, 'start' => time(), 'serial' => false, 'spawn' => 1);
$p = Pommo_Api::getParams($defaults, $args);
foreach ($p as $k => $v) {
$this->{'_' . $k} = $v;
}
// protect against safe mode timeouts
if (ini_get('safe_mode')) {
$this->_maxRunTime = ini_get('max_execution_time') - 10;
} else {
set_time_limit(0);
}
// protect against user (client) abort
ignore_user_abort(true);
// register shutdown method
register_shutdown_function(array(&$this, "shutdown"));
// set parameters from URL
$this->_code = empty($_GET['code']) ? 'invalid' : $_GET['code'];
$this->_test = isset($_GET['test']);
$this->_id = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : false;
// verify and initialize the current mailing
$p = array('active' => true, 'code' => $this->_skipSecurity ? null : $this->_code, 'id' => $this->_id ? $this->_id : null);
$this->_mailing = current(Pommo_Mailing::get($p));
if (!is_numeric($this->_mailing['id'])) {
$this->shutdown('Unable to initialize mailing.');
}
$this->_id = $this->_mailing['id'];
// make sure the $_GET global holds the mailing id
// (used in personalizations, etc.) TODO: Find another way to do this
$_GET['id'] = $this->_id;
// security routines
if ($this->_mailing['end'] > 0) {
$this->shutdown(Pommo::_T('Mailing Complete.'));
}
if (empty($this->_mailing['serial'])) {
if (!Pommo_Mail_Ctl::mark($this->_serial, $this->_id)) {
$this->shutdown('Unable to serialize mailing (ID: ' . $this->_id . ' SERIAL: ' . $this->_serial . ')');
}
}
if ($this->_maxRunTime < 15) {
$this->shutdown('Max Runtime must be at least 15 seconds!');
}
$this->_queue = $this->_sent = $this->_failed = array();
}