Other: Fix create draft action

If an InReplyTo entry in the header is present, the create draft action
should be reply, otherwise we use forward.
This commit is contained in:
James Houlahan
2022-10-28 16:46:56 +02:00
parent b72de5e3a4
commit a797c01943
2 changed files with 16 additions and 1 deletions

View File

@ -80,7 +80,7 @@ func sendWithKey( //nolint:funlen
return liteapi.Message{}, fmt.Errorf("failed to get armored message body: %w", err) return liteapi.Message{}, fmt.Errorf("failed to get armored message body: %w", err)
} }
draft, err := createDraft(ctx, client, emails, from, to, parentID, liteapi.DraftTemplate{ draft, err := createDraft(ctx, client, emails, from, to, parentID, message.InReplyTo, liteapi.DraftTemplate{
Subject: message.Subject, Subject: message.Subject,
Body: armBody, Body: armBody,
MIMEType: message.MIMEType, MIMEType: message.MIMEType,
@ -196,6 +196,7 @@ func createDraft(
from string, from string,
to []string, to []string,
parentID string, parentID string,
replyToID string,
template liteapi.DraftTemplate, template liteapi.DraftTemplate,
) (liteapi.Message, error) { ) (liteapi.Message, error) {
// Check sender: set the sender if it's missing. // Check sender: set the sender if it's missing.
@ -228,9 +229,18 @@ func createDraft(
} }
} }
var action liteapi.CreateDraftAction
if len(replyToID) > 0 {
action = liteapi.ReplyAction
} else {
action = liteapi.ForwardAction
}
return client.CreateDraft(ctx, liteapi.CreateDraftReq{ return client.CreateDraft(ctx, liteapi.CreateDraftReq{
Message: template, Message: template,
ParentID: parentID, ParentID: parentID,
Action: action,
}) })
} }

View File

@ -48,6 +48,7 @@ type Message struct {
PlainBody Body PlainBody Body
Attachments []Attachment Attachments []Attachment
MIMEType rfc822.MIMEType MIMEType rfc822.MIMEType
IsReply bool
Subject string Subject string
Sender *mail.Address Sender *mail.Address
@ -58,6 +59,7 @@ type Message struct {
References []string References []string
ExternalID string ExternalID string
InReplyTo string
} }
type Attachment struct { type Attachment struct {
@ -491,6 +493,9 @@ func parseMessageHeader(h message.Header) (Message, error) { //nolint:funlen
case "message-id": case "message-id":
m.ExternalID = regexp.MustCompile("<(.*)>").ReplaceAllString(fields.Value(), "$1") m.ExternalID = regexp.MustCompile("<(.*)>").ReplaceAllString(fields.Value(), "$1")
case "in-reply-to":
m.InReplyTo = regexp.MustCompile("<(.*)>").ReplaceAllString(fields.Value(), "$1")
case "references": case "references":
m.References = append(m.References, xslices.Map(strings.Fields(fields.Value()), func(ref string) string { m.References = append(m.References, xslices.Map(strings.Fields(fields.Value()), func(ref string) string {
return strings.Trim(ref, "<>") return strings.Trim(ref, "<>")