Skip to content

Commit

Permalink
mail: add CreateSingleInlineWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed May 14, 2019
1 parent 1e345aa commit ee22b72
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions mail/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"github.com/emersion/go-message"
)

func initInlineHeader(h *InlineHeader) {
h.Set("Content-Disposition", "inline")
func initInlineContentTransferEncoding(h *message.Header) {
if !h.Has("Content-Transfer-Encoding") {
t, _, _ := h.ContentType()
if strings.HasPrefix(t, "text/") {
Expand All @@ -19,6 +18,11 @@ func initInlineHeader(h *InlineHeader) {
}
}

func initInlineHeader(h *InlineHeader) {
h.Set("Content-Disposition", "inline")
initInlineContentTransferEncoding(&h.Header)
}

func initAttachmentHeader(h *AttachmentHeader) {
disp, _, _ := h.ContentDisposition()
if disp != "attachment" {
Expand Down Expand Up @@ -47,6 +51,15 @@ func CreateWriter(w io.Writer, header Header) (*Writer, error) {
return &Writer{mw}, nil
}

// CreateSingleInlineWriter writes a mail header to w. The mail will contain a
// single inline part. The body of the part should be written to the returned
// io.WriteCloser. Only one single inline part should be written, use
// CreateWriter if you want multiple parts.
func CreateSingleInlineWriter(w io.Writer, header Header) (io.WriteCloser, error) {
initInlineContentTransferEncoding(&header.Header)
return message.CreateWriter(w, header.Header)
}

// CreateInline creates a InlineWriter. One or more parts representing the same
// text in different formats can be written to a InlineWriter.
func (w *Writer) CreateInline() (*InlineWriter, error) {
Expand Down

0 comments on commit ee22b72

Please sign in to comment.