Documentation
¶
Index ¶
- func ExtractBouncedRecipient(email *Email) string
- func GetPrimaryConfirmationURL(urls ExtractedURLs, brokerDomain string) string
- func GetPrimaryFormURL(urls ExtractedURLs, brokerDomain string) string
- func MigrateNoDataResponses(store *history.Store) error
- func RecordReply(store *history.Store, e *Email, reclassify bool) (ClassifiedResponse, ReplyOutcome, error)
- func RecordReplyForProfile(store *history.Store, e *Email, profileID string, reclassify bool) (ClassifiedResponse, ReplyOutcome, error)
- type ClassifiedResponse
- type Email
- type ExtractedURLs
- type Monitor
- func (m *Monitor) ArchiveEmails(uids []uint32, folder string) error
- func (m *Monitor) Connect(ctx context.Context) error
- func (m *Monitor) Disconnect() error
- func (m *Monitor) EnsureFolderExists(name string) error
- func (m *Monitor) FetchBounceEmails(ctx context.Context, days int) ([]Email, error)
- func (m *Monitor) FetchBrokerEmails(ctx context.Context, days int) ([]Email, error)
- func (m *Monitor) FetchBrokerEmailsFromFolder(ctx context.Context, folder string, days int) ([]Email, error)
- func (m *Monitor) ScanAndStore(ctx context.Context, store *history.Store, opt ScanOptions) (ScanResult, error)
- func (m *Monitor) WatchForNewEmails(ctx context.Context, callback func(Email)) error
- type ReplyOutcome
- type ResponseType
- type ScanOptions
- type ScanResult
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractBouncedRecipient ¶
ExtractBouncedRecipient extracts the email address that bounced from an NDR email
func GetPrimaryConfirmationURL ¶
func GetPrimaryConfirmationURL(urls ExtractedURLs, brokerDomain string) string
GetPrimaryConfirmationURL returns the most likely confirmation URL
func GetPrimaryFormURL ¶
func GetPrimaryFormURL(urls ExtractedURLs, brokerDomain string) string
GetPrimaryFormURL returns the most likely opt-out form URL using scoring
func MigrateNoDataResponses ¶ added in v1.3.0
MigrateNoDataResponses uses only locally stored messages, never IMAP.
func RecordReply ¶ added in v0.9.0
func RecordReply(store *history.Store, e *Email, reclassify bool) (ClassifiedResponse, ReplyOutcome, error)
RecordReply classifies one broker reply and stores it (see ScanAndStore).
func RecordReplyForProfile ¶ added in v1.3.0
func RecordReplyForProfile(store *history.Store, e *Email, profileID string, reclassify bool) (ClassifiedResponse, ReplyOutcome, error)
RecordReplyForProfile stores a reply under an already resolved owner. Scoped callers must resolve/validate ownership first; this avoids resolving it again after a concurrent send by another profile.
Types ¶
type ClassifiedResponse ¶
type ClassifiedResponse struct {
Email *Email
Type ResponseType
URLs ExtractedURLs
FormURL string // Primary form URL (if form_required)
ConfirmURL string // Primary confirmation URL (if confirmation_required)
BouncedRecipient string // Email address that bounced (if bounced)
Confidence float64
Reason string // Human-readable reason for classification
NeedsReview bool // Whether manual review is recommended
}
ClassifiedResponse represents a classified email response
func ClassifyResponse ¶
func ClassifyResponse(email *Email) ClassifiedResponse
ClassifyResponse analyzes an email and determines the response type
type Email ¶
type Email struct {
UID uint32 // IMAP UID for operations like move/delete
MessageID string
From string
FromName string // Sender display name (e.g., "Mail Delivery System")
FromDomain string
Subject string
Body string
HTMLBody string
ReceivedAt time.Time
BrokerID string // Matched broker ID (if found)
BrokerName string // Matched broker name (if found)
}
Email represents a parsed email from a broker
type ExtractedURLs ¶
type ExtractedURLs struct {
FormURLs []string // URLs that look like opt-out forms
ConfirmationURLs []string // URLs that look like confirmation links
UnsubscribeURLs []string // Unsubscribe links
AllURLs []string // All URLs found
}
ExtractedURLs contains categorized URLs from an email
func ParseEmailURLs ¶
func ParseEmailURLs(email *Email) ExtractedURLs
ParseEmailURLs extracts and categorizes URLs from an email
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor handles IMAP connection and email monitoring
func NewMonitor ¶
func NewMonitor(cfg config.InboxConfig, brokerList []broker.Broker) *Monitor
NewMonitor creates a new inbox monitor
func (*Monitor) ArchiveEmails ¶
ArchiveEmails moves multiple emails to the archive folder
func (*Monitor) Disconnect ¶
Disconnect closes the IMAP connection
func (*Monitor) EnsureFolderExists ¶
EnsureFolderExists creates a folder/label if it doesn't already exist
func (*Monitor) FetchBounceEmails ¶
FetchBounceEmails fetches emails that look like bounce/undeliverable notifications
func (*Monitor) FetchBrokerEmails ¶
FetchBrokerEmails fetches only emails from known broker domains
func (*Monitor) FetchBrokerEmailsFromFolder ¶
func (m *Monitor) FetchBrokerEmailsFromFolder(ctx context.Context, folder string, days int) ([]Email, error)
FetchBrokerEmailsFromFolder fetches broker emails from a specific folder
func (*Monitor) ScanAndStore ¶ added in v0.9.0
func (m *Monitor) ScanAndStore(ctx context.Context, store *history.Store, opt ScanOptions) (ScanResult, error)
ScanAndStore fetches broker replies from a connected inbox, classifies them and stores new ones in the history, attributing each to the profile that emailed that broker (a shared inbox serves several profiles). New replies also advance the broker's pipeline status; replies seen before don't, so a re-scan can't undo progress made since. With AutoArchive, the INBOX replies are moved to the archive folder afterwards.
type ReplyOutcome ¶ added in v0.9.0
type ReplyOutcome int
ReplyOutcome is what RecordReply did with a reply.
const ( ReplySeen ReplyOutcome = iota // already stored, left as is ReplyNew // stored for the first time ReplyUpdated // already stored, reclassified )
type ResponseType ¶
type ResponseType string
ResponseType represents the type of broker response
const ( ResponseFormRequired ResponseType = "form_required" // Need to fill out a form ResponseConfirmationRequired ResponseType = "confirmation_required" // Need to click confirmation link ResponseSuccess ResponseType = "success" // Removal confirmed/completed ResponseNoData ResponseType = "no_data_held" // Broker holds no matching data ResponseRejected ResponseType = "rejected" // Request denied ResponsePending ResponseType = "pending" // Processing, will follow up ResponseBounced ResponseType = "bounced" // Email bounced - invalid address ResponseUnknown ResponseType = "unknown" // Needs manual review )
func ClassifyBySubjectOnly ¶
func ClassifyBySubjectOnly(subject string) (ResponseType, float64, bool)
ClassifyBySubjectOnly classifies based on subject line only (for reclassifying database records) Returns the response type, confidence, and whether it needs review
type ScanOptions ¶ added in v0.9.0
type ScanOptions struct {
Days int
// IncludeArchive also reads the archive folder, where earlier scans
// moved replies (the web UI's scans; `eraser monitor` reads INBOX only).
IncludeArchive bool
// Reclassify re-runs the classifier on replies already stored and
// updates them in place (the web UI's rescan).
Reclassify bool
}
ScanOptions picks what ScanAndStore reads and how it treats replies it has seen before.
type ScanResult ¶ added in v0.9.0
type ScanResult struct {
Summary Summary // every broker reply found, by type
New []ClassifiedResponse // replies stored for the first time
Updated int // stored replies reclassified (Reclassify only)
Archived int
}
ScanResult is what one ScanAndStore found.
type Summary ¶
type Summary struct {
Total int
Success int
FormRequired int
ConfirmRequired int
Rejected int
NoData int
Pending int
Bounced int
Unknown int
NeedReview int
}
Summary provides a summary of classified responses
func SummarizeResponses ¶
func SummarizeResponses(responses []ClassifiedResponse) Summary
SummarizeResponses generates a summary of classified responses