Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4b4307c32 | ||
|
|
546496992c |
@@ -3,7 +3,7 @@
|
||||
"description": "Laravel SDK for leadMail email sending and verification service",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/leadmnik/leadmail-sdk",
|
||||
"homepage": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Lead Magnet Oy",
|
||||
@@ -11,18 +11,18 @@
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/leadmnik/leadmail-sdk/issues",
|
||||
"source": "https://github.com/leadmnik/leadmail-sdk"
|
||||
"issues": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk/issues",
|
||||
"source": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk"
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"php": "^8.1",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"illuminate/mail": "^11.0|^12.0",
|
||||
"illuminate/support": "^11.0|^12.0"
|
||||
"illuminate/mail": "^9.0|^10.0",
|
||||
"illuminate/support": "^9.0|^10.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^9.0|^10.0",
|
||||
"pestphp/pest": "^3.0|^4.0"
|
||||
"orchestra/testbench": "^7.0|^8.0",
|
||||
"pestphp/pest": "^1.0|^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
@@ -44,13 +44,8 @@ class LeadMailServiceProvider extends ServiceProvider
|
||||
|
||||
Validator::extend('leadmail_verify', function (string $attribute, mixed $value) {
|
||||
$rule = $this->app->make(LeadMailVerify::class);
|
||||
$passed = true;
|
||||
|
||||
$rule->validate($attribute, $value, function () use (&$passed) {
|
||||
$passed = false;
|
||||
});
|
||||
|
||||
return $passed;
|
||||
return $rule->passes($attribute, $value);
|
||||
}, 'The :attribute email address could not be verified.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,23 +2,24 @@
|
||||
|
||||
namespace LeadM\LeadMail\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use LeadM\LeadMail\LeadMailClient;
|
||||
|
||||
class LeadMailVerify implements ValidationRule
|
||||
class LeadMailVerify implements Rule
|
||||
{
|
||||
protected string $failMessage = 'The :attribute email address could not be verified.';
|
||||
|
||||
public function __construct(
|
||||
protected readonly LeadMailClient $client,
|
||||
protected readonly bool $allowDisposable = false,
|
||||
) {}
|
||||
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
if (! is_string($value) || ! filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||
$fail('The :attribute must be a valid email address.');
|
||||
$this->failMessage = 'The :attribute must be a valid email address.';
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -26,10 +27,20 @@ class LeadMailVerify implements ValidationRule
|
||||
|
||||
if (! ($result['data']['valid'] ?? true)) {
|
||||
$reason = $result['data']['reason'] ?? 'verification failed';
|
||||
$fail("The :attribute email address is not deliverable ({$reason}).");
|
||||
$this->failMessage = "The :attribute email address is not deliverable ({$reason}).";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Throwable) {
|
||||
// Fail open — if the verification service is down, allow the email through
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function message(): string
|
||||
{
|
||||
return $this->failMessage;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user