~sircmpwn/aerc

7b12f2d1ea791139022b63029bbd8616564355f3 — Reto Brunner 24 days ago daf214a
reply: add References header
1 files changed, 28 insertions(+), 1 deletions(-)

M commands/msg/reply.go
M commands/msg/reply.go => commands/msg/reply.go +28 -1
@@ 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
}