From aeeef428b9247354064fda5a1fe45f975c1c636e Mon Sep 17 00:00:00 2001 From: Rich Lott Date: Thu, 3 Jan 2019 11:08:33 +0000 Subject: [PATCH] allow MAILGUN_API_KEY as override --- CRM/Mailgunny/Form/Settings.php | 3 ++- CRM/Mailgunny/Page/Webhook.php | 12 +++++++++--- mailgunny.php | 3 +++ settings/mailgunny.setting.php | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CRM/Mailgunny/Form/Settings.php b/CRM/Mailgunny/Form/Settings.php index b24a001..bdb90f8 100644 --- a/CRM/Mailgunny/Form/Settings.php +++ b/CRM/Mailgunny/Form/Settings.php @@ -9,7 +9,8 @@ use CRM_Mailgunny_ExtensionUtil as E; */ class CRM_Mailgunny_Form_Settings extends CRM_Admin_Form_Setting { 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() { parent::buildQuickForm(); diff --git a/CRM/Mailgunny/Page/Webhook.php b/CRM/Mailgunny/Page/Webhook.php index 73277d2..7761952 100644 --- a/CRM/Mailgunny/Page/Webhook.php +++ b/CRM/Mailgunny/Page/Webhook.php @@ -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 */ public function getApiKey() { + if (defined('MAILGUN_API_KEY')) { + return 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. $bounce_params = $this->extractVerpData($event); 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_reason'] = ($event->{'delivery-status'}->description ?? '') @@ -141,7 +147,7 @@ class CRM_Mailgunny_Page_Webhook extends CRM_Core_Page { return $verp_items; } - /** + /* * Get CiviCRM bounce type. * * @param string Name of bounce type, e.g. Invalid|Syntax|Spam|Relay|Quota|Loop|Inactive|Host|Dns|Away|AOL diff --git a/mailgunny.php b/mailgunny.php index af586fd..342d4b5 100644 --- a/mailgunny.php +++ b/mailgunny.php @@ -148,6 +148,9 @@ function mailgunny_civicrm_alterMailParams(&$params, $context) { // Copy this header to one that will be returned by Mailgun's webhook. $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` ⬦ $params['X-CiviMail-Mosaico'] = (string [3]) `Yes` diff --git a/settings/mailgunny.setting.php b/settings/mailgunny.setting.php index c80aa74..79ba25b 100644 --- a/settings/mailgunny.setting.php +++ b/settings/mailgunny.setting.php @@ -6,7 +6,7 @@ return [ 'title' => ts('Mailgun API key'), 'description' => ts('The Mailgun API key for the sending domain'), 'type' => 'String', - 'add' => '5.8', + 'add' => '5.0', 'html_type' => 'text', 'default' => '', 'is_domain' => 1,