Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ses): support +label subaddressing on mailbox simulator addresses (#2464)
Kenshin Okinakac969ffc31d10
diff --git a/docs/services/ses.md b/docs/services/ses.mdindex 772b48883f..f77edc7801 100644--- a/docs/services/ses.md+++ b/docs/services/ses.md@@ -271,6 +271,8 @@ Floci recognises the AWS [mailbox simulator addresses](https://docs.aws.amazon.c| `[email protected]` | `Complaint` || `[email protected]` | `Reject` |+A `+label` subaddress is supported on any of these, so `[email protected]` triggers a `Bounce` just like the bare address — the label lets senders distinguish test messages. Only `+` separates the label; `bounce-label@...` is not a simulator address.+A successful send without a simulator-address recipient emits only the `Send` event.Account-level VDM (Virtual Deliverability Manager) attributes are stored per region. `PutAccountVdmAttributes` sets `VdmEnabled` (opt-in, defaults `DISABLED`) plus the optional `DashboardAttributes.EngagementMetrics` and `GuardianAttributes.OptimizedSharedDelivery`. `GetAccount` omits `VdmAttributes` until VDM has been configured for the region, then returns `VdmEnabled`, adding the `DashboardAttributes`/`GuardianAttributes` sub-objects only while `VdmEnabled` is `ENABLED`. Floci stores the settings but does not run VDM analytics.diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SimulatorAddresses.java b/src/main/java/io/github/hectorvent/floci/services/ses/SimulatorAddresses.javaindex 9eac8bc06d..1ae54f2311 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SimulatorAddresses.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SimulatorAddresses.java@@ -4,6 +4,12 @@ package io.github.hectorvent.floci.services.ses;* Recognises the AWS Amazon SES mailbox simulator addresses* (see https://docs.aws.amazon.com/ses/latest/dg/send-an-email-from-console.html#send-email-simulator)* so Floci can deterministically emit the matching event types.+ *+ * <p>The simulator supports a label (subaddressing) on the local part so senders can distinguish test+ * messages, e.g. {@code [email protected]} triggers a bounce just like the bare+ * {@code [email protected]}. Matching strips a {@code +label} suffix from the local part+ * (only {@code +} is a separator — {@code bounce-label@...} is not a bounce) before comparing the type+ * case-insensitively.*/final class SimulatorAddresses {@@ -15,22 +21,37 @@ final class SimulatorAddresses {private SimulatorAddresses() {}static boolean isSuccess(String address) {- return SUCCESS.equalsIgnoreCase(strip(address));+ return SUCCESS.equalsIgnoreCase(canonicalize(address));}static boolean isBounce(String address) {- return BOUNCE.equalsIgnoreCase(strip(address));+ return BOUNCE.equalsIgnoreCase(canonicalize(address));}static boolean isComplaint(String address) {- return COMPLAINT.equalsIgnoreCase(strip(address));+ return COMPLAINT.equalsIgnoreCase(canonicalize(address));}static boolean isSuppressionList(String address) {- return SUPPRESSION_LIST.equalsIgnoreCase(strip(address));+ return SUPPRESSION_LIST.equalsIgnoreCase(canonicalize(address));}- private static String strip(String address) {- return address == null ? null : address.trim();+ // Drop a +label subaddress from the local part so labelled simulator addresses match their type,+ // leaving the domain untouched. A non-simulator or malformed address is returned trimmed as-is.+ private static String canonicalize(String address) {+ if (address == null) {+ return null;+ }+ String trimmed = address.trim();+ int at = trimmed.indexOf('@');+ if (at < 0) {+ return trimmed;+ }+ String localPart = trimmed.substring(0, at);+ int plus = localPart.indexOf('+');+ if (plus < 0) {+ return trimmed;+ }+ return localPart.substring(0, plus) + trimmed.substring(at);}}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SimulatorAddressesTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SimulatorAddressesTest.javaindex c7fa42d818..c07eb27203 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SimulatorAddressesTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SimulatorAddressesTest.java@@ -29,12 +29,40 @@ class SimulatorAddressesTest {assertTrue(SimulatorAddresses.isSuppressionList("[email protected]"));}+ @Test+ void recognisesLabelledAddresses() {+ // The simulator supports a +label subaddress so senders can distinguish test messages.+ assertTrue(SimulatorAddresses.isBounce("[email protected]"));+ assertTrue(SimulatorAddresses.isSuccess("[email protected]"));+ assertTrue(SimulatorAddresses.isComplaint("[email protected]"));+ assertTrue(SimulatorAddresses.isSuppressionList("[email protected]"));+ // Label with dots, an empty label, and an upper-case type are all still recognised.+ assertTrue(SimulatorAddresses.isBounce("[email protected]"));+ assertTrue(SimulatorAddresses.isBounce("[email protected]"));+ assertTrue(SimulatorAddresses.isBounce("[email protected]"));+ }++ @Test+ void onlyPlusIsALabelSeparator() {+ // A hyphen is part of the local part, not a label separator, so this is not a bounce.+ assertFalse(SimulatorAddresses.isBounce("[email protected]"));+ }++ @Test+ void labelDoesNotMakeUnknownTypesMatch() {+ // An unknown type with a label is not any simulator event.+ assertFalse(SimulatorAddresses.isSuccess("[email protected]"));+ assertFalse(SimulatorAddresses.isBounce("[email protected]"));+ }+@Testvoid rejectsRegularAddresses() {assertFalse(SimulatorAddresses.isSuccess("[email protected]"));assertFalse(SimulatorAddresses.isBounce("[email protected]"));assertFalse(SimulatorAddresses.isComplaint("[email protected]"));assertFalse(SimulatorAddresses.isSuppressionList("[email protected]"));+ // A +label on a non-simulator domain must not match either.+ assertFalse(SimulatorAddresses.isBounce("[email protected]"));}@Test