rosavox/lib/alveolata/email/base.php
2025-05-23 07:33:29 +00:00

244 lines
3.8 KiB
PHP

<?php
namespace alveolata\email;
require_once(DIR_ALVEOLATA . '/pod/wrapper-class.php');
/**
*/
class enum_negotiation_type
{
public const none = 'none';
public const opportunistic = 'opportunistic'; // STARTTLS
public const forced = 'forced';
}
/**
* @see https://en.m.wikipedia.org/wiki/SMTP_Authentication
*/
class enum_auth_type
{
public const none = 'none';
public const plain = 'plain';
public const login = 'login';
public const gssapi = 'gssapi';
public const md5 = 'md5';
public const digest_md5 = 'digest_md5';
public const cram_md5 = 'cram_md5';
public const oauth10a = 'oauth10a';
public const oauthbearer = 'oauthbearer';
public const xoauth2 = 'xoauth2';
}
/**
*/
class struct_credentials
{
/**
* @param string
*/
public $host;
/**
* @param int
*/
public $port;
/**
* @param string (enum_negotiation_type)
*/
public $negotiation_type;
/**
* @param string (enum_auth_type)
*/
public $auth_type;
/**
* @param string
*/
public $username;
/**
* @param string
*/
public $password;
/**
*/
public function __construct(
array $raw
)
{
$fields = [
[
'name' => 'host',
'default' => \alveolata\pod\class_pod::toom(),
],
[
'name' => 'port',
'default' => \alveolata\pod\class_pod::full(587),
],
[
'name' => 'negotiation_type',
'default' => \alveolata\pod\class_pod::full(enum_negotiation_type::forced),
],
[
'name' => 'auth_type',
'default' => \alveolata\pod\class_pod::full(enum_auth_type::login),
],
[
'name' => 'username',
'default' => \alveolata\pod\class_pod::toom(),
],
[
'name' => 'password',
'default' => \alveolata\pod\class_pod::toom(),
],
];
foreach ($fields as $field) {
if (
(! $field['default']->has())
&&
(! array_key_exists($field['name'], $raw))
) {
throw (new \Exception(sprintf('mandatory parameter "%s" missing', $field['name'])));
}
else {
$this->{$field['name']} = ($raw[$field['name']] ?? $field['default']->get());
}
}
}
}
/**
*/
class struct_data {
/**
* @param array {list<string>}
*/
public $to;
/**
* @param ?string {(null | string)}
*/
public $subject;
/**
* @param ?string {(null | string)}
*/
public $body_plain;
/**
* @param ?string {(null | string)}
*/
public $body_html;
/**
* @param ?string {(null | string)}
*/
public $from;
/**
* @param array {list<string>}
*/
public $cc;
/**
* @param array {list<string>}
*/
public $bcc;
/**
* @param ?string (null | string)
*/
public $reply_to;
/**
* @param array {list<record<kind:string,data:any>>}
*/
public $attachments;
/**
*/
public function __construct(
array $raw
)
{
$fields = [
[
'name' => 'to',
'default' => \alveolata\pod\class_pod::toom(),
],
[
'name' => 'subject',
'default' => \alveolata\pod\class_pod::toom(),
],
[
'name' => 'body_plain',
'default' => \alveolata\pod\class_pod::full(null),
],
[
'name' => 'body_html',
'default' => \alveolata\pod\class_pod::full(null),
],
[
'name' => 'from',
'default' => \alveolata\pod\class_pod::full(null),
],
[
'name' => 'cc',
'default' => \alveolata\pod\class_pod::full([]),
],
[
'name' => 'bcc',
'default' => \alveolata\pod\class_pod::full([]),
],
[
'name' => 'reply_to',
'default' => \alveolata\pod\class_pod::full(null),
],
[
'name' => 'attachments',
'default' => \alveolata\pod\class_pod::full([]),
],
];
foreach ($fields as $field) {
if (
(! $field['default']->has())
&&
(! array_key_exists($field['name'], $raw))
) {
throw (new \Exception(sprintf('mandatory parameter "%s" missing', $field['name'])));
}
else {
$this->{$field['name']} = ($raw[$field['name']] ?? $field['default']->get());
}
}
}
}
?>