Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Controller/AvatarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ public function image(string $email): Response {
}

$imageData = $this->avatarService->getAvatarImage($email, $this->uid);

if ($imageData === null) {
return $this->noAvatarFoundResponse();
}
[$avatar, $image] = $imageData;

if (is_null($imageData) || !$avatar->isExternal()) {
if (!$avatar->isExternal()) {
// This could happen if the cache invalidated meanwhile
return $this->noAvatarFoundResponse();
}
Expand Down
20 changes: 16 additions & 4 deletions lib/Controller/MessageApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,14 @@
$json['rawUrl'] = $this->urlGenerator->linkToOCSRouteAbsolute('mail.messageApi.getRaw', ['id' => $id]);

if (!$loadBody) {
return new DataResponse($json, Http::STATUS_PARTIAL_CONTENT);
/** @var DataResponse<Http::STATUS_PARTIAL_CONTENT, MailMessageApiResponse, array{}> $response */
$response = new DataResponse($json, Http::STATUS_PARTIAL_CONTENT);
return $response;
}

return new DataResponse($json, Http::STATUS_OK);
/** @var DataResponse<Http::STATUS_OK, MailMessageApiResponse, array{}> $response */
$response = new DataResponse($json, Http::STATUS_OK);
return $response;
}

/**
Expand Down Expand Up @@ -382,6 +386,10 @@
#[NoAdminRequired]
#[TrapError]
public function getAttachment(int $id, string $attachmentId): DataResponse {
if ($this->userId === null) {
return new DataResponse('Account not found.', Http::STATUS_NOT_FOUND);
}

try {
$message = $this->mailManager->getMessage($this->userId, $id);
$mailbox = $this->mailManager->getMailbox($this->userId, $message->getMailboxId());
Expand All @@ -407,20 +415,24 @@

// Body party and embedded messages do not have a name
if ($attachment->getName() === null) {
return new DataResponse([
/** @var DataResponse<Http::STATUS_OK, MailMessageApiAttachment, array{}> $response */
$response = new DataResponse([
'name' => $attachmentId . '.eml',
'mime' => $attachment->getType(),
'size' => $attachment->getSize(),
'content' => $attachment->getContent()
]);
return $response;
}

return new DataResponse([
/** @var DataResponse<Http::STATUS_OK, MailMessageApiAttachment, array{}> $response */
$response = new DataResponse([
'name' => $attachment->getName(),
'mime' => $attachment->getType(),
'size' => $attachment->getSize(),
'content' => $attachment->getContent()
]);
return $response;
}

/**
Expand All @@ -444,13 +456,13 @@
];
$file = new UploadedFile($filedata);
try {
$attachment = $this->attachmentService->addFile($this->userId, $file);

Check failure on line 459 in lib/Controller/MessageApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Controller/MessageApiController.php:459:53: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\Attachment\AttachmentService::addFile cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 459 in lib/Controller/MessageApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

PossiblyNullArgument

lib/Controller/MessageApiController.php:459:53: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\Attachment\AttachmentService::addFile cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 459 in lib/Controller/MessageApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

PossiblyNullArgument

lib/Controller/MessageApiController.php:459:53: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\Attachment\AttachmentService::addFile cannot be null, possibly null value provided (see https://psalm.dev/078)
$messageAttachments[] = $attachment;
} catch (UploadException $e) {
$this->logger->error('Could not convert attachment to local attachment.', ['exception' => $e]);
foreach ($messageAttachments as $attachment) {
// Handle possible dangling local attachments
$this->attachmentService->deleteAttachment($this->userId, $attachment->getId());

Check failure on line 465 in lib/Controller/MessageApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Controller/MessageApiController.php:465:49: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\Attachment\AttachmentService::deleteAttachment cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 465 in lib/Controller/MessageApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

PossiblyNullArgument

lib/Controller/MessageApiController.php:465:49: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\Attachment\AttachmentService::deleteAttachment cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 465 in lib/Controller/MessageApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

PossiblyNullArgument

lib/Controller/MessageApiController.php:465:49: PossiblyNullArgument: Argument 1 of OCA\Mail\Service\Attachment\AttachmentService::deleteAttachment cannot be null, possibly null value provided (see https://psalm.dev/078)
}
throw $e;
}
Expand Down
18 changes: 11 additions & 7 deletions lib/Controller/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
return false;
}
return $this->trustedSenderService->isTrusted(
$this->currentUserId,

Check failure on line 352 in lib/Controller/MessagesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Controller/MessagesController.php:352:4: PossiblyNullArgument: Argument 1 of OCA\Mail\Contracts\ITrustedSenderService::isTrusted cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 352 in lib/Controller/MessagesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

PossiblyNullArgument

lib/Controller/MessagesController.php:352:4: PossiblyNullArgument: Argument 1 of OCA\Mail\Contracts\ITrustedSenderService::isTrusted cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 352 in lib/Controller/MessagesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

PossiblyNullArgument

lib/Controller/MessagesController.php:352:4: PossiblyNullArgument: Argument 1 of OCA\Mail\Contracts\ITrustedSenderService::isTrusted cannot be null, possibly null value provided (see https://psalm.dev/078)
$email
);
}
Expand Down Expand Up @@ -380,7 +380,7 @@
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}

return new JSONResponse($this->mailManager->getThread($account, $message->getThreadRootId()));
return new JSONResponse($this->mailManager->getThread($account, (string)$message->getThreadRootId()));
}

/**
Expand Down Expand Up @@ -589,7 +589,7 @@
}

return new AttachmentDownloadResponse(
$source,
$source ?? '',
$message->getSubject() . '.eml',
'message/rfc822',
);
Expand Down Expand Up @@ -721,7 +721,8 @@
);

// Body party and embedded messages do not have a name
if ($attachment->getName() === null) {
$attachmentName = $attachment->getName();
if ($attachmentName === null) {
return new AttachmentDownloadResponse(
$attachment->getContent(),
$this->l10n->t('Embedded message %s', [
Expand All @@ -732,7 +733,7 @@
}
return new AttachmentDownloadResponse(
$attachment->getContent(),
$attachment->getName(),
$attachmentName,
$attachment->getType()
);
}
Expand Down Expand Up @@ -766,7 +767,7 @@
$zip = new ZipResponse($this->request, 'attachments');

foreach ($attachments as $attachment) {
$fileName = $attachment->getName();
$fileName = $attachment->getName() ?? '';
$fh = fopen('php://temp', 'r+');
if ($fh === false) {
continue;
Expand Down Expand Up @@ -800,6 +801,9 @@
if ($this->currentUserId === null) {
return new JSONResponse([], Http::STATUS_UNAUTHORIZED);
}
if ($this->userFolder === null) {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
try {
$message = $this->mailManager->getMessage($this->currentUserId, $id);
$mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId());
Expand Down Expand Up @@ -831,7 +835,7 @@
]) . '.eml';
$fileParts = pathinfo($fileName);
$fileName = $fileParts['filename'];
$fileExtension = $fileParts['extension'];
$fileExtension = $fileParts['extension'] ?? '';
$fullPath = "$targetPath/$fileName.$fileExtension";
$counter = 2;
while ($this->userFolder->nodeExists($fullPath)) {
Expand Down Expand Up @@ -995,7 +999,7 @@
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
try {
$replies = array_values($this->aiIntegrationService->getSmartReply($account, $mailbox, $message, $this->currentUserId));
$replies = array_values($this->aiIntegrationService->getSmartReply($account, $mailbox, $message, $this->currentUserId) ?? []);
} catch (ServiceException $e) {
$this->logger->error('Smart reply failed: ' . $e->getMessage(), [
'exception' => $e,
Expand Down
22 changes: 16 additions & 6 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@
* @return TemplateResponse renders the index page
*/
public function index(): TemplateResponse {
if ($this->currentUserId === null) {
// This should not happen as the route requires authentication,
// but handle it defensively.
return new TemplateResponse($this->appName, 'index');
}

$user = $this->userSession->getUser();
if ($user === null) {
return new TemplateResponse($this->appName, 'index');
}

if (class_exists(LoadViewer::class)) {
$this->dispatcher->dispatchTyped(new LoadViewer());
}
Expand Down Expand Up @@ -216,7 +227,6 @@
$passwordIsUnavailable,
);

$user = $this->userSession->getUser();
$response = new TemplateResponse($this->appName, 'index');
$this->initialStateService->provideInitialState('preferences', [
'attachment-size-limit' => $this->config->getSystemValue('app.mail.attachment-size-limit', 0),
Expand All @@ -235,7 +245,7 @@
]);
$this->initialStateService->provideInitialState(
'prefill_displayName',
$this->userManager->getDisplayName($this->currentUserId),

Check failure on line 248 in lib/Controller/PageController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Controller/PageController.php:248:4: PossiblyNullArgument: Argument 2 of OCP\AppFramework\Services\IInitialState::provideInitialState cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 248 in lib/Controller/PageController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

PossiblyNullArgument

lib/Controller/PageController.php:248:4: PossiblyNullArgument: Argument 2 of OCP\AppFramework\Services\IInitialState::provideInitialState cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 248 in lib/Controller/PageController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

PossiblyNullArgument

lib/Controller/PageController.php:248:4: PossiblyNullArgument: Argument 2 of OCP\AppFramework\Services\IInitialState::provideInitialState cannot be null, possibly null value provided (see https://psalm.dev/078)
);
$this->initialStateService->provideInitialState(
'importance_classification_default',
Expand Down Expand Up @@ -456,14 +466,14 @@
public function compose(string $uri): RedirectResponse {
$parts = parse_url($uri);
$params = [];
if (isset($parts['path'])) {
if (is_array($parts) && isset($parts['path'])) {
$params['to'] = $parts['path'];
}
if (isset($parts['query'])) {
$parts = explode('&', $parts['query']);
foreach ($parts as $part) {
if (is_array($parts) && isset($parts['query'])) {
$queryParts = explode('&', $parts['query']);
foreach ($queryParts as $part) {
$pair = explode('=', $part, 2);
$params[strtolower($pair[0])] = urldecode($pair[1]);
$params[strtolower($pair[0])] = urldecode($pair[1] ?? '');
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/SmimeCertificatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function create(): JsonResponse {
}

$certificateFile = new UploadedFile($attachedCertificate);
$certificateData = file_get_contents($certificateFile->getTempPath());
$certificateData = file_get_contents($certificateFile->getTempPath() ?? '');
if ($certificateData === false) {
return JsonResponse::fail(
'Could not read certificate file',
Expand All @@ -116,7 +116,7 @@ public function create(): JsonResponse {
$privateKeyData = null;
if ($attachedPrivateKey !== null) {
$privateKeyFile = new UploadedFile($attachedPrivateKey);
$privateKeyData = file_get_contents($privateKeyFile->getTempPath());
$privateKeyData = file_get_contents($privateKeyFile->getTempPath() ?? '');
if ($privateKeyData === false) {
return JsonResponse::fail(
'Could not read private key file',
Expand Down
26 changes: 18 additions & 8 deletions lib/Controller/ThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}

$threadRootId = $message->getThreadRootId();
if ($threadRootId === null) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
$this->mailManager->moveThread(
$srcAccount,
$srcMailbox,
$dstAccount,
$dstMailbox,
$message->getThreadRootId()
$threadRootId
);

return new JSONResponse();
Expand Down Expand Up @@ -149,14 +153,15 @@
} catch (DoesNotExistException $e) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
if (empty($message->getThreadRootId())) {
if ($message->getThreadRootId() === null || $message->getThreadRootId() === '') {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
$thread = $this->mailManager->getThread($account, $message->getThreadRootId());
$threadRootId = $message->getThreadRootId();
$thread = $this->mailManager->getThread($account, $threadRootId);

Check failure on line 160 in lib/Controller/ThreadController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Controller/ThreadController.php:160:53: PossiblyNullArgument: Argument 2 of OCA\Mail\Contracts\IMailManager::getThread cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 160 in lib/Controller/ThreadController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

PossiblyNullArgument

lib/Controller/ThreadController.php:160:53: PossiblyNullArgument: Argument 2 of OCA\Mail\Contracts\IMailManager::getThread cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 160 in lib/Controller/ThreadController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

PossiblyNullArgument

lib/Controller/ThreadController.php:160:53: PossiblyNullArgument: Argument 2 of OCA\Mail\Contracts\IMailManager::getThread cannot be null, possibly null value provided (see https://psalm.dev/078)
try {
$summary = $this->aiIntergrationsService->summarizeThread(
$account,
$message->getThreadRootId(),
$threadRootId,
$thread,
$this->currentUserId,
);
Expand All @@ -181,13 +186,14 @@
} catch (DoesNotExistException $e) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
if (empty($message->getThreadRootId())) {
if ($message->getThreadRootId() === null || $message->getThreadRootId() === '') {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
$thread = $this->mailManager->getThread($account, $message->getThreadRootId());
$threadRootId = $message->getThreadRootId();
$thread = $this->mailManager->getThread($account, $threadRootId);

Check failure on line 193 in lib/Controller/ThreadController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Controller/ThreadController.php:193:53: PossiblyNullArgument: Argument 2 of OCA\Mail\Contracts\IMailManager::getThread cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 193 in lib/Controller/ThreadController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

PossiblyNullArgument

lib/Controller/ThreadController.php:193:53: PossiblyNullArgument: Argument 2 of OCA\Mail\Contracts\IMailManager::getThread cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 193 in lib/Controller/ThreadController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

PossiblyNullArgument

lib/Controller/ThreadController.php:193:53: PossiblyNullArgument: Argument 2 of OCA\Mail\Contracts\IMailManager::getThread cannot be null, possibly null value provided (see https://psalm.dev/078)
$data = $this->aiIntergrationsService->generateEventData(
$account,
$message->getThreadRootId(),
$threadRootId,
$thread,
$this->currentUserId,
);
Expand All @@ -214,10 +220,14 @@
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}

$threadRootId = $message->getThreadRootId();
if ($threadRootId === null) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
$this->mailManager->deleteThread(
$account,
$mailbox,
$message->getThreadRootId()
$threadRootId
);

return new JSONResponse();
Expand Down
Loading
Loading