diff --git a/README.markdown b/README.markdown index 4c4eda674..e2f137ca2 100644 --- a/README.markdown +++ b/README.markdown @@ -107,6 +107,7 @@ Documentation - [Github webhooks](docs/github-webhooks.markdown) - [Gitlab webhooks](docs/gitlab-webhooks.markdown) - [Hipchat](docs/hipchat.markdown) +- [Mailgun](docs/mailgun.markdown) - [Slack](docs/slack.markdown) - [Postmark](docs/postmark.markdown) diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php index afa0543ad..06bfcd4ef 100644 --- a/app/Controller/Webhook.php +++ b/app/Controller/Webhook.php @@ -112,8 +112,20 @@ class Webhook extends Base $this->response->text('Not Authorized', 401); } - $result = $this->postmarkWebhook->parsePayload($this->request->getJson() ?: array()); + echo $this->postmarkWebhook->parsePayload($this->request->getJson() ?: array()) ? 'PARSED' : 'IGNORED'; + } - echo $result ? 'PARSED' : 'IGNORED'; + /** + * Handle Mailgun webhooks + * + * @access public + */ + public function mailgun() + { + if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { + $this->response->text('Not Authorized', 401); + } + + echo $this->mailgunWebhook->parsePayload($_POST) ? 'PARSED' : 'IGNORED'; } } diff --git a/app/Integration/MailgunWebhook.php b/app/Integration/MailgunWebhook.php new file mode 100644 index 000000000..17338faa5 --- /dev/null +++ b/app/Integration/MailgunWebhook.php @@ -0,0 +1,82 @@ +user->getByEmail($payload['sender']); + + if (empty($user)) { + $this->container['logger']->debug('MailgunWebhook: ignored => user not found'); + return false; + } + + // The project must have a short name + $project = $this->project->getByIdentifier($this->getMailboxHash($payload['recipient'])); + + if (empty($project)) { + $this->container['logger']->debug('MailgunWebhook: ignored => project not found'); + return false; + } + + // The user must be member of the project + if (! $this->projectPermission->isMember($project['id'], $user['id'])) { + $this->container['logger']->debug('MailgunWebhook: ignored => user is not member of the project'); + return false; + } + + // Get the Markdown contents + if (empty($payload['stripped-html'])) { + $description = $payload['stripped-text']; + } + else { + $markdown = new HTML_To_Markdown($payload['stripped-html'], array('strip_tags' => true)); + $description = $markdown->output(); + } + + // Finally, we create the task + return (bool) $this->taskCreation->create(array( + 'project_id' => $project['id'], + 'title' => $payload['subject'], + 'description' => $description, + 'creator_id' => $user['id'], + )); + } + + /** + * Get the project identifier + * + * @access public + * @param string $email + * @return string + */ + public function getMailboxHash($email) + { + list($local_part,) = explode('@', $email); + list(,$identifier) = explode('+', $local_part); + + return $identifier; + } +} diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index f021ea348..cc3809298 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index f58e46307..20d459775 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index 3160e6f65..f1d344be5 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index 934f90f47..728a57467 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index cdb9045bc..54370f3af 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -864,4 +864,6 @@ return array( 'Identifier' => 'Identificateur', 'Postmark (incoming emails)' => 'Postmark (emails entrants)', 'Help on Postmark integration' => 'Aide sur l\'intégration avec Postmark', + 'Mailgun (incoming emails)' => 'Mailgun (emails entrants)', + 'Help on Mailgun integration' => 'Aide sur l\'intégration avec Mailgun', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index 38bed1a2b..feca5d32f 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 59f057b3c..8601af4fa 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 9fa0a7239..3a08da17e 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index 5f57937c2..4a53bf484 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 42b2865e6..519fb32bd 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index 4dd237ec8..953f3a594 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index e3039db9d..dee35d70f 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php index 6e4a82288..c4bab8cbc 100644 --- a/app/Locale/sr_Latn_RS/translations.php +++ b/app/Locale/sr_Latn_RS/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index abdb2b70d..22286c369 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index b6c140d67..c8e253b67 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php index 7457e0b1d..5fb403e89 100644 --- a/app/Locale/tr_TR/translations.php +++ b/app/Locale/tr_TR/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 63570ca2d..7470bae1c 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -862,4 +862,6 @@ return array( // 'Identifier' => '', // 'Postmark (incoming emails)' => '', // 'Help on Postmark integration' => '', + // 'Mailgun (incoming emails)' => '', + // 'Help on Mailgun integration' => '', ); diff --git a/app/Model/Project.php b/app/Model/Project.php index 231d57e75..158de2955 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -68,6 +68,10 @@ class Project extends Base */ public function getByIdentifier($identifier) { + if (empty($identifier)) { + return false; + } + return $this->db->table(self::TABLE)->eq('identifier', strtoupper($identifier))->findOne(); } diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 0c02058e2..de9de546e 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -77,6 +77,7 @@ class ClassProvider implements ServiceProviderInterface 'GithubWebhook', 'BitbucketWebhook', 'Hipchat', + 'MailgunWebhook', 'SlackWebhook', 'PostmarkWebhook', ) diff --git a/app/Template/config/integrations.php b/app/Template/config/integrations.php index b7dab2b4c..a012b566b 100644 --- a/app/Template/config/integrations.php +++ b/app/Template/config/integrations.php @@ -6,6 +6,12 @@ = $this->formCsrf() ?> +