summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-16 12:15:34 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-16 12:15:34 -0400
commit475b697bdfd7a5821282174f14f8d904e47aff4d (patch)
tree7febf2e25cede5809f1d40c934d379315e06bd64 /lib
parent2b3e123cb86f9b4c5853e31d9e76c2b0d083f90a (diff)
downloadaerc-475b697bdfd7a5821282174f14f8d904e47aff4d.tar.gz
Implement (basic form) of :reply
Diffstat (limited to 'lib')
-rw-r--r--lib/msgid.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/msgid.go b/lib/msgid.go
new file mode 100644
index 0000000..8282d1d
--- /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)
+}
id=1076f2b6b3d3751d5d5db6fcb9ac8c247e04e893'>1076f2b
8a8b795 ^
439e15d ^

1076f2b


1076f2b


439e15d ^
1076f2b

366d81e ^






1076f2b
439e15d ^
16c67f3 ^
1076f2b
439e15d ^

8a8b795 ^
439e15d ^
1076f2b
39677ec ^
8a8b795 ^
39677ec ^

16c67f3 ^
39677ec ^
439e15d ^


366d81e ^

16c67f3 ^
366d81e ^
439e15d ^


16c67f3 ^
439e15d ^
366d81e ^

16c67f3 ^
366d81e ^
1076f2b
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76