diff --git a/app.yaml b/app.yaml index 31f4af0..8fac874 100644 --- a/app.yaml +++ b/app.yaml @@ -23,6 +23,8 @@ handlers: script: _go_app - url: /api.* script: _go_app +- url: /_ah/mail.* + script: _go_app - url: / static_files: web/index.html upload: / @@ -30,3 +32,5 @@ handlers: static_dir: web skip_files: - ^(.*/)?.*/node_modules/.* +inbound_services: +- mail \ No newline at end of file diff --git a/handle.go b/handle.go index d5a9c75..57fa6bb 100644 --- a/handle.go +++ b/handle.go @@ -18,6 +18,7 @@ import ( "google.golang.org/appengine/taskqueue" "io/ioutil" "net/url" + mail "github.com/curious-eyes/jmail" ) const ( @@ -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/gamefield@board-gamers.appspotmail.com", GamefieldHandler) } func TrickplayHandler(w http.ResponseWriter, r *http.Request) { @@ -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 }