chibenwa commented on code in PR #1093: URL: https://github.com/apache/james-project/pull/1093#discussion_r934110344
########## server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RSpamDScanner.java: ########## @@ -0,0 +1,116 @@ +/**************************************************************** + * 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.mailets; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Optional; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; + +import org.apache.james.core.MailAddress; +import org.apache.james.rspamd.client.RSpamDClientConfiguration; +import org.apache.james.rspamd.client.RSpamDHttpClient; +import org.apache.james.rspamd.model.AnalysisResult; +import org.apache.mailet.Attribute; +import org.apache.mailet.AttributeName; +import org.apache.mailet.AttributeValue; +import org.apache.mailet.Mail; +import org.apache.mailet.PerRecipientHeaders; +import org.apache.mailet.base.GenericMailet; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; + +public class RSpamDScanner extends GenericMailet { + public static final AttributeName FLAG_MAIL = AttributeName.of("org.apache.james.rspamd.flag"); + public static final AttributeName STATUS_MAIL = AttributeName.of("org.apache.james.rspamd.status"); + static final String RSPAMD_URL = "rSpamDUrl"; + static final String RSPAMD_PASSWORD = "rSpamDPassword"; + static final String RSPAMD_TIMEOUT = "rSpamDTimeout"; + + private RSpamDHttpClient rSpamDHttpClient; + + @Override + public void init() throws MessagingException { + Optional<Integer> rSpamDTimeoutConfigure = Optional.ofNullable(getInitParameter(RSPAMD_TIMEOUT)) + .filter(s -> !s.isEmpty()) + .map(Integer::valueOf) + .filter(i -> i > 0); + + RSpamDClientConfiguration rSpamDClientConfiguration = new RSpamDClientConfiguration(extractRSpamDUrl(), + getInitParameter(RSPAMD_PASSWORD, ""), rSpamDTimeoutConfigure); + rSpamDHttpClient = new RSpamDHttpClient(rSpamDClientConfiguration); Review Comment: Question: should this be injected? https://github.com/apache/james-project/pull/1092 injects this, we likely should be consistant... ########## server/mailet/mailets/src/test/resources/rspamd-config/actions.conf: ########## @@ -0,0 +1,29 @@ +# Actions settings Review Comment: Why is this file needed? ########## server/mailet/mailets/src/test/resources/eml/spam8.eml: ########## @@ -0,0 +1,321 @@ +From [email protected] Sun Jul 15 04:56:31 2001 Review Comment: Quick question: where is this mail taken from? Protected by some sort of license? Can we spend 5 minutes checking there is no issue? ########## server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/IsMarkedAsSpam.java: ########## @@ -51,9 +54,18 @@ public class IsMarkedAsSpam extends GenericMatcher { private static final String YES = "yes"; + private String spamStatusHeader = SpamAssassinResult.STATUS_MAIL.asString(); + @Override public String getMatcherInfo() { - return "Has org.apache.james.spamassassin.status per recipient header with a Yes value"; + return "Has " + spamStatusHeader + " per recipient header with a Yes value"; + } + + @Override + public void init() throws MessagingException { + spamStatusHeader = Optional.ofNullable(getCondition()) + .filter(s -> !s.isEmpty()) + .orElse(SpamAssassinResult.STATUS_MAIL.asString()); } Review Comment: Document this change (javadoc above, in `server/apps/distributed-app/docs/modules/ROOT/partials/IsMarkedAsSpam.adoc`) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
