Add Mailgun integration (incoming emails)
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
82
app/Integration/MailgunWebhook.php
Normal file
82
app/Integration/MailgunWebhook.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -862,4 +862,6 @@ return array(
|
||||
// 'Identifier' => '',
|
||||
// 'Postmark (incoming emails)' => '',
|
||||
// 'Help on Postmark integration' => '',
|
||||
// 'Mailgun (incoming emails)' => '',
|
||||
// 'Help on Mailgun integration' => '',
|
||||
);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ class ClassProvider implements ServiceProviderInterface
|
||||
'GithubWebhook',
|
||||
'BitbucketWebhook',
|
||||
'Hipchat',
|
||||
'MailgunWebhook',
|
||||
'SlackWebhook',
|
||||
'PostmarkWebhook',
|
||||
)
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
|
||||
<?= $this->formCsrf() ?>
|
||||
|
||||
<h3><img src="assets/img/mailgun-icon.png"/> <?= 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"/> <?= 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/>
|
||||
|
||||
Reference in New Issue
Block a user