Hi ive modified some code to import the mail to sugar and attach to the case based on case no. within the subject line, when u click the "Check Mail" u modify based on ur requirement.
changed modules/inboundEmail/InboundEmail.php
======================================
importOneEmail function
======================================
added this code to attach mail to the case and save the comment passed in the mail to case(myown functionality u may ommit this)
Code:
if (!empty($_REQUEST['parent_id']) && !empty($_REQUEST['parent_type'])) {
$email->parent_id = $_REQUEST['parent_id'];
$email->parent_type = $_REQUEST['parent_type'];
$mod = strtolower($email->parent_type);
$email->load_relationship($mod);
$email->$mod->add($email->parent_id);
if($_REQUEST['parent_type']=='Cases')
{
if(!class_exists('aCase')) {
require_once('modules/Cases/Case.php');
}
$c = new aCase();
if($caseId = InboundEmail::getCaseIdFromCaseNumber($email->custom_fields->bean->name, $c)) {
$c->retrieve($caseId);
$c->load_relationship('emails');
$c->emails->add($this->id);
$this->parent_type = "Cases";
$this->parent_id = $caseId;
//to save the comment from email...
global $db;
$cid=create_guid();
if($email->description!="")
{ $creator=($email->contact_name) ? $email->from_addr_name : $email->from_addr;
$db->query("insert into comments(id,case_id,comment,created,creator_name)values('{$cid}','{$caseId}','{$email->description}',NOW(),'{$creator}')");
}
} // if
}
}
//now if redirected from check email progress then parent_id and type is blank so hv to assign manually
if(empty($_REQUEST['parent_type']))
{
if(!class_exists('aCase')) {
require_once('modules/Cases/Case.php');
}
$c = new aCase();
if($caseId = InboundEmail::getCaseIdFromCaseNumber($email->custom_fields->bean->name, $c)) {
$c->retrieve($caseId);
$c->load_relationship('emails');
$c->emails->add($this->id);
$this->parent_type = "Cases";
$this->parent_id = $caseId;
//change by bc 5_4_11
//to save the comment from email...
global $db;
$cid=create_guid();
if($email->description!="")
{ $creator=($email->contact_name) ? $email->from_addr_name : $email->from_addr;
$db->query("insert into comments(id,case_id,comment,created,creator_name,modified_user)values('{$cid}','{$caseId}','{$email->description}',NOW(),'{$creator}','{$creator}')");
}
} // if
} ================================================== ===============================
then
======================================
handleCaseAssignment function
=====================================
Code:
function handleCaseAssignment(&$email) {
if(!class_exists('aCase')) {
require_once('modules/Cases/Case.php');
}
$c = new aCase();
if($caseId = $this->getCaseIdFromCaseNumber($email->name, $c)) {
$c->retrieve($caseId);
$c->load_relationship('emails');
$c->emails->add($email->id);
$email->retrieve($email->id);
$email->parent_type = "Cases";
$email->parent_id = $caseId;
// assign the email to the case owner
if(array_key_exists('email', get_defined_vars()))
{
if(array_key_exists('assigned_user_id', get_defined_vars()))
{
$email->$assigned_user_id = $c->assigned_user_id;
}
}
$email->save();
$GLOBALS['log']->debug('InboundEmail found exactly 1 match for a case: '.$c->name);
return true;
} // if
return false;
} // fn ================================================== ========
changed modules/Email/EmailUIAjax.php
Code:
case "checkEmailProgress":
debugbreak();
$GLOBALS['log']->info("[EMAIL] - Start checkEmail action for user [{$current_user->user_name}]");
if(isset($_REQUEST['ieId']) && !empty($_REQUEST['ieId'])) {
$ie->retrieve($_REQUEST['ieId']);
$ie->mailbox = (isset($_REQUEST['mbox']) && !empty($_REQUEST['mbox'])) ? $_REQUEST['mbox'] : "INBOX";
$synch = (isset($_REQUEST['synch']) && ($_REQUEST['synch'] == "true"));
if ($ie->protocol == "pop3") {
$return = $ie->pop3_checkPartialEmail($synch);
} else {
$return = $ie->checkEmailIMAPPartial(false, $synch);
}
$return['ieid'] = $ie->id;
$return['synch'] = $synch;
// echo $json->encode($return);
//================================================================================================adde this code copied from the importEmail case
$GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: importEmail");
$ie->retrieve($_REQUEST['ieId']);
$ie->mailbox = $_REQUEST['mbox'];
$ie->connectMailserver();
$return = array();
$status = true;
$count = 1;
global $current_user;
global $db;
$res=$db->query("select * from email_cache where ie_id='{$_REQUEST['ieId']}' and seen='0'");
while($data=$db->fetchByAssoc($res)){
if(strpos($data['imap_uid'], $app_strings['LBL_EMAIL_DELIMITER']) !== false) {
$exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $_REQUEST['imap_uid']);
foreach($exUids as $msgNo) {
$uid = $msgNo;
if($ie->protocol == 'imap') {
$msgNo = imap_msgno($ie->conn, $msgNo);
$status = $ie->importOneEmail($msgNo, $uid);
} else {
$status = $ie->importOneEmail($ie->getCorrectMessageNoForPop3($msgNo), $uid);
} // else
$return[] = "Message No " . $count . ", Status : " . ($status ? "Import Passed." : "Import Failed because either the message is already imported or deleted from server");
$count++;
if(($_REQUEST['delete'] == 'true') && $status && ($current_user->is_admin == 1 || $ie->group_id == $current_user->id)) {
$ie->deleteMessageOnMailServer($_REQUEST['uid']);
$ie->deleteMessageFromCache($_REQUEST['uid']);
} // if
} // for
} else {
$msgNo = $data['imap_uid'];
if($ie->protocol == 'imap') {
$msgNo = imap_msgno($ie->conn, $data['imap_uid']);
$status = $ie->importOneEmail($msgNo, $data['imap_uid']);
} else {
$status = $ie->importOneEmail($ie->getCorrectMessageNoForPop3($msgNo), $data['imap_uid']);
} // else
$return[] = "Message No " . $count . ", Status : " . ($status ? "Import Passed." : "Import Failed because the message is already imported or deleted from server");
if(($_REQUEST['delete'] == 'true') && $status && ($current_user->is_admin == 1 || $ie->group_id == $current_user->id)) {
$ie->deleteMessageOnMailServer($data['imap_uid']);
$ie->deleteMessageFromCache($data['imap_uid']);
} // if
} // else
}
echo $json->encode($return);
break;
//================================================================================================
} // if
break;
Bookmarks