about summary refs log tree commit diff stats
path: root/commands/msg
diff options
context:
space:
mode:
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/reply.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index fcd8341..778c0ef 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -154,7 +154,10 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
 	h.SetAddressList("from", []*mail.Address{from})
 	h.SetSubject(subject)
 	h.SetMsgIDList("in-reply-to", []string{msg.Envelope.MessageId})
-	//TODO: references header
+	err = setReferencesHeader(h, msg.RFC822Headers)
+	if err != nil {
+		aerc.PushError(fmt.Sprintf("could not set references: %v", err))
+	}
 	original := models.OriginalMail{
 		From:          format.FormatAddresses(msg.Envelope.From),
 		Date:          msg.Envelope.Date,
@@ -248,3 +251,27 @@ func (s addrSet) Contains(a *mail.Address) bool {
 	_, ok := s[a.Address]
 	return ok
 }
+
+//setReferencesHeader adds the references header to target based on parent
+//according to RFC2822
+func setReferencesHeader(target, parent *mail.Header) error {
+	refs, err := parent.MsgIDList("references")
+	if err != nil {
+		return err
+	}
+	if len(refs) == 0 {
+		// according to the RFC we need to fall back to in-reply-to only if
+		// References is not set
+		refs, err = parent.MsgIDList("in-reply-to")
+		if err != nil {
+			return err
+		}
+	}
+	msgID, err := parent.MessageID()
+	if err != nil {
+		return err
+	}
+	refs = append(refs, msgID)
+	target.SetMsgIDList("references", refs)
+	return nil
+}