Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-kent committed Apr 16, 2017
1 parent 98fee9b commit 024d554
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,31 @@ func (m *SMTPMessage) Bytes() io.Reader {
// FromBytes returns a SMTPMessage from raw message bytes (as output by SMTPMessage.Bytes())
func FromBytes(b []byte) *SMTPMessage {
msg := &SMTPMessage{}
var headerDone bool
for _, l := range strings.Split(string(b), "\n") {
if strings.HasPrefix(l, "HELO:<") {
l = strings.TrimPrefix(l, "HELO:<")
l = strings.TrimSuffix(l, ">\r")
msg.Helo = l
continue
}
if strings.HasPrefix(l, "FROM:<") {
l = strings.TrimPrefix(l, "FROM:<")
l = strings.TrimSuffix(l, ">\r")
msg.From = l
continue
}
if strings.HasPrefix(l, "TO:<") {
l = strings.TrimPrefix(l, "TO:<")
l = strings.TrimSuffix(l, ">\r")
msg.To = append(msg.To, l)
continue
if !headerDone {
if strings.HasPrefix(l, "HELO:<") {
l = strings.TrimPrefix(l, "HELO:<")
l = strings.TrimSuffix(l, ">\r")
msg.Helo = l
continue
}
if strings.HasPrefix(l, "FROM:<") {
l = strings.TrimPrefix(l, "FROM:<")
l = strings.TrimSuffix(l, ">\r")
msg.From = l
continue
}
if strings.HasPrefix(l, "TO:<") {
l = strings.TrimPrefix(l, "TO:<")
l = strings.TrimSuffix(l, ">\r")
msg.To = append(msg.To, l)
continue
}
if strings.TrimSpace(l) == "" {
headerDone = true
continue
}
}
msg.Data += l + "\n"
}
Expand Down

0 comments on commit 024d554

Please sign in to comment.