Skip to content

Commit

Permalink
local dev tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Aug 8, 2024
1 parent 95b6e22 commit 350bb50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/SparkPostApiTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e

$to = $email->getTo();

// check .local addresses
foreach ($to as $addr) {
if (str_ends_with($addr->getAddress(), '.local')) {
$disableSending = true;
}
}

if ($disableSending) {
$result = [
'total_rejected_recipients' => 0,
Expand Down
15 changes: 15 additions & 0 deletions src/SparkPostHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ public static function init()
}

$sending_disabled = self::getEnvSendingDisabled();
if ($sending_disabled === false) {
// In dev, if we didn't set a value, disable by default
// This can avoid sending emails by mistake :-) oops!
if (Director::isDev() && !self::hasEnvSendingDisabled()) {
$sending_disabled = true;
}
}
if ($sending_disabled) {
self::config()->disable_sending = $sending_disabled;
}
Expand Down Expand Up @@ -187,6 +194,14 @@ public static function getEnvSendingDisabled()
return Environment::getEnv('SPARKPOST_SENDING_DISABLED');
}

/**
* @return bool
*/
public static function hasEnvSendingDisabled()
{
return Environment::hasEnv('SPARKPOST_SENDING_DISABLED');
}

/**
* @return mixed
*/
Expand Down

0 comments on commit 350bb50

Please sign in to comment.