-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics.go
More file actions
106 lines (80 loc) · 1.53 KB
/
Copy pathmetrics.go
File metadata and controls
106 lines (80 loc) · 1.53 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package mail
import (
"context"
"net/mail"
"net/url"
"time"
)
type MessageID string
type Metrics struct {
Send
Subject string
Comment string
Keywords []string
Resent *Send
ReplyTo []*mail.Address
InReplyTo []MessageID
References []MessageID
// DKIM bool
// SPF bool
// DMARC bool
Attachments int
Embeds int
Hashes [][]byte
Links []*url.URL
}
func (m *Metrics) Date() time.Time {
return m.Send.Date
}
type Send struct {
ID MessageID
Date time.Time
Sender *mail.Address
From []*mail.Address
To []*mail.Address
Cc []*mail.Address
Bcc []*mail.Address
}
func compile(ctx context.Context, e *Email) (*Metrics, error) {
m := &Metrics{
Send: Send{
ID: MessageID(e.h.MessageID),
Date: e.h.Date,
To: e.h.To,
Sender: e.h.Sender,
From: e.h.From,
Cc: e.h.Cc,
Bcc: e.h.Bcc,
},
//DKIM: e.DKIM,
//SPF: e.SPF,
//DMARC: e.DMARC,
Attachments: len(e.AttachedFiles),
Embeds: len(e.InlineFiles),
}
for _, r := range e.h.InReplyTo {
m.InReplyTo = append(m.InReplyTo, MessageID(r))
}
if len(e.h.ResentFrom) > 0 || !e.h.ResentDate.IsZero() {
m.Resent = &Send{
ID: MessageID(e.h.ResentMessageID),
Date: e.h.ResentDate,
To: e.h.ResentTo,
Sender: e.h.ResentSender,
From: e.h.ResentFrom,
Cc: e.h.ResentCc,
Bcc: e.h.ResentBcc,
}
}
hashes, err := e.Hashes(ctx)
if err != nil {
return m, err
}
m.Hashes = hashes
links, err := e.Links()
if err != nil {
return m, err
}
m.Links = links
return m, nil
}