/**
* Process the default mailbox (ie. that is used by civiMail for the bounce)
*
- * @return bool
- * Always returns true (for the api). at a later stage we should
- * fix this to return true on success / false on failure etc.
+ * @param bool $is_create_activities
+ * Should activities be created
*/
- public static function processBounces() {
+ public static function processBounces($is_create_activities) {
$dao = new CRM_Core_DAO_MailSettings();
$dao->domain_id = CRM_Core_Config::domainID();
$dao->is_default = TRUE;
$dao->find();
while ($dao->fetch()) {
- self::_process(TRUE, $dao);
+ self::_process(TRUE, $dao, $is_create_activities);
}
-
- // always returns true, i.e. never fails :)
- return TRUE;
}
/**
$found = FALSE;
while ($dao->fetch()) {
$found = TRUE;
- self::_process(FALSE, $dao);
+ self::_process(FALSE, $dao, $is_create_activities);
}
if (!$found) {
CRM_Core_Error::fatal(ts('No mailboxes have been configured for Email to Activity Processing'));
/**
* @param $civiMail
* @param CRM_Core_DAO $dao
+ * @param bool $is_create_activities
+ * Create activities.
*
* @throws Exception
*/
- public static function _process($civiMail, $dao) {
+ public static function _process($civiMail, $dao, $is_create_activities) {
// 0 = activities; 1 = bounce;
$usedfor = $dao->is_default;
}
// preseve backward compatibility
- if ($usedfor == 0 || !$civiMail) {
+ if ($usedfor == 0 || $is_create_activities) {
// if its the activities that needs to be processed ..
try {
$mailParams = CRM_Utils_Mail_Incoming::parseMailingObject($mail);
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
}
- if (!CRM_Utils_Mail_EmailProcessor::processBounces()) {
- $lock->release();
- return civicrm_api3_create_error('Process Bounces failed');
- }
+ CRM_Utils_Mail_EmailProcessor::processBounces($params['is_create_activities']);
$lock->release();
- // FIXME: processBounces doesn't return true/false on success/failure
- $values = array();
- return civicrm_api3_create_success($values, $params, 'Job', 'fetch_bounces');
+ return civicrm_api3_create_success(1, $params, 'Job', 'fetch_bounces');
+}
+
+/**
+ * Metadata for bounce function.
+ *
+ * @param array $params
+ */
+function _civicrm_api3_job_fetch_bounces_spec(&$params) {
+ $params['is_create_activities'] = array(
+ 'api.default' => 0,
+ 'type' => CRM_Utils_Type::T_BOOLEAN,
+ 'title' => ts('Create activities for replies?'),
+ );
}
/**