diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-02-24 00:41:13 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-02-24 13:00:12 +0100 |
commit | 7811620eb809fb9c2eb0c015e7c1fc6d17dc05ac (patch) | |
tree | f9fa041c0f6040e2345cd237ef53c6f3bb32db53 /models/models.go | |
parent | 8f9a6335239052c676fbcf4d9ca0205ef15fdcf2 (diff) | |
download | aerc-7811620eb809fb9c2eb0c015e7c1fc6d17dc05ac.tar.gz |
threading: implement on-the-fly message threading
implement message threading on the message store level using the
jwz algorithm. Build threads on-the-fly when new message headers arrive.
Use the references header to create the threads and the in-reply-to
header as a fall-back option in case no references header is present.
Does not run when the worker provides its own threading (e.g. imap
server threads).
Include only those message headers that have been fetched and are
stored in the message store.
References: https://www.jwz.org/doc/threading.html
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Inwit <inwit@sindominio.net>
Tested-by: akspecs <akspecs@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'models/models.go')
-rw-r--r-- | models/models.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/models/models.go b/models/models.go index 45f3b9de..4087c9d3 100644 --- a/models/models.go +++ b/models/models.go @@ -1,6 +1,7 @@ package models import ( + "errors" "fmt" "io" "time" @@ -65,6 +66,50 @@ type MessageInfo struct { Error error } +func (mi *MessageInfo) MsgId() (msgid string, err error) { + if mi == nil { + return "", errors.New("msg is nil") + } + if mi.Envelope == nil { + return "", errors.New("envelope is nil") + } + return mi.Envelope.MessageId, nil +} + +func (mi *MessageInfo) InReplyTo() (msgid string, err error) { + if mi == nil { + return "", errors.New("msg is nil") + } + if mi.RFC822Headers == nil { + return "", errors.New("header is nil") + } + list, err := mi.RFC822Headers.MsgIDList("In-Reply-To") + if err != nil { + return "", err + } + if len(list) == 0 { + return "", errors.New("no results") + } + return list[0], err +} + +func (mi *MessageInfo) References() ([]string, error) { + if mi == nil { + return []string{}, errors.New("msg is nil") + } + if mi.RFC822Headers == nil { + return []string{}, errors.New("header is nil") + } + list, err := mi.RFC822Headers.MsgIDList("References") + if err != nil { + return []string{}, err + } + if len(list) == 0 { + return []string{}, errors.New("no results") + } + return list, err +} + // A MessageBodyPart can be displayed in the message viewer type MessageBodyPart struct { Reader io.Reader |