aboutsummaryrefslogtreecommitdiffstats
path: root/lib/messageview.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-10-23 21:27:06 +0200
committerRobin Jarry <robin@jarry.cc>2022-11-09 21:14:24 +0100
commit0f78cb2ea97ca501b6eb0d659f883197753ee075 (patch)
tree54f3d2d3a2837b414c59b534d2992a1450dddbff /lib/messageview.go
parent9921b33679f6b0c9d2a609fe3112178ec40b8dd2 (diff)
downloadaerc-0f78cb2ea97ca501b6eb0d659f883197753ee075.tar.gz
lib: implement an eml message view
Implement a MessageView representation for eml data that are not stored in a message store. With this, we can display any rfc822 message data in the message viewer. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/messageview.go')
-rw-r--r--lib/messageview.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/messageview.go b/lib/messageview.go
index 247cecbe..8507880b 100644
--- a/lib/messageview.go
+++ b/lib/messageview.go
@@ -28,6 +28,9 @@ type MessageView interface {
// Returns the message store that this message was originally sourced from
Store() *MessageStore
+ // Fetches the full message
+ FetchFull(cb func(io.Reader))
+
// Fetches a specific body part for this message
FetchBodyPart(part []int, cb func(io.Reader))
@@ -76,8 +79,8 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool,
}
if usePGP(messageInfo.BodyStructure) {
- store.FetchFull([]uint32{messageInfo.Uid}, func(fm *types.FullMessage) {
- reader := lib.NewCRLFReader(fm.Content.Reader)
+ msv.FetchFull(func(fm io.Reader) {
+ reader := lib.NewCRLFReader(fm)
md, err := pgp.Decrypt(reader, decryptKeys)
if err != nil {
cb(nil, err)
@@ -130,8 +133,19 @@ func (msv *MessageStoreView) MessageDetails() *models.MessageDetails {
return msv.details
}
+func (msv *MessageStoreView) FetchFull(cb func(io.Reader)) {
+ if msv.message == nil && msv.messageStore != nil {
+ msv.messageStore.FetchFull([]uint32{msv.messageInfo.Uid},
+ func(fm *types.FullMessage) {
+ cb(fm.Content.Reader)
+ })
+ return
+ }
+ cb(bytes.NewReader(msv.message))
+}
+
func (msv *MessageStoreView) FetchBodyPart(part []int, cb func(io.Reader)) {
- if msv.message == nil {
+ if msv.message == nil && msv.messageStore != nil {
msv.messageStore.FetchBodyPart(msv.messageInfo.Uid, part, cb)
return
}