Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2022-04-13 00:00:10 +0300
committerjulia.kirschenheuter <julia.kirschenheuter@nextcloud.com>2022-04-13 16:04:39 +0300
commite7b057e630727113d5f51d651840b9ea25586a4a (patch)
tree99b6f801ef8364a7736fdb4d5b57d3f8b50a7beb /lib
parentea93911bd2eff92a205a827c7c595a683053b3ce (diff)
Fix message attachments not sending
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/LocalMessageMapper.php29
-rw-r--r--lib/Service/Attachment/AttachmentStorage.php9
-rw-r--r--lib/Service/MailTransmission.php15
-rw-r--r--lib/Service/OutboxService.php5
4 files changed, 39 insertions, 19 deletions
diff --git a/lib/Db/LocalMessageMapper.php b/lib/Db/LocalMessageMapper.php
index 71029e672..d99550ace 100644
--- a/lib/Db/LocalMessageMapper.php
+++ b/lib/Db/LocalMessageMapper.php
@@ -28,7 +28,6 @@ namespace OCA\Mail\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\DB\Exception as DBException;
use Throwable;
-use function array_filter;
use function array_map;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -133,19 +132,31 @@ class LocalMessageMapper extends QBMapper {
$qb->expr()->lte('send_at', $qb->createNamedParameter($time, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)
);
$messages = $this->findEntities($select);
+
+ if (empty($messages)) {
+ return [];
+ }
+
$ids = array_map(function (LocalMessage $message) {
return $message->getId();
}, $messages);
+
$attachments = $this->attachmentMapper->findByLocalMessageIds($ids);
$recipients = $this->recipientMapper->findByLocalMessageIds($ids);
- return array_map(static function ($message) use ($attachments, $recipients) {
- $message->setAttachments(array_filter($attachments, function (LocalAttachment $attachment) use ($message) {
- return $attachment->getLocalMessageId() === $message->getId();
- }));
- $message->setRecipients(array_filter($recipients, function (Recipient $recipient) use ($message) {
- return $recipient->getLocalMessageId() === $message->getId();
- }));
- return $message;
+
+ $recipientMap = [];
+ foreach ($recipients as $r) {
+ $recipientMap[$r->getLocalMessageId()][] = $r;
+ }
+ $attachmentMap = [];
+ foreach ($attachments as $a) {
+ $attachmentMap[$a->getLocalMessageId()][] = $a;
+ }
+
+ return array_map(static function ($localMessage) use ($attachmentMap, $recipientMap) {
+ $localMessage->setAttachments($attachmentMap[$localMessage->getId()] ?? []);
+ $localMessage->setRecipients($recipientMap[$localMessage->getId()] ?? []);
+ return $localMessage;
}, $messages);
}
diff --git a/lib/Service/Attachment/AttachmentStorage.php b/lib/Service/Attachment/AttachmentStorage.php
index 7c31bd842..fdf7228a2 100644
--- a/lib/Service/Attachment/AttachmentStorage.php
+++ b/lib/Service/Attachment/AttachmentStorage.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace OCA\Mail\Service\Attachment;
-use Exception;
use OCA\Mail\Exception\AttachmentNotFoundException;
use OCA\Mail\Exception\UploadException;
use OCP\Files\IAppData;
@@ -127,6 +126,12 @@ class AttachmentStorage {
}
public function delete(string $userId, int $attachmentId): void {
- throw new Exception('not implemented');
+ $folder = $this->getAttachmentFolder($userId);
+ try {
+ $file = $folder->getFile((string)$attachmentId);
+ } catch (NotFoundException $e) {
+ return;
+ }
+ $file->delete();
}
}
diff --git a/lib/Service/MailTransmission.php b/lib/Service/MailTransmission.php
index f5868ebb9..66b2d7247 100644
--- a/lib/Service/MailTransmission.php
+++ b/lib/Service/MailTransmission.php
@@ -245,6 +245,13 @@ class MailTransmission implements IMailTransmission {
})
)
);
+ $attachments = array_map(function (LocalAttachment $attachment) {
+ // Convert to the untyped nested array used in \OCA\Mail\Controller\AccountsController::send
+ return [
+ 'type' => 'local',
+ 'id' => $attachment->getId(),
+ ];
+ }, $message->getAttachments());
$messageData = new NewMessageData(
$account,
$to,
@@ -252,13 +259,7 @@ class MailTransmission implements IMailTransmission {
$bcc,
$message->getSubject(),
$message->getBody(),
- array_map(function (LocalAttachment $attachment) {
- // Convert to the untyped nested array used in \OCA\Mail\Controller\AccountsController::send
- return [
- 'type' => 'local',
- 'id' => $attachment->getId(),
- ];
- }, $message->getAttachments()),
+ $attachments,
$message->isHtml()
);
diff --git a/lib/Service/OutboxService.php b/lib/Service/OutboxService.php
index 6c7d0470f..ce3754849 100644
--- a/lib/Service/OutboxService.php
+++ b/lib/Service/OutboxService.php
@@ -177,6 +177,10 @@ class OutboxService implements ILocalMailboxService {
$this->timeFactory->getTime()
);
+ if (empty($messages)) {
+ return;
+ }
+
$accountIds = array_unique(array_map(function ($message) {
return $message->getAccountId();
}, $messages));
@@ -187,7 +191,6 @@ class OutboxService implements ILocalMailboxService {
foreach ($messages as $message) {
try {
- // TODO: memoize accounts
$this->sendMessage(
$message,
$accounts[$message->getAccountId()],