basis seems to run in terminal, however mail() doesn't work yet

--HG--
branch : quitta-gsoc-2013
hg/feature/sse2
Quitta 11 years ago
parent 8ee02d9380
commit e058a475f9

@ -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'].">";
} }

@ -0,0 +1,7 @@
<?php
require( '../libinclude.php' );
require( '../../www/config.php' );
$mail_handler = new Mail_Handler();
$mail_handler->cron();

@ -3,6 +3,10 @@
// Base include file for library functions for AMS // Base include file for library functions for AMS
// *********************************************** // ***********************************************
function __autoload( $className ){ function __autoload( $className ){
if(file_exists( '/home/daan/ryzom/ryzomcore/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/' . strtolower ( $className ) . '.php')){
require_once 'autoload/' . strtolower ( $className ) . '.php'; require_once 'autoload/' . strtolower ( $className ) . '.php';
} }
if($className == "WebUsers")
require_once '/home/daan/ryzom/ryzomcore/code/ryzom/tools/server/ryzom_ams/www/html/autoload/' . strtolower ( $className ) . '.php';
}

@ -337,6 +337,37 @@
ENGINE = InnoDB; ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `" . $cfg['db']['lib']['name'] ."`.`email`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`email` ;
CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`email` (
`MailId` INT NOT NULL AUTO_INCREMENT ,
`Recipient` VARCHAR(50) NULL ,
`Subject` VARCHAR(60) NULL ,
`Body` VARCHAR(400) NULL ,
`Status` VARCHAR(45) NULL ,
`Attempts` VARCHAR(45) NULL DEFAULT 0 ,
`Sender` INT(10) UNSIGNED NOT NULL ,
`UserId` INT(10) UNSIGNED NOT NULL ,
`MessageId` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`MailId`) ,
INDEX `fk_email_ticket_user1` (`Sender` ASC) ,
INDEX `fk_email_ticket_user2` (`UserId` ASC) ,
CONSTRAINT `fk_email_ticket_user1`
FOREIGN KEY (`Sender` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_email_ticket_user2`
FOREIGN KEY (`UserId` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
"; ";
$dbl->executeWithoutParams($sql); $dbl->executeWithoutParams($sql);

@ -293,6 +293,37 @@ CREATE TABLE IF NOT EXISTS `mydb`.`forwarded` (
ENGINE = InnoDB; ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`email`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`email` ;
CREATE TABLE IF NOT EXISTS `mydb`.`email` (
`MailId` INT NOT NULL AUTO_INCREMENT ,
`Recipient` VARCHAR(50) NULL ,
`Subject` VARCHAR(60) NULL ,
`Body` VARCHAR(400) NULL ,
`Status` VARCHAR(45) NULL ,
`Attempts` VARCHAR(45) NULL DEFAULT 0 ,
`Sender` INT(10) UNSIGNED NOT NULL ,
`UserId` INT(10) UNSIGNED NOT NULL ,
`MessageId` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`MailId`) ,
INDEX `fk_email_ticket_user1` (`Sender` ASC) ,
INDEX `fk_email_ticket_user2` (`UserId` ASC) ,
CONSTRAINT `fk_email_ticket_user1`
FOREIGN KEY (`Sender` )
REFERENCES `mydb`.`ticket_user` (`TUserId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_email_ticket_user2`
FOREIGN KEY (`UserId` )
REFERENCES `mydb`.`ticket_user` (`TUserId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE; SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

Loading…
Cancel
Save