blob: b85ceb37a898f19463d04027ffde04acda2657c0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package alpsbase
import (
"fmt"
"git.sr.ht/~migadu/alps"
"github.com/emersion/go-message"
)
// ErrViewUnsupported is returned by Viewer.ViewMessagePart when the message
// part isn't supported.
var ErrViewUnsupported = fmt.Errorf("cannot generate message view: unsupported part")
// Viewer is a message part viewer.
type Viewer interface {
// ViewMessagePart renders a message part. The returned value is displayed
// in a template. ErrViewUnsupported is returned if the message part isn't
// supported.
ViewMessagePart(*alps.Context, *IMAPMessage, *message.Entity) (interface{}, error)
}
var viewers []Viewer
// RegisterViewer registers a message part viewer.
func RegisterViewer(viewer Viewer) {
viewers = append(viewers, viewer)
}
func viewMessagePart(ctx *alps.Context, msg *IMAPMessage, part *message.Entity) (interface{}, error) {
for _, viewer := range viewers {
v, err := viewer.ViewMessagePart(ctx, msg, part)
if err == ErrViewUnsupported {
continue
}
return v, err
}
return nil, ErrViewUnsupported
}
|