diff --git a/EmailHandler.php b/EmailHandler.php index 41592cb..36e071e 100644 --- a/EmailHandler.php +++ b/EmailHandler.php @@ -1,5 +1,4 @@ projectModel->getByEmail($payload['recipient']); + + if (empty($project)) { + $this->logger->info('Mailgun: ignored => project not found'); + return false; + } + // The user must exists in Kanboard $user = $this->userModel->getByEmail($payload['sender']); + // Check to see if a catchall user was specified - if the original sender is unrecognized if (empty($user)) { - $this->logger->info('Mailgun: ignored => user not found'); - return false; + $catchAllAddress = $this->projectMetadataModel->get($project['id'], 'mailgun_catch_all'); + $user = $this->userModel->getByEmail($catchAllAddress); + $this->logger->info('Mailgun: unknown user mapped to ' . $user['name'] . ' (' . $user['email'] . ') in project ' . $project['name']); } - // The project must have a short name - $project = $this->projectModel->getByEmail($payload['recipient']); - - if (empty($project)) { - $this->logger->info('Mailgun: ignored => project not found'); + if (empty($user)) { + $this->logger->info('Mailgun: ignored => user not found'); return false; } diff --git a/Locale/fr_FR/translations.php b/Locale/fr_FR/translations.php index 1e0a06d..7594d9a 100644 --- a/Locale/fr_FR/translations.php +++ b/Locale/fr_FR/translations.php @@ -2,5 +2,7 @@ return array( 'Help on Mailgun integration' => 'Aide sur l\'intégration avec Mailgun', + 'Catch-All Email Address' => 'Adresse e-mail « attrape-tout » (catch-all)', + 'Blank value will cause unknown senders to be ignored' => 'Une valeur vide ignore les expéditeurs inconnus' ); diff --git a/Plugin.php b/Plugin.php index 28f4dac..5a72b78 100644 --- a/Plugin.php +++ b/Plugin.php @@ -17,9 +17,10 @@ class Plugin extends Base public function initialize() { $this->emailClient->setTransport('mailgun', '\Kanboard\Plugin\Mailgun\EmailHandler'); + $this->template->hook->attach('template:project:integrations', 'mailgun:project/integration'); $this->template->hook->attach('template:config:integrations', 'mailgun:config/integration'); - $this->route->addRoute('/mailgun/handler/:token', 'WebhookController', 'receiver', 'mailgun'); $this->applicationAccessMap->add('WebhookController', 'receiver', Role::APP_PUBLIC); + $this->route->addRoute('/mailgun/handler/:token', 'WebhookController', 'receiver', 'mailgun'); } public function onStartup() @@ -39,7 +40,7 @@ public function getPluginAuthor() public function getPluginVersion() { - return '1.0.10'; + return '1.0.11'; } public function getPluginHomepage() diff --git a/README.md b/README.md index abcf4bf..7088aba 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,14 @@ Notes Changes ------- +### Version 1.0.11 + +- For unknown senders you can now accept them into a project by specifying a user to accept the task - this is configurable on a project level - leaving the setting blank will cause unknown senders to be ignored. + +### Version 1.0.10 + +- Update help link URL + ### Version 1.0.9 - Tasks created by incoming email are assigned to the recipient diff --git a/Template/project/integration.php b/Template/project/integration.php new file mode 100644 index 0000000..635ea88 --- /dev/null +++ b/Template/project/integration.php @@ -0,0 +1,14 @@ +

 Mailgun

+
+ form->label(t('Catch-All Email Address'), 'mailgun_catch_all') ?> + form->email('mailgun_catch_all', $values) ?> + +

+ - + +

+ +
+ +
+
diff --git a/Test/EmailHandlerTest.php b/Test/EmailHandlerTest.php index e84a52c..c1642ce 100644 --- a/Test/EmailHandlerTest.php +++ b/Test/EmailHandlerTest.php @@ -5,6 +5,7 @@ use Kanboard\Plugin\Mailgun\EmailHandler; use Kanboard\Model\TaskFinderModel; use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectMetadataModel; use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Model\UserModel; use Kanboard\Core\Security\Role; @@ -116,6 +117,38 @@ public function testHandlePayload() $this->assertEquals(2, $task['creator_id']); } + public function testHandlePayloadFromAnyone() + { + $emailHandler = new EmailHandler($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectMetadataModel = new ProjectMetadataModel($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'anyone', 'email' => 'anyone@localhost'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2', 'email' => 'test2@localhost'))); + + // Allow project 2 to receive E-Mail from any sender + $this->assertTrue($projectMetadataModel->save(2, array('mailgun_catch_all' => 'anyone@localhost'))); + + // Message is from a user not in a project - and should be mapped to the project user + $this->assertFalse($emailHandler->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'test2@localhost', 'stripped-text' => 'boo'))); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + + // The task must be created + $this->assertTrue($emailHandler->receiveEmail(array('sender' => 'd@e.f', 'subject' => 'Email task', 'recipient' => 'test2@localhost', 'stripped-html' => 'boo'))); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('Email task', $task['title']); + $this->assertEquals('**boo**', $task['description']); + $this->assertEquals(2, $task['creator_id']); + } + public function testGetSubject() { $handler = new EmailHandler($this->container);