-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudmailin.go
More file actions
68 lines (59 loc) · 2.11 KB
/
cloudmailin.go
File metadata and controls
68 lines (59 loc) · 2.11 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
package cloudmailin
import (
"encoding/json"
"io"
)
// A SPF (Sender Policy Framework) result for the given IP address and Domain.
type SPF struct {
Result string `json:"result"`
Domain string `json:"domain"`
}
// Envelope contains the data sent or gathered from the remote server.
type Envelope struct {
To string `json:"to"`
Recipients []string `json:"recipients"`
From string `json:"from"`
HeloDomain string `json:"helo_domain"`
RemoteIP string `json:"remote_ip"`
TLS bool `json:"tls"`
SPF SPF `json:"spf"`
}
// Headers contains all of the message headers extracted from the email.
type Headers struct {
Received []string `json:"received"`
Date string `json:"date"`
From string `json:"from"`
To string `json:"to"`
MessageID string `json:"message_id"`
Subject string `json:"subject"`
MimeVersion string `json:"mime_version"`
ContentType string `json:"content_type"`
ContentTransferEncoding string `json:"content_transfer_encoding"`
XOriginatingIP string `json:"x_originating_ip"`
XDomainSigner string `json:"x_domain_signer"`
DkimSignature string `json:"dkim_signature"`
}
// Attachments to the message
type Attachments struct {
Content string `json:"content"`
FileName string `json:"file_name"`
ContentType string `json:"content_type"`
Size string `json:"size"`
Disposition string `json:"disposition"`
ContentID interface{} `json:"content_id"`
}
// A Data struct contains all the fields of a decoded message
type Data struct {
Headers Headers `json:"headers"`
Envelope Envelope `json:"envelope"`
Plain *string `json:"plain"`
HTML *string `json:"html"`
ReplyPlain *string `json:"reply_plain"`
Attachments []Attachments `json:"attachments"`
}
// Decode a message into a Data struct
func Decode(r io.Reader) (Data, error) {
var ret Data
err := json.NewDecoder(r).Decode(&ret)
return ret, err
}