mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-23 22:34:04 +00:00
Hopefully fix #2
This commit is contained in:
parent
40a1071cb4
commit
5e34255a1d
1 changed files with 23 additions and 15 deletions
|
@ -1,11 +1,12 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
|
||||
type Messages []Message
|
||||
|
@ -44,8 +45,6 @@ type MIMEBody struct {
|
|||
Parts []*Content
|
||||
}
|
||||
|
||||
// TODO support nested MIME content
|
||||
|
||||
func ParseSMTPMessage(m *SMTPMessage, hostname string) *Message {
|
||||
arr := make([]*Path, 0)
|
||||
for _, path := range m.To {
|
||||
|
@ -79,15 +78,22 @@ func (content *Content) IsMIME() bool {
|
|||
}
|
||||
|
||||
func (content *Content) ParseMIMEBody() *MIMEBody {
|
||||
parts := make([]*Content, 0)
|
||||
|
||||
if hdr, ok := content.Headers["Content-Type"]; ok {
|
||||
if len(hdr) > 0 {
|
||||
re := regexp.MustCompile("boundary=\"([^\"]+)\"")
|
||||
match := re.FindStringSubmatch(content.Headers["Content-Type"][0])
|
||||
match := re.FindStringSubmatch(hdr[0])
|
||||
if len(match) < 2 {
|
||||
log.Printf("Boundary not found: %s")
|
||||
}
|
||||
log.Printf("Got boundary: %s", match[1])
|
||||
|
||||
p := strings.Split(content.Body, "--"+match[1])
|
||||
parts := make([]*Content, 0)
|
||||
for m := range p {
|
||||
if len(p[m]) > 0 {
|
||||
part := ContentFromString(strings.Trim(p[m], "\r\n"))
|
||||
|
||||
for _, s := range p {
|
||||
if len(s) > 0 {
|
||||
part := ContentFromString(strings.Trim(s, "\r\n"))
|
||||
if part.IsMIME() {
|
||||
log.Printf("Parsing inner MIME body")
|
||||
part.MIME = part.ParseMIMEBody()
|
||||
|
@ -95,6 +101,8 @@ func (content *Content) ParseMIMEBody() *MIMEBody {
|
|||
parts = append(parts, part)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &MIMEBody{
|
||||
Parts: parts,
|
||||
|
|
Loading…
Reference in a new issue