allow MAILGUN_API_KEY as override

This commit is contained in:
Rich Lott 2019-01-03 11:08:33 +00:00
parent 740624b858
commit aeeef428b9
4 changed files with 15 additions and 5 deletions

View File

@ -9,7 +9,8 @@ use CRM_Mailgunny_ExtensionUtil as E;
*/ */
class CRM_Mailgunny_Form_Settings extends CRM_Admin_Form_Setting { class CRM_Mailgunny_Form_Settings extends CRM_Admin_Form_Setting {
protected $_settings = [ protected $_settings = [
'mailgun_api_key' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'mailgun_api_key' => 'domain',
//'mailgun_api_key' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
]; ];
public function buildQuickForm() { public function buildQuickForm() {
parent::buildQuickForm(); parent::buildQuickForm();

View File

@ -53,11 +53,14 @@ class CRM_Mailgunny_Page_Webhook extends CRM_Core_Page {
} }
/** /**
* Get API key from Mailgun account. * Get API key for Mailgun account.
* *
* @return string * @return string
*/ */
public function getApiKey() { public function getApiKey() {
if (defined('MAILGUN_API_KEY')) {
return MAILGUN_API_KEY;
}
return Civi::settings()->get('mailgun_api_key'); return Civi::settings()->get('mailgun_api_key');
} }
@ -103,7 +106,10 @@ class CRM_Mailgunny_Page_Webhook extends CRM_Core_Page {
// Ideally we would have access to 'X-CiviMail-Bounce' but I don't think we do. // Ideally we would have access to 'X-CiviMail-Bounce' but I don't think we do.
$bounce_params = $this->extractVerpData($event); $bounce_params = $this->extractVerpData($event);
if (!$bounce_params) { if (!$bounce_params) {
throw new CRM_Mailgunny_WebhookRejectedException("Cannot find VERP data necessary to process bounce."); // @todo Find the email and put it on hold.
Civi::log()->info("Mailgun Webhook: $event #noverp @todo find email and put on hold.");
return;
//throw new CRM_Mailgunny_WebhookRejectedException("Cannot find VERP data necessary to process bounce.");
} }
$bounce_params['bounce_type_id'] = $this->getCiviBounceTypeId($type); $bounce_params['bounce_type_id'] = $this->getCiviBounceTypeId($type);
$bounce_params['bounce_reason'] = ($event->{'delivery-status'}->description ?? '') $bounce_params['bounce_reason'] = ($event->{'delivery-status'}->description ?? '')
@ -141,7 +147,7 @@ class CRM_Mailgunny_Page_Webhook extends CRM_Core_Page {
return $verp_items; return $verp_items;
} }
/** /*
* Get CiviCRM bounce type. * Get CiviCRM bounce type.
* *
* @param string Name of bounce type, e.g. Invalid|Syntax|Spam|Relay|Quota|Loop|Inactive|Host|Dns|Away|AOL * @param string Name of bounce type, e.g. Invalid|Syntax|Spam|Relay|Quota|Loop|Inactive|Host|Dns|Away|AOL

View File

@ -148,6 +148,9 @@ function mailgunny_civicrm_alterMailParams(&$params, $context) {
// Copy this header to one that will be returned by Mailgun's webhook. // Copy this header to one that will be returned by Mailgun's webhook.
$params['X-Mailgun-Variables'] = json_encode(['civimail-bounce' => $params['Return-Path']]); $params['X-Mailgun-Variables'] = json_encode(['civimail-bounce' => $params['Return-Path']]);
} }
else {
// Probably a single email, for which we don't have any useful information to add.
}
/* /*
$context = (string [10]) `flexmailer` $context = (string [10]) `flexmailer`
$params['X-CiviMail-Mosaico'] = (string [3]) `Yes` $params['X-CiviMail-Mosaico'] = (string [3]) `Yes`

View File

@ -6,7 +6,7 @@ return [
'title' => ts('Mailgun API key'), 'title' => ts('Mailgun API key'),
'description' => ts('The Mailgun API key for the sending domain'), 'description' => ts('The Mailgun API key for the sending domain'),
'type' => 'String', 'type' => 'String',
'add' => '5.8', 'add' => '5.0',
'html_type' => 'text', 'html_type' => 'text',
'default' => '', 'default' => '',
'is_domain' => 1, 'is_domain' => 1,