diff --git a/internal/user/smtp.go b/internal/user/smtp.go index 9edc8243..7679e8eb 100644 --- a/internal/user/smtp.go +++ b/internal/user/smtp.go @@ -80,7 +80,7 @@ func sendWithKey( //nolint:funlen 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, Body: armBody, MIMEType: message.MIMEType, @@ -196,6 +196,7 @@ func createDraft( from string, to []string, parentID string, + replyToID string, template liteapi.DraftTemplate, ) (liteapi.Message, error) { // 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{ Message: template, ParentID: parentID, + Action: action, }) } diff --git a/pkg/message/parser.go b/pkg/message/parser.go index 492e40e1..85d51703 100644 --- a/pkg/message/parser.go +++ b/pkg/message/parser.go @@ -48,6 +48,7 @@ type Message struct { PlainBody Body Attachments []Attachment MIMEType rfc822.MIMEType + IsReply bool Subject string Sender *mail.Address @@ -58,6 +59,7 @@ type Message struct { References []string ExternalID string + InReplyTo string } type Attachment struct { @@ -491,6 +493,9 @@ func parseMessageHeader(h message.Header) (Message, error) { //nolint:funlen case "message-id": m.ExternalID = regexp.MustCompile("<(.*)>").ReplaceAllString(fields.Value(), "$1") + case "in-reply-to": + m.InReplyTo = regexp.MustCompile("<(.*)>").ReplaceAllString(fields.Value(), "$1") + case "references": m.References = append(m.References, xslices.Map(strings.Fields(fields.Value()), func(ref string) string { return strings.Trim(ref, "<>")