Skip to content

Commit

Permalink
fix: honour MDN requests
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <[email protected]>
  • Loading branch information
miaulalala committed May 6, 2024
1 parent 078390e commit a281851
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/Controller/DraftsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function __construct(string $appName,
* @param int|null $smimeCertificateId
* @param int|null $sendAt
* @param int|null $draftId
* @param bool $requestMdn
*
* @return JsonResponse
* @throws DoesNotExistException
Expand All @@ -99,6 +100,7 @@ public function create(
array $cc = [],
array $bcc = [],
array $attachments = [],
bool $requestMdn,
?int $aliasId = null,
?string $inReplyToMessageId = null,
?int $smimeCertificateId = null,
Expand All @@ -121,6 +123,7 @@ public function create(
$message->setSendAt($sendAt);
$message->setSmimeSign($smimeSign);
$message->setSmimeEncrypt($smimeEncrypt);
$message->setRequestMdn($requestMdn);

if (!empty($smimeCertificateId)) {
$smimeCertificate = $this->smimeService->findCertificate($smimeCertificateId, $this->userId);
Expand All @@ -141,14 +144,14 @@ public function create(
* @param string $body
* @param string $editorBody
* @param bool $isHtml
* @param bool $failed
* @param array<int, string[]> $to i. e. [['label' => 'Linus', 'email' => '[email protected]'], ['label' => 'Pierre', 'email' => '[email protected]']]
* @param array<int, string[]> $cc
* @param array<int, string[]> $bcc
* @param array $attachments
* @param int|null $aliasId
* @param string|null $inReplyToMessageId
* @param int|null $sendAt
* @param bool $requestMdn
* @return JsonResponse
*/
#[TrapError]
Expand All @@ -160,11 +163,11 @@ public function update(int $id,
bool $isHtml,
?bool $smimeSign,
?bool $smimeEncrypt,
bool $failed = false,
array $to = [],
array $cc = [],
array $bcc = [],
array $attachments = [],
bool $requestMdn,
?int $aliasId = null,
?string $inReplyToMessageId = null,
?int $smimeCertificateId = null,
Expand All @@ -179,12 +182,12 @@ public function update(int $id,
$message->setBody($body);
$message->setEditorBody($editorBody);
$message->setHtml($isHtml);
$message->setFailed($failed);
$message->setInReplyToMessageId($inReplyToMessageId);
$message->setSendAt($sendAt);
$message->setUpdatedAt($this->timeFactory->getTime());
$message->setSmimeSign($smimeSign);
$message->setSmimeEncrypt($smimeEncrypt);
$message->setRequestMdn($requestMdn);

if (!empty($smimeCertificateId)) {
$smimeCertificate = $this->smimeService->findCertificate($smimeCertificateId, $this->userId);
Expand Down
8 changes: 6 additions & 2 deletions lib/Controller/OutboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function show(int $id): JsonResponse {
* @param int|null $aliasId
* @param string|null $inReplyToMessageId
* @param int|null $sendAt
* @param bool $requestMdn
*
* @return JsonResponse
* @throws DoesNotExistException
Expand All @@ -115,6 +116,7 @@ public function create(
array $cc = [],
array $bcc = [],
array $attachments = [],
bool $requestMdn,
?int $draftId = null,
?int $aliasId = null,
?string $inReplyToMessageId = null,
Expand All @@ -139,6 +141,7 @@ public function create(
$message->setSendAt($sendAt);
$message->setSmimeSign($smimeSign);
$message->setSmimeEncrypt($smimeEncrypt);
$message->setRequestMdn($requestMdn);

if (!empty($smimeCertificateId)) {
$smimeCertificate = $this->smimeService->findCertificate($smimeCertificateId, $this->userId);
Expand Down Expand Up @@ -178,14 +181,15 @@ public function createFromDraft(DraftsService $draftsService, int $id, ?int $sen
* @param string $body
* @param string $editorBody
* @param bool $isHtml
* @param bool $failed
* @param array $to i. e. [['label' => 'Linus', 'email' => '[email protected]'], ['label' => 'Pierre', 'email' => '[email protected]']]
* @param array $cc
* @param array $bcc
* @param array $attachments
* @param int|null $aliasId
* @param string|null $inReplyToMessageId
* @param int|null $sendAt
* @param bool $requestMdn
*
* @return JsonResponse
*/
#[TrapError]
Expand All @@ -198,11 +202,11 @@ public function update(
bool $isHtml,
bool $smimeSign,
bool $smimeEncrypt,
bool $failed = false,
array $to = [],
array $cc = [],
array $bcc = [],
array $attachments = [],
bool $requestMdn,
?int $aliasId = null,
?string $inReplyToMessageId = null,
?int $smimeCertificateId = null,
Expand Down
10 changes: 9 additions & 1 deletion lib/Db/LocalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@
* @method int|null getSmimeCertificateId()
* @method setSmimeCertificateId(?int $smimeCertificateId)
* @method bool|null getSmimeEncrypt()
* @method setSmimeEncrypt (bool $smimeEncryt)
* @method setSmimeEncrypt(bool $smimeEncryt)
* @method int|null getStatus();
* @method setStatus(?int $status);
* @method string|null getRaw()
* @method setRaw(string|null $raw)
* @method bool getRequestMdn()
* @method setRequestMdn(bool $mdn)
*/
class LocalMessage extends Entity implements JsonSerializable {
public const TYPE_OUTGOING = 0;
Expand Down Expand Up @@ -143,6 +145,9 @@ class LocalMessage extends Entity implements JsonSerializable {
/** @var string|null */
protected $raw;

/** @var bool */
protected $requestMdn;

public function __construct() {
$this->addType('type', 'integer');
$this->addType('accountId', 'integer');
Expand All @@ -155,6 +160,8 @@ public function __construct() {
$this->addType('smimeCertificateId', 'integer');
$this->addType('smimeEncrypt', 'boolean');
$this->addType('status', 'integer');
$this->addType('requestMdn', 'boolean');

}

#[ReturnTypeWillChange]
Expand Down Expand Up @@ -198,6 +205,7 @@ public function jsonSerialize() {
'smimeEncrypt' => $this->getSmimeEncrypt() === true,
'status' => $this->getStatus(),
'raw' => $this->getRaw(),
'mdn' => $this->getRequestMdn(),
];
}

Expand Down
53 changes: 53 additions & 0 deletions lib/Migration/Version3600Date20240319172810.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);
/**
* @copyright 2024 Anna Larch <[email protected]>
*
* @author Anna Larch <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OCA\Mail\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version3600Date20240319172810 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$localMessagesTable = $schema->getTable('mail_local_messages');
if (!$localMessagesTable->hasColumn('request_mdn')) {
$localMessagesTable->addColumn('request_mdn', Types::BOOLEAN, [
'notnull' => false,
'default' => false,
]);
}

return $schema;
}
}

0 comments on commit a281851

Please sign in to comment.