chibenwa commented on code in PR #2811:
URL: https://github.com/apache/james-project/pull/2811#discussion_r2351549003
##########
server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/Rule.java:
##########
@@ -129,33 +129,52 @@ public String toString() {
public static class Condition {
- public enum Field {
- FROM("from"),
- TO("to"),
- CC("cc"),
- SUBJECT("subject"),
- RECIPIENT("recipient");
-
- public static Optional<Field> find(String fieldName) {
- return Arrays.stream(values())
- .filter(value ->
value.fieldName.equalsIgnoreCase(fieldName))
- .findAny();
+ public interface Field {
+ static Optional<Field> find(String fieldName) {
+ return FixedField.find(fieldName)
+ .or(() -> CustomHeaderField.find(fieldName));
}
- public static Field of(String fieldName) {
+ static Field of(String fieldName) {
return find(fieldName).orElseThrow(() -> new
IllegalArgumentException("'" + fieldName + "' is not a valid field name"));
}
- private final String fieldName;
-
- Field(String fieldName) {
- this.fieldName = fieldName;
+ String asString();
+ }
+
+ public record FixedField(String fieldName) implements Field {
+ public static Field FROM = new FixedField("from");
+ public static Field TO = new FixedField("to");
+ public static Field CC = new FixedField("cc");
+ public static Field SUBJECT = new FixedField("subject");
+ public static Field RECIPIENT = new FixedField("recipient");
+ public static final ImmutableList<Field> VALUES =
ImmutableList.of(FROM, TO, CC, SUBJECT, RECIPIENT);
+
+ public static Optional<Field> find(String fieldName) {
+ return VALUES.stream()
+ .filter(value ->
value.asString().equalsIgnoreCase(fieldName))
+ .findAny();
}
-
+
public String asString() {
return fieldName;
}
}
+
+ public record CustomHeaderField(String headerName) implements Field {
+ public static final String PREFIX = "header:";
+
+ public static Optional<Field> find(String fieldName) {
+ if (fieldName.startsWith(PREFIX)) {
Review Comment:
IMO not needed as we expect machines to supply this input. Sanitizing the
input is thus not relevant to me.
Case insentivity of the header is handled by `jakarta.mail` itself.
--
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]