creating new tickets over email works

--HG--
branch : quitta-gsoc-2013
This commit is contained in:
Quitta 2013-08-17 03:06:22 +02:00
parent 2a02f35ae8
commit 483045c613
8 changed files with 72 additions and 35 deletions

View file

@ -42,7 +42,7 @@ class Mail_Handler{
} }
public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = 1) { public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = NULL) {
if(is_numeric($recipient)) { if(is_numeric($recipient)) {
$id_user = $recipient; $id_user = $recipient;
$recipient = NULL; $recipient = NULL;
@ -134,6 +134,7 @@ class Mail_Handler{
// Check mail // Check mail
$sGroups = Support_Group::getGroups(); $sGroups = Support_Group::getGroups();
$defaultGroup = new Support_Group(); $defaultGroup = new Support_Group();
$defaultGroup->setSGroupId(0);
$defaultGroup->setGroupEmail($default_groupemail); $defaultGroup->setGroupEmail($default_groupemail);
$defaultGroup->setIMAP_MailServer($cfg['mail']['default_mailserver']); $defaultGroup->setIMAP_MailServer($cfg['mail']['default_mailserver']);
$defaultGroup->setIMAP_Username($cfg['mail']['default_username']); $defaultGroup->setIMAP_Username($cfg['mail']['default_username']);
@ -148,7 +149,7 @@ class Mail_Handler{
for ($i = 1; $i <= $message_count; ++$i) { for ($i = 1; $i <= $message_count; ++$i) {
//return task ID //return task ID
self::incoming_mail_handler($mbox, $i); self::incoming_mail_handler($mbox, $i,$group);
$tid = 1; //self::ams_create_email($from, $subject, $txt, $html, $to, $from); $tid = 1; //self::ams_create_email($from, $subject, $txt, $html, $to, $from);
if($tid) { if($tid) {
@ -182,19 +183,36 @@ class Mail_Handler{
function get_ticket_id_from_subject($subject){ function get_ticket_id_from_subject($subject){
$startpos = strpos($subject, "[Ticket #"); $startpos = strpos($subject, "[Ticket #");
if($startpos){
$tempString = substr($subject, $startpos+9); $tempString = substr($subject, $startpos+9);
$endpos = strpos($tempString, "]"); $endpos = strpos($tempString, "]");
if($endpos){
$ticket_id = substr($tempString, 0, $endpos); $ticket_id = substr($tempString, 0, $endpos);
}else{
$ticket_id = 0;
}
}else{
$ticket_id = 0;
}
return $ticket_id; return $ticket_id;
} }
function incoming_mail_handler($mbox,$i){ function incoming_mail_handler($mbox,$i,$group){
$header = imap_header($mbox, $i); $header = imap_header($mbox, $i);
$subject = self::decode_utf8($header->subject); $subject = self::decode_utf8($header->subject);
$entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i);
$subject = self::decode_utf8($header->subject);
$to = $header->to[0]->mailbox;
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$txt = self::get_part($mbox, $i, "TEXT/PLAIN");
//$html = self::get_part($mbox, $i, "TEXT/HTML");
print_r($header); //get the id out of the email address of the person sending the email.
if($from !== NULL && !is_numeric($from)){
$from = Ticket_User::get_id_from_email($from);
}
//get ticket_id out of the message-id or else out of the subject line //get ticket_id out of the message-id or else out of the subject line
$ticket_id = 0; $ticket_id = 0;
@ -209,16 +227,9 @@ class Mail_Handler{
$ticket_id = self::get_ticket_id_from_subject($subject); $ticket_id = self::get_ticket_id_from_subject($subject);
} }
//if ticket id is found //if ticket id is found, that means it is a reply on an existing ticket
if($ticket_id){ if($ticket_id){
$entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i);
$subject = self::decode_utf8($header->subject);
$to = $header->to[0]->mailbox;
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$txt = self::get_part($mbox, $i, "TEXT/PLAIN");
//$html = self::get_part($mbox, $i, "TEXT/HTML");
//use the line ---------- Ticket # to make a distincton between the old message and the reply //use the line ---------- Ticket # to make a distincton between the old message and the reply
$endpos = strpos($txt, ">---------- Ticket #"); $endpos = strpos($txt, ">---------- Ticket #");
if($endpos){ if($endpos){
@ -230,10 +241,8 @@ class Mail_Handler{
} }
} }
//if email is sent from an existing email address in the db (else it will give an error while loading the user object)
//get the id out of the email address of the person sending the email. if($from != "FALSE"){
if($from !== NULL && !is_numeric($from)) $from = Ticket_User::get_id_from_email($from);
$user = new Ticket_User(); $user = new Ticket_User();
$user->load_With_TUserId($from); $user->load_With_TUserId($from);
$ticket = new Ticket(); $ticket = new Ticket();
@ -243,6 +252,22 @@ class Mail_Handler{
if((Ticket_User::isMod($user) or ($ticket->getAuthor() == $user->getTUserId())) and $txt != ""){ if((Ticket_User::isMod($user) or ($ticket->getAuthor() == $user->getTUserId())) and $txt != ""){
Ticket::createReply($txt, $user->getTUserId(), $ticket->getTId(), 0); Ticket::createReply($txt, $user->getTUserId(), $ticket->getTId(), 0);
} }
}
}else{
//if ticket_id isn't found, create a new ticket!
//if an existing email address mailed the ticket
if($from != "FALSE"){
$newTicketId = Ticket::create_Ticket($subject, $txt,1, $from, $from);
//if not default group, then forward it!
if($group->getSGroupId()){
Ticket::forwardTicket(0, $newTicketId, $group->getSGroupId());
}
}
} }

View file

@ -197,12 +197,15 @@ class Ticket{
public static function forwardTicket($user_id, $ticket_id, $group_id){ public static function forwardTicket($user_id, $ticket_id, $group_id){
if(self::ticketExists($ticket_id)){ if(self::ticketExists($ticket_id)){
if(isset($group_id) && $group_id != ""){ if(isset($group_id) && $group_id != ""){
//unassign the ticket incase the ticket is assined to yourself
self::unAssignTicket($user_id, $ticket_id);
//forward the ticket //forward the ticket
$returnvalue = Forwarded::forwardTicket($group_id, $ticket_id); $returnvalue = Forwarded::forwardTicket($group_id, $ticket_id);
if($user_id != 0){
//unassign the ticket incase the ticket is assined to yourself
self::unAssignTicket($user_id, $ticket_id);
//make a log entry of this action //make a log entry of this action
Ticket_Log::createLogEntry( $ticket_id, $user_id, 8, $group_id); Ticket_Log::createLogEntry( $ticket_id, $user_id, 8, $group_id);
}
return $returnvalue; return $returnvalue;
}else{ }else{
return "INVALID_SGROUP"; return "INVALID_SGROUP";

View file

@ -98,8 +98,12 @@ class Ticket_User{
public static function get_id_from_email($email){ public static function get_id_from_email($email){
$webUserId = WebUsers::getIdFromEmail($email); $webUserId = WebUsers::getIdFromEmail($email);
if($webUserId != "FALSE"){
$user = Ticket_User::constr_ExternId($webUserId); $user = Ticket_User::constr_ExternId($webUserId);
return $user->getTUserId(); return $user->getTUserId();
}else{
return "FALSE";
}
} }

View file

@ -46,6 +46,7 @@ $cfg['mail']['default_groupemail'] = 'support@ryzomcore.com';
$cfg['mail']['default_groupname'] = 'Ryzomcore Support'; $cfg['mail']['default_groupname'] = 'Ryzomcore Support';
$cfg['mail']['default_username'] = 'amsryzom@gmail.com'; $cfg['mail']['default_username'] = 'amsryzom@gmail.com';
$cfg['mail']['default_password'] = 'lol123bol'; $cfg['mail']['default_password'] = 'lol123bol';
$cfg['mail']['host'] = "ryzomcore.com";
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
// If true= the server will add automatically unknown user in the database // If true= the server will add automatically unknown user in the database

View file

@ -81,7 +81,11 @@ class WebUsers extends Users{
$dbw = new DBLayer("web"); $dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email)); $statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email));
$row = $statement->fetch(); $row = $statement->fetch();
if($row !== "FALSE"){
return $row['UId']; return $row['UId'];
}else{
return "FALSE";
}
} }
public function getUId(){ public function getUId(){

View file

@ -273,7 +273,7 @@
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;
INSERT IGNORE INTO `" . $cfg['db']['lib']['name'] ."`.`ticket_category` (`Name`) VALUES ('Hacking'),('Ingame-Bug'),('Website-Bug'),('Installation'); INSERT IGNORE INTO `" . $cfg['db']['lib']['name'] ."`.`ticket_category` (`Name`) VALUES ('Uncategorized'),('Hacking'),('Ingame-Bug'),('Website-Bug'),('Installation');
@ -374,7 +374,7 @@
CONSTRAINT `fk_email_support_group1` CONSTRAINT `fk_email_support_group1`
FOREIGN KEY (`Sender` ) FOREIGN KEY (`Sender` )
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`support_group` (`SGroupId` ) REFERENCES `" . $cfg['db']['lib']['name'] ."`.`support_group` (`SGroupId` )
ON DELETE NO ACTION ON DELETE CASCADE
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;

View file

@ -310,7 +310,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`email` (
`Status` VARCHAR(45) NULL , `Status` VARCHAR(45) NULL ,
`Attempts` VARCHAR(45) NULL DEFAULT 0 , `Attempts` VARCHAR(45) NULL DEFAULT 0 ,
`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 , `Sender` INT(10) UNSIGNED NULL ,
PRIMARY KEY (`MailId`) , PRIMARY KEY (`MailId`) ,
@ -330,7 +330,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`email` (
CONSTRAINT `fk_email_support_group1` CONSTRAINT `fk_email_support_group1`
FOREIGN KEY (`Sender` ) FOREIGN KEY (`Sender` )
REFERENCES `mydb`.`support_group` (`SGroupId` ) REFERENCES `mydb`.`support_group` (`SGroupId` )
ON DELETE NO ACTION ON DELETE CASCADE
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;