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);

a month later

This is something we definitely need, I've read though up to this point but not certain which pipe.php file is in working order..

Please advise if this is resolved. It would be very helpful for us!

11 days later

I also would love to have this feature as i have some people that are pretty much mobile workers and are not able to login to the system from their smartphone. thank you.

2 months later

Which files are working correctly on this??

Which files are working correctly on this??:

3 months later

Does anyone have an actual working set of files or code to accomplish this for 1.6ST?

I've seen tons of posts about it but can't really find anything assuring it is fully functional.

22 days later

This is absolutely a 'must be' implemented feature for IMAP/POP3 mail process.

Reply via web (without a WYSIWYG editor) is an hard job.... :)

3 months later

Does anybody know if this is working yet for 1.7. Would love for my staff to be able to reply by email so we are not tethered to the office pc always. Thanks for any reply in the correct direction. :)

25 days later

Does anybody know if this is working yet for 1.7. Would love for my staff to be able to reply by email so we are not tethered to the office pc always. Thanks for any reply in the correct direction. :)

Working on it

8 days later

1.7

Hi guys.

I see above there is a solution being worked on for 1.7!

That is fantastic news. Is there any ETA on this?

I'm happy to offer up my environment for any testing.

Jemson

7 days later

i'll be keeping an eye on this thread!

Just checking in to see if there is any news on this? Would make my staffs job so much easier. Is there anything I can do to help in anyway speed this along?

Kindest Regards,

Jeremy

5 days later

Working Replies (for IMAP) on 1.7

Hi All,

I managed to hack something together that works for me (I'm using IMAP).

I'm sure some of the elements could be streamlined or make better use of existing functions, but it works for me.

Please see the following thread: http://osticket.com/forums/showthread.php?t=14164(http://osticket.com/forums/showthread.php?t=14164)

Originally posted the mod, but it is actually a 1.7 mod so moved to the above thread so it can be tracked easier.

Write a Reply...