Beispiel #1
0
func (j *Job) IsValid() (message string, ok bool) {
	// URL failed to parse
	if j.Url == nil {
		blacklist.Blacklist(j.Url.String())
		message = "Sorry, but this URL doesn't look like it'll work."
		return
	}

	// URL is already blacklisted
	if blacklist.IsBlacklisted(j.Url.String()) {
		message = "Sorry, but this URL has proven to not work, and has been blacklisted."
		return
	}

	// Email is blacklisted
	if blacklist.IsBlacklisted(j.Email) {
		message = "Sorry, but this email has proven to not work. You might want to try carefully remaking your bookmarklet."
		return
	}

	return "", true
}
Beispiel #2
0
func Mail(j *job.Job) {
	go safely.Do(logger, j, FriendlyMessage, func() {
		if stat, err := os.Stat(j.MobiFilePath()); err != nil {
			logger.Panicf("Something weird happen. Mobi is missing in postmark.go: %s", err.Error())
		} else {
			if stat.Size() > MaxAttachmentSize {
				blacklist.Blacklist(j.Url.String())
				failFriendly("Sorry, this article is too big to send!")
			}
		}

		payload := map[string]Any{
			"From":     from,
			"To":       j.Email,
			"Subject":  Subject,
			"TextBody": fmt.Sprintf("Straight to your Kindle! %s: %s", j.Title, j.Url),
			"Attachments": []Any{
				map[string]Any{
					"Name":        j.MobiFilename(),
					"ContentType": "application/octet-stream",
					"Content":     readFile(j.MobiFilePath()),
				},
			},
		}

		var buffer bytes.Buffer
		json.NewEncoder(&buffer).Encode(payload)

		req, err := http.NewRequest("POST", Endpoint, &buffer)
		if err != nil {
			logger.Panicf("Making HTTP Request failed: %s", err.Error())
		}

		setupHeaders(req)
		resp, err := client.Do(req)
		if err != nil {
			logger.Panicf("Postmark failed: %s", err.Error())
		}

		defer resp.Body.Close()
		answer := util.ParseJSON(resp.Body, func(err error) {
			logger.Panicf("Something bad happened with Postmark: %s", err.Error())
		})

		if answer["ErrorCode"] != nil {
			code := int(answer["ErrorCode"].(float64))
			switch code {
			case 0:
				// All is well
			case 300:
				blacklist.Blacklist(j.Email)
				failFriendly("Your email appears invalid. Please try carefully remaking the bookmarklet.")
			default:
				logger.Panicf("Unknown error code from Postmark: %d, %s", code, answer)
			}
		}

		j.Progress("All done! Grab your Kindle and hang tight!")
		cleanup.Clean(j)
	})
}
Beispiel #3
-1
func checkDoc(data JSON, j *job.Job) {
	if data["error"] != nil && data["error"].(bool) {
		blacklist.Blacklist(j.Url.String())
		logger.Panicf("Readability failed: %s", data["messages"].(string))
	}

	if notParsed.MatchString(data["title"].(string)) {
		blacklist.Blacklist(j.Url.String())
		logger.Panicf("Readability failed, article could not be parsed.")
	}
}