func (p *Part) setupHeaders(r *bufio.Reader, defaultContentType string) error {
	header, err := readHeader(r, p)
	if err != nil {
		return err
	}
	p.Header = header
	ctype := header.Get(hnContentType)
	if ctype == "" {
		if defaultContentType == "" {
			p.addWarning(ErrorMissingContentType, "MIME parts should have a Content-Type header")
			return nil
		}
		ctype = defaultContentType
	}
	// Parse Content-Type header.
	mtype, mparams, minvalidParams, err := parseMediaType(ctype)
	if err != nil {
		return err
	}
	if mtype == "" && len(mparams) > 0 {
		p.addWarning(
			ErrorMissingContentType,
			"Content-Type header has parameters but no content type")
	}
	for i := range minvalidParams {
		p.addWarning(
			ErrorMalformedHeader,
			"Content-Type header has malformed parameter %q",
			minvalidParams[i])
	}
	p.ContentType = mtype
	// Set disposition, filename, charset if available.
	p.setupContentHeaders(mparams)
	p.Boundary = mparams[hpBoundary]
	p.ContentID = coding.FromIDHeader(header.Get(hnContentID))
	return nil
}
func (p *Part) setupHeaders(r *bufio.Reader, defaultContentType string) error {
	header, err := readHeader(r, p)
	if err != nil {
		return err
	}
	p.Header = header
	ctype := header.Get(hnContentType)
	if ctype == "" {
		if defaultContentType == "" {
			p.addWarning(ErrorMissingContentType, "MIME parts should have a Content-Type header")
			return nil
		}
		ctype = defaultContentType
	}
	
	mtype, mparams, minvalidParams, err := parseMediaType(ctype)
	if err != nil {
		return err
	}
	if mtype == "" && len(mparams) > 0 {
		p.addWarning(
			ErrorMissingContentType,
			"Content-Type header has parameters but no content type")
	}
	for i := range minvalidParams {
		p.addWarning(
			ErrorMalformedHeader,
			"Content-Type header has malformed parameter %q",
			minvalidParams[i])
	}
	p.ContentType = mtype
	
	p.setupContentHeaders(mparams)
	p.Boundary = mparams[hpBoundary]
	p.ContentID = coding.FromIDHeader(header.Get(hnContentID))
	return nil
}
func ( p * Part ) setupHeaders ( r * bufio . Reader , defaultContentType string ) error { header , err := readHeader ( r , p ) if err != nil { return err } p . Header = header ctype := header . Get ( hnContentType ) if ctype == " " { if defaultContentType == " " { p . addWarning ( ErrorMissingContentType , " " ) return nil } ctype = defaultContentType } // Parse Content-Type header. mtype , mparams , minvalidParams , err := parseMediaType ( ctype ) if err != nil { return err } if mtype == " " && len ( mparams ) > 0 { p . addWarning ( ErrorMissingContentType , " " ) } for i := range minvalidParams { p . addWarning ( ErrorMalformedHeader , " " , minvalidParams [ i ] ) } p . ContentType = mtype // Set disposition, filename, charset if available. p . setupContentHeaders ( mparams ) p . Boundary = mparams [ hpBoundary ] p . ContentID = coding . FromIDHeader ( header . Get ( hnContentID ) ) return nil }
// setupHeaders reads the header, then populates the MIME header values for this Part.
setupHeaders reads the header then populates the MIME header values for this Part .