Skip to content

Commit

Permalink
Add notification subtypes to log
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed Nov 14, 2024
1 parent 08f0bfd commit 8dd0115
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion classes/sns_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function is_unsubscription(): bool {
/**
* Get SNS Notification object
*
* @return sns_notification SNS Notification Object
* @return sns_notification|null SNS Notification Object
*/
public function get_notification() {
if (isset($this->notification)) {
Expand Down
75 changes: 74 additions & 1 deletion classes/sns_notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,76 @@ public function get_destination(): string {
return $this->message['mail']['destination'][0];
}

/**
* Gets the type of bounce that occured
* https://docs.aws.amazon.com/ses/latest/dg/notification-contents.html#bounce-types
* @return string Bounce type
*/
public function get_bouncetype(): string {
if ($this->is_bounce()) {
return $this->message['bounce']['bounceType'];
}
return '';
}

/**
* Gets the subtype of bounce that occured
* https://docs.aws.amazon.com/ses/latest/dg/notification-contents.html#bounce-types
* @return string Bounce sub type
*/
public function get_bouncesubtype(): string {
if ($this->is_bounce()) {
return $this->message['bounce']['bounceSubType'];
}
return '';
}

/**
* Gets the type of complaint that occured
* https://docs.aws.amazon.com/ses/latest/dg/notification-contents.html#complaint-types
* @return string Complaint type
*/
public function get_complainttype(): string {
if ($this->is_complaint()) {
// Feedback type is only available if a feedback report is attached to the complaint.
return $this->message['complaint']['complaintFeedbackType'] ?? '';
}
return '';
}

/**
* Gets the subtype of complaint that occured
* This should either be field can either be null or OnAccountSuppressionList
* https://docs.aws.amazon.com/ses/latest/dg/notification-contents.html#complaint-object
* @return string Complaint sub type
*/
public function get_complaintsubtype(): string {
if ($this->is_complaint()) {
return $this->message['complaint']['complaintSubType'] ?? '';
}
return '';
}

/**
* Returns all the message subtypes as an array
* @return string subtypes as a array
*/
protected function get_subtypes(): array {
$subtypes = [];
if ($this->is_complaint()) {
$subtypes = [
$this->get_complainttype(),
$this->get_complaintsubtype(),
];
} else if ($this->is_bounce()) {
$subtypes = [
$this->get_bouncetype(),
$this->get_bouncesubtype(),
];
}
return array_filter($subtypes);
}

/**
* Is the message about a complaint?
* @return bool Is complaint?
Expand All @@ -144,7 +214,10 @@ public function is_bounce(): bool {
*/
public function get_messageasstring(): string {
if ($this->is_complaint() || $this->is_bounce()) {
return $this->get_type() . ' about ' . $this->get_source_email() . ' from ' . $this->get_destination();
$subtypes = $this->get_subtypes();
$subtypestring = !empty($subtypes) ? ' (' . implode(':', $subtypes) . ')' : '';
$type = $this->get_type() . $subtypestring;
return $type . ' about ' . $this->get_source_email() . ' from ' . $this->get_destination();
} else {
http_response_code(400); // Invalid request.
exit;
Expand Down

0 comments on commit 8dd0115

Please sign in to comment.