I’m currently working on an issue related to case creation from email in SuiteCRM version 7.14.3. The problem I’m facing is when a case is created from an incoming email and the customer replies to the autoresponse email, the pollMonitoredInboxesAOP scheduler runs as expected. However, it seems to process the same reply two or three times. Has anyone encountered this issue or know what might be causing the scheduler to process the same email multiple times?
What exactly is that about processing the same reply? Somebody is getting more than one automatically generated email? Are the two emails exactly alike, or slightly different?
public function handleCaseAssignment($email)
{
$c = BeanFactory::newBean('Cases');
if ($caseId = $this->getCaseIdFromCaseNumber($email->name, $c)) {
$c->retrieve($caseId);
$email->retrieve($email->id);
//assign the case info to parent id and parent type so that the case can be linked to the email on Email Save
$email->parent_type = "Cases";
$email->parent_id = $caseId;
// assign the email to the case owner
$email->assigned_user_id = $c->assigned_user_id;
$this->createCustomerReplyAlert($email, $c);
$email->save();
$GLOBALS['log']->debug('InboundEmail found exactly 1 match for a case: ' . $c->name);
return true;
} // if
return false;
} // fn
Hi @pgr. This handleCaseAssignment method is used for the reply. When a customer replies to the email that he/she gets from CRM, a successful case is created. I am getting 2 or sometimes 3 alerts. While I debug it, it seems the schedulers run multiple times for the same reply.
Right. You haven’t said explicitly whether the various emails are exactly alike or not - I will assume they are.
This is buggy, convoluted code. The thing to watch out for is that the beans being saved will trigger logic hooks, and so sometimes a reply will be triggered in the middle of handling a reply, just because a bean was saved.
When you say you are “debugging” I hope you mean you are really debugging with XDEBUG and a proper IDE. Otherwise, I don’t think you will be able to trace this code.
My debug notes for this, in case it helps:
- main function handleCreateCase. Watch out for all the hooks getting silently triggered: assignment, email save, case save...
- case c$->save: assignment email from cases mailbox to assigned user
- $c->contacts->add: creationNotify hook sends "receveived" email to customer
- $email->save when saving inbound email into DB, two saveEmailUpdate hooks send trash to user
- $reply->send fails sending with wrong "from" and unreplaced vars...
Hi,
The issue relates to duplicate case updates or note creation in SuiteCRM v7.14.3, where the poll Monitored Inboxes AOP scheduler processes the same email multiple times. This typically occurs when incoming customer replies to auto-response emails are not handled properly, primarily due to issues with email UID tracking or the email not being marked as read/seen after processing.
1-IMAP UID Not Tracked Correctly: If the UID of incoming emails is not properly retrieved or stored, SuiteCRM cannot accurately determine if the email was already processed, leading to repeated actions. Ensure this line is present and functioning in your AOPInboundEmail.php: $uid = imap_uid($connection, $email_number); Also verify that the email_uid field in the emails table is populated correctly.
2-Emails Not Marked as Seen: If emails are not marked as seen after being processed, the scheduler may reprocess them in subsequent runs. To fix this, ensure the following is executed after successful email handling: imap_setflag_full($connection, $email_number, “\Seen”);
3-Lack of Duplicate Email Processing Checks: Before creating a new case update or note, SuiteCRM should verify that the content hasn’t already been logged. You can implement a duplicate check based on:Email UID,Email body hash,Subject + Parent Case combination