sections

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package sections models the individual multipart sections of an MHT file: their headers, decoded bodies, and re-encoding on output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuotedPrintableEncode

func QuotedPrintableEncode(input string) (string, error)

QuotedPrintableEncode encodes input in quoted-printable format.

func Scan

func Scan(scanner *bufio.Scanner, boundary string, section *Section) error

Scan reads one section (headers and body) from scanner into section. It assumes the opening boundary has already been consumed. Scan returns nil when it stops at an intermediate boundary and io.EOF when it stops at the closing boundary or the end of input; in both cases the section is valid.

Types

type Section

type Section struct {
	Headers textproto.MIMEHeader `json:"headers"`
	Body    string               `json:"content"`
}

Section is a single multipart section. Body holds the decoded content: text for quoted-printable sections, the undecoded base64 string (without line breaks) for base64 sections.

func New

func New() *Section

New returns an empty Section with initialized headers.

func (*Section) Image

func (section *Section) Image() (image.Image, string, error)

Image decodes the section body as an image, returning the image and the format name reported by image.Decode (e.g. "png").

func (*Section) ImageBytes

func (section *Section) ImageBytes() ([]byte, error)

ImageBytes returns the section body decoded from base64 into raw image bytes.

func (*Section) IsBase64

func (section *Section) IsBase64() bool

IsBase64 reports whether the section body is base64 encoded.

func (*Section) IsQuotedPrintable

func (section *Section) IsQuotedPrintable() bool

IsQuotedPrintable reports whether the section body is quoted-printable encoded. A missing Content-Transfer-Encoding counts as quoted-printable, since some ingestion paths strip the header.

func (*Section) ReplaceImage

func (section *Section) ReplaceImage(contentType, contentEncoding string, imageBytes []byte) error

ReplaceImage replaces the section's content with imageBytes, updating the Content-Type and Content-Transfer-Encoding headers. If contentEncoding is "base64" the bytes are encoded; otherwise they are stored verbatim.

func (*Section) Write

func (section *Section) Write(writer io.Writer) error

Write writes the section (headers, blank line, encoded body) to writer. The opening boundary is written by the caller. If the section has no Content-Transfer-Encoding header, one is added, defaulting to quoted-printable — some ingestion paths strip it.

Jump to

Keyboard shortcuts

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