From 27069160d9e25706fcd574590e9952c497ba7681 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Sat, 31 Jul 2021 12:07:53 +0100 Subject: [PATCH] Return & display error information when fetching email texts. This covers the case where we partially fetch a set of messages in a thread for whatever reason. --- .../client/components/emails/ThreadMessage.jsx | 10 ++++++++++ kanmail/client/stores/thread.js | 4 ++++ kanmail/server/mail/__init__.py | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/kanmail/client/components/emails/ThreadMessage.jsx b/kanmail/client/components/emails/ThreadMessage.jsx index 7e5dd063..a151ce97 100644 --- a/kanmail/client/components/emails/ThreadMessage.jsx +++ b/kanmail/client/components/emails/ThreadMessage.jsx @@ -6,6 +6,7 @@ import { openLink } from 'window.js'; import Avatar from 'components/Avatar.jsx'; import ThreadMessageAttachment from 'components/emails/ThreadMessageAttachment.jsx'; +import threadStore from 'stores/thread.js'; import { ensureInView } from 'util/element.js'; import { cleanHtml } from 'util/html.js'; @@ -364,6 +365,15 @@ export default class ThreadMessage extends React.Component { uid, } = this.props.message; + if (body.error) { + return
+ Error fetching message content: {body.error}.  + threadStore.reloadThread()}> + Click here to reload the thread + . +
; + } + let html = body.html || body.text; if (this.state.showPlainText) { html = body.text; diff --git a/kanmail/client/stores/thread.js b/kanmail/client/stores/thread.js index 6885a41f..f9b69333 100644 --- a/kanmail/client/stores/thread.js +++ b/kanmail/client/stores/thread.js @@ -206,6 +206,10 @@ class ThreadStore extends BaseStore { }); } + reloadThread() { + this.loadThread(this.props.thread); + } + close(triggerUpdate=true) { if (!this.isOpen) { return; diff --git a/kanmail/server/mail/__init__.py b/kanmail/server/mail/__init__.py index 6914e659..3c078f8c 100644 --- a/kanmail/server/mail/__init__.py +++ b/kanmail/server/mail/__init__.py @@ -164,9 +164,14 @@ def get_folder_email_texts(account_key, folder_name, uids): uid_to_html_part_number = {} uid_to_headers = folder.get_email_headers(uids) + uid_to_error = {} for uid in uids: - headers = uid_to_headers[uid] + headers = uid_to_headers.get(uid) + + if not headers: + uid_to_error[uid] = 'Missing headers' + continue uid_to_allow_images[uid] = all( is_email_allowed_images(email) @@ -192,6 +197,8 @@ def get_folder_email_texts(account_key, folder_name, uids): if text: uid_parts.append((uid, text)) uid_to_text_part_number[uid] = text + else: + uid_to_error[uid] = 'No text or HTML content' uid_part_data = _get_folder_email_parts(account_key, folder_name, uid_parts) @@ -213,6 +220,12 @@ def get_folder_email_texts(account_key, folder_name, uids): 'text': text_data, 'html': html_data, } + + for uid, error in uid_to_error.items(): + uid_part_data_with_cids[uid] = { + 'error': error, + } + return uid_part_data_with_cids