Set Message-Id header v1 SUPERSEDED

Jesse Olson: 1
 Set Message-Id header

 1 files changed, 20 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/alps-dev/patches/11847/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Set Message-Id header Export this patch


Hi! I have personal interest in getting this patch upstream because it is biting a few of my users.
This is a proof of concept Message-ID implementation, mostly for discussion.

The format is partially gleaned from https://talk.begriffs.com/pipermail/friends/2020-August/001144.html

This patch doesn't work exactly as provided, but is a rough draft of the idea - I'm sure you'd like to see
generateMessageID moved to a different place, for example, but I wasn't sure where. So, here are my questions.

todo: currently the domain isn't stripped from the from addr, but it should be trivial to do.

0. do you want have plans for this or am i stepping on toes here?
1. would you like the helper functions moved to a different place? If so, where?
2. would you prefer to encode in base70? I chose base64 because the stdlib makes it easy.
 plugins/base/smtp.go | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/plugins/base/smtp.go b/plugins/base/smtp.go
index 19c9e0b..8d0ba2b 100644
--- a/plugins/base/smtp.go
+++ b/plugins/base/smtp.go
@@ -3,9 +3,12 @@ package alpsbase
import (
	b64 "encoding/base64"
@@ -120,6 +123,21 @@ func writeAttachment(mw *mail.Writer, att Attachment) error {
	return nil

// Message-ID format is base64 encoded epoch.rand@example.com
func generateMessageID(domain string) string {
	epoch := time.Now().Unix()
	rand := rand.Int63()

	messageID := base64Encode(epoch) + "." + base64Encode(rand) + domain
	return messageID

func base64Encode(i int64) string {
	buf := make([]byte, 8)
	binary.LittleEndian.PutUint64(buf, uint64(i))
	return b64.URLEncoding.EncodeToString(buf)

func (msg *OutgoingMessage) WriteTo(w io.Writer) error {
	from := []*mail.Address{{"", msg.From}}

@@ -138,7 +156,8 @@ func (msg *OutgoingMessage) WriteTo(w io.Writer) error {
	if msg.InReplyTo != "" {
		h.Set("In-Reply-To", msg.InReplyTo)
	// TODO: set Message-ID

	h.Set("Message-ID", generateMessageID(msg.From))

	mw, err := mail.CreateWriter(w, h)
	if err != nil {