Changed the internal representation of a part
This commit is contained in:
parent
71e3f5a0b4
commit
4586cb75ac
15
message.go
15
message.go
|
@ -26,7 +26,7 @@ type Message struct {
|
|||
type header map[string][]string
|
||||
|
||||
type part struct {
|
||||
contentType string
|
||||
header header
|
||||
copier func(io.Writer) error
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ func (m *Message) DelHeader(field string) {
|
|||
func (m *Message) SetBody(contentType, body string) {
|
||||
m.parts = []part{
|
||||
{
|
||||
contentType: contentType,
|
||||
header: m.getPartHeader(contentType),
|
||||
copier: func(w io.Writer) error {
|
||||
_, err := io.WriteString(w, body)
|
||||
return err
|
||||
|
@ -223,7 +223,7 @@ func (m *Message) SetBody(contentType, body string) {
|
|||
func (m *Message) AddAlternative(contentType, body string) {
|
||||
m.parts = append(m.parts,
|
||||
part{
|
||||
contentType: contentType,
|
||||
header: m.getPartHeader(contentType),
|
||||
copier: func(w io.Writer) error {
|
||||
_, err := io.WriteString(w, body)
|
||||
return err
|
||||
|
@ -244,12 +244,19 @@ func (m *Message) AddAlternative(contentType, body string) {
|
|||
func (m *Message) AddAlternativeWriter(contentType string, f func(io.Writer) error) {
|
||||
m.parts = []part{
|
||||
{
|
||||
contentType: contentType,
|
||||
header: m.getPartHeader(contentType),
|
||||
copier: f,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Message) getPartHeader(contentType string) header {
|
||||
return map[string][]string{
|
||||
"Content-Type": {contentType + "; charset=" + m.charset},
|
||||
"Content-Transfer-Encoding": {string(m.encoding)},
|
||||
}
|
||||
}
|
||||
|
||||
// A File represents a file that can be attached or embedded in an email.
|
||||
type File struct {
|
||||
// Name represents the base name of the file. If the file is attached to the
|
||||
|
|
|
@ -38,11 +38,7 @@ func (w *messageWriter) writeMessage(m *Message) {
|
|||
w.openMultipart("alternative")
|
||||
}
|
||||
for _, part := range m.parts {
|
||||
contentType := part.contentType + "; charset=" + m.charset
|
||||
w.writeHeaders(map[string][]string{
|
||||
"Content-Type": {contentType},
|
||||
"Content-Transfer-Encoding": {string(m.encoding)},
|
||||
})
|
||||
w.writeHeaders(part.header)
|
||||
w.writeBody(part.copier, m.encoding)
|
||||
}
|
||||
if m.hasAlternativePart() {
|
||||
|
|
Loading…
Reference in New Issue