|
21 | 21 | use OCA\Mail\Service\AliasesService; |
22 | 22 | use OCA\Mail\Service\Attachment\AttachmentService; |
23 | 23 | use OCA\Mail\Service\Attachment\UploadedFile; |
| 24 | +use OCA\Mail\Service\DelegationService; |
24 | 25 | use OCA\Mail\Service\ItineraryService; |
25 | 26 | use OCA\Mail\Service\MailManager; |
26 | 27 | use OCA\Mail\Service\OutboxService; |
@@ -66,6 +67,7 @@ public function __construct( |
66 | 67 | private IDkimService $dkimService, |
67 | 68 | private ItineraryService $itineraryService, |
68 | 69 | private TrustedSenderService $trustedSenderService, |
| 70 | + private DelegationService $delegationService, |
69 | 71 | ) { |
70 | 72 | parent::__construct($appName, $request); |
71 | 73 | $this->userId = $userId; |
@@ -120,15 +122,16 @@ public function send( |
120 | 122 | } |
121 | 123 |
|
122 | 124 | try { |
123 | | - $mailAccount = $this->accountService->find($this->userId, $accountId); |
| 125 | + $effectiveUserId = $this->delegationService->resolveAccountUserId($accountId, $this->userId); |
| 126 | + $mailAccount = $this->accountService->find($effectiveUserId, $accountId); |
124 | 127 | } catch (ClientException $e) { |
125 | 128 | $this->logger->error("Mail account #$accountId not found", ['exception' => $e]); |
126 | 129 | return new DataResponse('Account not found.', Http::STATUS_NOT_FOUND); |
127 | 130 | } |
128 | 131 |
|
129 | 132 | if ($fromEmail !== $mailAccount->getEmail()) { |
130 | 133 | try { |
131 | | - $alias = $this->aliasesService->findByAliasAndUserId($fromEmail, $this->userId); |
| 134 | + $alias = $this->aliasesService->findByAliasAndUserId($fromEmail, $effectiveUserId); |
132 | 135 | } catch (DoesNotExistException $e) { |
133 | 136 | $this->logger->error("Alias $fromEmail for mail account $accountId not found", ['exception' => $e]); |
134 | 137 | // Cannot send from this email as it is not configured as an alias |
@@ -234,9 +237,10 @@ public function get(int $id): DataResponse { |
234 | 237 | } |
235 | 238 |
|
236 | 239 | try { |
237 | | - $message = $this->mailManager->getMessage($this->userId, $id); |
238 | | - $mailbox = $this->mailManager->getMailbox($this->userId, $message->getMailboxId()); |
239 | | - $account = $this->accountService->find($this->userId, $mailbox->getAccountId()); |
| 240 | + $effectiveUserId = $this->delegationService->resolveMessageUserId($id, $this->userId); |
| 241 | + $message = $this->mailManager->getMessage($effectiveUserId, $id); |
| 242 | + $mailbox = $this->mailManager->getMailbox($effectiveUserId, $message->getMailboxId()); |
| 243 | + $account = $this->accountService->find($effectiveUserId, $mailbox->getAccountId()); |
240 | 244 | } catch (ClientException|DoesNotExistException $e) { |
241 | 245 | $this->logger->error('Message, Account or Mailbox not found', ['exception' => $e->getMessage()]); |
242 | 246 | return new DataResponse('Account not found.', Http::STATUS_NOT_FOUND); |
@@ -322,9 +326,10 @@ public function getRaw(int $id): DataResponse { |
322 | 326 | } |
323 | 327 |
|
324 | 328 | try { |
325 | | - $message = $this->mailManager->getMessage($this->userId, $id); |
326 | | - $mailbox = $this->mailManager->getMailbox($this->userId, $message->getMailboxId()); |
327 | | - $account = $this->accountService->find($this->userId, $mailbox->getAccountId()); |
| 329 | + $effectiveUserId = $this->delegationService->resolveMessageUserId($id, $this->userId); |
| 330 | + $message = $this->mailManager->getMessage($effectiveUserId, $id); |
| 331 | + $mailbox = $this->mailManager->getMailbox($effectiveUserId, $message->getMailboxId()); |
| 332 | + $account = $this->accountService->find($effectiveUserId, $mailbox->getAccountId()); |
328 | 333 | } catch (ClientException|DoesNotExistException $e) { |
329 | 334 | $this->logger->error('Message, Account or Mailbox not found', ['exception' => $e->getMessage()]); |
330 | 335 | return new DataResponse('Message, Account or Mailbox not found', Http::STATUS_NOT_FOUND); |
@@ -383,9 +388,10 @@ private function enrichDownloadUrl(int $id, array $attachment): array { |
383 | 388 | #[TrapError] |
384 | 389 | public function getAttachment(int $id, string $attachmentId): DataResponse { |
385 | 390 | try { |
386 | | - $message = $this->mailManager->getMessage($this->userId, $id); |
387 | | - $mailbox = $this->mailManager->getMailbox($this->userId, $message->getMailboxId()); |
388 | | - $account = $this->accountService->find($this->userId, $mailbox->getAccountId()); |
| 391 | + $effectiveUserId = $this->delegationService->resolveMessageUserId($id, $this->userId); |
| 392 | + $message = $this->mailManager->getMessage($effectiveUserId, $id); |
| 393 | + $mailbox = $this->mailManager->getMailbox($effectiveUserId, $message->getMailboxId()); |
| 394 | + $account = $this->accountService->find($effectiveUserId, $mailbox->getAccountId()); |
389 | 395 | } catch (DoesNotExistException|ClientException $e) { |
390 | 396 | return new DataResponse('Message, Account or Mailbox not found', Http::STATUS_NOT_FOUND); |
391 | 397 | } |
|
0 commit comments