From b70d057cb89772f71b04dcc71993925f297abae7 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 23 Nov 2021 01:23:45 +0100 Subject: [PATCH] Parse to and subject mail headers --- honeypot/smtp/server.go | 14 +++++++++++++- version.go | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/honeypot/smtp/server.go b/honeypot/smtp/server.go index 1c5f6cc..f65fd67 100644 --- a/honeypot/smtp/server.go +++ b/honeypot/smtp/server.go @@ -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 } diff --git a/version.go b/version.go index 2fb009e..0fac254 100644 --- a/version.go +++ b/version.go @@ -5,7 +5,7 @@ import ( "runtime" ) -var Version = "v0.1.25" +var Version = "v0.1.26" var Build string func FullVersion() string {