webmail: fix loading a "view" (messages in a mailbox) when the "initial" message cannot be parsed

when we send a list of messages from the mox backend to the js frontend, we
include a parsed form of the "initial" message: the one we immediately show,
typically the top-most (unread) message. however, if that message could not be
parsed (due to invalid header syntax), we would fail the entire operation of
loading the view.

with this change, we simply don't return a parsed form of an initial message if
we cannot parse it. that will cause the webmail frontend to not select &
display a message immediately. if you then try to open the message, you'll
still get an error message as before. but at least the view has been loaded,
and you can open the raw message to inspect the contents.

for issue #219 by wneessen
This commit is contained in:
Mechiel Lukkien
2024-10-05 09:39:46 +02:00
parent 5d97bf198a
commit fb65ec0676
3 changed files with 26 additions and 8 deletions

View File

@ -1486,16 +1486,19 @@ func queryMessages(ctx context.Context, log mlog.Log, acc *store.Account, tx *bs
var pm *ParsedMessage
if m.ID == page.DestMessageID || page.DestMessageID == 0 && have == 0 && page.AnchorMessageID == 0 {
// For threads, if there was not DestMessageID, we may be getting the newest
// For threads, if there was no DestMessageID, we may be getting the newest
// message. For an initial view, this isn't necessarily the first the user is
// expected to read first, that would be the first unread, which we'll get below
// when gathering the thread.
found = true
xpm, err := parsedMessage(log, m, &state, true, false)
if err != nil {
if err != nil && errors.Is(err, message.ErrHeader) {
log.Debug("not returning parsed message due to invalid headers", slog.Int64("msgid", m.ID), slog.Any("err", err))
} else if err != nil {
return fmt.Errorf("parsing message %d: %v", m.ID, err)
} else {
pm = &xpm
}
pm = &xpm
}
mi, err := messageItem(log, m, &state)
@ -1613,10 +1616,13 @@ func gatherThread(log mlog.Log, tx *bstore.Tx, acc *store.Account, v view, m sto
if tm.ID == destMessageID || destMessageID == 0 && first && (pm == nil || !firstUnread && !tm.Seen) {
firstUnread = !tm.Seen
xpm, err := parsedMessage(log, tm, &xstate, true, false)
if err != nil {
if err != nil && errors.Is(err, message.ErrHeader) {
log.Debug("not returning parsed message due to invalid headers", slog.Int64("msgid", m.ID), slog.Any("err", err))
} else if err != nil {
return fmt.Errorf("parsing thread message %d: %v", tm.ID, err)
} else {
pm = &xpm
}
pm = &xpm
}
return nil
}()
@ -1631,10 +1637,13 @@ func gatherThread(log mlog.Log, tx *bstore.Tx, acc *store.Account, v view, m sto
xstate := msgState{acc: acc}
defer xstate.clear()
xpm, err := parsedMessage(log, m, &xstate, true, false)
if err != nil {
if err != nil && errors.Is(err, message.ErrHeader) {
log.Debug("not returning parsed message due to invalid headers", slog.Int64("msgid", m.ID), slog.Any("err", err))
} else if err != nil {
return nil, nil, fmt.Errorf("parsing thread message %d: %v", m.ID, err)
} else {
pm = &xpm
}
pm = &xpm
}
return mil, pm, nil