Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
isch authored and Mario Hros committed Sep 2, 2023
1 parent abb3b23 commit 47ee9e8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions parsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ func parseContentType(contentTypeHeader string) (contentType string, params map[
}

func parseAttachmentOnlyEmail(body io.Reader, header mail.Header) (attachments []Attachment, err error) {
attachmentData, err := decodeContent(body, header.Get("Content-Transfer-Encoding"))
contentDisposition := header.Get("Content-Disposition")

if err != nil {
return attachments, err
}

if len(contentDisposition) > 0 && strings.Contains(contentDisposition, "attachment;") {

attachmentData, err := decodeContent(body, header.Get("Content-Transfer-Encoding"))
if err != nil {
return attachments, err
}

fileName := strings.Replace(contentDisposition, "attachment; filename=\"", "", -1)
fileName = strings.TrimRight(fileName, "\"")

Expand All @@ -123,6 +124,7 @@ func parseAttachmentOnlyEmail(body io.Reader, header mail.Header) (attachments [
ContentType: "application/octet-stream",
Data: attachmentData,
}

attachments = append(attachments, at)
}

Expand Down

0 comments on commit 47ee9e8

Please sign in to comment.