func BounceHandler(res Response, req *http.Request) { decoder := json.NewDecoder(req.Body) var bounce postmark.Bounce err := decoder.Decode(&bounce) if err != nil { logger.Printf("failed decoding bounce: %s", err) return } if looper.AlreadyResent(bounce.MessageID, bounce.Email) { logger.Printf("skipping resend of message ID %s", bounce.MessageID) } else { err = app.Reactivate(bounce) if err != nil { logger.Printf("failed reactivating bounce: %s", err) return } uri := looper.MarkResent(bounce.MessageID, bounce.Email) if job, err := J.New(bounce.Email, uri, ""); err != nil { logger.Printf("bounced email failed to validate as a job: %s", err) } else { app.Queue(*job) logger.Printf("resending %#v to %#v after bounce", uri, bounce.Email) } } w := res.Plain() io.WriteString(w, "ok") }
func main() { check(url, email, rdbToken, pmToken, from, kindlegen) app := tinderizer.New(rdbToken, pmToken, from, kindlegen, logger) app.Run(1) job, err := J.New(email, url, "") if err != nil { log.Fatalf("failed building job: %s", err) } app.Queue(*job) app.Shutdown() }
func Submit(encoder *json.Encoder, email, url, content string) { job, err := J.New(email, url, content) if err != nil { HandleSubmitError(encoder, err) return } job.Progress("Working...") app.Queue(*job) encoder.Encode(JSON{ "message": "Submitted! Hang tight...", "id": job.Key.String(), }) }
func InboundHandler(res Response, req *http.Request) { decoder := json.NewDecoder(req.Body) var inbound InboundEmail err := decoder.Decode(&inbound) if err != nil { logger.Printf("failed decoding inbound email: %s", err) } else { email, url, err := ExtractParts(&inbound) if err != nil { logger.Printf("failed extracting needed parts from email: %s", err) } else { logger.Printf("email submission of %#v to %#v", url, email) if job, err := J.New(email, url, ""); err == nil { app.Queue(*job) } } } w := res.Plain() io.WriteString(w, "ok") }