summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Controller/Webhook.php16
-rw-r--r--app/Integration/MailgunWebhook.php82
-rw-r--r--app/Locale/da_DK/translations.php2
-rw-r--r--app/Locale/de_DE/translations.php2
-rw-r--r--app/Locale/es_ES/translations.php2
-rw-r--r--app/Locale/fi_FI/translations.php2
-rw-r--r--app/Locale/fr_FR/translations.php2
-rw-r--r--app/Locale/hu_HU/translations.php2
-rw-r--r--app/Locale/it_IT/translations.php2
-rw-r--r--app/Locale/ja_JP/translations.php2
-rw-r--r--app/Locale/nl_NL/translations.php2
-rw-r--r--app/Locale/pl_PL/translations.php2
-rw-r--r--app/Locale/pt_BR/translations.php2
-rw-r--r--app/Locale/ru_RU/translations.php2
-rw-r--r--app/Locale/sr_Latn_RS/translations.php2
-rw-r--r--app/Locale/sv_SE/translations.php2
-rw-r--r--app/Locale/th_TH/translations.php2
-rw-r--r--app/Locale/tr_TR/translations.php2
-rw-r--r--app/Locale/zh_CN/translations.php2
-rw-r--r--app/Model/Project.php4
-rw-r--r--app/ServiceProvider/ClassProvider.php1
-rw-r--r--app/Template/config/integrations.php6
22 files changed, 141 insertions, 2 deletions
diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php
index afa0543a..06bfcd4e 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 00000000..17338faa
--- /dev/null
+++ b/app/Integration/MailgunWebhook.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace Integration;
+
+use HTML_To_Markdown;
+
+/**
+ * Mailgun Webhook
+ *
+ * @package integration
+ * @author Frederic Guillot
+ */
+class MailgunWebhook extends Base
+{
+ /**
+ * Parse incoming email
+ *
+ * @access public
+ * @param array $payload Incoming email
+ * @return boolean
+ */
+ public function parsePayload(array $payload)
+ {
+ if (empty($payload['sender']) || empty($payload['subject']) || empty($payload['recipient']) || empty($payload['stripped-text'])) {
+ return false;
+ }
+
+ // The user must exists in Kanboard
+ $user = $this->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 f021ea34..cc380929 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 f58e4630..20d45977 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 3160e6f6..f1d344be 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 934f90f4..728a5746 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 cdb9045b..54370f3a 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 38bed1a2..feca5d32 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 59f057b3..8601af4f 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 9fa0a723..3a08da17 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 5f57937c..4a53bf48 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 42b2865e..519fb32b 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 4dd237ec..953f3a59 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 e3039db9..dee35d70 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 6e4a8228..c4bab8cb 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 abdb2b70..22286c36 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 b6c140d6..c8e253b6 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 7457e0b1..5fb403e8 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 63570ca2..7470bae1 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 231d57e7..158de295 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 0c02058e..de9de546 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 b7dab2b4..a012b566 100644
--- a/app/Template/config/integrations.php
+++ b/app/Template/config/integrations.php
@@ -6,6 +6,12 @@
<?= $this->formCsrf() ?>
+ <h3><img src="assets/img/mailgun-icon.png"/>&nbsp;<?= t('Mailgun (incoming emails)') ?></h3>
+ <div class="listing">
+ <input type="text" class="auto-select" readonly="readonly" value="<?= $this->getCurrentBaseUrl().$this->u('webhook', 'mailgun', array('token' => $values['webhook_token'])) ?>"/><br/>
+ <p class="form-help"><a href="http://kanboard.net/documentation/mailgun" target="_blank"><?= t('Help on Mailgun integration') ?></a></p>
+ </div>
+
<h3><img src="assets/img/postmark-icon.png"/>&nbsp;<?= t('Postmark (incoming emails)') ?></h3>
<div class="listing">
<input type="text" class="auto-select" readonly="readonly" value="<?= $this->getCurrentBaseUrl().$this->u('webhook', 'postmark', array('token' => $values['webhook_token'])) ?>"/><br/>