mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ses): support +label subaddressing on mailbox simulator addresses (#2464)
The SES mailbox simulator lets senders add a +label to distinguish test messages, so bounce+order-123@simulator.amazonses.com triggers a bounce like the bare address. SimulatorAddresses now strips a +label from the local part (only + separates the label; bounce-label@... is not a simulator address) before matching the type case-insensitively. Add unit tests and document the behavior.
This commit is contained in:
1 parent
f3b22e7964
commit
c969ffc31d
3 files changed
+57
-6
No files matched your search
@@ -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 bounce+order-123@simulator.amazonses.com} triggers a bounce just like the bare
|
||||
* {@code bounce@simulator.amazonses.com}. 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user