Documentation
¶
Index ¶
- type Attachment
- type DisplayMode
- type InlineImage
- type ParseOptions
- type ParsedEmail
- func (p *ParsedEmail) GetAttachmentByID(id string) *Attachment
- func (p *ParsedEmail) GetAvailableFormats() []string
- func (p *ParsedEmail) GetBestContent(mode DisplayMode) (string, string)
- func (p *ParsedEmail) GetInlineImageByID(id string) *InlineImage
- func (p *ParsedEmail) HasAttachments() bool
- func (p *ParsedEmail) HasInlineImages() bool
- type Parser
- type RenderEngine
- func (r *RenderEngine) FormatForCLI(parsed *ParsedEmail, mode DisplayMode, maxWidth int) string
- func (r *RenderEngine) ParseFromBytes(rawEmail []byte) (*ParsedEmail, error)
- func (r *RenderEngine) ParseFromEncrypted(encryptedBody, privateKeyBase64 string) (*ParsedEmail, error)
- func (r *RenderEngine) RenderForDisplay(parsed *ParsedEmail, mode DisplayMode) (string, string, error)
- type Sanitizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct {
ID string `json:"id"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
Size int64 `json:"size"`
Content []byte `json:"-"` // Not serialized in JSON for API responses
CID string `json:"cid,omitempty"` // Content-ID for inline attachments
}
Attachment represents an email attachment
type DisplayMode ¶
type DisplayMode string
DisplayMode represents different ways to display email content
const ( DisplayModeAuto DisplayMode = "auto" // Smart detection (prefer plain text, fallback to HTML) DisplayModePlain DisplayMode = "plain" // Plain text only DisplayModeHTML DisplayMode = "html" // Sanitized HTML DisplayModeRaw DisplayMode = "raw" // Raw content without parsing DisplayModeMarkdown DisplayMode = "markdown" // Convert HTML to markdown )
func GetDisplayModeFromString ¶
func GetDisplayModeFromString(mode string) DisplayMode
GetDisplayModeFromString converts string to DisplayMode
type InlineImage ¶
type InlineImage struct {
ID string `json:"id"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
Size int64 `json:"size"`
Content []byte `json:"-"` // Not serialized in JSON
CID string `json:"cid"` // Content-ID for referencing in HTML
}
InlineImage represents an inline image in HTML email
type ParseOptions ¶
type ParseOptions struct {
ExtractAttachments bool `json:"extract_attachments"`
ExtractInlineImages bool `json:"extract_inline_images"`
MaxAttachmentSize int64 `json:"max_attachment_size"` // In bytes, 0 = no limit
SanitizeHTML bool `json:"sanitize_html"`
}
ParseOptions represents options for email parsing
func DefaultParseOptions ¶
func DefaultParseOptions() ParseOptions
DefaultParseOptions returns sensible defaults for email parsing
type ParsedEmail ¶
type ParsedEmail struct {
// Basic metadata
Headers map[string]string `json:"headers"`
ContentType string `json:"content_type"`
IsMultipart bool `json:"is_multipart"`
// Content variants
PlainText string `json:"plain_text,omitempty"`
HTML string `json:"html,omitempty"`
// Attachments and inline content
Attachments []Attachment `json:"attachments,omitempty"`
InlineImages []InlineImage `json:"inline_images,omitempty"`
// Parsed metadata
Subject string `json:"subject"`
From string `json:"from"`
To []string `json:"to,omitempty"`
CC []string `json:"cc,omitempty"`
BCC []string `json:"bcc,omitempty"`
Date time.Time `json:"date,omitempty"`
MessageID string `json:"message_id,omitempty"`
// Statistics
PlainTextSize int `json:"plain_text_size"`
HTMLSize int `json:"html_size"`
TotalSize int `json:"total_size"`
}
ParsedEmail represents a fully parsed email with all content types extracted
func (*ParsedEmail) GetAttachmentByID ¶
func (p *ParsedEmail) GetAttachmentByID(id string) *Attachment
GetAttachmentByID returns an attachment by its ID
func (*ParsedEmail) GetAvailableFormats ¶
func (p *ParsedEmail) GetAvailableFormats() []string
GetAvailableFormats returns a list of available content formats
func (*ParsedEmail) GetBestContent ¶
func (p *ParsedEmail) GetBestContent(mode DisplayMode) (string, string)
GetBestContent returns the best content for the given display mode
func (*ParsedEmail) GetInlineImageByID ¶
func (p *ParsedEmail) GetInlineImageByID(id string) *InlineImage
GetInlineImageByID returns an inline image by its ID
func (*ParsedEmail) HasAttachments ¶
func (p *ParsedEmail) HasAttachments() bool
HasAttachments returns true if the email has attachments
func (*ParsedEmail) HasInlineImages ¶
func (p *ParsedEmail) HasInlineImages() bool
HasInlineImages returns true if the email has inline images
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles email parsing and content extraction
func NewDefaultParser ¶
func NewDefaultParser() *Parser
NewDefaultParser creates a new email parser with default options
func NewParser ¶
func NewParser(options ParseOptions) *Parser
NewParser creates a new email parser with the given options
func (*Parser) ParseEmail ¶
func (p *Parser) ParseEmail(rawEmail []byte) (*ParsedEmail, error)
ParseEmail parses raw email bytes into a structured ParsedEmail
type RenderEngine ¶
type RenderEngine struct {
// contains filtered or unexported fields
}
RenderEngine is the main interface for email rendering
func NewRenderEngine ¶
func NewRenderEngine() *RenderEngine
NewRenderEngine creates a new email rendering engine
func (*RenderEngine) FormatForCLI ¶
func (r *RenderEngine) FormatForCLI(parsed *ParsedEmail, mode DisplayMode, maxWidth int) string
FormatForCLI formats email content for CLI display
func (*RenderEngine) ParseFromBytes ¶
func (r *RenderEngine) ParseFromBytes(rawEmail []byte) (*ParsedEmail, error)
ParseFromBytes parses raw email bytes
func (*RenderEngine) ParseFromEncrypted ¶
func (r *RenderEngine) ParseFromEncrypted(encryptedBody, privateKeyBase64 string) (*ParsedEmail, error)
ParseFromEncrypted decrypts and parses an encrypted email
func (*RenderEngine) RenderForDisplay ¶
func (r *RenderEngine) RenderForDisplay(parsed *ParsedEmail, mode DisplayMode) (string, string, error)
RenderForDisplay renders email content for display in the specified mode
type Sanitizer ¶
type Sanitizer struct {
// contains filtered or unexported fields
}
Sanitizer handles HTML sanitization for safe email display
func NewSanitizer ¶
func NewSanitizer() *Sanitizer
NewSanitizer creates a new HTML sanitizer with email-safe policies
func NewStrictSanitizer ¶
func NewStrictSanitizer() *Sanitizer
NewStrictSanitizer creates a very strict sanitizer that only allows basic text formatting
func (*Sanitizer) SanitizeHTML ¶
SanitizeHTML sanitizes HTML content to make it safe for display