mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-27 16:24: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
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"labix.org/v2/mgo/bson"
|
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"labix.org/v2/mgo/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Messages []Message
|
type Messages []Message
|
||||||
|
@ -44,8 +45,6 @@ type MIMEBody struct {
|
||||||
Parts []*Content
|
Parts []*Content
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO support nested MIME content
|
|
||||||
|
|
||||||
func ParseSMTPMessage(m *SMTPMessage, hostname string) *Message {
|
func ParseSMTPMessage(m *SMTPMessage, hostname string) *Message {
|
||||||
arr := make([]*Path, 0)
|
arr := make([]*Path, 0)
|
||||||
for _, path := range m.To {
|
for _, path := range m.To {
|
||||||
|
@ -79,20 +78,29 @@ func (content *Content) IsMIME() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (content *Content) ParseMIMEBody() *MIMEBody {
|
func (content *Content) ParseMIMEBody() *MIMEBody {
|
||||||
re := regexp.MustCompile("boundary=\"([^\"]+)\"")
|
|
||||||
match := re.FindStringSubmatch(content.Headers["Content-Type"][0])
|
|
||||||
log.Printf("Got boundary: %s", match[1])
|
|
||||||
|
|
||||||
p := strings.Split(content.Body, "--"+match[1])
|
|
||||||
parts := make([]*Content, 0)
|
parts := make([]*Content, 0)
|
||||||
for m := range p {
|
|
||||||
if len(p[m]) > 0 {
|
if hdr, ok := content.Headers["Content-Type"]; ok {
|
||||||
part := ContentFromString(strings.Trim(p[m], "\r\n"))
|
if len(hdr) > 0 {
|
||||||
if part.IsMIME() {
|
re := regexp.MustCompile("boundary=\"([^\"]+)\"")
|
||||||
log.Printf("Parsing inner MIME body")
|
match := re.FindStringSubmatch(hdr[0])
|
||||||
part.MIME = part.ParseMIMEBody()
|
if len(match) < 2 {
|
||||||
|
log.Printf("Boundary not found: %s")
|
||||||
|
}
|
||||||
|
log.Printf("Got boundary: %s", match[1])
|
||||||
|
|
||||||
|
p := strings.Split(content.Body, "--"+match[1])
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
parts = append(parts, part)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
parts = append(parts, part)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue