You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "chibenwa (via GitHub)" <gi...@apache.org> on 2024/11/28 15:20:33 UTC
[PR] [ENHANCEMENT] Add a PartHasContentType [james-project]
chibenwa opened a new pull request, #2530:
URL: https://github.com/apache/james-project/pull/2530
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] [ENHANCEMENT] Add a PartHasContentType [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2530:
URL: https://github.com/apache/james-project/pull/2530#discussion_r1863102525
##########
mailet/standard/src/test/java/org/apache/james/transport/matchers/PartHasContentTypeTest.java:
##########
@@ -0,0 +1,105 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collection;
+
+import org.apache.james.core.MailAddress;
+import org.apache.james.core.builder.MimeMessageBuilder;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.jupiter.api.Test;
+
+class PartHasContentTypeTest {
+ @Test
+ void shouldNotMatchWhenNoContentType() throws Exception {
+ PartHasContentType testee = new PartHasContentType();
+ testee.init(FakeMatcherConfig.builder()
+ .matcherName("PartHasContentType")
+ .condition("image/png")
+ .build());
+
+ Mail mail = FakeMail.builder()
+ .name("mail")
+ .recipient(ANY_AT_JAMES)
+ .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+ .setMultipartWithBodyParts(
+ MimeMessageBuilder.bodyPartBuilder()
+ .disposition("attachment")
+ .filename("xxx.zip")))
+ .build();
+ Collection<MailAddress> matched = testee.match(mail);
+
+ assertThat(matched)
+ .isNull();
+ }
+
+ @Test
+ void shouldNotMatchWhenWrongContentType() throws Exception {
+ PartHasContentType testee = new PartHasContentType();
+ testee.init(FakeMatcherConfig.builder()
+ .matcherName("PartHasContentType")
+ .condition("image/png")
+ .build());
+
+ Mail mail = FakeMail.builder()
+ .name("mail")
+ .recipient(ANY_AT_JAMES)
+ .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+ .setMultipartWithBodyParts(
+ MimeMessageBuilder.bodyPartBuilder()
+ .type("text/plain")
+ .disposition("attachment")
+ .filename("xxx.zip")))
+ .build();
+ Collection<MailAddress> matched = testee.match(mail);
+
+ assertThat(matched)
+ .isNull();
+ }
+
+ @Test
+ void shouldMatchWhenGoodContentType() throws Exception {
+ PartHasContentType testee = new PartHasContentType();
+ testee.init(FakeMatcherConfig.builder()
+ .matcherName("PartHasContentType")
+ .condition("image/png")
+ .build());
+
+ Mail mail = FakeMail.builder()
+ .name("mail")
+ .recipient(ANY_AT_JAMES)
+ .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+ .setMultipartWithBodyParts(
+ MimeMessageBuilder.bodyPartBuilder()
+ .type("image/png")
+ .disposition("attachment")
+ .filename("xxx.zip")))
+ .build();
+ Collection<MailAddress> matched = testee.match(mail);
+
+ assertThat(matched)
+ .isNotEmpty();
+ }
Review Comment:
That's the point of the refactoring: it leverages complexity of mime types and have that covered by AttachmentFileNameIs.
Code coverage is 100%
I do not see the point of adding more tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] [ENHANCEMENT] Add a PartHasContentType [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on code in PR #2530:
URL: https://github.com/apache/james-project/pull/2530#discussion_r1862897172
##########
mailet/standard/src/test/java/org/apache/james/transport/matchers/PartHasContentTypeTest.java:
##########
@@ -0,0 +1,105 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collection;
+
+import org.apache.james.core.MailAddress;
+import org.apache.james.core.builder.MimeMessageBuilder;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.jupiter.api.Test;
+
+class PartHasContentTypeTest {
+ @Test
+ void shouldNotMatchWhenNoContentType() throws Exception {
+ PartHasContentType testee = new PartHasContentType();
+ testee.init(FakeMatcherConfig.builder()
+ .matcherName("PartHasContentType")
+ .condition("image/png")
+ .build());
+
+ Mail mail = FakeMail.builder()
+ .name("mail")
+ .recipient(ANY_AT_JAMES)
+ .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+ .setMultipartWithBodyParts(
+ MimeMessageBuilder.bodyPartBuilder()
+ .disposition("attachment")
+ .filename("xxx.zip")))
+ .build();
+ Collection<MailAddress> matched = testee.match(mail);
+
+ assertThat(matched)
+ .isNull();
+ }
+
+ @Test
+ void shouldNotMatchWhenWrongContentType() throws Exception {
+ PartHasContentType testee = new PartHasContentType();
+ testee.init(FakeMatcherConfig.builder()
+ .matcherName("PartHasContentType")
+ .condition("image/png")
+ .build());
+
+ Mail mail = FakeMail.builder()
+ .name("mail")
+ .recipient(ANY_AT_JAMES)
+ .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+ .setMultipartWithBodyParts(
+ MimeMessageBuilder.bodyPartBuilder()
+ .type("text/plain")
+ .disposition("attachment")
+ .filename("xxx.zip")))
+ .build();
+ Collection<MailAddress> matched = testee.match(mail);
+
+ assertThat(matched)
+ .isNull();
+ }
+
+ @Test
+ void shouldMatchWhenGoodContentType() throws Exception {
+ PartHasContentType testee = new PartHasContentType();
+ testee.init(FakeMatcherConfig.builder()
+ .matcherName("PartHasContentType")
+ .condition("image/png")
+ .build());
+
+ Mail mail = FakeMail.builder()
+ .name("mail")
+ .recipient(ANY_AT_JAMES)
+ .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+ .setMultipartWithBodyParts(
+ MimeMessageBuilder.bodyPartBuilder()
+ .type("image/png")
+ .disposition("attachment")
+ .filename("xxx.zip")))
+ .build();
+ Collection<MailAddress> matched = testee.match(mail);
+
+ assertThat(matched)
+ .isNotEmpty();
+ }
Review Comment:
How about a test with multiple content types configured with the matcher?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] [ENHANCEMENT] Add a PartHasContentType [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa closed pull request #2530: [ENHANCEMENT] Add a PartHasContentType
URL: https://github.com/apache/james-project/pull/2530
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org