mime

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// QuotedPrintableContentEncoding represents the quoted-printable Encoding as defined in RFC 2045.
	QuotedPrintableContentEncoding = "quoted-printable"
	BinaryContentEncoding          = "binary"
	Base64ContentEncoding          = "base64"
	UuencodeContentEncoding        = "uuencode"
	XUuencodeContentEncoding       = "x-uuencode"
	XUueContentEncoding            = "x-uue"
	SevenDashBitContentEncoding    = "7-bit"
	SevenBitContentEncoding        = "7bit"
	EightDashBitContentEncoding    = "8-bit"
	EightBitContentEncoding        = "8bit"
	NoneContentEncoding            = ""

	BoundaryAttribute          = "boundary"
	MultipartContentType       = "multipart/"
	MultipartSignedContentType = MultipartContentType + "signed"
	MessageContentType         = "message/"
	MessageRfc822ContentType   = MessageContentType + "rfc822"
	TextContentType            = "text/"
	TextPlainContentType       = TextContentType + "plain"
	DefaultContentType         = TextPlainContentType + "; charset=us-ascii"

	InlineDisposition     = "inline"
	AttachmentDisposition = "attachment"
	NoneDisposition       = ""

	CRLF                  = "\r\n"
	LF                    = "\n"
	TAB                   = "\t"
	DefaultBoundaryLength = 60
	MinBoundaryLength     = 1
	MaxBoundaryLength     = 69
	Base64LineLength      = 76
	Utf8Charset           = "UTF-8"
	FilenameParameter     = "filename"
	NameParameter         = "name"
	CharsetParameter      = "charset"
	MainPartOrder         = 0
)
View Source
const (
	UueStart               = "begin"
	UueSpace               = " "
	UueEnd                 = "end"
	UueMaxLineLength       = 45
	UueMaxSymbolIdentifier = "M"
	UueBytesEncodeFactor   = 3
	UueBytesDecodeFactor   = 4
	UueOffset              = 32
	UueLastSymbol          = "`"
	UueDefaultName         = "data.txt"
	UueDefaultPerm         = "0644"
)

Variables

View Source
var DefaultLimitWriterDelimiter = []byte(CRLF)

Functions

func BoundaryValid

func BoundaryValid(boundary string) bool

func FakeTextFixedSize

func FakeTextFixedSize(n int) string

func FormatDate

func FormatDate(date time.Time) string

FormatDate форматирует дату в формате RFC 5322 (RFC1123Z).

func NewCharsetReader

func NewCharsetReader(charset string, input io.Reader) (io.Reader, error)

func NewDecoder

func NewDecoder(data io.Reader, contentEncoding string) (io.Reader, string, error)

func NewFakeMailWriterTo

func NewFakeMailWriterTo(bodySize int, attachSizes, embedSizes []int) (io.WriterTo, error)

func ParseContentDisposition

func ParseContentDisposition(in string) string

func PrepareValue

func PrepareValue(key, value string) string

func RandomBoundary

func RandomBoundary(n int) string

func UueDecode

func UueDecode(w io.Writer, data []byte) (int, string, string, error)

func UueEncode

func UueEncode(w io.Writer, filename, perm string, d []byte) (int, error)

Types

type Builder

type Builder struct {
	Header      Header     // Заголовки письма (From, To, Subject, ...)
	Parts       []PartInfo // Части тела (plain text, HTML и пр.)
	Attachments []FileInfo // Вложения (Content-Disposition: attachment)
	Embedded    []FileInfo // Встроенные файлы (Content-Disposition: inline)
	Charset     string     // Кодировка (по умолчанию UTF-8)
	Encoding    string     // Схема кодирования (Base64 / QuotedPrintable)
}

Builder используется для пошаговой сборки MIME-сообщения. Поддерживает заголовки, body, альтернативные версии, вложения и inline-ресурсы (картинки).

func NewMessageBuilder

func NewMessageBuilder() Builder

NewMessageBuilder создаёт новый объект Builder с настройками по умолчанию: - Charset: UTF-8 - Encoding: Base64

func (Builder) AddAlternative

func (m Builder) AddAlternative(contentType, body string) Builder

AddAlternative добавляет альтернативное тело письма (например, plain и HTML). Первой должна идти "text/plain", второй — "text/html".

func (Builder) AddAlternativeWriter

func (m Builder) AddAlternativeWriter(contentType string, content []byte) Builder

AddAlternativeWriter добавляет альтернативное тело письма из []byte.

func (Builder) Attach

func (m Builder) Attach(filename string) (_ Builder, err error)

Attach добавляет файл как вложение (attachment).

func (Builder) Embed

func (m Builder) Embed(filename string) (_ Builder, err error)

Embed добавляет файл как inline-ресурс (например, картинка для HTML).

func (Builder) SetBody

func (m Builder) SetBody(contentType, body string) Builder

SetBody задаёт тело письма (заменяет все предыдущие части).

func (Builder) SetCharset

func (m Builder) SetCharset(charset string) Builder

SetCharset задаёт кодировку для сообщения.

func (Builder) SetHeader

func (m Builder) SetHeader(field string, value ...string)

SetHeader устанавливает заголовок письма (например, Subject, From, To). Значения автоматически кодируются в соответствии с m.Encoding.

func (Builder) WriteTo

func (m Builder) WriteTo(w io.Writer) (int64, error)

WriteTo реализует io.WriterTo и записывает готовое MIME-сообщение.

type FileInfo

type FileInfo struct {
	Name    string // Имя файла
	Content []byte // Содержимое
}

FileInfo описывает файл (вложение или inline-ресурс).

type Header textproto.MIMEHeader

func (Header) Add

func (h Header) Add(key, value string)

func (Header) ContentDisposition

func (h Header) ContentDisposition() (string, map[string]string, error)

func (Header) ContentTransferEncoding

func (h Header) ContentTransferEncoding() (string, map[string]string, error)

func (Header) ContentType

func (h Header) ContentType() (string, map[string]string, error)

func (Header) Get

func (h Header) Get(key string) string

func (Header) GetMany

func (h Header) GetMany(key string) []string

func (Header) MIMEHeader

func (h Header) MIMEHeader() textproto.MIMEHeader

func (Header) Set

func (h Header) Set(key, value string)

func (Header) SetContentType

func (h Header) SetContentType(ct string)

func (Header) SetMany

func (h Header) SetMany(key string, values []string)

func (Header) WriteTo

func (h Header) WriteTo(w io.Writer) (int64, error)

type LimitWriter

type LimitWriter struct {
	W          io.Writer
	MaxLineLen int
	Delimiter  []byte
	// contains filtered or unexported fields
}

func (*LimitWriter) Write

func (w *LimitWriter) Write(p []byte) (int, error)

type Message

type Message struct {
	Parts   []*Part
	Counter int
}

func NewMessage

func NewMessage() *Message

func Parse

func Parse(message []byte) (*Message, error)

func (*Message) AddPart

func (m *Message) AddPart(p *Part)

func (*Message) Bcc

func (m *Message) Bcc() ([]*mail.Address, error)

func (*Message) Cc

func (m *Message) Cc() ([]*mail.Address, error)

func (*Message) Date

func (m *Message) Date() (time.Time, error)

func (*Message) FindChildPartWithContentType

func (m *Message) FindChildPartWithContentType(parent *Part, ct string) (*Part, error)

func (*Message) From

func (m *Message) From() (*mail.Address, error)

func (*Message) FromAsString

func (m *Message) FromAsString() string

func (*Message) GetMainPart

func (m *Message) GetMainPart() (*Part, error)

func (*Message) GetMainPartPos

func (m *Message) GetMainPartPos() (uint, error)

func (*Message) GetNextOrder

func (m *Message) GetNextOrder() int

func (*Message) GetPartWithOrder

func (m *Message) GetPartWithOrder(order int) (*Part, error)

func (*Message) IsValid

func (m *Message) IsValid() (bool, error)

func (*Message) Subject

func (m *Message) Subject() string

func (*Message) To

func (m *Message) To() ([]*mail.Address, error)

func (*Message) ToAsString

func (m *Message) ToAsString() string

func (*Message) WriteBodyTo

func (m *Message) WriteBodyTo(w io.Writer, order int, repair bool) (int64, error)

func (*Message) WriteHeadersTo

func (m *Message) WriteHeadersTo(w io.Writer, order int, repair bool) (int64, error)

func (*Message) WriteTo

func (m *Message) WriteTo(w io.Writer) (int64, error)

func (*Message) WriteToOrder

func (m *Message) WriteToOrder(w io.Writer, order int) (int64, error)

type Pair

type Pair struct {
	Key   string
	Value string
}

type Part

type Part struct {
	Header     Header
	Body       []byte
	Order      int
	Children   []int
	UuFilename string
}

func NewPart

func NewPart() *Part

func (*Part) Charset

func (p *Part) Charset() string

func (*Part) ContentDisposition

func (p *Part) ContentDisposition() string

func (*Part) ContentTransferEncoding

func (p *Part) ContentTransferEncoding() string

func (*Part) ContentType

func (p *Part) ContentType() string

func (*Part) Filename

func (p *Part) Filename() (filename string)

type PartInfo

type PartInfo struct {
	ContentType string // MIME Content-Type (например, "text/plain")
	Content     []byte // Данные части
	Encoding    string // Кодировка содержимого
}

PartInfo описывает часть тела сообщения.

Directories

Path Synopsis
internal