2 Commits
v0.1.0 ... 1.x

Author SHA1 Message Date
netlas
c4b4307c32 Downgrade SDK for Laravel 9-10 compatibility 2026-03-09 10:51:55 +02:00
netlas
546496992c Update URLs from GitHub to Gitea 2026-03-04 17:17:18 +02:00
3 changed files with 27 additions and 21 deletions

View File

@@ -3,7 +3,7 @@
"description": "Laravel SDK for leadMail email sending and verification service", "description": "Laravel SDK for leadMail email sending and verification service",
"type": "library", "type": "library",
"license": "MIT", "license": "MIT",
"homepage": "https://github.com/leadmnik/leadmail-sdk", "homepage": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk",
"authors": [ "authors": [
{ {
"name": "Lead Magnet Oy", "name": "Lead Magnet Oy",
@@ -11,18 +11,18 @@
} }
], ],
"support": { "support": {
"issues": "https://github.com/leadmnik/leadmail-sdk/issues", "issues": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk/issues",
"source": "https://github.com/leadmnik/leadmail-sdk" "source": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk"
}, },
"require": { "require": {
"php": "^8.2", "php": "^8.1",
"guzzlehttp/guzzle": "^7.0", "guzzlehttp/guzzle": "^7.0",
"illuminate/mail": "^11.0|^12.0", "illuminate/mail": "^9.0|^10.0",
"illuminate/support": "^11.0|^12.0" "illuminate/support": "^9.0|^10.0"
}, },
"require-dev": { "require-dev": {
"orchestra/testbench": "^9.0|^10.0", "orchestra/testbench": "^7.0|^8.0",
"pestphp/pest": "^3.0|^4.0" "pestphp/pest": "^1.0|^2.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@@ -44,13 +44,8 @@ class LeadMailServiceProvider extends ServiceProvider
Validator::extend('leadmail_verify', function (string $attribute, mixed $value) { Validator::extend('leadmail_verify', function (string $attribute, mixed $value) {
$rule = $this->app->make(LeadMailVerify::class); $rule = $this->app->make(LeadMailVerify::class);
$passed = true;
$rule->validate($attribute, $value, function () use (&$passed) { return $rule->passes($attribute, $value);
$passed = false;
});
return $passed;
}, 'The :attribute email address could not be verified.'); }, 'The :attribute email address could not be verified.');
} }
} }

View File

@@ -2,23 +2,24 @@
namespace LeadM\LeadMail\Rules; namespace LeadM\LeadMail\Rules;
use Closure; use Illuminate\Contracts\Validation\Rule;
use Illuminate\Contracts\Validation\ValidationRule;
use LeadM\LeadMail\LeadMailClient; 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( public function __construct(
protected readonly LeadMailClient $client, protected readonly LeadMailClient $client,
protected readonly bool $allowDisposable = false, 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)) { 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 { try {
@@ -26,10 +27,20 @@ class LeadMailVerify implements ValidationRule
if (! ($result['data']['valid'] ?? true)) { if (! ($result['data']['valid'] ?? true)) {
$reason = $result['data']['reason'] ?? 'verification failed'; $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) { } catch (\Throwable) {
// Fail open — if the verification service is down, allow the email through // Fail open — if the verification service is down, allow the email through
return true;
} }
} }
public function message(): string
{
return $this->failMessage;
}
} }