mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:44:35 +03:00
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:
@ -33,6 +33,7 @@ var Pedantic bool
|
||||
|
||||
var (
|
||||
ErrBadContentType = errors.New("bad content-type")
|
||||
ErrHeader = errors.New("bad message header")
|
||||
)
|
||||
|
||||
var (
|
||||
@ -394,6 +395,8 @@ func newPart(log mlog.Log, strict bool, r io.ReaderAt, offset int64, parent *Par
|
||||
}
|
||||
|
||||
// Header returns the parsed header of this part.
|
||||
//
|
||||
// Returns a ErrHeader for messages with invalid header syntax.
|
||||
func (p *Part) Header() (textproto.MIMEHeader, error) {
|
||||
if p.header != nil {
|
||||
return p.header, nil
|
||||
@ -431,6 +434,12 @@ func parseHeader(r io.Reader) (textproto.MIMEHeader, error) {
|
||||
}
|
||||
msg, err := mail.ReadMessage(bytes.NewReader(buf))
|
||||
if err != nil {
|
||||
// Recognize parsing errors from net/mail.ReadMessage.
|
||||
// todo: replace with own message parsing code that returns proper error types.
|
||||
errstr := err.Error()
|
||||
if strings.HasPrefix(errstr, "malformed initial line:") || strings.HasPrefix(errstr, "malformed header line:") {
|
||||
err = fmt.Errorf("%w: %v", ErrHeader, err)
|
||||
}
|
||||
return zero, err
|
||||
}
|
||||
return textproto.MIMEHeader(msg.Header), nil
|
||||
|
Reference in New Issue
Block a user