(james-jdkim) 01/03: Add DMARC compliant result method

[email protected]
Newsgroups gmane.comp.jakarta.james.devel
Message-ID <[email protected]>
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-jdkim.git

commit 5d172ddc4509948459eafe5b45ed5ee3c3172893
Author: Emerson Pinter <[email protected]>
AuthorDate: Wed Mar 26 14:19:16 2025 -0300

    Add DMARC compliant result method
    
    Also updates javadoc.
---
 .../java/org/apache/james/jdkim/DKIMVerifier.java    | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java b/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java
index 84fcedd..40e9836 100644
--- a/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java
+++ b/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java
@@ -413,7 +413,11 @@ public class DKIMVerifier {
     }
 
     /**
-     * Return the results of all signature checks, success and fail.
+     * Returns the results of all signature checks, success and fail.
+     * If a message doesn't have a DKIM-Signature header the result list will
+     * be empty. Use {@link Result#getResultType} or {@link Result#isSuccess}
+     * to get verification result of each DKIM-Signature check. Call {@link #resetResults}
+     * if the same instance of {@code DKIMVerifier} is reused for a new {@code verify} call.
      *
      * @return List of {@link Result} object.
      */
@@ -421,6 +425,20 @@ public class DKIMVerifier {
         return result;
     }
 
+    /**
+     * Returns {@code true} if at least one signature is successfully verified.
+     * A message pass the DKIM check when at least one signature is valid.
+     * This method is DMARC compliant, and should be called after {@code DKIMVerifier.verify}.
+     * Use {@link #getResults} to get result details.
+     *
+     * @return {@code true} if a valid signature is found,
+     * {@code false} if there's no valid signature.
+     * @see #getResults
+     */
+    public boolean hasAnyValidSignature() {
+        return result.stream().anyMatch(Result::isSuccess);
+    }
+
     /**
      * Returns true when all signature verification are successful. A message without dkim-signature is considered a success.
      *
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.