I am completely baffled here. Thought I had found the issue but still not working
All I want is that if a customer replys to a ticket that we in the support department get an alert telling us that they have responded so we can act on it.
This is the pipe.php code anything wrong here?
!/usr/bin/php -q
<?php
/*********************************************************************
pipe.php
Converts piped emails to ticket. Both local and remote!
Peter Rotich <peter@osticket.com>
Copyright (c) 2006,2007,2008,2009 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
$Id: $
**********************************************************************/
<USERMENTION username="chdir">@chdir</USERMENTION>(realpath(dirname(__FILE__)).'/'); //Change dir.
ini_set('memory_limit', '256M'); //The concern here is having enough mem for emails with attachments.
require('api.inc.php');
require_once(INCLUDE_DIR.'class.mailparse.php');
require_once(INCLUDE_DIR.'class.email.php');
//Make sure piping is enabled!
if(!$cfg->enableEmailPiping())
api_exit(EX_UNAVAILABLE,'Email piping not enabled - check MTA settings.');
//Get the input
$data=isset($_SERVER)?file_get_contents('php://input')('php://stdin');
if(empty($data)){
api_exit(EX_NOINPUT,'No data');
}
//Parse the email.
$parser= new Mail_Parse($data);
if(!$parser->decode()){ //Decode...returns false on decoding errors
api_exit(EX_DATAERR,'Email parse failed \n\n".$data);
}
//Check from address. make sure it is not a banned address.
$fromlist = $parser->getFromAddressList();
//Check for parsing errors on FROM address.
if(!$fromlist || PEAR:($fromlist)){
api_exit(EX_DATAERR,'Invalid FROM address \n\n".$data);
}
$from=$fromlist; //Default.
foreach($fromlist as $fromobj){
if(!Validator:($fromobj->mailbox.'@'.$fromobj->host))
continue;
$from=$fromobj;
break;
}
//TO Address to figure out the email associated with the message.
$tolist = $parser->getToAddressList();
foreach ($tolist as $toaddr){
if(($emailId=Email:($toaddr->mailbox.'@'.$toaddr->host))){
//We've found target email.
break;
}
}
if(!$emailId && ($cclist=$parser->getCcAddressList())) {
foreach ($cclist as $ccaddr){
if(($emailId=Email:($ccaddr->mailbox.'@'.$ccaddr->host))){
break;
}
}
}
//TODO: Options to reject emails without a matching To address in db? May be it was Bcc? Current Policy: If you pipe, we accept policy
require_once(INCLUDE_DIR.'class.ticket.php'); //We now need this bad boy!
$var=array();
$deptId=0;
$name=trim($from->personal,'"');
if($from->comment && $from->comment)
$name.=' ('.$from->comment.')';
$subj=utf8_encode($parser->getSubject());
if(!($body=Format:($parser->getBody())) && $subj)
$body=$subj;
$var=$parser->getMessageId();
$var=$from->mailbox.'@'.$from->host;
$var=$name?utf8_encode($name):$var;
$var=$emailId?$emailId:$cfg->getDefaultEmailId();
$var=$subj?$subj:'';
$var=utf8_encode(Format:($body));
$var=$parser->getHeader();
$var=$cfg->useEmailPriority()?$parser->getPriority();
$ticket=null;
if(ereg ("{1,10}",$var,$regs)) {
$extid=trim(preg_replace("/", "", $regs));
$ticket= new Ticket(Ticket:($extid));
//Allow mismatched emails?? For now hell NO.
if(!is_object($ticket) || strcasecmp($ticket->getEmail(),$var))
$ticket=null;
}
$errors=array();
$msgid=0;
if(!$ticket){ //New tickets...
$ticket=Ticket:($var,$errors,'email');
if(!is_object($ticket) || $errors){
api_exit(EX_DATAERR,'Ticket create Failed '.implode("\n",$errors)."\n\n");
}
$msgid=$ticket->getLastMsgId();
}else{
$message=$var;
//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);
//post message....postMessage does the cleanup.
if(!($msgid=$ticket->postMessage($message,'Email',$var,$var))) {
api_exit(EX_DATAERR,"Unable to post message \n\n $message\n");
}
}
//Ticket created...save attachments if enabled.
$struct=$parser->getStruct();
if($struct && $struct->parts && $cfg->allowEmailAttachments()) {
for($i = 0; $i < count($struct->parts); $i++) {
$part=$struct->parts;
if($part->disposition
&& (!strcasecmp($part->disposition,'attachment') || !strcasecmp($part->disposition,'inline') || !strcasecmp($part->ctype_primary,'image'))){
$filename=$part->d_parameters;
if($filename && $cfg->canUploadFileType($filename)) {
$ticket->saveAttachment($filename,$part->body,$msgid,'M');
}
}
}
}
//print_r($var);
api_exit(EX_SUCCESS);
?>