generated from Nodarx/template
feat: smtp sending
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderImap\Smtp\Auth;
|
||||
|
||||
/**
|
||||
* Supported SASL authentication mechanisms, in preference order.
|
||||
*/
|
||||
enum AuthMechanism: string
|
||||
{
|
||||
case Plain = 'PLAIN';
|
||||
case Login = 'LOGIN';
|
||||
|
||||
/**
|
||||
* Select the most preferred mechanism the server advertises.
|
||||
*
|
||||
* @param list<string> $advertised mechanisms offered by the server (uppercased)
|
||||
*/
|
||||
public static function select(array $advertised): ?self
|
||||
{
|
||||
foreach ([self::Plain, self::Login] as $mechanism) {
|
||||
if (in_array($mechanism->value, $advertised, true)) {
|
||||
return $mechanism;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The initial AUTH response for the PLAIN mechanism:
|
||||
* base64( authzid NUL authcid NUL passwd ).
|
||||
*/
|
||||
public static function plainToken(string $username, string $password): string
|
||||
{
|
||||
return base64_encode("\0" . $username . "\0" . $password);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user