sending mail with supportgroup ID is possible

This commit is contained in:
Quitta 2013-08-16 21:43:39 +02:00
parent 141f40835f
commit 420454f7f3
5 changed files with 36 additions and 34 deletions

View file

@ -58,11 +58,14 @@ class Mail_Handler{
//the main function //the main function
function cron() { function cron() {
global $cfg; global $cfg;
$inbox_username = $cfg['mail']['username']; $default_groupemail = $cfg['mail']['default_groupemail'];
$default_groupname = $cfg['mail']['default_groupname'];
/*$inbox_username = $cfg['mail']['username'];
$inbox_password = $cfg['mail']['password']; $inbox_password = $cfg['mail']['password'];
$inbox_host = $cfg['mail']['host']; $inbox_host = $cfg['mail']['host'];
$oms_reply_to = "Ryzom Ticketing Support <ticketing@".$inbox_host.">"; $oms_reply_to = "Ryzom Ticketing Support <ticketing@".$inbox_host.">";
global $MAIL_DIR; global $MAIL_DIR;*/
// Deliver new mail // Deliver new mail
echo("mail cron\n"); echo("mail cron\n");
@ -70,15 +73,14 @@ class Mail_Handler{
//creates child process //creates child process
$pid = self::mail_fork(); $pid = self::mail_fork();
$pidfile = '/tmp/ams_cron_email_pid'; $pidfile = '/tmp/ams_cron_email_pid';
//INFO: if $pid =
//-1: "Could not fork!\n";
// 0: "In child!\n";
//>0: "In parent!\n";
if($pid) { if($pid) {
// We're the parent process, do nothing! // We're the parent process, do nothing!
//INFO: if $pid =
//-1: "Could not fork!\n";
// 0: "In child!\n";
//>0: "In parent!\n";
} else { } else {
//make db connection here because the children have to make the connection. //make db connection here because the children have to make the connection.
@ -86,6 +88,7 @@ class Mail_Handler{
//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)) {
//create the file and write the child processes id in it! //create the file and write the child processes id in it!
$pid = getmypid(); $pid = getmypid();
$file = fopen($pidfile, 'w'); $file = fopen($pidfile, 'w');
@ -106,18 +109,16 @@ class Mail_Handler{
$email['Recipient'] = Ticket_User::get_email_by_user_id($email['UserId']); $email['Recipient'] = Ticket_User::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 which refers to the department id
if($email['Sender'] != 0) { if($email['Sender'] == NULL) {
$username = Ticket_User::get_username_from_id($email['Sender']); $from = $default_groupname ." <".$default_groupemail.">";
$from = "$username <$username@$inbox_host>";
} else { } else {
$from = $oms_reply_to; $group = Support_Group::getGroup($email['Sender']);
$from = $group->getName()." <".$group->getGroupEmail().">";
} }
$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");
@ -127,13 +128,12 @@ class Mail_Handler{
} }
//change the status of the emails. //change the status of the emails.
$this->db->execute('update email set Status = ?, MessageId = ?, Attempts = Attempts + 1 where MailId = ?', array($status, $message_id, $email['MailId'])); $this->db->execute('update email set Status = ?, MessageId = ?, Attempts = Attempts + 1 where MailId = ?', array($status, $message_id, $email['MailId']));
//db_exec('update email set status = ?, message_id = ?, attempts = attempts + 1 where id_email = ?', array($status, $message_id, $email['id_email']));
} }
unlink($pidfile); unlink($pidfile);
} }
// Check mail // Check mail
//$mailbox = imap_open("{localhost:110/pop3/novalidate-cert}INBOX", $inbox_username, $inbox_password);
$mbox = imap_open($cfg['mail']['server'], $inbox_username, $inbox_password) or die('Cannot connect to mail server: ' . imap_last_error()); $mbox = imap_open($cfg['mail']['server'], $inbox_username, $inbox_password) or die('Cannot connect to mail server: ' . imap_last_error());
$message_count = imap_num_msg($mbox); $message_count = imap_num_msg($mbox);

View file

@ -31,9 +31,11 @@ $cfg['db']['ring']['name'] = 'ring_open';
$cfg['db']['ring']['user'] = 'shard'; $cfg['db']['ring']['user'] = 'shard';
$cfg['db']['ring']['pass'] = ''; $cfg['db']['ring']['pass'] = '';
$cfg['mail']['default_groupemail'] = 'support@ryzomcore.com';
$cfg['mail']['default_groupname'] = 'Ryzomcore Support';
$cfg['mail']['username'] = 'amsryzom@gmail.com'; $cfg['mail']['username'] = 'amsryzom@gmail.com';
$cfg['mail']['password'] = 'lol123bol'; $cfg['mail']['password'] = 'lol123bol';
$cfg['mail']['host'] = 'ryzomcore.com'; //$cfg['mail']['host'] = 'ryzomcore.com';
// To connect to an IMAP server running on port 143 on the local machine, // To connect to an IMAP server running on port 143 on the local machine,
// do the following: $mbox = imap_open("{localhost:143}INBOX", "user_id", "password"); // do the following: $mbox = imap_open("{localhost:143}INBOX", "user_id", "password");

View file

@ -353,19 +353,14 @@
`Body` VARCHAR(400) NULL , `Body` VARCHAR(400) NULL ,
`Status` VARCHAR(45) NULL , `Status` VARCHAR(45) NULL ,
`Attempts` VARCHAR(45) NULL DEFAULT 0 , `Attempts` VARCHAR(45) NULL DEFAULT 0 ,
`Sender` INT(10) UNSIGNED NOT NULL ,
`UserId` INT(10) UNSIGNED NOT NULL , `UserId` INT(10) UNSIGNED NOT NULL ,
`MessageId` VARCHAR(45) NOT NULL , `MessageId` VARCHAR(45) NULL ,
`TicketId` INT UNSIGNED NOT NULL , `TicketId` INT UNSIGNED NOT NULL ,
`Sender` INT(10) UNSIGNED NULL ,
PRIMARY KEY (`MailId`) , PRIMARY KEY (`MailId`) ,
INDEX `fk_email_ticket_user1` (`Sender` ASC) ,
INDEX `fk_email_ticket_user2` (`UserId` ASC) , INDEX `fk_email_ticket_user2` (`UserId` ASC) ,
INDEX `fk_email_ticket1` (`TicketId` ASC) , INDEX `fk_email_ticket1` (`TicketId` ASC) ,
CONSTRAINT `fk_email_ticket_user1` INDEX `fk_email_support_group1` (`Sender` ASC) ,
FOREIGN KEY (`Sender` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_email_ticket_user2` CONSTRAINT `fk_email_ticket_user2`
FOREIGN KEY (`UserId` ) FOREIGN KEY (`UserId` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` ) REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket_user` (`TUserId` )
@ -375,6 +370,11 @@
FOREIGN KEY (`TicketId` ) FOREIGN KEY (`TicketId` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket` (`TId` ) REFERENCES `" . $cfg['db']['lib']['name'] ."`.`ticket` (`TId` )
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_email_support_group1`
FOREIGN KEY (`Sender` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`support_group` (`SGroupId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;

View file

@ -309,19 +309,14 @@ CREATE TABLE IF NOT EXISTS `mydb`.`email` (
`Body` VARCHAR(400) NULL , `Body` VARCHAR(400) NULL ,
`Status` VARCHAR(45) NULL , `Status` VARCHAR(45) NULL ,
`Attempts` VARCHAR(45) NULL DEFAULT 0 , `Attempts` VARCHAR(45) NULL DEFAULT 0 ,
`Sender` INT(10) UNSIGNED NOT NULL ,
`UserId` INT(10) UNSIGNED NOT NULL , `UserId` INT(10) UNSIGNED NOT NULL ,
`MessageId` VARCHAR(45) NOT NULL , `MessageId` VARCHAR(45) NOT NULL ,
`TicketId` INT UNSIGNED NOT NULL , `TicketId` INT UNSIGNED NOT NULL ,
`Sender` INT(10) UNSIGNED NULL ,
PRIMARY KEY (`MailId`) , PRIMARY KEY (`MailId`) ,
INDEX `fk_email_ticket_user1` (`Sender` ASC) ,
INDEX `fk_email_ticket_user2` (`UserId` ASC) , INDEX `fk_email_ticket_user2` (`UserId` ASC) ,
INDEX `fk_email_ticket1` (`TicketId` ASC) , INDEX `fk_email_ticket1` (`TicketId` ASC) ,
CONSTRAINT `fk_email_ticket_user1` INDEX `fk_email_support_group1` (`Sender` ASC) ,
FOREIGN KEY (`Sender` )
REFERENCES `mydb`.`ticket_user` (`TUserId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_email_ticket_user2` CONSTRAINT `fk_email_ticket_user2`
FOREIGN KEY (`UserId` ) FOREIGN KEY (`UserId` )
REFERENCES `mydb`.`ticket_user` (`TUserId` ) REFERENCES `mydb`.`ticket_user` (`TUserId` )
@ -331,6 +326,11 @@ CREATE TABLE IF NOT EXISTS `mydb`.`email` (
FOREIGN KEY (`TicketId` ) FOREIGN KEY (`TicketId` )
REFERENCES `mydb`.`ticket` (`TId` ) REFERENCES `mydb`.`ticket` (`TId` )
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_email_support_group1`
FOREIGN KEY (`Sender` )
REFERENCES `mydb`.`support_group` (`SGroupId` )
ON DELETE NO ACTION
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;