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
|
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,15 +78,22 @@ func (content *Content) IsMIME() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (content *Content) ParseMIMEBody() *MIMEBody {
|
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=\"([^\"]+)\"")
|
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])
|
log.Printf("Got boundary: %s", match[1])
|
||||||
|
|
||||||
p := strings.Split(content.Body, "--"+match[1])
|
p := strings.Split(content.Body, "--"+match[1])
|
||||||
parts := make([]*Content, 0)
|
|
||||||
for m := range p {
|
for _, s := range p {
|
||||||
if len(p[m]) > 0 {
|
if len(s) > 0 {
|
||||||
part := ContentFromString(strings.Trim(p[m], "\r\n"))
|
part := ContentFromString(strings.Trim(s, "\r\n"))
|
||||||
if part.IsMIME() {
|
if part.IsMIME() {
|
||||||
log.Printf("Parsing inner MIME body")
|
log.Printf("Parsing inner MIME body")
|
||||||
part.MIME = part.ParseMIMEBody()
|
part.MIME = part.ParseMIMEBody()
|
||||||
|
@ -95,6 +101,8 @@ func (content *Content) ParseMIMEBody() *MIMEBody {
|
||||||
parts = append(parts, part)
|
parts = append(parts, part)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &MIMEBody{
|
return &MIMEBody{
|
||||||
Parts: parts,
|
Parts: parts,
|
||||||
|
|
Loading…
Reference in a new issue