From 475b697bdfd7a5821282174f14f8d904e47aff4d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 16 May 2019 12:15:34 -0400 Subject: Implement (basic form) of :reply --- lib/msgid.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/msgid.go (limited to 'lib/msgid.go') diff --git a/lib/msgid.go b/lib/msgid.go new file mode 100644 index 00000000..8282d1d6 --- /dev/null +++ b/lib/msgid.go @@ -0,0 +1,34 @@ +package lib + +// TODO: Remove this pending merge into github.com/emersion/go-message + +import ( + "bytes" + "encoding/binary" + "fmt" + "math/rand" + "os" + "time" + + "github.com/martinlindhe/base36" +) + +// Generates an RFC 2822-complaint Message-Id based on the informational draft +// "Recommendations for generating Message IDs", for lack of a better +// authoritative source. +func GenerateMessageId() string { + var ( + now bytes.Buffer + nonce bytes.Buffer + ) + binary.Write(&now, binary.BigEndian, time.Now().UnixNano()) + binary.Write(&nonce, binary.BigEndian, rand.Uint64()) + hostname, err := os.Hostname() + if err != nil { + hostname = "localhost" + } + return fmt.Sprintf("<%s.%s@%s>", + base36.EncodeBytes(now.Bytes()), + base36.EncodeBytes(nonce.Bytes()), + hostname) +} -- cgit