~dricottone/digestion

3f168fd6c4767b4a62a3303fe211045971e43d92 — Dominic Ricottone 4 years ago 8ca2e16
Added structure for renderers; Tweak on message boundary
6 files changed, 42 insertions(+), 7 deletions(-)

M Makefile
M decoder/encodings.go
M go.sum
M main.go
M message/part.go
A renderer/formats.go
M Makefile => Makefile +7 -0
@@ 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


M decoder/encodings.go => decoder/encodings.go +3 -3
@@ 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
	}

M go.sum => go.sum +0 -2
@@ 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=

M main.go => main.go +1 -1
@@ 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)

M message/part.go => message/part.go +9 -1
@@ 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 {

A renderer/formats.go => renderer/formats.go +22 -0
@@ 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
	}
}