~ci-train-bot/account-polld/account-polld-ubuntu-yakkety-landing-054

« back to all changes in this revision

Viewing changes to plugins/gmail/api.go

  • Committer: Sergio Schvezov
  • Date: 2014-08-23 20:00:22 UTC
  • mfrom: (27.11.1 qtcontact)
  • mto: This revision was merged to the branch mainline in revision 69.
  • Revision ID: sergio.schvezov@canonical.com-20140823200022-eh501y1cuuz98fbx
Merged qtcontact into loop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import (
21
21
        "fmt"
 
22
        "time"
22
23
 
23
24
        "launchpad.net/account-polld/plugins"
24
25
)
25
26
 
 
27
const gmailTime = "Mon, 2 Jan 2006 15:04:05 -0700"
 
28
 
26
29
type pushes map[string]plugins.PushMessage
 
30
type headers map[string]string
27
31
 
28
32
// messageList holds a response to call to Users.messages: list
29
33
// defined in https://developers.google.com/gmail/api/v1/reference/users/messages/list
71
75
        Headers []messageHeader `json:"headers"`
72
76
}
73
77
 
74
 
func (p *payload) mapHeaders() map[string]string {
 
78
func (p *payload) mapHeaders() headers {
75
79
        headers := make(map[string]string)
76
80
        for _, hdr := range p.Headers {
77
81
                headers[hdr.Name] = hdr.Value
79
83
        return headers
80
84
}
81
85
 
 
86
func (hdr headers) getTimestamp() time.Time {
 
87
        timestamp, ok := hdr[hdrDATE]
 
88
        if !ok {
 
89
                return time.Now()
 
90
        }
 
91
 
 
92
        if t, err := time.Parse(gmailTime, timestamp); err == nil {
 
93
                return t
 
94
        }
 
95
        return time.Now()
 
96
}
 
97
 
 
98
func (hdr headers) getEpoch() int64 {
 
99
        return hdr.getTimestamp().Unix()
 
100
}
 
101
 
82
102
// messageHeader represents the message headers.
83
103
type messageHeader struct {
84
104
        Name  string `json:"name"`