// WriteTo generates and writes the text representation of mail messages.
WriteTo generates and writes the text representation of mail messages.
// WriteTo generates and writes the text representation of mail messages .
func (m *GoogleMessage) WriteTo(w io.Writer) (int64, error) {
	var numBytes int64
	if len(m.parts) == 0 {
		return 0, errors.New("contents are undefined")
	}
	var headers = make(textproto.MIMEHeader)
	if m.Header.Get("MIME-Version") == "" {
		headers.Set("MIME-Version", "1.0")
	}
	for k, v := range m.Header {
		for _, v2 := range v {
			headers.Add(k, v2)
		}
	}
	if len(m.parts) == 1 && m.Has(_body) {
		body := m.parts[_body]
		for k, v := range body.Header {
			for _, v2 := range v {
				headers.Add(k, v2)
			}
		}
		numBytes += int64(writeEmailHeaders(w, headers, m.WriteHeadersSorted))
		if bytesWritten, err := body.writeGoogleData(w); err != nil {
			return numBytes + int64(bytesWritten), err
		}
		return numBytes, nil
	}
	var mw = multipart.NewWriter(w)
	defer mw.Close()
	headers.Set("Content-Type", fmt.Sprintf("multipart/mixed; boundary=%s", mw.Boundary()))
	writeEmailHeaders(w, headers, m.WriteHeadersSorted)
	for _, p := range m.parts {
		pw, err := mw.CreatePart(p.Header)
		if err != nil {
			return numBytes, err
		}
		if bytesWritten, err := p.writeGoogleData(pw); err != nil {
			return numBytes + int64(bytesWritten), err
		}
	}
	return numBytes, nil
}
func ( m * GoogleMessage ) WriteTo ( w io . Writer ) ( int64 , error ) { var numBytes int64 if len ( m . parts ) == 0 { return 0 , errors . New ( " " ) } var headers = make ( textproto . MIMEHeader ) if m . Header . Get ( " " ) == " " { headers . Set ( " " , " " ) } for k , v := range m . Header { for _ , v2 := range v { headers . Add ( k , v2 ) } } if len ( m . parts ) == 1 && m . Has ( _body ) { body := m . parts [ _body ] for k , v := range body . Header { for _ , v2 := range v { headers . Add ( k , v2 ) } } numBytes += int64 ( writeEmailHeaders ( w , headers , m . WriteHeadersSorted ) ) if bytesWritten , err := body . writeGoogleData ( w ) ; err != nil { return numBytes + int64 ( bytesWritten ) , err } return numBytes , nil } var mw = multipart . NewWriter ( w ) defer mw . Close ( ) headers . Set ( " " , fmt . Sprintf ( " " , mw . Boundary ( ) ) ) writeEmailHeaders ( w , headers , m . WriteHeadersSorted ) for _ , p := range m . parts { pw , err := mw . CreatePart ( p . Header ) if err != nil { return numBytes , err } if bytesWritten , err := p . writeGoogleData ( pw ) ; err != nil { return numBytes + int64 ( bytesWritten ) , err } } return numBytes , nil }
WriteTo generates and writes the text representation of mail messages.
WriteTo generates and writes the text representation of mail messages .
// copy the primary header of the message // check that only defined the basic message, no attachments // there are attached files