Skip to content

Commit

Permalink
Return & display error information when fetching email texts.
Browse files Browse the repository at this point in the history
This covers the case where we partially fetch a set of messages in a
thread for whatever reason.
  • Loading branch information
Fizzadar committed Jul 31, 2021
1 parent fec24c8 commit 2706916
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions kanmail/client/components/emails/ThreadMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -364,6 +365,15 @@ export default class ThreadMessage extends React.Component {
uid,
} = this.props.message;

if (body.error) {
return <div>
Error fetching message content: {body.error}.&nbsp;
<a onClick={() => threadStore.reloadThread()}>
Click here to reload the thread
</a>.
</div>;
}

let html = body.html || body.text;
if (this.state.showPlainText) {
html = body.text;
Expand Down
4 changes: 4 additions & 0 deletions kanmail/client/stores/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ class ThreadStore extends BaseStore {
});
}

reloadThread() {
this.loadThread(this.props.thread);
}

close(triggerUpdate=true) {
if (!this.isOpen) {
return;
Expand Down
15 changes: 14 additions & 1 deletion kanmail/server/mail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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


Expand Down

0 comments on commit 2706916

Please sign in to comment.