I’m simply poking around trying to see hot to get this working. I think i might be able to with some simple code changes.
So far I am working backwards. So right now I have been able to get the email close to send. First I edited AOPInboundEmail.php
Particularly the handleCreateCase function.
First I wanted to change the priority to low for every created case. Not all emails are high priority, and we can then change the priority to high or medium dependent on the case.
$c->assigned_user_id = $userId;
$c->name = $email->name;
$c->status = 'New';
$c->priority = 'P3';//HERE I CHANGED THE PRIORITY FROM P1 to P3
Then in studio I created a custom field called email_c to store the incoming email that created the case. Later I should expand this to find a method to save all emails in the thread. So all emails in the thread can be updated. Like if we included a manager etc.
So after the above code in the function i added
if(!empty($email->reply_to_email)) {
$contactAddr = $email->reply_to_email;
} else {
$contactAddr = $email->from_addr;
}
//ADDING STORING EMAIL FROM WHO CREATED THE CASE, THE ORIGIN EMAIL!
//MAYBE THIS WILL WORK TOWARD GETTING CASES TO WORK WITH ALL EMAILS
$c->email_c = $contactAddr;
Then I had to look in CaseUpdatesHook.php located /modules/AOP_Case_Updates/
Changed the following code inside sendClosureEmail function
$contact = $bean->get_linked_beans("contacts","Contact");
if($contact){
$contact = $contact[0];
}else{
return false;
}
$emailSettings = getPortalEmailSettings();
$text = $this->populateTemplate($email_template, $bean, $contact);
$mailer->Subject = $text['subject'];
$mailer->Body = $text['body'];
$mailer->IsHTML(true);
$mailer->AltBody = $text['body_alt'];
$mailer->From = $emailSettings['from_address'];
$mailer->FromName = $emailSettings['from_name'];
$email = $contact->emailAddress->getPrimaryAddress($contact);
To this code
$contact = $bean->get_linked_beans("contacts","Contact");
if($contact){
$contact = $contact[0];
$emailSettings = getPortalEmailSettings();
$text = $this->populateTemplate($email_template, $bean, $contact);
$mailer->Subject = $text['subject'];
$mailer->Body = $text['body'];
$mailer->IsHTML(true);
$mailer->AltBody = $text['body_alt'];
$mailer->From = $emailSettings['from_address'];
$mailer->FromName = $emailSettings['from_name'];
$email = $contact->emailAddress->getPrimaryAddress($contact);
}else{
$emailSettings = getPortalEmailSettings();
$text = $this->populateTemplateNoContact($email_template, $bean);
$mailer->Subject = $text['subject'];
$mailer->Body = $text['body'];
$mailer->IsHTML(true);
$mailer->AltBody = $text['body_alt'];
$mailer->From = $emailSettings['from_address'];
$mailer->FromName = $emailSettings['from_name'];
$email = $bean->email_c;
//return false;
}
I also created a copy of the populateTemplate function to one that does not include contacts.
private function populateTemplateNoContact(EmailTemplate $template, aCase $bean){
global $app_strings, $sugar_config;
//Order of beans seems to matter here so we place contact first.
$beans = array(
//"Contacts" => $contact->id,
"Cases" => $bean->id,
"Users" => $bean->assigned_user_id
);
$ret = array();
$ret['subject'] = from_html(aop_parse_template($template->subject,$beans));
$ret['body'] = from_html($app_strings['LBL_AOP_EMAIL_REPLY_DELIMITER'].aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body_html),$beans));
$ret['body_alt'] = strip_tags(from_html(aop_parse_template(str_replace("\$sugarurl",$sugar_config['site_url'],$template->body),$beans)));
return $ret;
}
So far this allows the case close email to be sent without a contact