/** * Process queue * Using lock file */ function process() { global $db, $config, $lang; set_config('last_queue_run', time(), true); // Delete stale lock file if (file_exists($this->cache_file . '.lock') && !file_exists($this->cache_file)) { @unlink($this->cache_file . '.lock'); return; } if (!file_exists($this->cache_file) || file_exists($this->cache_file . '.lock') && filemtime($this->cache_file) > time() - $config['queue_interval']) { return; } $fp = @fopen($this->cache_file . '.lock', 'wb'); fclose($fp); @chmod($this->cache_file . '.lock', 0777); include $this->cache_file; foreach ($this->queue_data as $object => $data_ary) { @set_time_limit(0); if (!isset($data_ary['package_size'])) { $data_ary['package_size'] = 0; } $package_size = $data_ary['package_size']; $num_items = !$package_size || sizeof($data_ary['data']) < $package_size ? sizeof($data_ary['data']) : $package_size; // If the amount of emails to be sent is way more than package_size than we need to increase it to prevent backlogs... if (sizeof($data_ary['data']) > $package_size * 2.5) { $num_items = sizeof($data_ary['data']); } switch ($object) { case 'email': // Delete the email queued objects if mailing is disabled if (!$config['email_enable']) { unset($this->queue_data['email']); continue 2; } break; case 'jabber': if (!$config['jab_enable']) { unset($this->queue_data['jabber']); continue 2; } include_once IP_ROOT_PATH . 'includes/functions_jabber.' . PHP_EXT; $this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], $config['jab_password'], $config['jab_use_ssl']); if (!$this->jabber->connect()) { messenger::error('JABBER', $lang['ERR_JAB_CONNECT']); continue 2; } if (!$this->jabber->login()) { messenger::error('JABBER', $lang['ERR_JAB_AUTH']); continue 2; } break; default: return; } for ($i = 0; $i < $num_items; $i++) { // Make variables available... extract(array_shift($this->queue_data[$object]['data'])); switch ($object) { case 'email': $err_msg = ''; $to = !$to ? 'undisclosed-recipients:;' : $to; if ($config['smtp_delivery']) { $result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers); } else { $result = phpbb_mail($to, $subject, $msg, $headers, $this->eol, $err_msg); } if (!$result) { @unlink($this->cache_file . '.lock'); emailer::error('EMAIL', $err_msg); continue 2; } break; case 'jabber': foreach ($addresses as $address) { if ($this->jabber->send_message($address, $msg, $subject) === false) { emailer::error('JABBER', $this->jabber->get_log()); continue 3; } } break; } } // No more data for this object? Unset it if (!sizeof($this->queue_data[$object]['data'])) { unset($this->queue_data[$object]); } // Post-object processing switch ($object) { case 'jabber': // Hang about a couple of secs to ensure the messages are // handled, then disconnect $this->jabber->disconnect(); break; } } if (!sizeof($this->queue_data)) { @unlink($this->cache_file); } else { if ($fp = @fopen($this->cache_file, 'wb')) { @flock($fp, LOCK_EX); fwrite($fp, "<?php\nif (!defined('IN_ICYPHOENIX')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>"); @flock($fp, LOCK_UN); fclose($fp); phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE); } } @unlink($this->cache_file . '.lock'); }