package smtp2shoutrrr import ( "slices" "strings" ) // BodyFormat names the representation a recipient's targets want the message // body in. Only an HTML body is ever rewritten: a message that already arrived // as plain text is forwarded untouched whatever the recipient asked for. type BodyFormat string const ( // FormatRaw forwards the body exactly as the message carried it. FormatRaw BodyFormat = "raw" // FormatMarkdown renders an HTML body as Markdown. There is deliberately // no plain-text format beside it: Markdown reads as plain text wherever // nothing renders it, so a second conversion would only be a worse copy // of this one. FormatMarkdown BodyFormat = "markdown" ) var bodyFormats = []BodyFormat{FormatRaw, FormatMarkdown} // normalize maps an unset Format to the one that changes nothing, and accepts // the casing a hand-written configuration file is likely to use. func (f BodyFormat) normalize() BodyFormat { normalized := BodyFormat(strings.ToLower(strings.TrimSpace(string(f)))) if normalized == "" { return FormatRaw } return normalized } // valid normalizes first, so a Config assembled in Go rather than loaded from // a file does not fail validation on a Format nobody set. func (f BodyFormat) valid() bool { return slices.Contains(bodyFormats, f.normalize()) } func formatNames() string { names := make([]string, 0, len(bodyFormats)) for _, format := range bodyFormats { names = append(names, string(format)) } return strings.Join(names, ", ") }