Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by mail-b.sr.ht (Postfix) with ESMTPS id E9142FF0D7 for <~emersion/alps-dev@lists.sr.ht>; Tue, 4 Aug 2020 03:57:33 +0000 (UTC) Authentication-Results: mail-b.sr.ht; dkim=fail reason="key not found in DNS" (0-bit key) header.d=c3f.net header.i=@c3f.net header.b=FX8Awp9I X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c3f.net; s=key1; t=1596513452; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=NLKa8Pb1zyctam9Eegx4vTEH5zofdVXix8x88HboCMs=; b=FX8Awp9IIdt4ohmcyQVIc2Xx7TIwRxmXhmgZmv674FpH2wpUdhf0AoXziUT7B7eXA5b633 an709VE+o29Bze0pF6oMdJhBnuDBKjbU92uXdvFrwWGkDfTC+OrpkT5Z7IHsV0L937aMVt 3kTRqsorF2jMfH/gsg0458s8FIYjRbdkWRzmrdGXwtEukt+B4gH3NQsR/BfESJxh2CLtWN fICFXq3Cy4winYMRb0D0NIgxXJY+QrcjYYKmFOhkq6I8aFccirFi6QjCM+7Xckw0ffx4hT gzoYGb+xGvSqhbqWEh8OauRfpKTJ3tcV85hBF1MQhcLOE9USX2qNR949yvtT2A== From: Jesse Olson To: ~emersion/alps-dev@lists.sr.ht Cc: Jesse Olson Subject: [PATCH] Set Message-Id header Date: Tue, 4 Aug 2020 03:56:59 +0000 Message-Id: <20200804035659.5600-1-j3s@c3f.net> MIME-Version: 1.0 X-Spam-Score: 0.00 Content-Transfer-Encoding: quoted-printable --- 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 discussi= on. 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 s= ure where. So, here are my questions. todo: currently the domain isn't stripped from the from addr, but it shou= ld 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 stdli= b 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 ( "bufio" "bytes" + b64 "encoding/base64" + "encoding/binary" "fmt" "io" "io/ioutil" + "math/rand" "mime" "mime/multipart" "strings" @@ -120,6 +123,21 @@ func writeAttachment(mw *mail.Writer, att Attachment= ) error { return nil } =20 +// Message-ID format is base64 encoded epoch.rand@example.com +func generateMessageID(domain string) string { + epoch :=3D time.Now().Unix() + rand :=3D rand.Int63() + + messageID :=3D base64Encode(epoch) + "." + base64Encode(rand) + domain + return messageID +} + +func base64Encode(i int64) string { + buf :=3D make([]byte, 8) + binary.LittleEndian.PutUint64(buf, uint64(i)) + return b64.URLEncoding.EncodeToString(buf) +} + func (msg *OutgoingMessage) WriteTo(w io.Writer) error { from :=3D []*mail.Address{{"", msg.From}} =20 @@ -138,7 +156,8 @@ func (msg *OutgoingMessage) WriteTo(w io.Writer) erro= r { if msg.InReplyTo !=3D "" { h.Set("In-Reply-To", msg.InReplyTo) } - // TODO: set Message-ID + + h.Set("Message-ID", generateMessageID(msg.From)) =20 mw, err :=3D mail.CreateWriter(w, h) if err !=3D nil { --=20 2.28.0