$this->generateNotifications();
-
+ $this->assignQueues();
+
//DB_DataObject::debugLevel(1);
$w = DB_DataObject::factory($this->table);
$total = 0;
$w->evtype = $this->evtype;
}
+ $ff = HTML_FlexyFramework::get();
+ if (!empty($ff->Core_Notify['servers'])) {
+ if (!isset($ff->Core_Notify['servers'][gethostname()])) {
+ $this->jerr("Core_Notify['servers']['" . gethostname() ."'] is not set");
+ }
+ $w->server_id = array_search(gethostname(),array_keys($ff->Core_Notify['servers']));
+ }
+
+
+
+
+ $this->addFilter($w);
+
$w->autoJoin();
$w->find();
exit;
}
+
+
+
function generateNotifications()
{
// this should check each module for 'GenerateNotifications.php' class..
}
-
+ function assignQueues()
+ {
+ $ff = HTML_FlexyFramework::get();
+
+ if (empty($ff->Core_Notify['servers'])) {
+ return;
+ }
+
+ $num_servers = count(array_keys($ff->Core_Notify['servers']));
+
+ // 6 seconds on this machne...
+ $p->query("
+ UPDATE
+ {$this->table}
+ SET
+ server_id = ((@row_number := CASE WHEN @row_number IS NULL THEN 0 ELSE @row_number END +1) % {$num_servers})
+ WHERE
+ sent < '2000-01-01'
+ and
+ event_id = 0
+ and
+ act_start < NOW()
+ and
+ server_id < 0
+ ORDER BY
+ id ASC
+ LIMIT
+ 20000
+ ");
+
+
+ }
function run($id, $email='', $cmdOpts="")
{
if (isset($email['later'])) {
$old = clone($w);
$w->act_when = $email['later'];
+ $this->updateServer($w);
$w->update($old);
$this->errorHandler(date('Y-m-d h:i:s ') . " Delivery postponed by email creator to {$email['later']}");
}
if ($retry < 240) {
$this->addEvent('NOTIFY', $w, 'MX LOOKUP FAILED ' . $dom );
$w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
+ $this->updateServer($w);
$w->update($ww);
$this->errorHandler(date('Y-m-d h:i:s') . " - MX LOOKUP FAILED\n");
}
$w->to_email = $p->email;
//$this->addEvent('NOTIFY', $w, 'GREYLISTED ' . $p->email . ' ' . $res->toString());
// we can only update act_when if it has not been sent already (only happens when running in force mode..)
+ // set act when if it's empty...
$w->act_when = (!$w->act_when || $w->act_when == '0000-00-00 00:00:00') ? date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES')) : $w->act_when;
+
$w->update($ww);
$ww = clone($w);
));
$core_domain->insert();
}
+
+
+ $this->initHelo();
+
+ if (!isset($ff->Mail['helo'])) {
+ $this->errorHandler("config Mail[helo] is not set");
+ }
+
+
foreach($mxs as $mx) {
- if (!isset($ff->Mail['helo'])) {
- $this->errorHandler("config Mail[helo] is not set");
- }
+
$this->debug_str = '';
$this->debug("Trying SMTP: $mx / HELO {$ff->Mail['helo']}");
$mailer = Mail::factory('smtp', array(
if($core_notify->count()){
$old = clone($w);
$w->act_when = date("Y-m-d H:i:s", time() + $seconds);
+ $this->updateServer($w);
$w->update($old);
$this->errorHandler(date('Y-m-d h:i:s ') . " Too many emails sent by {$dom}");
}
//print_r($res);
$this->addEvent('NOTIFY', $w, 'GREYLISTED - ' . $errmsg);
$w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
+ $this->updateServer($w);
$w->domain_id = $core_domain->id;
$w->update($ww);
$this->addEvent('NOTIFY', $w, 'NO HOST CAN BE CONTACTED:' . $p->email);
- $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + 5 MINUTES'));
+ $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
+
+ $this->updateServer($w);
+
$w->domain_id = $core_domain->id;
$w->update($ww);
$this->errorHandler(date('Y-m-d h:i:s') ." - NO HOST AVAILABLE\n");
}
+
+ function updateServer($w)
+ {
+ $ff = HTML_FlexyFramework::get();
+
+ if (empty($ff->Core_Notify['servers'])) {
+ return;
+ }
+ // next server..
+ $w->server_id = ($w->server_id + 1) % count(array_keys($ff->Core_Notify['servers']));
+
+ }
+
+ function initHelo()
+ {
+ $ff = HTML_FlexyFramework::get();
+ if (empty($ff->Core_Notify['servers'])) {
+ return;
+ }
+ if (!isset($ff->Core_Notify['servers'][gethostname()]) || !isset($ff->Core_Notify['servers'][gethostname()]['helo']) ) {
+ $this->jerr("Core_Notify['servers']['" . gethostname() . "']['helo'] not set");
+ }
+ $ff->Mail['helo'] = $ff->Core_Notify['servers'][gethostname()]['helo'];
+
+ }
+
}
\ No newline at end of file