|
|
@ -4,13 +4,13 @@ class Mail_Handler{
|
|
|
|
|
|
|
|
|
|
|
|
private $db;
|
|
|
|
private $db;
|
|
|
|
|
|
|
|
|
|
|
|
function mail_fork() {
|
|
|
|
public function mail_fork() {
|
|
|
|
/*global $db;
|
|
|
|
/*global $db;
|
|
|
|
$db = NULL;
|
|
|
|
$db = NULL;
|
|
|
|
$pid = pcntl_fork();
|
|
|
|
$pid = pcntl_fork();
|
|
|
|
oms_db_connect();
|
|
|
|
oms_db_connect();
|
|
|
|
return $pid;*/
|
|
|
|
return $pid;*/
|
|
|
|
$this->db = new DBLayer("lib");
|
|
|
|
|
|
|
|
//Start a new thread and return the thread id!
|
|
|
|
//Start a new thread and return the thread id!
|
|
|
|
$pid = pcntl_fork();
|
|
|
|
$pid = pcntl_fork();
|
|
|
|
return $pid;
|
|
|
|
return $pid;
|
|
|
@ -45,14 +45,14 @@ class Mail_Handler{
|
|
|
|
$user = new Ticket_User();
|
|
|
|
$user = new Ticket_User();
|
|
|
|
$user->load_With_TUserId($id);
|
|
|
|
$user->load_With_TUserId($id);
|
|
|
|
$webUser = new WebUsers($user->getExternId());
|
|
|
|
$webUser = new WebUsers($user->getExternId());
|
|
|
|
return $webUsers->getEmail();
|
|
|
|
return $webUser->getEmail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_username_from_id($id){
|
|
|
|
function get_username_from_id($id){
|
|
|
|
$user = new Ticket_User();
|
|
|
|
$user = new Ticket_User();
|
|
|
|
$user->load_With_TUserId($id);
|
|
|
|
$user->load_With_TUserId($id);
|
|
|
|
$webUser = new WebUsers($user->getExternId());
|
|
|
|
$webUser = new WebUsers($user->getExternId());
|
|
|
|
return $webUsers->getUsername();
|
|
|
|
return $webUser->getUsername();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -67,7 +67,7 @@ class Mail_Handler{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mail_cron() {
|
|
|
|
function cron() {
|
|
|
|
global $cfg;
|
|
|
|
global $cfg;
|
|
|
|
$inbox_username = $cfg['mail']['username'];
|
|
|
|
$inbox_username = $cfg['mail']['username'];
|
|
|
|
$inbox_password = $cfg['mail']['password'];
|
|
|
|
$inbox_password = $cfg['mail']['password'];
|
|
|
@ -79,7 +79,7 @@ class Mail_Handler{
|
|
|
|
echo("mail cron\n");
|
|
|
|
echo("mail cron\n");
|
|
|
|
|
|
|
|
|
|
|
|
//creates child process
|
|
|
|
//creates child process
|
|
|
|
$pid = mail_fork();
|
|
|
|
$pid = self::mail_fork();
|
|
|
|
$pidfile = '/tmp/ams_cron_email_pid';
|
|
|
|
$pidfile = '/tmp/ams_cron_email_pid';
|
|
|
|
|
|
|
|
|
|
|
|
//INFO: if $pid =
|
|
|
|
//INFO: if $pid =
|
|
|
@ -92,6 +92,8 @@ class Mail_Handler{
|
|
|
|
// We're the parent process, do nothing!
|
|
|
|
// We're the parent process, do nothing!
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//make db connection here because the children have to make the connection.
|
|
|
|
|
|
|
|
$this->db = new DBLayer("lib");
|
|
|
|
|
|
|
|
|
|
|
|
//if $pidfile doesn't exist yet, then start sending the mails that are in the db.
|
|
|
|
//if $pidfile doesn't exist yet, then start sending the mails that are in the db.
|
|
|
|
if(!file_exists($pidfile)) {
|
|
|
|
if(!file_exists($pidfile)) {
|
|
|
@ -107,24 +109,26 @@ class Mail_Handler{
|
|
|
|
$statement = $this->db->executeWithoutParams("select * from email where Status = 'NEW' or Status = 'FAILED'");
|
|
|
|
$statement = $this->db->executeWithoutParams("select * from email where Status = 'NEW' or Status = 'FAILED'");
|
|
|
|
$emails = $statement->fetchAll();
|
|
|
|
$emails = $statement->fetchAll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach($emails as $email) {
|
|
|
|
foreach($emails as $email) {
|
|
|
|
$message_id = new_message_id();
|
|
|
|
$message_id = self::new_message_id();
|
|
|
|
//if recipient isn't given, then use the email of the id_user instead!
|
|
|
|
//if recipient isn't given, then use the email of the id_user instead!
|
|
|
|
echo("Emailing {$email['Recipient']}\n");
|
|
|
|
echo("Emailing {$email['Recipient']}\n");
|
|
|
|
if(!$email['Recipient']) {
|
|
|
|
if(!$email['Recipient']) {
|
|
|
|
$email['Recipient'] = get_email_by_user_id($email['UserId']);
|
|
|
|
$email['Recipient'] = self::get_email_by_user_id($email['UserId']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//create sending email adres based on the $sender id
|
|
|
|
//create sending email adres based on the $sender id
|
|
|
|
if($email['Sender']) {
|
|
|
|
if($email['Sender']) {
|
|
|
|
$username = get_username_from_id($email['Sender']);
|
|
|
|
$username = self::get_username_from_id($email['Sender']);
|
|
|
|
$from = "$username <$username@$inbox_host>";
|
|
|
|
$from = "$username <$username@$inbox_host>";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$from = $oms_reply_to;
|
|
|
|
$from = $oms_reply_to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$headers = "From: $from\r\n" . "Message-ID: " . $message_id;
|
|
|
|
$headers = "From: $from\r\n" . "Message-ID: " . $message_id;
|
|
|
|
|
|
|
|
print("recip: " . $email['Recipient']);
|
|
|
|
|
|
|
|
print("subj: " .$email['Subject']);
|
|
|
|
|
|
|
|
print("body: " . $email['Body']);
|
|
|
|
|
|
|
|
print("headers: " . $headers);
|
|
|
|
if(mail($email['Recipient'], $email['Subject'], $email['Body'], $headers)) {
|
|
|
|
if(mail($email['Recipient'], $email['Subject'], $email['Body'], $headers)) {
|
|
|
|
$status = "DELIVERED";
|
|
|
|
$status = "DELIVERED";
|
|
|
|
echo("Emailed {$email['Recipient']}\n");
|
|
|
|
echo("Emailed {$email['Recipient']}\n");
|
|
|
@ -178,7 +182,7 @@ class Mail_Handler{
|
|
|
|
global $cfg;
|
|
|
|
global $cfg;
|
|
|
|
global $ams_mail_count;
|
|
|
|
global $ams_mail_count;
|
|
|
|
$ams_mail_count = ($ams_mail_count == '') ? 1 : $ams_mail_count + 1;
|
|
|
|
$ams_mail_count = ($ams_mail_count == '') ? 1 : $ams_mail_count + 1;
|
|
|
|
return "<ams.message".$pid.$ams_mail_count.$time."@".$cfg['web']['host'].">";
|
|
|
|
return "<ams.message".$pid.$ams_mail_count.$time."@".$cfg['mail']['host'].">";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|