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 Jun 10, 2024
1 parent 9d258fc commit 752b012
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The rating depends on the installed text processing backend. See [the rating ove
Learn more about the Nextcloud Ethical AI Rating [in our blog](https://nextcloud.com/blog/nextcloud-ethical-ai-rating/).
]]></description>
<version>3.7.0-alpha.2</version>
<version>3.8.0-alpha.1</version>
<licence>agpl</licence>
<author>Christoph Wurst</author>
<author homepage="https://github.com/nextcloud/groupware">Nextcloud Groupware Team</author>
Expand Down
8 changes: 6 additions & 2 deletions lib/Controller/DraftsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public function create(
?string $inReplyToMessageId = null,
?int $smimeCertificateId = null,
?int $sendAt = null,
?int $draftId = null) : JsonResponse {
?int $draftId = null,
bool $requestMdn = false) : JsonResponse {
$account = $this->accountService->find($this->userId, $accountId);
if ($draftId !== null) {
$this->service->handleDraft($account, $draftId);
Expand All @@ -121,6 +122,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 @@ -168,7 +170,8 @@ public function update(int $id,
?int $aliasId = null,
?string $inReplyToMessageId = null,
?int $smimeCertificateId = null,
?int $sendAt = null): JsonResponse {
?int $sendAt = null,
bool $requestMdn = false): JsonResponse {
$message = $this->service->getMessage($id, $this->userId);
$account = $this->accountService->find($this->userId, $accountId);

Expand All @@ -185,6 +188,7 @@ public function update(int $id,
$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 @@ -119,7 +119,8 @@ public function create(
?int $aliasId = null,
?string $inReplyToMessageId = null,
?int $smimeCertificateId = null,
?int $sendAt = null
?int $sendAt = null,
bool $requestMdn = false,
): JsonResponse {
$account = $this->accountService->find($this->userId, $accountId);

Expand All @@ -139,6 +140,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 @@ -206,7 +208,8 @@ public function update(
?int $aliasId = null,
?string $inReplyToMessageId = null,
?int $smimeCertificateId = null,
?int $sendAt = null
?int $sendAt = null,
bool $requestMdn = false,
): JsonResponse {
$message = $this->service->getMessage($id, $this->userId);
if ($message->getStatus() === LocalMessage::STATUS_PROCESSED) {
Expand All @@ -224,6 +227,7 @@ public function update(
$message->setSendAt($sendAt);
$message->setSmimeSign($smimeSign);
$message->setSmimeEncrypt($smimeEncrypt);
$message->setRequestMdn($requestMdn);

if (!empty($smimeCertificateId)) {
$smimeCertificate = $this->smimeService->findCertificate($smimeCertificateId, $this->userId);
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(),
'requestMdn' => $this->getRequestMdn(),
];
}

Expand Down
55 changes: 55 additions & 0 deletions lib/Migration/Version3700Date20240506161400.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 Version3700Date20240506161400 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;
}
}
4 changes: 4 additions & 0 deletions lib/Service/MailTransmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public function sendMessage(Account $account, LocalMessage $localMessage): void
$headers['In-Reply-To'] = $inReplyTo;
}

if ($localMessage->getRequestMdn()) {
$headers[Horde_Mime_Mdn::MDN_HEADER] = $from->first()->toHorde();
}

$mail = new Horde_Mime_Mail();
$mail->addHeaders($headers);

Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/Controller/DraftsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public function testCreate(): void {
$message->setType(LocalMessage::TYPE_DRAFT);
$message->setSendAt(null);
$message->setUpdatedAt(123456);
$message->setRequestMdn(false);
$to = [['label' => 'Lewis', 'email' => '[email protected]']];
$cc = [['label' => 'Pierre', 'email' => '[email protected]']];

Expand Down Expand Up @@ -264,6 +265,7 @@ public function testCreateFromDraft(): void {
$message->setType(LocalMessage::TYPE_DRAFT);
$message->setSendAt(null);
$message->setUpdatedAt(123456);
$message->setRequestMdn(false);
$to = [['label' => 'Lewis', 'email' => '[email protected]']];
$cc = [['label' => 'Pierre', 'email' => '[email protected]']];

Expand Down Expand Up @@ -298,7 +300,8 @@ public function testCreateFromDraft(): void {
$message->getInReplyToMessageId(),
null,
null,
1
1,
false
);

$this->assertEquals($expected, $actual);
Expand All @@ -316,6 +319,7 @@ public function testCreateWithEmptyRecipients(): void {
$message->setType(LocalMessage::TYPE_DRAFT);
$message->setSendAt(null);
$message->setUpdatedAt(123456);
$message->setRequestMdn(false);

$account = new Account(new MailAccount());
$this->accountService->expects(self::once())
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Controller/OutboxControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public function testCreate(): void {
$message->setSmimeEncrypt(false);
$message->setInReplyToMessageId('abc');
$message->setType(LocalMessage::TYPE_OUTGOING);
$message->setRequestMdn(false);
$to = [['label' => 'Lewis', 'email' => '[email protected]']];
$cc = [['label' => 'Pierre', 'email' => '[email protected]']];

Expand Down

0 comments on commit 752b012

Please sign in to comment.