Example #1
0
func handleImages(con *data.Context, em *emailparse.Email) error {
	imgurclient := imgurclient.GetWithLongDeadline(con)

	var urls []string

	errorHappend := false
	for _, im := range em.Images {
		ii, status, err := imgurclient.UploadImage(im.Body, "", im.Encoding, em.Subject, "")
		if status > 399 || err != nil {
			con.Log.Errorf("Error while uploading image. Status: %v Error: %v", status, err)
			errorHappend = true
			continue
		}
		var iu data.ImageUpload
		iu.DeleteHash = ii.Deletehash
		iu.URL = ii.Link
		if err := iu.Store(con); err != nil {
			con.Log.Errorf("Error while storing upload in datastore Error: %v", err)
			// Not an important error ...
			// errorHappend = true
		}
		urls = append(urls, ii.Link)
	}
	if err := share.URLsNamespaces(urls, em.Namespaces, con); err != nil {
		return fmt.Errorf("Error while sharing URLs. Error: %v", err)
	}

	if errorHappend {
		return fmt.Errorf("There were some error. We'll retry.")
	}

	return nil
}
Example #2
0
func handleText(con *data.Context, em *emailparse.Email) error {
	urls, err := emailparse.URLsFromText(con, em)
	if err != nil {
		return fmt.Errorf("Error at parsing the body. Error: %v", err)
	}
	con.Log.Debugf("Found urls: %v", urls)

	if err = share.URLsNamespaces(urls, em.Namespaces, con); err != nil {
		return fmt.Errorf("Error while sharing URLs. Error: %v", err)
	}
	return nil
}