fixing a lot of mail bug problems

This commit is contained in:
Quitta 2013-08-20 02:08:12 +02:00
parent 72a0c8303c
commit 78aa1074af
7 changed files with 85 additions and 55 deletions

View file

@ -115,9 +115,13 @@ class Helpers{
//Time output function for handling the time display function. //Time output function for handling the time display function.
static public function outputTime($time){ static public function outputTime($time, $str = 1){
global $TIME_FORMAT; global $TIME_FORMAT;
if($str){
return date($TIME_FORMAT,strtotime($time)); return date($TIME_FORMAT,strtotime($time));
}else{
return date($TIME_FORMAT,$time);
}
} }
static public function check_login_ingame(){ static public function check_login_ingame(){

View file

@ -12,14 +12,14 @@ class Mail_Handler{
} }
public static function send_ticketing_mail($ticketObj, $content, $type, $sendingGroupId = 0) { public static function send_ticketing_mail($ticketObj, $content, $type, $sendingId = 0) {
global $TICKET_MAILING_SUPPORT; global $TICKET_MAILING_SUPPORT;
if($TICKET_MAILING_SUPPORT){ if($TICKET_MAILING_SUPPORT){
//$txt = ""; //$txt = "";
//$subject = ""; //$subject = "";
if($sendingGroupId == 0){ if($sendingId == 0){
//if it is not forwarded (==public == which returns 0) then make it NULL which is needed to be placed in the DB. //if it is not forwarded (==public == which returns 0) then make it NULL which is needed to be placed in the DB.
$sendingGroupId = NULL; $sendingId = NULL;
} }
$author = $ticketObj->getAuthor(); $author = $ticketObj->getAuthor();
$webUser = new WebUsers($author); $webUser = new WebUsers($author);
@ -34,7 +34,7 @@ class Mail_Handler{
$subject = "New reply on [Ticket #" . $ticketObj->getTId() ."]"; $subject = "New reply on [Ticket #" . $ticketObj->getTId() ."]";
$endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!"; $endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!";
$txt = $txt . $content . $endTxt; $txt = $txt . $content . $endTxt;
self::send_mail($author,$subject,$txt, $ticketObj->getTId(),$sendingGroupId); self::send_mail($author,$subject,$txt, $ticketObj->getTId(),$sendingId);
break; break;
case "NEW": case "NEW":
@ -43,7 +43,7 @@ class Mail_Handler{
$subject = "New ticket created [Ticket #" . $ticketObj->getTId() ."]"; $subject = "New ticket created [Ticket #" . $ticketObj->getTId() ."]";
$endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!"; $endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!";
$txt = $txt . $content . $endTxt; $txt = $txt . $content . $endTxt;
self::send_mail($author,$subject,$txt, $ticketObj->getTId(), $sendingGroupId); self::send_mail($author,$subject,$txt, $ticketObj->getTId(), $sendingId);
break; break;
} }
} }
@ -52,10 +52,12 @@ class Mail_Handler{
public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = NULL) { public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = NULL) {
$id_user = NULL;
if(is_numeric($recipient)) { if(is_numeric($recipient)) {
$id_user = $recipient; $id_user = $recipient;
$recipient = NULL; $recipient = NULL;
} }
$query = "INSERT INTO email (Recipient,Subject,Body,Status,Attempts,Sender,UserId,MessageId,TicketId) VALUES (:recipient, :subject, :body, :status, :attempts, :sender, :id_user, :messageId, :ticketId)"; $query = "INSERT INTO email (Recipient,Subject,Body,Status,Attempts,Sender,UserId,MessageId,TicketId) VALUES (:recipient, :subject, :body, :status, :attempts, :sender, :id_user, :messageId, :ticketId)";
$values = array('recipient' => $recipient, 'subject' => $subject, 'body' => $body, 'status' => 'NEW', 'attempts'=> 0, 'sender' => $from,'id_user' => $id_user, 'messageId' => 0, 'ticketId'=> $ticket_id); $values = array('recipient' => $recipient, 'subject' => $subject, 'body' => $body, 'status' => 'NEW', 'attempts'=> 0, 'sender' => $from,'id_user' => $id_user, 'messageId' => 0, 'ticketId'=> $ticket_id);
$db = new DBLayer("lib"); $db = new DBLayer("lib");
@ -74,9 +76,8 @@ class Mail_Handler{
$oms_reply_to = "Ryzom Ticketing Support <ticketing@".$inbox_host.">";*/ $oms_reply_to = "Ryzom Ticketing Support <ticketing@".$inbox_host.">";*/
global $MAIL_DIR; global $MAIL_DIR;
echo("\n========================================================\n");
// Deliver new mail echo("mailing cron Job started at: ". Helpers::outputTime(time(),0) . "\n");
echo("mail cron\n");
//creates child process //creates child process
$pid = self::mail_fork(); $pid = self::mail_fork();
@ -91,6 +92,7 @@ class Mail_Handler{
//>0: "In parent!\n"; //>0: "In parent!\n";
} else { } else {
//deliver new mail
//make db connection here because the children have to make the connection. //make db connection here because the children have to make the connection.
$this->db = new DBLayer("lib"); $this->db = new DBLayer("lib");
@ -112,7 +114,6 @@ class Mail_Handler{
$message_id = self::new_message_id($email['TicketId']); $message_id = self::new_message_id($email['TicketId']);
//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");
if(!$email['Recipient']) { if(!$email['Recipient']) {
$email['Recipient'] = Ticket_User::get_email_by_user_id($email['UserId']); $email['Recipient'] = Ticket_User::get_email_by_user_id($email['UserId']);
} }
@ -146,7 +147,7 @@ class Mail_Handler{
//decrypt passwords in the db! //decrypt passwords in the db!
$crypter = new MyCrypt($cfg['crypt']); $crypter = new MyCrypt($cfg['crypt']);
foreach($sGroups as $group){ foreach($sGroups as $group){
$group->setIMAP_Password($crypter->decrypt($cfg['mail']['default_password'])); $group->setIMAP_Password($crypter->decrypt($group->getIMAP_Password()));
} }
$defaultGroup = new Support_Group(); $defaultGroup = new Support_Group();
@ -161,18 +162,19 @@ class Mail_Handler{
foreach($sGroups as $group){ foreach($sGroups as $group){
//check if group has mailing stuff filled in! //check if group has mailing stuff filled in!
if($group->getGroupEmail() != "" && $group->getIMAP_MailServer() != "" && $group->getIMAP_Username() != "" && $group->getIMAP_Password() != "") if($group->getGroupEmail() != "" && $group->getIMAP_MailServer() != "" && $group->getIMAP_Username() != "" && $group->getIMAP_Password() != ""){
$mbox = imap_open($group->getIMAP_MailServer(), $group->getIMAP_Username(), $group->getIMAP_Password()) or die('Cannot connect to mail server: ' . imap_last_error()); $mbox = imap_open($group->getIMAP_MailServer(), $group->getIMAP_Username(), $group->getIMAP_Password()) or die('Cannot connect to mail server: ' . imap_last_error());
$message_count = imap_num_msg($mbox); $message_count = imap_num_msg($mbox);
for ($i = 1; $i <= $message_count; ++$i) { for ($i = 1; $i <= $message_count; ++$i) {
//return task ID //return task ID
$tid = self::incoming_mail_handler($mbox, $i,$group); $tkey = self::incoming_mail_handler($mbox, $i,$group);
if($tid) { if($tkey) {
//TODO: base file on Ticket + timestamp //TODO: base file on Ticket + timestamp
$file = fopen($MAIL_DIR."/mail/ticket".$tid.".".time(), 'w'); $file = fopen($MAIL_DIR."/ticket".$tkey, 'w');
print("Email was written to ".$MAIL_DIR."/ticket".$tkey."\n");
fwrite($file, imap_fetchheader($mbox, $i) . imap_body($mbox, $i)); fwrite($file, imap_fetchheader($mbox, $i) . imap_body($mbox, $i));
fclose($file); fclose($file);
@ -186,8 +188,11 @@ class Mail_Handler{
imap_close($mbox); imap_close($mbox);
} }
} }
print("\nChild Cron job finished at ". Helpers::outputTime(time(),0) . "\n");
echo("========================================================\n");
} }
} }
@ -227,6 +232,7 @@ class Mail_Handler{
$subject = self::decode_utf8($header->subject); $subject = self::decode_utf8($header->subject);
$to = $header->to[0]->mailbox; $to = $header->to[0]->mailbox;
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host; $from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$fromEmail = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$txt = self::get_part($mbox, $i, "TEXT/PLAIN"); $txt = self::get_part($mbox, $i, "TEXT/PLAIN");
//$html = self::get_part($mbox, $i, "TEXT/HTML"); //$html = self::get_part($mbox, $i, "TEXT/HTML");
@ -251,32 +257,52 @@ class Mail_Handler{
//if ticket id is found, that means it is a reply on an existing ticket //if ticket id is found, that means it is a reply on an existing ticket
if($ticket_id){ if($ticket_id){
//use the line ---------- Ticket # to make a distincton between the old message and the reply $ticket = new Ticket();
/*$endpos = strpos($txt, ">---------- Ticket #"); $ticket->load_With_TId($ticket_id);
if($endpos){
$txt = substr($txt, 0, $endpos);
}else{
$endpos = strpos($txt, "---------- Ticket #");
if($endpos){
$txt = substr($txt, 0, $endpos);
}
}*/
//if email is sent from an existing email address in the db (else it will give an error while loading the user object) //if email is sent from an existing email address in the db (else it will give an error while loading the user object)
if($from != "FALSE"){ if($from != "FALSE"){
$user = new Ticket_User(); $user = new Ticket_User();
$user->load_With_TUserId($from); $user->load_With_TUserId($from);
$ticket = new Ticket();
$ticket->load_With_TId($ticket_id);
//if user has access to it! //if user has access to it!
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);
print("Email found that is a reply to a ticket at:".$group->getGroupEmail()."\n");
}else{
//if user has no access to it
//Warn real ticket owner + person that send the mail
$subject_warnAuthor = "Someone tried to reply to your ticket: [Ticket #" . $ticket->getTId() ."]";
$body_warnAuthor = "Someone tried to reply at your ticket: " . $ticket->getTitle() ."by sending an email from ".$fromEmail."! Please use the email address matching to your account if you want to auto reply!\n\n
If ". $fromEmail. " isn't one of your email addresses, please contact us by replying to this ticket!" ;
Mail_Handler::send_mail($ticket->getAuthor(), $subject_warnAuthor , $body_warnAuthor, $ticket->getTId(), NULL);
$subject_warnSender = "You tried to reply to someone elses ticket!";
$body_warnSender = "It seems you tried to reply to someone elses ticket, please use the matching email address to that account!\n\n
This action is notified to the real ticket owner!" ;
Mail_Handler::send_mail($from, $subject_warnSender , $body_warnSender, $ticket->getTId(), NULL);
print("Email found that was a reply to a ticket, though send by another user to ".$group->getGroupEmail()."\n");
} }
}else{
//if a reply to a ticket is being sent by a non-user!
//Warn real ticket owner + person that send the mail
$subject_warnAuthor = "Someone tried to reply to your ticket: [Ticket #" . $ticket->getTId() ."]";
$body_warnAuthor = "Someone tried to reply at your ticket:' " . $ticket->getTitle() ."' by sending an email from ".$fromEmail." ! Please use the email address matching to your account if you want to auto reply!\n\n
If ". $fromEmail. " isn't one of your email addresses, please contact us by replying to this ticket!" ;
Mail_Handler::send_mail($ticket->getAuthor(), $subject_warnAuthor , $body_warnAuthor, $ticket->getTId(), NULL);
$subject_warnSender = "You tried to reply to someone's ticket!";
$body_warnSender = "It seems you tried to reply to someone's ticket, However this email address isn't linked to any account, please use the matching email address to that account!\n\n
This action is notified to the real ticket owner!" ;
Mail_Handler::send_mail($fromEmail, $subject_warnSender , $body_warnSender, $ticket->getTId(), NULL);
print("Email found that was a reply to a ticket, though send by an unknown email address to ".$group->getGroupEmail()."\n");
} }
print("\n Email found that is a reply to a ticket at:".$group->getGroupEmail());
return $ticket_id; return $ticket_id .".".time();
}else if($from != "FALSE"){ }else if($from != "FALSE"){
@ -286,13 +312,13 @@ class Mail_Handler{
//if not default group, then forward it by giving the $group->getSGroupId's param //if not default group, then forward it by giving the $group->getSGroupId's param
$newTicketId = Ticket::create_Ticket($subject, $txt,1, $from, $from, $group->getSGroupId()); $newTicketId = Ticket::create_Ticket($subject, $txt,1, $from, $from, $group->getSGroupId());
print("\n Email regarding new ticket found at:".$group->getGroupEmail()); print("Email regarding new ticket found at:".$group->getGroupEmail()."\n");
return $newTicketId; return $newTicketId .".".time();
}else{ }else{
//if it's a email that has nothing to do with ticketing, return 0; //if it's a email that has nothing to do with ticketing, return 0;
print("\n Email found that isn't a reply or new ticket, at:".$group->getGroupEmail()); print("Email found that isn't a reply or new ticket, at:".$group->getGroupEmail()."\n");
return 0; return 0;
} }
@ -367,3 +393,4 @@ class Mail_Handler{
} // END OF FUNCTION } // END OF FUNCTION
} }

View file

@ -55,7 +55,7 @@ user_not_existing = "The user doesn't seem to exist"
not_mod_or_admin = "You can only add Moderators or Admins!" not_mod_or_admin = "You can only add Moderators or Admins!"
modify_mail_of_group_success = "The Support Group's email settings have been modified!" modify_mail_of_group_success = "The Support Group's email settings have been modified!"
email_not_valid = "The group email address is invalid!" email_not_valid = "The group email address is invalid!"
no_password_given = "There was no password filled in!" no_password_given = "Be aware that there was no password filled in, so the password is empty atm!"
[sgroup_list] [sgroup_list]
group_success = "The group has been created!" group_success = "The group has been created!"

View file

@ -51,7 +51,7 @@ user_not_existing = "cet user n'existe pas"
not_mod_or_admin = "C'est possible d'ajoute seulement des mods et admins!" not_mod_or_admin = "C'est possible d'ajoute seulement des mods et admins!"
modify_mail_of_group_success = "Les parametres de messagerie du Groupe d'appui ont ete modifies!" modify_mail_of_group_success = "Les parametres de messagerie du Groupe d'appui ont ete modifies!"
email_not_valid = "L'adresse email de groupe est invalide!" email_not_valid = "L'adresse email de groupe est invalide!"
no_password_given = "Il'n y a pas une passport!" no_password_given = "Soyez conscient qu'il n'y avait aucun mot de passe remplie, de sorte que le mot de passe est atm vide!"
[sgroup_list] [sgroup_list]

View file

@ -51,7 +51,7 @@ $cfg['mail']['host'] = "ryzomcore.com";
//Defines mailing related stuff //Defines mailing related stuff
$SUPPORT_GROUP_IMAP_CRYPTKEY = "azerty"; $SUPPORT_GROUP_IMAP_CRYPTKEY = "azerty";
$TICKET_MAILING_SUPPORT = true; $TICKET_MAILING_SUPPORT = true;
$MAIL_DIR = "/tmp"; $MAIL_DIR = "/tmp/mail";
$cfg['crypt']['key'] = 'Sup3rS3cr3tStuff'; $cfg['crypt']['key'] = 'Sup3rS3cr3tStuff';
$cfg['crypt']['enc_method'] = 'AES-256-CBC'; $cfg['crypt']['enc_method'] = 'AES-256-CBC';

View file

@ -9,9 +9,8 @@ function modify_email_of_sgroup(){
$sgroupid = filter_var($_POST['target_id'],FILTER_SANITIZE_NUMBER_INT); $sgroupid = filter_var($_POST['target_id'],FILTER_SANITIZE_NUMBER_INT);
$group = Support_Group::getGroup($sgroupid); $group = Support_Group::getGroup($sgroupid);
$groupemail = filter_var($_POST['GroupEmail'],FILTER_SANITIZE_STRING); $groupemail = filter_var($_POST['GroupEmail'],FILTER_SANITIZE_STRING);
if(Users::validEmail($groupemail)){ if(Users::validEmail($groupemail) || $groupemail == ""){
$password = filter_var($_POST['IMAP_Password'],FILTER_SANITIZE_STRING); $password = filter_var($_POST['IMAP_Password'],FILTER_SANITIZE_STRING);
if($password != ""){
$group->setGroupEmail($groupemail); $group->setGroupEmail($groupemail);
$group->setIMAP_MailServer(filter_var($_POST['IMAP_MailServer'],FILTER_SANITIZE_STRING)); $group->setIMAP_MailServer(filter_var($_POST['IMAP_MailServer'],FILTER_SANITIZE_STRING));
$group->setIMAP_Username(filter_var($_POST['IMAP_Username'],FILTER_SANITIZE_STRING)); $group->setIMAP_Username(filter_var($_POST['IMAP_Username'],FILTER_SANITIZE_STRING));
@ -23,7 +22,7 @@ function modify_email_of_sgroup(){
$group->setIMAP_Password($enc_password); $group->setIMAP_Password($enc_password);
$group->update(); $group->update();
$result['RESULT_OF_MODIFYING'] = "SUCCESS"; $result['RESULT_OF_MODIFYING'] = "SUCCESS";
}else{ if($password == ""){
$result['RESULT_OF_MODIFYING'] = "NO_PASSWORD"; $result['RESULT_OF_MODIFYING'] = "NO_PASSWORD";
} }
}else{ }else{

View file

@ -164,7 +164,7 @@
{$email_not_valid} {$email_not_valid}
</div> </div>
{else if isset($RESULT_OF_MODIFYING) and $RESULT_OF_MODIFYING eq "NO_PASSWORD"} {else if isset($RESULT_OF_MODIFYING) and $RESULT_OF_MODIFYING eq "NO_PASSWORD"}
<div class="alert alert-error"> <div class="alert alert-warning">
{$no_password_given} {$no_password_given}
</div> </div>
{/if} {/if}