mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-24 14:40:49 +01:00
Add new content types and refactor message writer
Introduced "multipart/mixed" and "multipart/related" content types in encoding.go and updated msgwriter.go to accommodate these. Adjustments made in related tests for these new types. Additionally, removed unnecessary print statements and improved multipart alternative parsing in eml.go.
This commit is contained in:
parent
59e85809f7
commit
3facbde703
4 changed files with 18 additions and 7 deletions
7
eml.go
7
eml.go
|
@ -178,9 +178,6 @@ func parseEMLHeaders(mh *nm.Header, m *Msg) error {
|
|||
for _, h := range commonHeaders {
|
||||
if v := mh.Get(h.String()); v != "" {
|
||||
m.SetGenHeader(h, v)
|
||||
if strings.EqualFold(h.String(), "subject") {
|
||||
fmt.Printf("SUBJECT: %s\n", m.GetGenHeader(HeaderSubject)[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,7 +201,8 @@ func parseEMLBodyParts(pm *nm.Message, bodybuf *bytes.Buffer, m *Msg) error {
|
|||
if err := parseEMLBodyPlain(mediatype, pm, bodybuf, m); err != nil {
|
||||
return fmt.Errorf("failed to parse plain body: %w", err)
|
||||
}
|
||||
case strings.EqualFold(mediatype, TypeMultipartAlternative.String()):
|
||||
case strings.EqualFold(mediatype, TypeMultipartAlternative.String()),
|
||||
strings.EqualFold(mediatype, "multipart/mixed"):
|
||||
if err := parseEMLMultipartAlternative(params, bodybuf, m); err != nil {
|
||||
return fmt.Errorf("failed to parse multipart/alternative body: %w", err)
|
||||
}
|
||||
|
@ -261,7 +259,6 @@ func parseEMLMultipartAlternative(params map[string]string, bodybuf *bytes.Buffe
|
|||
_ = mpart.Close()
|
||||
return fmt.Errorf("failed to read multipart: %w", err)
|
||||
}
|
||||
fmt.Printf("CTE: %+v", params)
|
||||
|
||||
mpContentType, ok := mpart.Header[HeaderContentType.String()]
|
||||
if !ok {
|
||||
|
|
|
@ -140,6 +140,8 @@ const (
|
|||
const (
|
||||
TypeAppOctetStream ContentType = "application/octet-stream"
|
||||
TypeMultipartAlternative ContentType = "multipart/alternative"
|
||||
TypeMultipartMixed ContentType = "multipart/mixed"
|
||||
TypeMultipartRelated ContentType = "multipart/related"
|
||||
TypePGPSignature ContentType = "application/pgp-signature"
|
||||
TypePGPEncrypted ContentType = "application/pgp-encrypted"
|
||||
TypeTextHTML ContentType = "text/html"
|
||||
|
|
|
@ -40,6 +40,18 @@ func TestContentType_String(t *testing.T) {
|
|||
"ContentType: application/octet-stream", TypeAppOctetStream,
|
||||
"application/octet-stream",
|
||||
},
|
||||
{
|
||||
"ContentType: multipart/alternative", TypeMultipartAlternative,
|
||||
"multipart/alternative",
|
||||
},
|
||||
{
|
||||
"ContentType: multipart/mixed", TypeMultipartMixed,
|
||||
"multipart/mixed",
|
||||
},
|
||||
{
|
||||
"ContentType: multipart/related", TypeMultipartRelated,
|
||||
"multipart/related",
|
||||
},
|
||||
{
|
||||
"ContentType: application/pgp-signature", TypePGPSignature,
|
||||
"application/pgp-signature",
|
||||
|
|
|
@ -89,11 +89,11 @@ func (mw *msgWriter) writeMsg(m *Msg) {
|
|||
}
|
||||
|
||||
if m.hasMixed() {
|
||||
mw.startMP("mixed", m.boundary)
|
||||
mw.startMP(MIMEMixed, m.boundary)
|
||||
mw.writeString(DoubleNewLine)
|
||||
}
|
||||
if m.hasRelated() {
|
||||
mw.startMP("related", m.boundary)
|
||||
mw.startMP(MIMERelated, m.boundary)
|
||||
mw.writeString(DoubleNewLine)
|
||||
}
|
||||
if m.hasAlt() {
|
||||
|
|
Loading…
Reference in a new issue