My ADD ON / MOD for adding a CC list to OST 1.6rc5 relies on creating a separate field in the database for them. This was the only way that made sense to me.
You will need to add one field to the ticket table. Something like this... replace the 'ostticket' prefix with whatever your prefix is.
ALTER TABLE `ost_ticket` ADD `emailcc` TEXT NOT NULL AFTER `email`
The character limit on the field is up to you.
Summary: These changes will create an email CC list in comma delimited form and store them in the database. Then each time a response is made it will send out send to the main requestor and CC the list. It will also compare incoming emails to see if new ones were added to the CC list. It checks the email list against the system emails from OST so that it won't CC itself (and create a huge mess of emails = ugly). You should test this out in a test bed first to make sure it works with your setup as always.
Here are the files I updated. I tried to make the solution complete in that I started with pipe email and then went to imap so it works with both and even though I don't use the form to open tickets I added it there. Not perfect but should get things going.
PART I
../api/pipe.php
replace this
$from=$fromlist; //Default.
foreach($fromlist as $fromobj){
if(!Validator:($fromobj->mailbox.'@'.$fromobj->host))
continue;
$from=$fromobj;
break;
}
with this
//need to make sure FROM is not one of our emails... you would think they have this already --kurt
$ouremailquery=db_query('SELECT `email` FROM `ost_email`');
$from=$fromlist; //Default.
foreach($fromlist as $fromobj){
if(!Validator:($fromobj->mailbox.'@'.$fromobj->host))
continue;
//add in a check to make sure FROM does not contain one of our own emails..
//may be unique to our situation with an email list and adding cc --kurt
while (list($ouremail) = db_fetch_row($ouremailquery)){
if(strtolower($ouremail)==strtolower($fromobj->mailbox.'@'.$fromobj->host)){
api_exit(EX_DATAERR,'Invalid FROM address \n\n".$data);
}
}
$from=$fromobj;
break;
}
after this TODO
//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
place this code:
$ccray = array();
if($ccd=$parser->getCcAddressList()) {
foreach ($ccd as $ccEmails){
$ccCandidate = $ccEmails->mailbox.'@'.$ccEmails->host;
array_push($ccray, strtolower($ccCandidate));
}
}
if($tos=$parser->getMyToAddressList()) {
foreach ($tos as $toEmails){
$ccCandidate = $toEmails->mailbox.'@'.$toEmails->host;
array_push($ccray, strtolower($ccCandidate));
}
}
if(isset($ccray)){
$ouremailquery=db_query('SELECT `email` FROM ost_email');
$ouremails = array();
while(list($ouremail) = db_fetch_row($ouremailquery)){
array_push($ouremails, $ouremail);
}
$ccscrub = array_diff($ccray,$ouremails);
$cc = implode(",",$ccscrub);
}
after:
$var=$from->mailbox.'@'.$from->host;
add:
$var=$cc;
right above this comment
//post message....postMessage does the cleanup.
Add:
if(!($msgid=$ticket->updateEmailcc($var.','.$var))){
api_exit(EX_DATAERR,"Unable to update cc list \n\n"); //put error here to see if we break it
}
then in ../include/class.mailfetch.php
after this block
function getHeaderInfo($mid) {
$headerinfo=imap_headerinfo($this->mbox,$mid);
$sender=$headerinfo->from;
add in this code
//slightly different from pipe... using native php imap mail functions to get to and cc objects
$ccray = array();
$tos = $headerinfo->to;
foreach ($tos as $id => $toobject) {
$ccaddress = $toobject->mailbox . "@" . $toobject->host;
array_push($ccray, strtolower($ccaddress));
}
$ccs = $headerinfo->cc;
foreach ($ccs as $id => $ccobject) {
$ccaddress = $ccobject->mailbox . "@" . $ccobject->host;
array_push($ccray, strtolower($ccaddress));
}
if(isset($ccray)){
$ouremailquery=db_query('SELECT `email` FROM ost_email');
$ouremails = array();
while(list($ouremail) = db_fetch_row($ouremailquery)){
array_push($ouremails, $ouremail);
}
$ccscrub = array_diff($ccray,$ouremails);
$cc = implode(",",$ccscrub);
$cc=ltrim($cc, ",");
$cc=rtrim($cc, ",");
}
change this
//Parse what we need...
$header=array(
'from' =>array('name' =>@$sender->personal,'email' =>strtolower($sender->mailbox).'@'.$sender->host),
'subject'=>@$headerinfo->subject,
'mid' =>$headerinfo->message_id);
return $header;
}
to this
//Parse what we need...
$header=array(
'from' =>array('name' =>@$sender->personal,'email' =>strtolower($sender->mailbox).'@'.$sender->host),
'cc' =>$cc,
'subject'=>@$headerinfo->subject,
'mid' =>$headerinfo->message_id);
return $header;
}
after this line
$var=$mailinfo;
add this
$var=$mailinfo;
after this line
$msgid=$ticket->postMessage($message,'Email',$var,$var);
add this
$msgid=$ticket->updateEmailcc($var.','.$var);
then in ../include/class.email.php
after
var $email;
add
var $emailcc;
change this line
function send($to,$subject,$message,$attachment=null) {
to this
function send($to,$cc,$subject,$message,$attachment=null) {
after
global $cfg;
add this
$cc = str_replace('|',',',$cc);
after
$to = preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
add this
//in order for smtp emails to work with CC we have to send a full list of recipients into PEAR mail factory
//the headers tell the client what to display to vs cc --Kurt
$recipients=$to.','.preg_replace("/(\r\n|\r|\n)/s",'', trim($cc));
change this array
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Message-ID' =>'<'.Misc:(6).''.time().'-'.$this->getEmail().'>',
'X-Mailer' =>'osTicket v 1.6'
);
to this
$headers = array ('From' => $from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject,
'Message-ID' =>'<'.Misc:(6).''.time().'-'.$this->getEmail().'>',
'Content-Type' => 'text/html; charset=UTF-8',
'X-Mailer' =>'osTicket v 1.6'
);
Also change the sendmail function
function sendmail($to,$subject,$message,$from) {
to this
function sendmail($to,$cc,$subject,$message,$from) {
update the array to include cc from this
$headers = array ('From' =>$from,
'To' => $to,
'Subject' => $subject,
'Message-ID' =>'<'.Misc:(10).''.time().'@osTicket>',
'X-Mailer' =>'osTicket v 1.6'
);
to this
$headers = array ('From' =>$from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject,
'Message-ID' =>'<'.Misc:(10).''.time().'@osTicket>',
'X-Mailer' =>'osTicket v 1.6'
);