~emersion/alps-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Set Message-Id header

Details
Message ID
<20200804035659.5600-1-j3s@c3f.net>
DKIM signature
fail
Download raw message
Patch: +20 -1 DKIM signature: fail
---

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 (
	"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
}

// 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 {
-- 
2.28.0
Details
Message ID
<tCWTaI3uZWn2cTkaWQTIwjNXZhHBb9TrUiwTzgjOfw0CM2FnbRwQsn0T5niNeKdEYZJwIJRtdWdDFS1QcccDYxorObghpBj0aJHF4-0lFas=@emersion.fr>
In-Reply-To
<20200804035659.5600-1-j3s@c3f.net> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
> Hi! I have personal interest in getting this patch upstream because it is biting a few of my users.

Hi! Thanks for your patch!

> 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?

The reason I haven't done this yet is that I wanted to retain any previous
Message-Id, if the draft was composed from another client (to allow clients to
track draft changes). But I'm perfectly fine with overwriting it as a first
step.

> 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.

go-message already has a helper to generate Message-Id header fields:

https://godoc.org/github.com/emersion/go-message/mail#GenerateMessageID

Can we use it instead?
Reply to thread Export thread (mbox)