From 5e0b8ece65bfb1cf31d6330108da000daffc2b12 Mon Sep 17 00:00:00 2001 From: grapswiz Date: Mon, 30 May 2016 00:09:03 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=83=AB=E3=82=92=E5=8F=97?= =?UTF-8?q?=E3=81=91=E5=8F=96=E3=82=8C=E3=81=9F=20#8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.yaml | 4 ++++ handle.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) 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 }