tools

package
v1.27.8 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package tools provides various methods for various things

Index

Constants

This section is empty.

Variables

View Source
var (

	// TagsTitleCase enforces TitleCase on all tags
	TagsTitleCase bool
)

Functions

func ArgsParser

func ArgsParser(s string) []string

ArgsParser will split a string by new words and quotes phrases

func CleanTag

func CleanTag(s string) string

CleanTag returns a clean tag, trimming whitespace and replacing invalid characters

func CreateSnippet added in v1.9.5

func CreateSnippet(text, html string) string

CreateSnippet returns a message snippet. It will use the HTML version (if it exists) otherwise the text version.

func GetHTMLAttributeVal

func GetHTMLAttributeVal(e *html.Node, key string) (string, error)

GetHTMLAttributeVal returns the value of an HTML Attribute, else an error. Returns a blank value if the attribute is set but empty.

func InArray added in v1.18.0

func InArray(k string, arr []string) bool

InArray tests if a string is within an array. It is not case sensitive.

func IsDir added in v1.22.3

func IsDir(path string) bool

IsDir returns whether a path is a directory

func IsFile added in v1.22.3

func IsFile(path string) bool

IsFile returns whether a file exists and is readable

func ListUnsubscribeParser added in v1.13.0

func ListUnsubscribeParser(v string) ([]string, error)

ListUnsubscribeParser will attempt to parse a `List-Unsubscribe` header and return a slide of addresses (mail & URLs)

func Normalize added in v1.18.7

func Normalize(s string) string

Normalize will remove any extra spaces, remove newlines, and trim leading and trailing spaces

func OverrideFromHeader added in v1.22.0

func OverrideFromHeader(msg []byte, address string) ([]byte, error)

OverrideFromHeader scans a message for the From header and replaces it with a different email address.

func Plural added in v1.18.0

func Plural(total int, singular, plural string) string

Plural returns a singular or plural of a word together with the total

func PrepareSocket added in v1.21.0

func PrepareSocket(address string) error

PrepareSocket returns an error if an active socket file already exists

func RemoveMessageHeaders

func RemoveMessageHeaders(msg []byte, headers []string) ([]byte, error)

RemoveMessageHeaders scans a message for headers, if found them removes them. It will only remove a single instance of any given message header.

func SafeUint64 added in v1.27.2

func SafeUint64(i any) uint64

SafeUint64 converts an int or int64 to uint64, ensuring it does not exceed the maximum value for uint64.

func SetHTMLAttributeVal added in v1.22.1

func SetHTMLAttributeVal(n *html.Node, key, val string)

SetHTMLAttributeVal sets an attribute on a node.

func SetMessageHeader added in v1.23.0

func SetMessageHeader(msg []byte, header, value string) ([]byte, error)

SetMessageHeader scans a message for a header and updates its value if found. It does not consider multiple instances of the same header. If not found it will add the header to the beginning of the message.

func SetTagCasing added in v1.18.0

func SetTagCasing(s []string) []string

SetTagCasing returns the slice of tags, title-casing if set

func UnixSocket added in v1.21.0

func UnixSocket(address string) (string, fs.FileMode, bool)

UnixSocket returns a path and a FileMode if the address is in the format of unix:<path>:<permission>

func WalkHTML added in v1.22.1

func WalkHTML(n *html.Node, fn func(*html.Node))

WalkHTML traverses the entire HTML tree and calls fn on each node.

Types

This section is empty.

Jump to

Keyboard shortcuts

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