From 3d58d8362ed959d8cae35e0772ed8cd860fe693a Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Thu, 22 Feb 2018 22:10:50 -0600 Subject: [PATCH] Moved creation of URLs to net.URL instances to handle custom paths and parameters. Fixes #969 --- models/maillog.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/models/maillog.go b/models/maillog.go index b378f5cd..8ed9741e 100644 --- a/models/maillog.go +++ b/models/maillog.go @@ -9,6 +9,8 @@ import ( "io" "math" "net/mail" + "net/url" + "path" "strings" "text/template" "time" @@ -213,10 +215,20 @@ func (m *MailLog) Generate(msg *gomail.Message) error { fn = f.Address } msg.SetAddressHeader("From", f.Address, f.Name) - url, err := buildTemplate(c.URL, r) + campaignURL, err := buildTemplate(c.URL, r) if err != nil { return err } + + phishURL, _ := url.Parse(campaignURL) + q := phishURL.Query() + q.Set("rid", r.RId) + phishURL.RawQuery = q.Encode() + + trackingURL, _ := url.Parse(campaignURL) + trackingURL.Path = path.Join(trackingURL.Path, "/track") + trackingURL.RawQuery = q.Encode() + td := struct { Result URL string @@ -225,9 +237,9 @@ func (m *MailLog) Generate(msg *gomail.Message) error { From string }{ r, - url + "?rid=" + r.RId, - url + "/track?rid=" + r.RId, - "", + phishURL.String(), + trackingURL.String(), + "", fn, }