Skip to content

Commit

Permalink
メールを受け取れた #8
Browse files Browse the repository at this point in the history
  • Loading branch information
grapswiz committed May 29, 2016
1 parent fa1837f commit 5e0b8ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ handlers:
script: _go_app
- url: /api.*
script: _go_app
- url: /_ah/mail.*
script: _go_app
- url: /
static_files: web/index.html
upload: /
- url: /
static_dir: web
skip_files:
- ^(.*/)?.*/node_modules/.*
inbound_services:
- mail
23 changes: 23 additions & 0 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"google.golang.org/appengine/taskqueue"
"io/ioutil"
"net/url"
mail "github.com/curious-eyes/jmail"
)

const (
Expand Down Expand Up @@ -141,6 +142,8 @@ func init() {
http.HandleFunc("/twitter/login", TwitterLoginHandler)
http.HandleFunc("/twitter/callback", TwitterCallbackHandler)
http.HandleFunc("/twitter/logout", TwitterLogoutHandler)

http.HandleFunc("/_ah/mail/[email protected]", GamefieldHandler)
}

func TrickplayHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -297,6 +300,26 @@ var fetchBanestoGames = delay.Func("fetchBanestoGames", func(ctx context.Context
//TODO ゲームがあればsaveArrivalOfGamesとpush
})

func GamefieldHandler(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
defer r.Body.Close()
m, err := mail.ReadMessage(r.Body)
if err != nil {
log.Errorf(ctx, "Error reading r.Body: %v", err)
return
}
header := m.Header
log.Infof(ctx, "Date: %s", header.Get("Date"))
log.Infof(ctx, "From: %s", header.Get("From"))
log.Infof(ctx, "To: %s", header.Get("To"))
log.Infof(ctx, "Subject: %s", m.DecSubject())
body, err := m.DecBody()
if err != nil {
log.Errorf(ctx, "Error reading body: %v", err)
}
log.Infof(ctx, "%s", body)
}

func extractGamefieldGames(text string) (games []string) {
return games
}
Expand Down

0 comments on commit 5e0b8ec

Please sign in to comment.