- Edited
Problems with below code
I just implemented this customisation for osticket.
The file should be class.mailfetch.php if you are using pop to retreive message.
Also I found the attachment is missing. I believe code below Line 281
//Save attachments if any.
if($msg_id && $cfg->allowEmailAttachments()){
is attach the file to the message not response. So is there any way to attach it to the response not message ?
Osticket is the best !!!
The patch below (against 1.6.0 ST) allows a response to be received from staff via imap / pop and then processed as if it had come from the web ui.The response is deemed to be from 'staff' if the from email address matches the email address for the staff member in the staff table.
diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -237,8 +237,8 @@
$var=$this->getPriority($mid);
$ticket=null;
- $newticket=true;
+ $staffId = 0;
//Check the subject line for possible ID.
if(preg_match ("",$var,$regs)) {
$extid=trim(preg_replace("/", "", $regs));
$ticket= new Ticket(Ticket:($extid));
@@ -241,9 +241,10 @@
//Check the subject line for possible ID.
if(preg_match ("",$var,$regs)) {
$extid=trim(preg_replace("/", "", $regs));
$ticket= new Ticket(Ticket:($extid));
- //Allow mismatched emails?? For now NO.
- if(!$ticket || strcasecmp($ticket->getEmail(),$var))
+ //Allow mismatched emails?? For now NO, unless it is a staff reply.
+ $staffId = $this->getStaffId($var);
+ if(!$ticket || (strcasecmp($ticket->getEmail(),$var) && $staffId == 0))
$ticket=null;
}
@@ -257,7 +258,12 @@
//Strip quoted reply...TODO: figure out how mail clients do it without special tag..
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()) && strpos($var,$tag))
list($message)=split($tag,$var);
- $msgid=$ticket->postMessage($message,'Email',$var,$var);
+ if ($staffId) {
+ $lastMsgId = $ticket->getLastMessageId();
+ $ticket->postResponseByStaff($staffId,$lastMsgId,$message);
+ } else {
+ $msgid=$ticket->postMessage($message,'Email',$var,$var);
+ }
}
//Save attachments if any.
if($msgid && $cfg->allowEmailAttachments()){
@@ -271,6 +277,16 @@
return $ticket;
}
+ function getStaffId($email) {
+ $staffId = 0;
+ $sql='SELECT staff_id FROM '.STAFF_TABLE.' WHERE email='.db_input($email);
+ if(($result=db_query($sql)) && db_num_rows($result)) {
+ $row = db_fetch_array($result);
+ $staffId = $row;
+ }
+ return $staffId;
+ }
+
function saveAttachments($ticket,$mid,$part,$index=0) {
global $cfg;
diff --git a/include/class.ticket.php b/include/class.ticket.php
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -724,4 +724,11 @@
if(!$thisuser || !$thisuser->getId() || !$thisuser->isStaff()) //just incase
return 0;
+
+ return $this->postResponseByStaff($thisuser->getId(), $msgid, $response, $signature, $attachment, $canalert);
+
+ }
+
+ function postResponseByStaff($staffId,$msgid,$response,$signature='none',$attachment=false,$canalert=true){
+ global $thisuser,$cfg;
@@ -727,6 +734,12 @@
-
+ $ipAddress = '';
+ if($thisuser) {
+ $ipAddress = $thisuser->getIP();
+ }
+
+ $staff = new Staff($staffId);
+
$sql= 'INSERT INTO '.TICKET_RESPONSE_TABLE.' SET created=NOW() '.
',ticket_id='.db_input($this->getId()).
',msg_id='.db_input($msgid).
',response='.db_input(Format:($response)).
@@ -729,10 +742,10 @@
$sql= 'INSERT INTO '.TICKET_RESPONSE_TABLE.' SET created=NOW() '.
',ticket_id='.db_input($this->getId()).
',msg_id='.db_input($msgid).
',response='.db_input(Format:($response)).
- ',staff_id='.db_input($thisuser->getId()).
- ',staff_name='.db_input($thisuser->getName()).
- ',ip_address='.db_input($thisuser->getIP());
+ ',staff_id='.db_input($staffId).
+ ',staff_name='.db_input($staff->getName()).
+ ',ip_address='.db_input($ipAddress);
$resp_id=0;
//echo $sql;
if(db_query($sql) && ($resp_id=db_insert_id())):
@@ -1061,7 +1074,16 @@
return $id;
}
-+ function getLastMessageId() {
+ $lastMessageId = 0;
+ $sql='SELECT ticketID,MAX(msg_id) AS lastMsgId FROM '.TICKET_TABLE. ' AS t '.
+ 'LEFT JOIN '.TICKET_MESSAGE_TABLE.' AS m USING(ticket_id) '.
+ 'WHERE t.ticketID='.db_input($this->extid);
+ if(($res=db_query($sql)) && db_num_rows($res))
+ list($ticketId,$lastMessageId)=db_fetch_row($res);
+ return $lastMessageId;
+ }
+
function getOpenTicketsByEmail($email){
$sql='SELECT count(*) as open FROM '.TICKET_TABLE.' WHERE status='.db_input('open').' AND email='.db_input($email);