From a63d6ef7f01e7946a128ca792fd568250d94b980 Mon Sep 17 00:00:00 2001 From: itsscb Date: Sun, 14 Aug 2022 12:00:44 +0200 Subject: [PATCH] Adding Filters for Filetypes to prevent Printing of invalid Files. --- mailmonitor.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mailmonitor.go b/mailmonitor.go index 568c98f..07ee9f4 100644 --- a/mailmonitor.go +++ b/mailmonitor.go @@ -343,7 +343,7 @@ func (m *Monitor) PrintAll() error { tfp = fp + ".html" } else if strings.Contains(ct, "text/plain") { tfp = fp + ".txt" - } else { + } else if strings.Contains(ct, "application/pdf") || strings.Contains(ct, "image") { filename := strings.Split( strings.Split(ct, ";")[1], "=")[1] @@ -351,7 +351,17 @@ func (m *Monitor) PrintAll() error { } case *mail.AttachmentHeader: - filename, _ := h.Filename() + var filename string + if strings.Contains(ct, "text/html") { + tfp = fp + ".html" + } else if strings.Contains(ct, "text/plain") { + tfp = fp + ".txt" + } else if strings.Contains(ct, "application/pdf") || strings.Contains(ct, "image") { + filename, _ = h.Filename() + tfp = fp + filename + } else { + continue + } tfp = fp + filename }