Parse to and subject mail headers
This commit is contained in:
parent
603d70334e
commit
b70d057cb8
@ -3,6 +3,7 @@ package smtp
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/mail"
|
||||
"time"
|
||||
|
||||
smtplib "github.com/emersion/go-smtp"
|
||||
@ -70,11 +71,22 @@ func (sess *session) Data(r io.Reader) error {
|
||||
|
||||
sess.mail.Data = buf.String()
|
||||
|
||||
var toAddr string
|
||||
var subject string
|
||||
// Parse mail headers
|
||||
msg, err := mail.ReadMessage(&buf)
|
||||
if err != nil {
|
||||
sess.honeypot.Logger.Infow("Unable to parse mail.", "error", err, "remote_addr", sess.remoteAddr)
|
||||
} else {
|
||||
toAddr = msg.Header.Get("To")
|
||||
subject = msg.Header.Get("Subject")
|
||||
}
|
||||
|
||||
if err := sess.honeypot.Store.AddMailData(&sess.mail); err != nil {
|
||||
sess.honeypot.Logger.Warnw("Error storing maildata.", "error", err, "remote_addr", sess.remoteAddr)
|
||||
return smtplib.ErrDataTooLarge
|
||||
}
|
||||
sess.honeypot.Logger.Infow("Mail received", "from", sess.mail.From, "remote_addr", sess.remoteAddr, "size", len(sess.mail.Data))
|
||||
sess.honeypot.Logger.Infow("Mail received", "from", sess.mail.From, "to", toAddr, "subject", subject, "remote_addr", sess.remoteAddr, "size", len(sess.mail.Data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var Version = "v0.1.25"
|
||||
var Version = "v0.1.26"
|
||||
var Build string
|
||||
|
||||
func FullVersion() string {
|
||||
|
Loading…
Reference in New Issue
Block a user