diff --git a/mailhog/data/message.go b/mailhog/data/message.go index a82bdf3..7c202a3 100644 --- a/mailhog/data/message.go +++ b/mailhog/data/message.go @@ -117,24 +117,35 @@ func PathFromString(path string) *Path { func ContentFromString(data string) *Content { log.Printf("Parsing Content from string: '%s'", data) x := strings.SplitN(data, "\r\n\r\n", 2) - headers, body := x[0], x[1] - h := make(map[string][]string, 0) - hdrs := strings.Split(headers, "\r\n") - for _, hdr := range hdrs { - if(strings.Contains(hdr, ": ")) { - y := strings.SplitN(hdr, ": ", 2) - key, value := y[0], y[1] - // TODO multiple header fields - h[key] = []string{value} - } else { - log.Printf("Found invalid header: '%s'", hdr) + + if len(x) == 2 { + headers, body := x[0], x[1] + hdrs := strings.Split(headers, "\r\n") + var lastHdr = "" + for _, hdr := range hdrs { + if lastHdr != "" && strings.HasPrefix(hdr, " ") { + h[lastHdr][len(h[lastHdr])-1] = h[lastHdr][len(h[lastHdr])-1] + hdr + } else if strings.Contains(hdr, ": ") { + y := strings.SplitN(hdr, ": ", 2) + key, value := y[0], y[1] + // TODO multiple header fields + h[key] = []string{value} + lastHdr = key + } else { + log.Printf("Found invalid header: '%s'", hdr) + } + } + return &Content{ + Size: len(data), + Headers: h, + Body: body, + } + } else { + return &Content{ + Size: len(data), + Headers: h, + Body: x[0], } } - - return &Content{ - Size: len(data), - Headers: h, - Body: body, - } } diff --git a/mailhog/templates/js/controllers.go b/mailhog/templates/js/controllers.go index 9b3853b..15115ac 100644 --- a/mailhog/templates/js/controllers.go +++ b/mailhog/templates/js/controllers.go @@ -33,10 +33,14 @@ mailhogApp.controller('MailCtrl', function ($scope, $http, $sce) { if(message.MIME) { for(var p in message.MIME.Parts) { - if(message.MIME.Parts[p].Headers["Content-Type"][0] == "text/plain") { - part = message.MIME.Parts[p]; - break; - } + if("Content-Type" in message.MIME.Parts[p].Headers) { + if(message.MIME.Parts[p].Headers["Content-Type"].length > 0) { + if(message.MIME.Parts[p].Headers["Content-Type"][0].match(/text\/plain;?.*/)) { + part = message.MIME.Parts[p]; + break; + } + } + } } } @@ -49,10 +53,14 @@ mailhogApp.controller('MailCtrl', function ($scope, $http, $sce) { if(message.MIME) { for(var p in message.MIME.Parts) { - if(message.MIME.Parts[p].Headers["Content-Type"][0] == "text/html") { - part = message.MIME.Parts[p]; - break; - } + if("Content-Type" in message.MIME.Parts[p].Headers) { + if(message.MIME.Parts[p].Headers["Content-Type"].length > 0) { + if(message.MIME.Parts[p].Headers["Content-Type"][0].match(/text\/html;?.*/)) { + part = message.MIME.Parts[p]; + break; + } + } + } } }