// NewEmailFromReader reads a stream of bytes from an io.Reader, r,
// and returns an email struct containing the parsed data.
// This function expects the data in RFC 5322 format.
169204
func NewEmailFromReader(r io.Reader) (*Email, error) {
	e := NewEmail()
	s := trimReader{rd: r}
	tp := textproto.NewReader(bufio.NewReader(s))
	// Parse the main headers
	hdrs, err := tp.ReadMIMEHeader()
	if err != nil {
		return e, err
	}
	// Set the subject, to, cc, bcc, and from
	for h, v := range hdrs {
		switch {
		case h == "Subject":
			e.Subject = v[0]
			delete(hdrs, h)
		case h == "To":
			e.To = v
			delete(hdrs, h)
		case h == "Cc":
			e.Cc = v
			delete(hdrs, h)
		case h == "Bcc":
			e.Bcc = v
			delete(hdrs, h)
		case h == "From":
			e.From = v[0]
			delete(hdrs, h)
		}
	}
	e.Headers = hdrs
	body := tp.R
	// Recursively parse the MIME parts
	ps, err := parseMIMEParts(e.Headers, body)
	if err != nil {
		return e, err
	}
	for _, p := range ps {
		if ct := p.header.Get("Content-Type"); ct == "" {
			return e, ErrMissingContentType
		}
		ct, _, err := mime.ParseMediaType(p.header.Get("Content-Type"))
		if err != nil {
			return e, err
		}
		switch {
		case ct == "text/plain":
			e.Text = p.body
		case ct == "text/html":
			e.HTML = p.body
		}
	}
	return e, nil
}
733955
func NewObjectFromStream(header textproto.MIMEHeader, body io.ReadCloser) (*Object, error) {
	objectID, err := strconv.ParseInt(header.Get("Object-ID"), 10, 64)
	if err != nil {
		objectID = -1
	}
	preferred, err := strconv.ParseBool(header.Get("Preferred"))
	if err != nil {
		preferred = false
	}
	objectData := make(map[string]string)
	for _, v := range header[textproto.CanonicalMIMEHeaderKey("ObjectData")] {
		kv := strings.Split(v, "=")
		objectData[kv[0]] = kv[1]
	}
	blob, err := ioutil.ReadAll(body)
	if err != nil {
		return nil, err
	}

	// 5.6.7
	retsError, _ := strconv.ParseBool(header.Get("RETS-Error"))
	retsMsg, err := ReadResponse(ioutil.NopCloser(bytes.NewReader(blob)))

	// there is a rets message, stash it and wipe the content
	if err == nil {
		blob = nil
	}

	object := Object{
		// required
		ObjectID:    int(objectID),
		ContentID:   header.Get("Content-ID"),
		ContentType: header.Get("Content-Type"),
		// optional
		UID:            header.Get("UID"),
		Description:    header.Get("Content-Description"),
		SubDescription: header.Get("Content-Sub-Description"),
		Location:       header.Get("Location"),
		RetsError:      retsError,
		RetsMessage:    retsMsg,
		Preferred:      preferred,
		ObjectData:     objectData,
		Blob:           blob,
	}

	return &object, nil
}
1312084
func NewReaderOnError(r io.Reader, notify func(error)) io.Reader {
	return &readerOnError{r, notify}
}
312528
func (p *PushEventRepoOwner) GetEmail() string {
	if p == nil || p.Email == nil {
		return ""
	}
	return *p.Email
}
1109586
func NewRequestReaderWithInitialResponse(c *http.Client, r *http.Request, maxfail uint32, totalsize int64, initialResponse *http.Response) io.ReadCloser {
	return &requestReader{client: c, request: r, maxFailures: maxfail, totalSize: totalsize, currentResponse: initialResponse, waitDuration: 5 * time.Second}
}
567825
func (s *DomainsService) CreateEmailForward(accountID string, domainIdentifier string, forwardAttributes EmailForward) (*emailForwardResponse, error) {
	path := versioned(emailForwardPath(accountID, domainIdentifier, 0))
	forwardResponse := &emailForwardResponse{}

	resp, err := s.client.post(path, forwardAttributes, forwardResponse)
	if err != nil {
		return nil, err
	}

	forwardResponse.HttpResponse = resp
	return forwardResponse, nil
}
1323778
func NewReader(r io.Reader) *Reader {
	return &Reader{
		Delimiter: '\t',
		r:         bufio.NewReader(r),
	}
}
42827
func NewReader(r io.Reader) (*Reader, error) {
	if r == nil {
		return nil, errors.New("Reader must not be nil")
	}

	return &Reader{r: r}, nil
}
1195110
func (h HelloElems) ReadFrom(r io.Reader) (int64, error) {
	var helloElemType HelloElemType

	rm := func() (io.ReaderFrom, error) {
		if rm, ok := helloElemMap[helloElemType]; ok {
			rd, err := rm.MakeReader()
			h = append(h, rd.(HelloElem))
			return rd, err
		}

		format := "ofp: unknown hello element type: '%x'"
		return nil, fmt.Errorf(format, helloElemType)
	}

	return encoding.ScanFrom(r, &helloElemType,
		encoding.ReaderMakerFunc(rm))
}
90403
func NewReader(r io.Reader, contentType string) (io.Reader, error) {
	preview := make([]byte, 1024)
	n, err := io.ReadFull(r, preview)
	switch {
	case err == io.ErrUnexpectedEOF:
		preview = preview[:n]
		r = bytes.NewReader(preview)
	case err != nil:
		return nil, err
	default:
		r = io.MultiReader(bytes.NewReader(preview), r)
	}

	if e, _, _ := DetermineEncoding(preview, contentType); e != encoding.Nop {
		r = transform.NewReader(r, e.NewDecoder())
	}
	return r, nil
}
238687
func NewByteReader(buf []byte) (reader *ByteReader) {
	reader = new(ByteReader)
	reader.buf = buf
	return
}
853166
func NewFromReader(reader io.Reader) (GCSCli, error) {

	dec := json.NewDecoder(reader)
	var c GCSCli
	if err := dec.Decode(&c); err != nil {
		return GCSCli{}, err
	}

	if c.BucketName == "" {
		return GCSCli{}, ErrEmptyBucketName
	}

	if c.CredentialsSource == ServiceAccountFileCredentialsSource &&
		c.ServiceAccountFile == "" {
		return GCSCli{}, ErrEmptyServiceAccountFile
	}

	if len(c.EncryptionKey) != 32 && c.EncryptionKey != nil {
		return GCSCli{}, ErrWrongLengthEncryptionKey
	}

	return c, nil
}
858360
func NewReaderFuncLoader(rfl ReaderFuncLoader, r io.Reader) Loader {
	return &readerFuncLoader{
		rfl: rfl,
		r:   r,
	}
}
495955
func (g *GPG) EmailFromKey(ctx context.Context, id string) string {
	return g.findKey(ctx, id).Identity().Email
}
517896
func EmailError(f reflect.StructField, actual string) error {
	return fmt.Errorf("%s: unsupported email format %s", f.Name, actual)
}
337351
func NewEmailServerFromService(appEnv *cfenv.App) *EmailServer {
	serviceName := os.Getenv("SMTP_SERVICE_NAME")
	hostName := os.Getenv("SMTP_HOST")
	portName := os.Getenv("SMTP_PORT")
	userName := ""
	passName := ""
	supportEmail := os.Getenv("SUPPORT_EMAIL")
	service, err := appEnv.Services.WithName(serviceName)

	if err != nil {
		panic(fmt.Sprintf("email service name error: %s", err.Error()))
	}

	if service.Credentials[hostName] == nil {
		panic(fmt.Sprintf("credentials contains a nil value for (%s, %s or %s): %v", userName, passName, hostName, service.Credentials))
	}
	auth := smtp.PlainAuth("", userName, passName, service.Credentials[hostName].(string))
	port, err := strconv.Atoi(service.Credentials[portName].(string))
	if err != nil {
		panic(fmt.Sprintf("The port for email server is not a valid integer %s", err.Error()))
	}
	return &EmailServer{
		host:         service.Credentials[hostName].(string),
		port:         port,
		auth:         auth,
		sendMailFunc: DefaultSMTPSendEmail,
		supportEmail: service.Credentials[supportEmail].(string),
	}
}
269816
func NewReader(r io.Reader) *Reader {
	return &Reader{
		r:   r,
		ctx: context.Background(),
	}
}