*/
// we should consider moving this to the settings table
+use Civi\Api4\Activity;
+
define('MAIL_BATCH_SIZE', 50);
/**
// create an array of all of to, from, cc, bcc that are in use for this Mail Account, so we don't create contacts for emails we aren't adding to the activity.
$emailFields = array_merge($targetFields, $assigneeFields, $sourceFields);
$createContact = !($dao->is_contact_creation_disabled_if_no_match);
+ $bounceActivityTypeID = $activityTypeID = (int) $dao->activity_type_id;
+ $activityTypes = Activity::getFields(TRUE)
+ ->setLoadOptions(['id', 'name'])
+ ->addWhere('name', '=', 'activity_type_id')
+ ->execute()->first()['options'];
+ foreach ($activityTypes as $activityType) {
+ if ($activityType['name'] === 'Bounce') {
+ $bounceActivityTypeID = (int) $activityType['id'];
+ }
+ }
// retrieve the emails
try {
// if its the activities that needs to be processed ..
try {
+ if ($incomingMail->isBounce()) {
+ $activityTypeID = $bounceActivityTypeID;
+ }
$mailParams = CRM_Utils_Mail_Incoming::parseMailingObject($mail, $incomingMail->getAttachments(), $createContact, $emailFields, [$incomingMail->getFrom()]);
$activityParams = [
- 'activity_type_id' => (int) $dao->activity_type_id,
+ 'activity_type_id' => $activityTypeID,
'campaign_id' => $dao->campaign_id ? (int) $dao->campaign_id : NULL,
'status_id' => $dao->activity_status,
'subject' => $incomingMail->getSubject(),
return (bool) $this->action;
}
+ /**
+ * Is this a bounce email.
+ *
+ * At the moment we are only able to detect verp bounces but maybe in the future...
+ *
+ * @return bool
+ */
+ public function isBounce() : bool {
+ return $this->getAction() === 'b';
+ }
+
/**
* @param \ezcMail $mail
* @param string $emailDomain
<?php
+use Civi\Api4\OptionValue;
+
/**
* Class CRM_Utils_Mail_EmailProcessorTest
* @group headless
'activity_assignees' => 'from',
],
]);
+ $this->createTestEntity('OptionValue', ['option_group_id:name' => 'activity_type', 'name' => 'Bounce', 'label' => "Bounce"]);
}
/**
public function tearDown(): void {
CRM_Utils_File::cleanDir(__DIR__ . '/data/mail');
parent::tearDown();
+ OptionValue::delete(FALSE)->addWhere('name', '=', 'Bounce')->execute();
$this->quickCleanup([
'civicrm_group',
'civicrm_group_contact',
$this->callAPISuccess('job', 'fetch_bounces', ['is_create_activities' => TRUE]);
$this->assertFileDoesNotExist(__DIR__ . '/data/mail/' . $mail);
$this->checkMailingBounces(1);
- $this->callAPISuccessGetSingle('Activity', ['source_contact_id' => $this->contactID, 'activity_type_id' => 'Inbound Email']);
+ $this->callAPISuccessGetSingle('Activity', ['source_contact_id' => $this->contactID, 'activity_type_id' => 'Bounce']);
}
/**