You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2022/08/05 09:01:37 UTC

[GitHub] [james-project] quantranhong1999 commented on a diff in pull request #1106: JAMES-3775 RSpamD mailet should support rewrite subject

quantranhong1999 commented on code in PR #1106:
URL: https://github.com/apache/james-project/pull/1106#discussion_r938607329


##########
third-party/rspamd/src/main/java/org/apache/james/rspamd/RSpamDScanner.java:
##########
@@ -36,25 +36,36 @@
 import org.apache.mailet.PerRecipientHeaders;
 import org.apache.mailet.base.GenericMailet;
 
+import com.github.fge.lambdas.Throwing;
 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");
 
     private final RSpamDHttpClient rSpamDHttpClient;
+    private boolean rewriteSubject;
 
     @Inject
     public RSpamDScanner(RSpamDHttpClient rSpamDHttpClient) {
         this.rSpamDHttpClient = rSpamDHttpClient;
     }
 
+    @Override
+    public void init() {
+        rewriteSubject = getBooleanParameter(getInitParameter("rewriteSubject"), false);
+    }
+
     @Override
     public void service(Mail mail) throws MessagingException {
         AnalysisResult rSpamDResult = rSpamDHttpClient.checkV2(new MimeMessageInputStream(mail.getMessage())).block();
 
         mail.getRecipients()
             .forEach(recipient -> appendRSpamDResultHeader(mail, recipient, rSpamDResult));
+
+        rSpamDResult.getDesiredRewriteSubject()
+            .filter(any -> rewriteSubject)
+            .ifPresent(Throwing.consumer(desiredRewriteSubject -> mail.getMessage().setSubject(desiredRewriteSubject)));

Review Comment:
   That was exactly the solution that came up to me first, but then I switch to the current code which looks more functional.
   Anyway as you wish.



-- 
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