- Edited
RCS file: pipe.php,v
retrieving revision 1.1
diff -u -r1.1 pipe.php
--- pipe.php 2010/10/19 21 1.1
+++ pipe.php 2010/11/08 19
@@ -13,7 +13,7 @@
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
- $Id: pipe.php,v 1.1 2010/10/19 21 root Exp $
+ $Id: pipe.php,v 1.4 2010/11/08 19 root Exp root $
**********************************************************************/
Hi, can you post here your pipe.txt or send it to my mail please? I can't understand something posted here with rcsdiff.
my pipe.php:
#!/usr/bin/php -q
<?php
/*********************************************************************
pipe.php
Converts piped emails to ticket. Both local and remote!
Peter Rotich <peter@osticket.com>
Copyright (c) 2006-2010 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());
//1
$subj=preg_replace('/^[\+/', '', $subj);
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();
//2
$var=$parser->getStruct();
$var=$var->headers;
$var=$var->headers;
$var=trim($var);
$var=strlen($var);
$var=trim($var,'<>');
if ($var===strlen($var)+2) {
$var=preg_split('/>+</', $var, PREG_SPLIT_NO_EMPTY);
} else {
$var=array();
}$var=trim($var);
$var=strlen($var);
$var=trim($var,'<>');
if ($var===strlen($var)+2) {
$var=preg_split('/>+</', $var, PREG_SPLIT_NO_EMPTY);
} else {
$var=array();
}$var=array_unique(
array_merge($var, $var));
unset($var, $var, $var,
$var);
foreach($var as $k_mmestnik => $v_mmestnik){
$var='<'.$v_mmestnik.'>';
}unset($k_mmestnik,$v_mmestnik);
openlog("OSTicket: Pipe", LOG_PID, LOG_MAIL);
syslog(LOG_DEBUG, 'Starting run for msg-id: '.$var);
$ticket=null;
foreach($var as $k_mmestnik => $v_mmestnik){
syslog(LOG_INFO, 'Search msg-id: '.$v_mmestnik);
$tickrow_mmestnik=db_query(
"SELECT ticket_id FROM ost_ticket_message WHERE messageId='$v_mmestnik'");
while($row_mmestnik = mysql_fetch_array($tickrow_mmestnik)) {
$tickid_mmestnik = $row_mmestnik;
syslog(LOG_NOTICE, 'Open ticket: '.$extid);
$ticket= new Ticket(Ticket:($extid));
if($ticket) break 2;
syslog(LOG_ERR, 'Open ticket '.$extid.' failed.');
}
}# TODO: Look for more then one and handle what else is found.
unset($var, $k_mmestnik, $v_mmestnik, $tickrow_mmestnik,
$row_mmestnik, $tickid_mmestnik);
# TODO: Clean up mysql objects properly, how?
if(!$ticket && preg_match ('/',$var,$regs)) {
$extid=trim(preg_replace("/", "", $regs));
$ticket= new Ticket(Ticket:($extid));
//Allow mismatched emails?? For now hell NO.
list($message)=split($tag,$var);
//post message....postMessage does the cleanup.
if(!($msgid=$ticket->postMessage($message,'Email',$var,$var))) {
syslog(LOG_CRIT,'Ticket postMessage failed.');
api_exit(EX_DATAERR,"Unable to post message \n\n $message\n");
}
}
closelog();
//Ticket created...save attachments if enabled.
if($cfg->allowEmailAttachments()) {
if($attachments=$parser->getAttachments()){
}
}
api_exit(EX_SUCCESS);
return NULL;
?>
No results.
Maybe it's because I have mail title like "New ticket created ". I tried answering with different titles - new tickets only.
Maybe it's because "@chdir(realpath(dirname(__FILE__)).'/'); //Change dir."? I tried using "/var/www/ost/api/pipe.php" and "/var/www/ost/api/", where it's located.