Mail bugfix, gpg, profile frontend WIP

This commit is contained in:
2024-04-06 19:09:12 +02:00
parent fe81e0f6fa
commit e97ac34365
17 changed files with 377 additions and 102 deletions

View File

@@ -55,14 +55,15 @@ namespace Core\API\Mail {
use Core\External\PHPMailer\PHPMailer;
use Core\Objects\Context;
use Core\Objects\DatabaseEntity\GpgKey;
use PhpParser\Node\Param;
class Test extends MailAPI {
public function __construct(Context $context, bool $externalCall = false) {
parent::__construct($context, $externalCall, array(
parent::__construct($context, $externalCall, [
"receiver" => new Parameter("receiver", Parameter::TYPE_EMAIL),
"gpgFingerprint" => new StringType("gpgFingerprint", 64, true, null)
));
]);
}
public function _execute(): bool {
@@ -74,10 +75,12 @@ namespace Core\API\Mail {
"subject" => "Test E-Mail",
"body" => "Hey! If you receive this e-mail, your mail configuration seems to be working.",
"gpgFingerprint" => $this->getParam("gpgFingerprint"),
"async" => false
"async" => false,
"debug" => true,
));
$this->lastError = $req->getLastError();
$this->result["output"] = $req->getResult()["output"];
return $this->success;
}
@@ -95,7 +98,8 @@ namespace Core\API\Mail {
'replyTo' => new Parameter('replyTo', Parameter::TYPE_EMAIL, true, null),
'replyName' => new StringType('replyName', 32, true, ""),
'gpgFingerprint' => new StringType("gpgFingerprint", 64, true, null),
'async' => new Parameter("async", Parameter::TYPE_BOOLEAN, true, null)
'async' => new Parameter("async", Parameter::TYPE_BOOLEAN, true, null),
'debug' => new Parameter("debug", Parameter::TYPE_BOOLEAN, true, false)
));
$this->isPublic = false;
}
@@ -115,6 +119,7 @@ namespace Core\API\Mail {
$replyName = $this->getParam('replyName');
$body = $this->getParam('body');
$gpgFingerprint = $this->getParam("gpgFingerprint");
$debug = $this->getParam("debug");
$mailAsync = $this->getParam("async");
if ($mailAsync === null) {
@@ -156,8 +161,9 @@ namespace Core\API\Mail {
$mail->addReplyTo($replyTo, $replyName);
}
$mail->Subject = $subject;
$mail->SMTPDebug = 0;
$mail->SMTPDebug = $debug ? 2 : 0;
$mail->Host = $mailConfig->getHost();
$mail->Port = $mailConfig->getPort();
$mail->SMTPAuth = true;
@@ -193,12 +199,22 @@ namespace Core\API\Mail {
$mail->AltBody = strip_tags($body);
}
ob_start();
$this->success = @$mail->Send();
$output = ob_get_contents();
ob_end_clean();
if (!$this->success) {
$this->lastError = "Error sending Mail: $mail->ErrorInfo";
$this->logger->error("sendMail() failed: $mail->ErrorInfo");
if ($debug) {
$this->logger->debug($output);
$this->result["output"] = $output;
}
} else {
$this->result["messageId"] = $mail->getLastMessageID();
if ($debug) {
$this->result["output"] = $output;
}
}
} catch (Exception $e) {
$this->success = false;

View File

@@ -1240,9 +1240,9 @@ namespace Core\API\User {
class ImportGPG extends UserAPI {
public function __construct(Context $context, bool $externalCall = false) {
parent::__construct($context, $externalCall, array(
parent::__construct($context, $externalCall, [
"pubkey" => new StringType("pubkey")
));
]);
$this->loginRequired = true;
$this->forbidMethod("GET");
}
@@ -1342,6 +1342,10 @@ namespace Core\API\User {
return $this->success;
}
public static function getDefaultACL(Insert $insert): void {
$insert->addRow(self::getEndpoint(), [], "Allows users to import gpg keys for a secure e-mail communication", true);
}
}
class RemoveGPG extends UserAPI {
@@ -1371,6 +1375,10 @@ namespace Core\API\User {
return $this->success;
}
public static function getDefaultACL(Insert $insert): void {
$insert->addRow(self::getEndpoint(), [], "Allows users to unlink gpg keys from their profile", true);
}
}
class ConfirmGPG extends UserAPI {