scrubber

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

Overview

The scrubber package defines an interface for content sanitization (e.g. ensuring the content provided is user generated content only) and creates sane defaults for sanitizing plain text and HTML content. The goal is to allow customizable content sanitization for newman's delivery.

Usage

To use the scrubber package, you can either use the provided default implementations or create your own custom implementations of the scrubber interface.

Example:

	import (
		"html"
		"strings"

		"github.com/theopenlane/newman/scrubber"
		"github.com/theopenlane/newman"
	)

	func main() {
		email := newman.NewEmailMessage("newman@usps.com", []string{"jerry@seinfeld.com"}, "Subject", "<p>HTML content</p>")

		customTextScrubber := scrubber.ScrubberFunc(func(content string) string {
			//Implement your custom scrubber logic
			return strings.ToLower(strings.TrimSpace(content))
		})

		customHtmlScrubber := scrubber.ScrubberFunc(func(content string) string {
			//Implement your custom scrubber logic
			return html.EscapeString(content)
		})

		email.SetCustomTextScrubber(customTextScrubber)
		email.SetCustomHTMLScrubber(customHtmlScrubber)
	}

Documentation

Overview

Package scrubber is designed to be used in conjunction with the newman project for flexible email content sanitization

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scrubber

type Scrubber interface {
	// Scrub scrubs the provided content
	Scrub(content string) string
}

Scrubber defines a method for sanitizing content

func DefaultHTMLScrubber

func DefaultHTMLScrubber() Scrubber

DefaultHTMLScrubber returns an instance of defaultHTMLScrubber

func DefaultTextScrubber

func DefaultTextScrubber() Scrubber

DefaultTextScrubber returns an instance of defaultTextScrubber

func NonScrubber

func NonScrubber() Scrubber

NonScrubber returns an instance of nonScrubber

type ScrubberFunc

type ScrubberFunc func(message string) string

ScrubberFunc is an adapter that allows the use of functions as Scrubbers

Example
package main

import (
	"fmt"
	"strings"

	"github.com/theopenlane/newman/scrubber"
)

func main() {
	scrubFunc := scrubber.ScrubberFunc(func(message string) string {
		return strings.ReplaceAll(strings.ToLower(strings.TrimSpace(message)), " ", "_")
	})
	scrubdMessage := scrubFunc.Scrub("  some text  ")
	fmt.Println(scrubdMessage)
}
Output:

func (ScrubberFunc) Scrub

func (f ScrubberFunc) Scrub(message string) string

Scrub calls the function f with the given message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL