Skip to content
Merged
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
4 changes: 3 additions & 1 deletion lib/Controller/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,13 @@ public function getHtmlBody(int $id, bool $plain = false): Response {
$message = $this->mailManager->getMessage($this->currentUserId, $id);
$mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId());
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
} catch (DoesNotExistException $e) {
} catch (DoesNotExistException) {
return new TemplateResponse(
$this->appName,
'error',
['message' => 'Not allowed'],
TemplateResponse::RENDER_AS_BLANK,
Http::STATUS_NOT_FOUND,
);
}

Expand Down Expand Up @@ -637,6 +638,7 @@ public function getHtmlBody(int $id, bool $plain = false): Response {
'error',
['message' => $ex->getMessage()],
TemplateResponse::RENDER_AS_BLANK,
Http::STATUS_INTERNAL_SERVER_ERROR
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/service/MessageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ export async function fetchMessage(id) {
}
}

export async function fetchMessageHtmlBody(id) {
const url = generateUrl('/apps/mail/api/messages/{id}/html?plain=true', {
id,
})

try {
return (await axios.get(url)).data
} catch (e) {
throw convertAxiosError(e)
}
}

export async function fetchMessageItineraries(id) {
const url = generateUrl('/apps/mail/api/messages/{id}/itineraries', {
id,
Expand Down
40 changes: 19 additions & 21 deletions src/store/mainStore/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import Axios from '@nextcloud/axios'
import { showError, showWarning } from '@nextcloud/dialogs'
import { showError, showWarning, TOAST_DEFAULT_TIMEOUT } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import DOMPurify from 'dompurify'
import escapeRegExp from 'lodash/fp/escapeRegExp.js'
import flatMapDeep from 'lodash/fp/flatMapDeep.js'
Expand Down Expand Up @@ -77,6 +75,7 @@ import {
fetchEnvelopes,
fetchMessage,
fetchMessageDkim,
fetchMessageHtmlBody,
fetchMessageItineraries,
fetchThread,
moveMessage,
Expand Down Expand Up @@ -473,16 +472,8 @@ export default function mainStoreActions() {

// Fetch and transform the body into a rich text object
if (original.hasHtmlBody) {
const resp = await Axios.get(generateUrl('/apps/mail/api/messages/{id}/html?plain=true', {
id: original.databaseId,
}))

resp.data = DOMPurify.sanitize(resp.data, {
FORBID_TAGS: ['style'],
})

data.isHtml = true
data.bodyHtml = resp.data
data.bodyHtml = await this.processHtmlBody(original.databaseId)
if (reply.suggestedReply) {
data.bodyHtml = `<p>${reply.suggestedReply}<\\p>` + data.bodyHtml
}
Expand Down Expand Up @@ -567,16 +558,8 @@ export default function mainStoreActions() {

// Fetch and transform the body into a rich text object
if (message.hasHtmlBody) {
const resp = await Axios.get(generateUrl('/apps/mail/api/messages/{id}/html?plain=true', {
id: templateMessageId,
}))

resp.data = DOMPurify.sanitize(resp.data, {
FORBID_TAGS: ['style'],
})

data.isHtml = true
data.bodyHtml = resp.data
data.bodyHtml = await this.processHtmlBody(templateMessageId)
} else {
data.isHtml = false
data.bodyPlain = message.body
Expand Down Expand Up @@ -2460,5 +2443,20 @@ export default function mainStoreActions() {
getQuickActions() {
return this.quickActions
},
async processHtmlBody(id) {
try {
const response = await handleHttpAuthErrors(async () => {
return await fetchMessageHtmlBody(id)
})
return DOMPurify.sanitize(response.data, {
FORBID_TAGS: ['style'],
})
} catch (error) {
if (error.response?.status === 404) {
showError(t('mail', 'Sorry, the message could not be loaded. The draft may no longer exist. Please refresh the page and try again.'), { timeout: TOAST_DEFAULT_TIMEOUT * 2 })
}
throw error
}
},
}
}
Loading