folder

package
v0.0.0-...-bb9e38b Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

folder formats header fields, folding lines when needed

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FWS

type FWS int

func (FWS) Fold

func (f FWS) Fold(limit int) string

func (FWS) Priority

func (f FWS) Priority() int

func (FWS) Value

func (f FWS) Value() string

type Foldable

type Foldable interface {
	Value() string         // value before optional transformations
	Fold(limit int) string // folded output
	Priority() int         // folding priority, priority 0 is ignored
}

type Folder

type Folder struct {
	Err error // io.Writer error
	// contains filtered or unexported fields
}

func New

func New(w io.Writer) *Folder

New returns folder that supports header folding. Max line length is set to 78 octets, excluding CRLF.

Folder only has 1 line lookahead and respects priority of folding locations over minimising number of folded lines

func (*Folder) Close

func (f *Folder) Close()

Close flushes rest of buffered content and closes header

func (*Folder) Write

func (f *Folder) Write(tokens ...interface{})

Write expects a list of header string values and folding white space integer values, where lower int values takes precedence over higher values.

The positioning of integer values signifies where folding may occur. If no int is specified, no folding will occur.

Tokens can be int, string or Foldable

type MIMEParam

type MIMEParam struct {
	Attribute    string
	Val          string
	FoldPriority int
}

MIMEParam implements RFC 2231 MIME parameter encoding and folding (continuation)

parameter              :=   regular-parameter / extended-parameter
regular-parameter      :=   regular-parameter-name "=" value
regular-parameter-name :=   attribute
attribute              :=   1*attribute-char
attribute-char         :=   <any (US-ASCII) CHAR except SPACE, CTLs,
                            "*", "'", "%", or tspecials>
value                  :=   token / quoted-string
token                  :=   1*<any (US-ASCII) CHAR except SPACE, CTLs, or tspecials>
extended-parameter     :=   (extended-initial-name "=" extended-initial-value) /
                            (extended-other-names  "=" extended-other-values)
extended-initial-name  :=   attribute [initial-section] "*"
extended-initial-value :=   [charset] "'" [language] "'"extended-other-values
extended-other-names   :=   attribute other-sections "*"
extended-other-values  :=   *(ext-octet / attribute-char)
initial-section        :=   "*0"
other-sections         :=   "*" ("1" / "2" / "3" / "4" / "5" /
                            "6" / "7" / "8" / "9") *DIGIT
ext-octet              :=   "%" 2(DIGIT / "A" / "B" / "C" / "D" / "E" / "F")
charset                :=   <registered character set name>
language               :=   <registered language tag [RFC-1766]>

func (MIMEParam) Fold

func (m MIMEParam) Fold(limit int) string

Fold performs both encoding and folding, though it probably should not according to Single Responsibility Principle. However since both encoded and folded form have the same extended parameter syntax, we deduplicate work by only accepting unencoded values and deciding whether to encode/fold at the same time

func (MIMEParam) Priority

func (m MIMEParam) Priority() int

func (MIMEParam) Value

func (m MIMEParam) Value() string

type WordEncodable

type WordEncodable struct {
	Decoded      string
	Enc          mime.WordEncoder
	MustEncode   bool
	FoldPriority int
}

NewWordEncodable represents a managed optionally encodable string that handles folding at a customizable position. This is useful for folding an otherwise long string where a foldable white space may not be present. Non us-ascii will trigger encoding.

func (WordEncodable) Fold

func (w WordEncodable) Fold(limit int) string

func (WordEncodable) Priority

func (w WordEncodable) Priority() int

func (WordEncodable) Value

func (w WordEncodable) Value() string

Jump to

Keyboard shortcuts

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