From 3f168fd6c4767b4a62a3303fe211045971e43d92 Mon Sep 17 00:00:00 2001 From: Dominic Ricottone Date: Wed, 19 Aug 2020 19:15:06 -0400 Subject: [PATCH] Added structure for renderers; Tweak on message boundary --- Makefile | 7 +++++++ decoder/encodings.go | 6 +++--- go.sum | 2 -- main.go | 2 +- message/part.go | 10 +++++++++- renderer/formats.go | 22 ++++++++++++++++++++++ 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 renderer/formats.go diff --git a/Makefile b/Makefile index 9295f4d..325e7a9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,13 @@ +SHARE_DIR?=/usr/local/share +INSTALL_DIR?=$(SHARE_DIR)/mail-filters + clean: rm -rf digestion build: go build +install: build + mkdir -m755 -p $(INSTALL_DIR) + install -m755 digestion $(INSTALL_DIR)/digestion + diff --git a/decoder/encodings.go b/decoder/encodings.go index 20bb069..49bce5a 100644 --- a/decoder/encodings.go +++ b/decoder/encodings.go @@ -12,12 +12,12 @@ const ( ) func DetermineEncoding(encoding string) string { - if strings.Contains(encoding, "base64") { + if strings.Contains(encoding, "utf-8") { + return EncodedUTF8 + } else if strings.Contains(encoding, "base64") { return EncodedBase64 } else if strings.Contains(encoding, "quoted-printable") { return EncodedQuotedPrintable - } else if strings.Contains(encoding, "utf-8") { - return EncodedUTF8 } else { return EncodedUnknown } diff --git a/go.sum b/go.sum index 86f7b19..38d741c 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,2 @@ -git.dominic-ricottone.com/textwrap v0.0.1 h1:vOkmBCgYfMcm4zgkI2InIUfxx74Nvma10UFr2I8gKrQ= -git.dominic-ricottone.com/textwrap v0.0.1/go.mod h1:oMsi+AbzUET9rjr9bDbtRUhD+bUPNjWMCIEhsLK80ZA= git.dominic-ricottone.com/textwrap v0.0.2 h1:BoCxezIxM2i/Mvs8gREB4XSLmQh+5DHmiEW/jiwdUbA= git.dominic-ricottone.com/textwrap v0.0.2/go.mod h1:oMsi+AbzUET9rjr9bDbtRUhD+bUPNjWMCIEhsLK80ZA= diff --git a/main.go b/main.go index dc082dd..dd85b6b 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func parse_stream(reader io.Reader, length int) { input := bufio.NewScanner(reader) // Compile regular expressions - re_message_break, err := regexp.Compile("^-+$") + re_message_break, err := regexp.Compile("^-{5,}$") if err != nil { fmt.Printf("internal error - %v\n", err) os.Exit(1) diff --git a/message/part.go b/message/part.go index 7039d9c..86f3947 100644 --- a/message/part.go +++ b/message/part.go @@ -2,6 +2,7 @@ package message import ( "git.dominic-ricottone.com/digestion/decoder" + "git.dominic-ricottone.com/digestion/renderer" ) type MessagePart struct { @@ -14,7 +15,14 @@ func NewPart() *MessagePart { } func (m *MessagePart) evaluate_type() int { - return 0 + switch renderer.DetermineFormatting(m.Header.ContentType) { + case renderer.FormattedTextPlain: + return 0 + case renderer.FormattedTextHTML: + return 20 + default: + return 30 + } } func (m *MessagePart) evaluate_encoding() int { diff --git a/renderer/formats.go b/renderer/formats.go new file mode 100644 index 0000000..61dca81 --- /dev/null +++ b/renderer/formats.go @@ -0,0 +1,22 @@ +package renderer + +import ( + "strings" +) + +const ( + FormattedTextPlain = "FormattedTextPlain" + FormattedTextHTML = "FormattedTextHTML" + FormattedUnknown = "FormattedUnknown" +) + +func DetermineFormatting(formatting string) string { + if strings.Contains(formatting, "text/plain") { + return FormattedTextPlain + } else if strings.Contains(formatting, "text/html") { + return FormattedTextHTML + } else { + return FormattedUnknown + } +} + -- 2.45.2