From d0e7bcf2f3af57e3fe80bcd540f8612ac667a136 Mon Sep 17 00:00:00 2001 From: Glenn Wilkinson Date: Thu, 26 Mar 2020 14:40:34 +0000 Subject: [PATCH] Fixed issue whereby attached campaign emails weren't being decoded --- imap/monitor.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/imap/monitor.go b/imap/monitor.go index 7fa74191..0c0f3346 100644 --- a/imap/monitor.go +++ b/imap/monitor.go @@ -7,6 +7,7 @@ package imap * - Add field to User for numner of non-campaign emails reported */ import ( + "bytes" "context" "regexp" "strconv" @@ -216,7 +217,15 @@ func checkRIDs(em *email.Email) (map[string]int, error) { //Next check each attachment for _, a := range em.Attachments { if a.Header.Get("Content-Type") == "message/rfc822" { - for _, r := range goPhishRegex.FindAllStringSubmatch(string(a.Content), -1) { + + //Let's decode the email + rawBodyStream := bytes.NewReader(a.Content) + attachementemail, err := email.NewEmailFromReader(rawBodyStream) + if err != nil { + return rids, err + } + + for _, r := range goPhishRegex.FindAllStringSubmatch(string(attachementemail.Text)+string(attachementemail.HTML), -1) { newrid := r[len(r)-1] if _, ok := rids[newrid]; ok { rids[newrid]++