1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
7
// This file handles receiving mail.
20
http.HandleFunc("/_ah/mail/", handleMail)
23
var subjectRegexp = regexp.MustCompile(`.*code review (\d+):.*`)
25
func handleMail(w http.ResponseWriter, r *http.Request) {
26
c := appengine.NewContext(r)
29
msg, err := mail.ReadMessage(r.Body)
31
c.Errorf("mail.ReadMessage: %v", err)
35
subj := msg.Header.Get("Subject")
36
m := subjectRegexp.FindStringSubmatch(subj)
38
c.Debugf("Subject %q did not match /%v/", subj, subjectRegexp)
42
c.Infof("Found issue %q", m[1])
44
// Track the MessageID.
45
key := datastore.NewKey(c, "CL", m[1], 0, nil)
46
err = datastore.RunInTransaction(c, func(c appengine.Context) error {
48
err := datastore.Get(c, key, cl)
49
if err != nil && err != datastore.ErrNoSuchEntity {
52
if err == datastore.ErrNoSuchEntity {
53
// Must set sentinel values for time.Time fields
54
// if this is a new entity.
55
cl.Created = time.Unix(0, 0)
56
cl.Modified = time.Unix(0, 0)
58
cl.LastMessageID = msg.Header.Get("Message-ID")
59
_, err = datastore.Put(c, key, cl)
63
c.Errorf("datastore transaction failed: %v", err)
66
// Update the CL after a delay to give Rietveld a chance to catch up.
67
UpdateCLLater(c, m[1], 10*time.Second)