mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ses): apply suppression list during send with per-CS SuppressionOptions override (#1109)
When SendEmail / SendRawEmail is called with a recipient on the
account-level suppression list whose reason matches the effective
SuppressedReasons (the configuration set's SuppressionOptions
override if present, else the account-level reasons), Floci now:
1. Emits a synthetic Bounce or Complaint event (per the suppression
reason) through the configured event destinations alongside the
always-emitted Send event.
2. Drops the suppressed recipient from the SMTP relay step, while
still delivering the message to non-suppressed recipients on the
same send.
The SendEmail API response (200 + MessageId), the stored SentEmail
(used by the LocalStack-compatible /_aws/ses inspection endpoint),
and the published event's mail.destination all continue to reflect
the original recipient list — matching how AWS reports the message
at the API and event layers.
This PR bundles two related pieces:
- The per-configuration-set SuppressionOptions block (Put endpoint +
GetConfigurationSet response shape + getEffectiveSuppressedReasons
helper). Mirrors AWS V2 PutConfigurationSetSuppressionOptions:
empty list = explicit "no suppression filtering" for this CS,
unset block = fall back to account-level reasons. The validation
message for the new endpoint matches the AWS V2 natural-language
form ("Reason <X> is invalid, must be one of [BOUNCE, COMPLAINT].")
which is distinct from the V1-style nested message returned by the
three older suppression endpoints; both forms were verified
against live AWS on 2026-06-03.
- The send-time filter + synthetic-event partitioning, plumbed
through getEffectiveSuppressedReasons so the override takes effect
per-send. collectSuppressedReasons and resolveSuppressionReason
now both take configurationSetName, hitting the per-CS override
when present and falling back to the account-level reasons
otherwise.
Per-recipient: when only some recipients are suppressed, the
non-suppressed ones still reach smtpRelay.relay() / relayRaw().
The relay is skipped entirely only when every recipient is
suppressed.
- Recipient suppressed with reason BOUNCE (and BOUNCE in the
effective reasons) -> synthetic Bounce event; not relayed.
- Recipient suppressed with reason COMPLAINT (and COMPLAINT in the
effective reasons) -> synthetic Complaint event; not relayed.
- Reason mismatch or address not on the list -> Send only; relayed
normally.
- Simulator-address recipients and suppression-listed recipients
are unioned into the same event's recipient list, deduplicated.
Tests
- SesConfigurationSetSuppressionOptionsV2IntegrationTest (16 cases)
for the CRUD + helper.
- SesConfigurationSetTest SDK compat (6 V2 cases) using
SesV2Client.PutConfigurationSetSuppressionOptions and the typed
SuppressionListReason enum (+ the WithStrings escape hatch for
the server-side validation path).
- SesServiceSmtpTest grows four cases pinning the send-time
override behaviour: empty list on the CS disables filtering and
the relay receives the address; BOUNCE-only override leaves
COMPLAINT-suppressed addresses unfiltered; a CS without an
override falls back to account-level (parity with no-CS sends);
raw-send mirrors the JSON-send path.
- SesEventPayload / SesEventPublishingV2IntegrationTest / further
send-path coverage from the original suppression PR is preserved.
- All 452 SES tests pass.
This commit is contained in:
1 parent
2a14f35c2d
commit
19b0432b8c
13 files changed
+1136
-34
No files matched your search
@@ -648,12 +648,55 @@ public class SesController {
|
||||
tagNode.put("Value", t.value());
|
||||
tags.add(tagNode);
|
||||
}
|
||||
if (cs.getSuppressionOptions() != null) {
|
||||
ObjectNode suppressionNode = result.putObject("SuppressionOptions");
|
||||
ArrayNode reasons = suppressionNode.putArray("SuppressedReasons");
|
||||
for (String r : cs.getSuppressionOptions().getSuppressedReasons()) {
|
||||
reasons.add(r);
|
||||
}
|
||||
}
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/configuration-sets/{configurationSetName}/suppression-options")
|
||||
public Response putConfigurationSetSuppressionOptions(@Context HttpHeaders headers,
|
||||
@PathParam("configurationSetName") String name,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode reasonsNode = request.path("SuppressedReasons");
|
||||
List<String> reasons = new ArrayList<>();
|
||||
if (!reasonsNode.isMissingNode() && !reasonsNode.isNull()) {
|
||||
if (!reasonsNode.isArray()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"SuppressedReasons must be an array.", 400);
|
||||
}
|
||||
for (JsonNode r : reasonsNode) {
|
||||
if (r.isNull() || !r.isTextual()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"SuppressedReasons entries must be strings.", 400);
|
||||
}
|
||||
reasons.add(r.asText());
|
||||
}
|
||||
}
|
||||
sesService.putConfigurationSetSuppressionOptions(name, reasons, region);
|
||||
LOG.infov("SES V2 PutConfigurationSetSuppressionOptions: {0} on {1}", reasons, name);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/configuration-sets/{configurationSetName}")
|
||||
public Response deleteConfigurationSet(@Context HttpHeaders headers,
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.ses.model.MessageTag;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -35,6 +36,8 @@ final class SesEventPayload {
|
||||
String sourceArn, String sendingAccountId, String subject,
|
||||
List<String> toAddresses, List<String> ccAddresses,
|
||||
List<String> bccAddresses, List<String> envelopeDestinations,
|
||||
List<String> suppressionBounceRecipients,
|
||||
List<String> suppressionComplaintRecipients,
|
||||
String configurationSetName, List<MessageTag> emailTags,
|
||||
List<MessageHeader> additionalHeaders, Instant timestamp) {
|
||||
ObjectNode root = mapper.createObjectNode();
|
||||
@@ -43,7 +46,8 @@ final class SesEventPayload {
|
||||
subject, toAddresses, ccAddresses, bccAddresses, envelopeDestinations,
|
||||
configurationSetName, emailTags, additionalHeaders, timestamp));
|
||||
root.set(blockName(eventType),
|
||||
buildEventBlock(mapper, eventType, messageId, envelopeDestinations, timestamp));
|
||||
buildEventBlock(mapper, eventType, messageId, envelopeDestinations,
|
||||
suppressionBounceRecipients, suppressionComplaintRecipients, timestamp));
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -146,7 +150,10 @@ final class SesEventPayload {
|
||||
}
|
||||
|
||||
private static ObjectNode buildEventBlock(ObjectMapper mapper, String eventType, String messageId,
|
||||
List<String> destination, Instant timestamp) {
|
||||
List<String> destination,
|
||||
List<String> suppressionBounceRecipients,
|
||||
List<String> suppressionComplaintRecipients,
|
||||
Instant timestamp) {
|
||||
ObjectNode body = mapper.createObjectNode();
|
||||
switch (eventType) {
|
||||
case "DELIVERY" -> {
|
||||
@@ -164,24 +171,16 @@ final class SesEventPayload {
|
||||
case "BOUNCE" -> {
|
||||
body.put("bounceType", "Permanent");
|
||||
body.put("bounceSubType", "General");
|
||||
ArrayNode bounced = body.putArray("bouncedRecipients");
|
||||
for (String d : destination) {
|
||||
if (SimulatorAddresses.isBounce(d)) {
|
||||
ObjectNode br = bounced.addObject();
|
||||
br.put("emailAddress", d.trim());
|
||||
}
|
||||
}
|
||||
emitDedupedRecipientObjects(body.putArray("bouncedRecipients"),
|
||||
destination, SimulatorAddresses::isBounce,
|
||||
suppressionBounceRecipients);
|
||||
body.put("timestamp", ISO_MILLIS.format(timestamp));
|
||||
body.put("feedbackId", "feedback-" + messageId);
|
||||
}
|
||||
case "COMPLAINT" -> {
|
||||
ArrayNode complained = body.putArray("complainedRecipients");
|
||||
for (String d : destination) {
|
||||
if (SimulatorAddresses.isComplaint(d)) {
|
||||
ObjectNode cr = complained.addObject();
|
||||
cr.put("emailAddress", d.trim());
|
||||
}
|
||||
}
|
||||
emitDedupedRecipientObjects(body.putArray("complainedRecipients"),
|
||||
destination, SimulatorAddresses::isComplaint,
|
||||
suppressionComplaintRecipients);
|
||||
body.put("timestamp", ISO_MILLIS.format(timestamp));
|
||||
body.put("feedbackId", "feedback-" + messageId);
|
||||
}
|
||||
@@ -193,6 +192,33 @@ final class SesEventPayload {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit `{emailAddress: ...}` objects into {@code arr} for every recipient that either
|
||||
* matches {@code simulatorPredicate} in {@code envelope} or is listed in
|
||||
* {@code suppressionRecipients}. Addresses are trimmed and deduplicated by trimmed
|
||||
* form so the same address never appears twice when both inputs claim it.
|
||||
*/
|
||||
private static void emitDedupedRecipientObjects(ArrayNode arr,
|
||||
List<String> envelope,
|
||||
java.util.function.Predicate<String> simulatorPredicate,
|
||||
List<String> suppressionRecipients) {
|
||||
LinkedHashSet<String> emitted = new LinkedHashSet<>();
|
||||
if (envelope != null) {
|
||||
for (String d : envelope) {
|
||||
if (d != null && simulatorPredicate.test(d) && emitted.add(d.trim())) {
|
||||
arr.addObject().put("emailAddress", d.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (suppressionRecipients != null) {
|
||||
for (String d : suppressionRecipients) {
|
||||
if (d != null && emitted.add(d.trim())) {
|
||||
arr.addObject().put("emailAddress", d.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String eventTypeLabel(String eventType) {
|
||||
return switch (eventType) {
|
||||
case "SEND" -> "Send";
|
||||
|
||||
@@ -39,6 +39,8 @@ public class SesEventPublisher {
|
||||
String source, String sourceArn, String sendingAccountId,
|
||||
String subject, List<String> toAddresses, List<String> ccAddresses,
|
||||
List<String> bccAddresses, List<String> envelopeDestinations,
|
||||
List<String> suppressionBounceRecipients,
|
||||
List<String> suppressionComplaintRecipients,
|
||||
List<MessageTag> emailTags, List<MessageHeader> additionalHeaders,
|
||||
Instant timestamp, String defaultRegion) {
|
||||
if (configurationSet == null || configurationSet.getEventDestinations().isEmpty()) {
|
||||
@@ -47,6 +49,7 @@ public class SesEventPublisher {
|
||||
ObjectNode payload = SesEventPayload.build(objectMapper, eventType, messageId, source,
|
||||
sourceArn, sendingAccountId, subject,
|
||||
toAddresses, ccAddresses, bccAddresses, envelopeDestinations,
|
||||
suppressionBounceRecipients, suppressionComplaintRecipients,
|
||||
configurationSet.getName(), emailTags, additionalHeaders, timestamp);
|
||||
String payloadJson = payload.toString();
|
||||
for (EventDestination ed : configurationSet.getEventDestinations()) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.github.hectorvent.floci.services.ses.model.MessageHeader;
|
||||
import io.github.hectorvent.floci.services.ses.model.MessageTag;
|
||||
import io.github.hectorvent.floci.services.ses.model.SentEmail;
|
||||
import io.github.hectorvent.floci.services.ses.model.SuppressedDestination;
|
||||
import io.github.hectorvent.floci.services.ses.model.SuppressionOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -32,6 +33,7 @@ import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HexFormat;
|
||||
@@ -202,15 +204,25 @@ public class SesService {
|
||||
bccAddresses, replyToAddresses, subject, bodyText, bodyHtml);
|
||||
emailStore.put("email::" + region + "::" + messageId, email);
|
||||
|
||||
smtpRelay.relay(source, toAddresses, ccAddresses, bccAddresses,
|
||||
replyToAddresses, subject, bodyText, bodyHtml);
|
||||
List<String> envelope = allRecipients(toAddresses, ccAddresses, bccAddresses);
|
||||
Map<String, String> suppressedReasons = collectSuppressedReasons(envelope, configurationSetName, region);
|
||||
|
||||
List<String> relayedTo = filterUnsuppressed(toAddresses, suppressedReasons);
|
||||
List<String> relayedCc = filterUnsuppressed(ccAddresses, suppressedReasons);
|
||||
List<String> relayedBcc = filterUnsuppressed(bccAddresses, suppressedReasons);
|
||||
if (sizeOf(relayedTo) + sizeOf(relayedCc) + sizeOf(relayedBcc) > 0) {
|
||||
smtpRelay.relay(source, relayedTo, relayedCc, relayedBcc,
|
||||
replyToAddresses, subject, bodyText, bodyHtml);
|
||||
} else {
|
||||
LOG.infov("SES email accepted but not relayed (all recipients suppressed): messageId={0}",
|
||||
messageId);
|
||||
}
|
||||
|
||||
LOG.infov("SES email sent: from={0}, to={1}, subject={2}, messageId={3}",
|
||||
source, toAddresses, subject, messageId);
|
||||
publishSendEvents(configurationSetName, messageId, source, subject,
|
||||
toAddresses, ccAddresses, bccAddresses,
|
||||
allRecipients(toAddresses, ccAddresses, bccAddresses),
|
||||
emailTags, additionalHeaders, region);
|
||||
toAddresses, ccAddresses, bccAddresses, envelope,
|
||||
suppressedReasons, emailTags, additionalHeaders, region);
|
||||
return messageId;
|
||||
}
|
||||
|
||||
@@ -237,7 +249,15 @@ public class SesService {
|
||||
SentEmail email = new SentEmail(messageId, region, source, effectiveDestinations, rawMessage);
|
||||
emailStore.put("email::" + region + "::" + messageId, email);
|
||||
|
||||
smtpRelay.relayRaw(source, effectiveDestinations, rawMessage);
|
||||
Map<String, String> suppressedReasons = collectSuppressedReasons(effectiveDestinations, configurationSetName, region);
|
||||
|
||||
List<String> relayedDestinations = filterUnsuppressed(effectiveDestinations, suppressedReasons);
|
||||
if (!relayedDestinations.isEmpty()) {
|
||||
smtpRelay.relayRaw(source, relayedDestinations, rawMessage);
|
||||
} else {
|
||||
LOG.infov("SES raw email accepted but not relayed (all recipients suppressed): messageId={0}",
|
||||
messageId);
|
||||
}
|
||||
|
||||
LOG.infov("SES raw email sent: from={0}, messageId={1}", source, messageId);
|
||||
publishSendEvents(configurationSetName, messageId, source,
|
||||
@@ -246,7 +266,7 @@ public class SesService {
|
||||
headers != null ? headers.cc() : List.of(),
|
||||
headers != null ? headers.bcc() : List.of(),
|
||||
effectiveDestinations,
|
||||
emailTags, List.of(), region);
|
||||
suppressedReasons, emailTags, List.of(), region);
|
||||
return messageId;
|
||||
}
|
||||
|
||||
@@ -286,6 +306,7 @@ public class SesService {
|
||||
String subject, List<String> toAddresses,
|
||||
List<String> ccAddresses, List<String> bccAddresses,
|
||||
List<String> envelopeDestinations,
|
||||
Map<String, String> suppressedReasons,
|
||||
List<MessageTag> emailTags,
|
||||
List<MessageHeader> additionalHeaders, String region) {
|
||||
if (eventPublisher == null) {
|
||||
@@ -312,14 +333,28 @@ public class SesService {
|
||||
? null
|
||||
: AwsArnUtils.Arn.of("ses", region, sendingAccountId, "identity/" + source).toString();
|
||||
|
||||
for (String eventType : determineSendEventTypes(envelope)) {
|
||||
List<String> suppressionBounceRecipients = new ArrayList<>();
|
||||
List<String> suppressionComplaintRecipients = new ArrayList<>();
|
||||
for (Map.Entry<String, String> e : suppressedReasons.entrySet()) {
|
||||
if ("BOUNCE".equals(e.getValue())) {
|
||||
suppressionBounceRecipients.add(e.getKey());
|
||||
} else if ("COMPLAINT".equals(e.getValue())) {
|
||||
suppressionComplaintRecipients.add(e.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for (String eventType : determineSendEventTypes(envelope,
|
||||
suppressionBounceRecipients, suppressionComplaintRecipients)) {
|
||||
eventPublisher.publish(cs, eventType, messageId, source, sourceArn, sendingAccountId,
|
||||
subject, toAddresses, ccAddresses, bccAddresses, envelope,
|
||||
suppressionBounceRecipients, suppressionComplaintRecipients,
|
||||
emailTags, additionalHeaders, timestamp, region);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> determineSendEventTypes(List<String> destinations) {
|
||||
private static List<String> determineSendEventTypes(List<String> destinations,
|
||||
List<String> suppressionBounceRecipients,
|
||||
List<String> suppressionComplaintRecipients) {
|
||||
List<String> events = new ArrayList<>();
|
||||
events.add("SEND");
|
||||
for (String d : destinations) {
|
||||
@@ -336,6 +371,12 @@ public class SesService {
|
||||
events.add("REJECT");
|
||||
}
|
||||
}
|
||||
if (!suppressionBounceRecipients.isEmpty() && !events.contains("BOUNCE")) {
|
||||
events.add("BOUNCE");
|
||||
}
|
||||
if (!suppressionComplaintRecipients.isEmpty() && !events.contains("COMPLAINT")) {
|
||||
events.add("COMPLAINT");
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
@@ -686,6 +727,53 @@ public class SesService {
|
||||
eventDestinationName, configSetName, region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores per-configuration-set suppression overrides. Mirrors the AWS V2
|
||||
* {@code PutConfigurationSetSuppressionOptions} contract: {@code reasons} may
|
||||
* be {@code null} or empty (explicit "no filtering" for this set) or a subset
|
||||
* of {@code [BOUNCE, COMPLAINT]}. Once set, the value is returned through
|
||||
* {@link #getConfigurationSet}; downstream callers can resolve the effective
|
||||
* reasons for a given send via {@link #getEffectiveSuppressedReasons}.
|
||||
*/
|
||||
public void putConfigurationSetSuppressionOptions(String configSetName,
|
||||
List<String> reasons, String region) {
|
||||
List<String> sanitized = new ArrayList<>();
|
||||
if (reasons != null) {
|
||||
for (String r : reasons) {
|
||||
validateConfigSetSuppressionReason(r);
|
||||
sanitized.add(r);
|
||||
}
|
||||
}
|
||||
ConfigurationSet cs = getConfigurationSet(configSetName, region);
|
||||
SuppressionOptions options = new SuppressionOptions();
|
||||
options.setSuppressedReasons(sanitized);
|
||||
cs.setSuppressionOptions(options);
|
||||
configSetStore.put(configSetKey(region, configSetName), cs);
|
||||
LOG.infov("Updated SuppressionOptions on configuration set {0} in region {1}: {2}",
|
||||
configSetName, region, sanitized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective suppression reasons for a send that is using
|
||||
* {@code configurationSetName}. Per the AWS V2 contract, a configuration
|
||||
* set's {@code SuppressionOptions} (when present) overrides the
|
||||
* account-level reasons — including an empty list, which explicitly
|
||||
* disables suppression filtering for that set. Falls back to the
|
||||
* account-level reasons when the configuration set has no override, or
|
||||
* when {@code configurationSetName} is null/blank (i.e. the caller didn't
|
||||
* specify a configuration set).
|
||||
*/
|
||||
public List<String> getEffectiveSuppressedReasons(String configurationSetName, String region) {
|
||||
if (configurationSetName != null && !configurationSetName.isBlank()) {
|
||||
ConfigurationSet cs = getConfigurationSet(configurationSetName, region);
|
||||
SuppressionOptions options = cs.getSuppressionOptions();
|
||||
if (options != null) {
|
||||
return List.copyOf(options.getSuppressedReasons());
|
||||
}
|
||||
}
|
||||
return List.copyOf(getAccountSuppressionAttributes(region).getSuppressedReasons());
|
||||
}
|
||||
|
||||
private static int indexOfEventDestination(List<EventDestination> destinations, String name) {
|
||||
for (int i = 0; i < destinations.size(); i++) {
|
||||
if (name != null && name.equals(destinations.get(i).getName())) {
|
||||
@@ -1100,6 +1188,101 @@ public class SesService {
|
||||
return "suppression::" + region + "::" + emailAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the effective suppression reason for each address in a single pass over the
|
||||
* store and the effective settings. The returned map only contains entries for
|
||||
* addresses that ARE suppressed (i.e., on the list AND whose reason matches the
|
||||
* effective {@code suppressedReasons} — the configuration set's
|
||||
* {@code SuppressionOptions} override if present, else the account-level reasons).
|
||||
* Callers reuse this map for both the SMTP relay filter and the event-publishing
|
||||
* partitioning so the store is read once per send regardless of the number of
|
||||
* consumers.
|
||||
*/
|
||||
Map<String, String> collectSuppressedReasons(Collection<String> addresses,
|
||||
String configurationSetName, String region) {
|
||||
if (addresses == null || addresses.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<String> effectiveReasons = getEffectiveSuppressedReasons(configurationSetName, region);
|
||||
if (effectiveReasons == null || effectiveReasons.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Set<String> reasonFilter = Set.copyOf(effectiveReasons);
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
for (String address : addresses) {
|
||||
if (address == null || address.isBlank() || result.containsKey(address)) {
|
||||
continue;
|
||||
}
|
||||
String normalized = normalizeSuppressionEmail(address);
|
||||
SuppressedDestination entry = suppressionStore.get(suppressionKey(region, normalized))
|
||||
.orElse(null);
|
||||
if (entry != null && entry.getReason() != null
|
||||
&& reasonFilter.contains(entry.getReason())) {
|
||||
result.put(address, entry.getReason());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out recipients whose effective suppression reason is non-null. Returns a new
|
||||
* list containing only the addresses that should reach the SMTP relay, mirroring AWS
|
||||
* SES's "accept the message, but doesn't send it" behaviour for suppressed addresses.
|
||||
* Returns the original reference when {@code addresses} is {@code null} or empty.
|
||||
*/
|
||||
static List<String> filterUnsuppressed(List<String> addresses, Map<String, String> suppressedReasons) {
|
||||
if (addresses == null || addresses.isEmpty()) {
|
||||
return addresses;
|
||||
}
|
||||
if (suppressedReasons.isEmpty()) {
|
||||
return addresses;
|
||||
}
|
||||
List<String> kept = new ArrayList<>(addresses.size());
|
||||
for (String a : addresses) {
|
||||
if (!suppressedReasons.containsKey(a)) {
|
||||
kept.add(a);
|
||||
}
|
||||
}
|
||||
return kept;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the suppression reason that applies to a given recipient in the given region
|
||||
* for sends using {@code configurationSetName}, or {@code null} if the recipient is not
|
||||
* suppressed. The recipient is suppressed only when it appears in the address-level
|
||||
* suppression list AND its stored reason intersects the effective {@code suppressedReasons}
|
||||
* — the configuration set's {@code SuppressionOptions} override if present, else the
|
||||
* account-level reasons. {@code configurationSetName} may be {@code null} or blank to
|
||||
* scope the check to account-level reasons only.
|
||||
*
|
||||
* <p>The returned value is one of {@code "BOUNCE"} / {@code "COMPLAINT"}, allowing
|
||||
* callers (publishSendEvents) to map the recipient to a synthetic Bounce / Complaint
|
||||
* event without consulting the store again. Both the per-address suppression entries
|
||||
* and the account-level / per-CS {@code suppressedReasons} go through
|
||||
* {@link #validateSuppressionReason} / {@link #validateConfigSetSuppressionReason},
|
||||
* which enforce exact case-sensitive equality with the two canonical values, so
|
||||
* {@code entry.getReason()} is guaranteed to be canonical and downstream
|
||||
* {@code .equals("BOUNCE")} / {@code .equals("COMPLAINT")} checks are safe.
|
||||
*/
|
||||
String resolveSuppressionReason(String emailAddress, String configurationSetName, String region) {
|
||||
if (emailAddress == null || emailAddress.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
// Share the same normalization used when entries are stored
|
||||
// (`normalizeSuppressionEmail`) so lookups can't drift apart from inserts.
|
||||
String normalized = normalizeSuppressionEmail(emailAddress);
|
||||
SuppressedDestination entry = suppressionStore.get(suppressionKey(region, normalized))
|
||||
.orElse(null);
|
||||
if (entry == null || entry.getReason() == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> effective = getEffectiveSuppressedReasons(configurationSetName, region);
|
||||
if (effective == null || effective.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return effective.contains(entry.getReason()) ? entry.getReason() : null;
|
||||
}
|
||||
|
||||
private static String normalizeSuppressionEmail(String emailAddress) {
|
||||
if (emailAddress == null || emailAddress.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "EmailAddress is required.", 400);
|
||||
@@ -1108,6 +1291,17 @@ public class SesService {
|
||||
return emailAddress.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation message used by PutAccountSuppressionAttributes,
|
||||
* PutSuppressedDestination, and ListSuppressedDestinations — all three
|
||||
* return the AWS "1 validation error detected: Value at '<fieldName>'
|
||||
* failed to satisfy constraint: ..." V1-style nested message verbatim.
|
||||
* (Verified against real AWS V2 SES on 2026-06-03.) The {@code nested}
|
||||
* flag controls whether the inner enum constraint is wrapped in
|
||||
* {@code Member must satisfy constraint: [...]} — PutSuppressedDestination
|
||||
* (single Reason field) returns the unwrapped form; the two list-bearing
|
||||
* APIs return the wrapped form.
|
||||
*/
|
||||
private static void validateSuppressionReason(String reason, String fieldName, boolean nested) {
|
||||
if (reason == null || (!"BOUNCE".equals(reason) && !"COMPLAINT".equals(reason))) {
|
||||
String constraint = nested
|
||||
@@ -1119,6 +1313,20 @@ public class SesService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation message used by PutConfigurationSetSuppressionOptions. AWS
|
||||
* V2 SES uses a different, simpler natural-language sentence on this
|
||||
* endpoint than on the three older suppression APIs above:
|
||||
* "Reason <X> is invalid, must be one of [BOUNCE, COMPLAINT]."
|
||||
* (Verified against real AWS V2 SES on 2026-06-03.)
|
||||
*/
|
||||
private static void validateConfigSetSuppressionReason(String reason) {
|
||||
if (reason == null || (!"BOUNCE".equals(reason) && !"COMPLAINT".equals(reason))) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Reason " + reason + " is invalid, must be one of [BOUNCE, COMPLAINT].", 400);
|
||||
}
|
||||
}
|
||||
|
||||
static void validateTag(Tag tag) {
|
||||
if (tag == null) {
|
||||
throw new AwsException("InvalidParameterValue", "Tag must not be null.", 400);
|
||||
|
||||
@@ -24,6 +24,9 @@ public class ConfigurationSet {
|
||||
@JsonProperty("EventDestinations")
|
||||
private List<EventDestination> eventDestinations = new ArrayList<>();
|
||||
|
||||
@JsonProperty("SuppressionOptions")
|
||||
private SuppressionOptions suppressionOptions;
|
||||
|
||||
public ConfigurationSet() {}
|
||||
|
||||
public ConfigurationSet(String name) {
|
||||
@@ -44,4 +47,9 @@ public class ConfigurationSet {
|
||||
public void setEventDestinations(List<EventDestination> eventDestinations) {
|
||||
this.eventDestinations = eventDestinations != null ? eventDestinations : new ArrayList<>();
|
||||
}
|
||||
|
||||
public SuppressionOptions getSuppressionOptions() { return suppressionOptions; }
|
||||
public void setSuppressionOptions(SuppressionOptions suppressionOptions) {
|
||||
this.suppressionOptions = suppressionOptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.github.hectorvent.floci.services.ses.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Per-configuration-set override of the account-level suppression reasons.
|
||||
* Mirrors the AWS SES V2 {@code SuppressionOptions} shape. When present on a
|
||||
* {@link ConfigurationSet}, its {@code SuppressedReasons} take precedence over
|
||||
* the account-level {@link AccountSuppressionAttributes} for any send using
|
||||
* that configuration set; an empty list explicitly disables suppression
|
||||
* filtering for the set.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SuppressionOptions {
|
||||
|
||||
@JsonProperty("SuppressedReasons")
|
||||
private List<String> suppressedReasons = new ArrayList<>();
|
||||
|
||||
public SuppressionOptions() {}
|
||||
|
||||
public List<String> getSuppressedReasons() { return suppressedReasons; }
|
||||
public void setSuppressedReasons(List<String> suppressedReasons) {
|
||||
this.suppressedReasons = suppressedReasons != null ? suppressedReasons : new ArrayList<>();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user