1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2026-01-29 06:25:56 +00:00

More MIME dev, new unit test libs

MIME parsing code is now in an acceptable state to integrate into
web UI.  It should be able to display text and/or HTML (sans
attachments).

Added "testify" unit testing library, providing assertions and mocks.
This commit is contained in:
James Hillyerd
2012-10-17 20:25:27 -07:00
parent bc7526abef
commit e76fad1523
4 changed files with 73 additions and 13 deletions

View File

@@ -64,6 +64,21 @@ func (n *MIMENode) String() string {
return fmt.Sprintf("[%v %v] %v", n.Type, children, siblings)
}
func IsMIMEMessage(mailMsg *mail.Message) bool {
// Parse top-level multipart
ctype := mailMsg.Header.Get("Content-Type")
mediatype, _, err := mime.ParseMediaType(ctype)
if err != nil {
return false
}
switch mediatype {
case "multipart/alternative":
return true
}
return false
}
func ParseMIMEMessage(mailMsg *mail.Message) (*MIMEMessage, error) {
mimeMsg := new(MIMEMessage)
@@ -86,9 +101,7 @@ func ParseMIMEMessage(mailMsg *mail.Message) (*MIMEMessage, error) {
// Root Node of our tree
root := NewMIMENode(nil, mediatype)
err = parseNodes(root, mailMsg.Body, boundary)
fmt.Println(root.String())
// Locate text body
match := root.BreadthFirstSearch(func(node *MIMENode) bool {
@@ -106,8 +119,6 @@ func ParseMIMEMessage(mailMsg *mail.Message) (*MIMEMessage, error) {
mimeMsg.Html = string(match.Content)
}
fmt.Println(mimeMsg.String())
return mimeMsg, err
}