~sircmpwn/aerc

ref: 0.1.1 aerc/lib/msgid.go -rw-r--r-- 767 bytes
eabdcff8Jonas Kalderstam Added config file to Make clean 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}