From 270fe4c1cbdd4295087f283a77a7f7e5a6c81970 Mon Sep 17 00:00:00 2001 From: Koda Date: Wed, 18 Oct 2017 20:19:05 +0900 Subject: [PATCH] #902 Change a check condition to part of the mail address matches to post article from E-mail. --- .../knowledge/logic/MailhookLogic.java | 2 +- .../integration/IntegrationMailReadTest.java | 129 ++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/support/project/knowledge/logic/MailhookLogic.java b/src/main/java/org/support/project/knowledge/logic/MailhookLogic.java index 7ba4d16cc..53987644d 100644 --- a/src/main/java/org/support/project/knowledge/logic/MailhookLogic.java +++ b/src/main/java/org/support/project/knowledge/logic/MailhookLogic.java @@ -742,7 +742,7 @@ private boolean checkCondition(Message msg, MailHookConditionsEntity condition) for (Address address : to) { if (address instanceof InternetAddress) { InternetAddress a = (InternetAddress) address; - if (a.getAddress().equals(condition.getCondition())) { + if (a.getAddress().indexOf(condition.getCondition()) != -1) { return true; } } else { diff --git a/src/test/java/org/support/project/knowledge/integration/IntegrationMailReadTest.java b/src/test/java/org/support/project/knowledge/integration/IntegrationMailReadTest.java index 950dec05a..88f9ebbe7 100644 --- a/src/test/java/org/support/project/knowledge/integration/IntegrationMailReadTest.java +++ b/src/test/java/org/support/project/knowledge/integration/IntegrationMailReadTest.java @@ -167,4 +167,133 @@ public void testCheckDataAfterComment() throws Exception { assertNotificationCount(COMMENT_USER, 1); } + + + /** + * メールアドレスで投稿 + * @throws Exception + */ + @Test + @Order(order = 300) + public void testPostOnRecipient1() throws Exception { + // データ完全初期化 + setUpBeforeClass(); + + // テストユーザ追加 + addUser(CONFIG_USER); + addUser(POST_USER); + LoginedUser user = super.getLoginUser(CONFIG_USER); + + // メールから投稿設定(受信メールアドレスの一部で) + MailHookConditionsEntity condition = new MailHookConditionsEntity(); + condition.setHookId(MailhookLogic.MAIL_HOOK_ID); + condition.setConditionNo(-1); + condition.setConditionKind(MailHookCondition.Recipient.getValue()); + condition.setCondition("hoge@example.com"); + condition.setProcessUser(user.getUserId()); + condition.setProcessUserKind(1); + condition.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PUBLIC); + condition.setTags("メールの宛先の一部で投稿"); + MailhookLogic.get().saveCondition(condition); + + // メールから投稿 + user = super.getLoginUser(POST_USER); + List conditions = MailHookConditionsDao.get().selectOnHookId(MailhookLogic.MAIL_HOOK_ID); + StubMessage msg = new StubMessage(); + Address[] addresses = {new StubAddress(user.getLoginUser().getMailAddress())}; + msg.addFrom(addresses); + Address[] recipients = {new StubAddress("hoge@example.com")}; + msg.setAllRecipients(recipients); + msg.setContent("投稿の本文になる"); + msg.setSubject("メールアドレスの部分一致で投稿"); + msg.addHeader("Message-ID", "MailHookTest-02"); + + MailhookLogic.get().checkConditionsAndPost(msg, conditions); + Knowledge result = knowledgeGetOnAPI(POST_USER, 1); + Assert.assertEquals((long) 1, result.getKnowledgeId().longValue()); + Assert.assertEquals("メールアドレスの部分一致で投稿", result.getTitle()); + + // メールから投稿 + user = super.getLoginUser(POST_USER); + conditions = MailHookConditionsDao.get().selectOnHookId(MailhookLogic.MAIL_HOOK_ID); + msg = new StubMessage(); + addresses[0] = new StubAddress(user.getLoginUser().getMailAddress()); + msg.addFrom(addresses); + recipients[0] = new StubAddress("hoge_info@example.com"); + msg.setAllRecipients(recipients); + msg.setContent("投稿の本文になる"); + msg.setSubject("これは対象外になる"); + msg.addHeader("Message-ID", "MailHookTest-03"); + + MailhookLogic.get().checkConditionsAndPost(msg, conditions); + result = knowledgeGetOnAPI(POST_USER, 1); + Assert.assertEquals((long) 1, result.getKnowledgeId().longValue()); + Assert.assertEquals("メールアドレスの部分一致で投稿", result.getTitle()); + } + + /** + * メールアドレスの一部で投稿 + * @throws Exception + */ + @Test + @Order(order = 301) + public void testPostOnRecipient2() throws Exception { + // データ完全初期化 + setUpBeforeClass(); + + // テストユーザ追加 + addUser(CONFIG_USER); + addUser(POST_USER); + LoginedUser user = super.getLoginUser(CONFIG_USER); + + // メールから投稿設定(受信メールアドレスの一部で) + MailHookConditionsEntity condition = new MailHookConditionsEntity(); + condition.setHookId(MailhookLogic.MAIL_HOOK_ID); + condition.setConditionNo(-1); + condition.setConditionKind(MailHookCondition.Recipient.getValue()); + condition.setCondition("hoge"); + condition.setProcessUser(user.getUserId()); + condition.setProcessUserKind(1); + condition.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PUBLIC); + condition.setTags("メールの宛先の一部で投稿"); + MailhookLogic.get().saveCondition(condition); + + // メールから投稿 + user = super.getLoginUser(POST_USER); + List conditions = MailHookConditionsDao.get().selectOnHookId(MailhookLogic.MAIL_HOOK_ID); + StubMessage msg = new StubMessage(); + Address[] addresses = {new StubAddress(user.getLoginUser().getMailAddress())}; + msg.addFrom(addresses); + Address[] recipients = {new StubAddress("hoge@example.com")}; + msg.setAllRecipients(recipients); + msg.setContent("投稿の本文になる"); + msg.setSubject("メールアドレスの部分一致で投稿"); + msg.addHeader("Message-ID", "MailHookTest-02"); + + MailhookLogic.get().checkConditionsAndPost(msg, conditions); + Knowledge result = knowledgeGetOnAPI(POST_USER, 1); + Assert.assertEquals((long) 1, result.getKnowledgeId().longValue()); + Assert.assertEquals("メールアドレスの部分一致で投稿", result.getTitle()); + + // メールから投稿 + user = super.getLoginUser(POST_USER); + conditions = MailHookConditionsDao.get().selectOnHookId(MailhookLogic.MAIL_HOOK_ID); + msg = new StubMessage(); + addresses[0] = new StubAddress(user.getLoginUser().getMailAddress()); + msg.addFrom(addresses); + recipients[0] = new StubAddress("hoge_info@example.com"); + msg.setAllRecipients(recipients); + msg.setContent("投稿の本文になる"); + msg.setSubject("こんどは投稿する"); + msg.addHeader("Message-ID", "MailHookTest-03"); + + MailhookLogic.get().checkConditionsAndPost(msg, conditions); + result = knowledgeGetOnAPI(POST_USER, 2); + Assert.assertEquals((long) 2, result.getKnowledgeId().longValue()); + Assert.assertEquals("こんどは投稿する", result.getTitle()); + } + + + + }