fetcher

package
v0.27.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 22 Imported by: 0

README

fetcher

The fetcher package handles all email retrieval operations over IMAP. It connects to mail servers, fetches email headers and bodies, manages attachments, and supports mailbox operations like delete, archive, and move.

Architecture

This package is the IMAP client layer for Matcha. It:

  • Establishes TLS/STARTTLS connections to IMAP servers based on account configuration
  • Fetches email lists with pagination and per-account filtering (using FetchEmail to match relevant messages)
  • Retrieves full email bodies with MIME part traversal (preferring HTML over plain text)
  • Handles attachments including inline images (with CID references) and file attachments
  • Supports S/MIME decryption (opaque and enveloped) and detached signature verification
  • Provides mailbox operations: delete (expunge), archive (move), and folder-to-folder moves
  • Exposes both mailbox-specific and convenience functions (e.g., FetchEmails defaults to INBOX)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchiveEmail

func ArchiveEmail(account *config.Account, uid uint32) error

func ArchiveEmailFromMailbox added in v0.10.0

func ArchiveEmailFromMailbox(account *config.Account, mailbox string, uid uint32) error

func ArchiveFolderEmail added in v0.22.0

func ArchiveFolderEmail(account *config.Account, folder string, uid uint32) error

ArchiveFolderEmail archives an email from an arbitrary folder.

func ArchiveSentEmail added in v0.10.0

func ArchiveSentEmail(account *config.Account, uid uint32) error

func DeleteArchiveEmail added in v0.16.0

func DeleteArchiveEmail(account *config.Account, uid uint32) error

DeleteArchiveEmail deletes an email from archive (moves to trash)

func DeleteEmail

func DeleteEmail(account *config.Account, uid uint32) error

func DeleteEmailFromMailbox added in v0.10.0

func DeleteEmailFromMailbox(account *config.Account, mailbox string, uid uint32) error

func DeleteFolderEmail added in v0.22.0

func DeleteFolderEmail(account *config.Account, folder string, uid uint32) error

DeleteFolderEmail deletes an email from an arbitrary folder.

func DeleteSentEmail added in v0.10.0

func DeleteSentEmail(account *config.Account, uid uint32) error

func DeleteTrashEmail added in v0.16.0

func DeleteTrashEmail(account *config.Account, uid uint32) error

DeleteTrashEmail permanently deletes an email from trash

func FetchArchiveAttachment added in v0.16.0

func FetchArchiveAttachment(account *config.Account, uid uint32, partID string, encoding string) ([]byte, error)

FetchArchiveAttachment fetches an attachment from archive

func FetchAttachment

func FetchAttachment(account *config.Account, uid uint32, partID string, encoding string) ([]byte, error)

func FetchAttachmentFromMailbox added in v0.10.0

func FetchAttachmentFromMailbox(account *config.Account, mailbox string, uid uint32, partID string, encoding string) ([]byte, error)

func FetchFolderAttachment added in v0.22.0

func FetchFolderAttachment(account *config.Account, folder string, uid uint32, partID string, encoding string) ([]byte, error)

FetchFolderAttachment fetches an attachment from an arbitrary folder.

func FetchSentAttachment added in v0.10.0

func FetchSentAttachment(account *config.Account, uid uint32, partID string, encoding string) ([]byte, error)

func FetchTrashAttachment added in v0.16.0

func FetchTrashAttachment(account *config.Account, uid uint32, partID string, encoding string) ([]byte, error)

FetchTrashAttachment fetches an attachment from trash

func MarkEmailAsReadInMailbox added in v0.26.0

func MarkEmailAsReadInMailbox(account *config.Account, mailbox string, uid uint32) error

func MoveEmailToFolder added in v0.22.0

func MoveEmailToFolder(account *config.Account, uid uint32, sourceFolder, destFolder string) error

MoveEmailToFolder moves an email from one folder to another via IMAP.

Types

type Attachment

type Attachment struct {
	Filename         string
	PartID           string // Keep PartID to fetch on demand
	Data             []byte
	Encoding         string // Store encoding for proper decoding
	MIMEType         string // Full MIME type (e.g., image/png)
	ContentID        string // Content-ID for inline assets (e.g., cid: references)
	Inline           bool   // True when the part is meant to be displayed inline
	IsSMIMESignature bool   // True if this attachment is an S/MIME signature
	SMIMEVerified    bool   // True if the S/MIME signature was verified successfully
	IsSMIMEEncrypted bool   // True if the S/MIME content was successfully decrypted
}

Attachment holds data for an email attachment.

func FetchArchiveEmailBody added in v0.16.0

func FetchArchiveEmailBody(account *config.Account, uid uint32) (string, []Attachment, error)

FetchArchiveEmailBody fetches the body of an email from archive

func FetchEmailBody

func FetchEmailBody(account *config.Account, uid uint32) (string, []Attachment, error)

func FetchEmailBodyFromMailbox added in v0.10.0

func FetchEmailBodyFromMailbox(account *config.Account, mailbox string, uid uint32) (string, []Attachment, error)

func FetchFolderEmailBody added in v0.22.0

func FetchFolderEmailBody(account *config.Account, folder string, uid uint32) (string, []Attachment, error)

FetchFolderEmailBody fetches the body of an email from an arbitrary folder.

func FetchSentEmailBody added in v0.10.0

func FetchSentEmailBody(account *config.Account, uid uint32) (string, []Attachment, error)

func FetchTrashEmailBody added in v0.16.0

func FetchTrashEmailBody(account *config.Account, uid uint32) (string, []Attachment, error)

FetchTrashEmailBody fetches the body of an email from trash

type Email

type Email struct {
	UID         uint32
	From        string
	To          []string
	Subject     string
	Body        string
	Date        time.Time
	IsRead      bool
	MessageID   string
	References  []string
	Attachments []Attachment
	AccountID   string // ID of the account this email belongs to
}

func FetchArchiveEmails added in v0.16.0

func FetchArchiveEmails(account *config.Account, limit, offset uint32) ([]Email, error)

FetchArchiveEmails fetches emails from the archive/all mail folder Archive contains all emails, so we match where user is sender OR recipient

func FetchEmails

func FetchEmails(account *config.Account, limit, offset uint32) ([]Email, error)

func FetchFolderEmails added in v0.22.0

func FetchFolderEmails(account *config.Account, folder string, limit, offset uint32) ([]Email, error)

FetchFolderEmails fetches emails from an arbitrary folder.

func FetchMailboxEmails added in v0.10.0

func FetchMailboxEmails(account *config.Account, mailbox string, limit, offset uint32) ([]Email, error)

func FetchSentEmails added in v0.10.0

func FetchSentEmails(account *config.Account, limit, offset uint32) ([]Email, error)

func FetchTrashEmails added in v0.16.0

func FetchTrashEmails(account *config.Account, limit, offset uint32) ([]Email, error)

FetchTrashEmails fetches emails from the trash folder

type Folder added in v0.22.0

type Folder struct {
	Name       string
	Delimiter  string
	Attributes []string
}

Folder represents an IMAP mailbox/folder.

func FetchFolders added in v0.22.0

func FetchFolders(account *config.Account) ([]Folder, error)

FetchFolders lists all IMAP folders/mailboxes for an account.

Jump to

Keyboard shortcuts

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