Documentation
¶
Index ¶
- Constants
- Variables
- func GetConfigDir() (string, error)
- func SaveUserConfig(config UserConfig) error
- type Attachment
- type Config
- type GmailProvider
- func (p *GmailProvider) Connect() error
- func (p *GmailProvider) Disconnect() error
- func (p *GmailProvider) GetEmails(limit int) ([]*IncomingMessage, error)
- func (p *GmailProvider) GetUserInfo() (auth.Credentials, error)
- func (p *GmailProvider) QuickSend(to, subject, body string) error
- func (p *GmailProvider) SendEmail(message *OutgoingMessage) error
- type IncomingMessage
- type MailProvider
- type OutgoingMessage
- func (msg *OutgoingMessage) AddBCC(email string)
- func (msg *OutgoingMessage) AddCC(email string)
- func (msg *OutgoingMessage) AddRecipient(email string)
- func (msg *OutgoingMessage) AppendAttachmentPath(path string) error
- func (msg *OutgoingMessage) ConvertToBytes() ([]byte, error)
- func (msg *OutgoingMessage) PrepAttachment(filename string) (a *Attachment, err error)
- func (msg *OutgoingMessage) SendMessage(addr string, a smtp.Auth) error
- func (msg *OutgoingMessage) SetTextBody(textContent string)
- type UserConfig
Constants ¶
const MaxLineLength = 76 // MaxLineLength is the maximum line length per RFC 2045
Variables ¶
var DefaultConfig = Config{
SMTPHost: "smtp.gmail.com",
SMTPPort: "587",
IMAPHost: "imap.gmail.com",
IMAPPort: "993",
}
DefaultConfig provides standard connection settings for Gmail's SMTP and IMAP servers.
var DefaultUserConfig = UserConfig{
Theme: "blue",
DefaultNumMails: 50,
}
DefaultUserConfig provides default UI and behavior settings for the application.
Functions ¶
func GetConfigDir ¶
GetConfigDir returns the configuration directory
func SaveUserConfig ¶
func SaveUserConfig(config UserConfig) error
SaveUserConfig saves user preferences to config file
Types ¶
type Attachment ¶ added in v1.0.0
type Attachment struct { Filename string ContentType string Header textproto.MIMEHeader Content []byte }
Attachment is a struct representing an email attachment. Based on the mime/multipart.FileHeader struct, Attachment contains the name, MIMEHeader, and content of the attachment in question
type Config ¶
type Config struct { SMTPHost string `json:"smtp_host"` SMTPPort string `json:"smtp_port"` IMAPHost string `json:"imap_host"` IMAPPort string `json:"imap_port"` }
Config holds email provider settings
func (*Config) GetIMAPAddress ¶
GetIMAPAddress returns the complete IMAP server address with port for email fetching.
func (*Config) GetSMTPAddress ¶
GetSMTPAddress returns the complete SMTP server address with port for email sending.
type GmailProvider ¶
type GmailProvider struct {
// contains filtered or unexported fields
}
GmailProvider implements the MailProvider interface for Gmail
func NewGmailProvider ¶
func NewGmailProvider(config Config, userInfo auth.Credentials) (*GmailProvider, error)
NewGmailProvider creates a new Gmail provider and connects immediately
func (*GmailProvider) Connect ¶
func (p *GmailProvider) Connect() error
Connect establishes a connection to Gmail's IMAP server using the provider's credentials. If already connected, it returns nil without reconnecting.
func (*GmailProvider) Disconnect ¶
func (p *GmailProvider) Disconnect() error
Disconnect closes the IMAP connection to the Gmail server. If already disconnected, returns nil without any action.
func (*GmailProvider) GetEmails ¶
func (p *GmailProvider) GetEmails(limit int) ([]*IncomingMessage, error)
GetEmails retrieves and parses emails
func (*GmailProvider) GetUserInfo ¶
func (p *GmailProvider) GetUserInfo() (auth.Credentials, error)
GetUserInfo returns the user information
func (*GmailProvider) QuickSend ¶
func (p *GmailProvider) QuickSend(to, subject, body string) error
QuickSend provides a simple way to send a text email
func (*GmailProvider) SendEmail ¶
func (p *GmailProvider) SendEmail(message *OutgoingMessage) error
SendEmail sends an email message
type IncomingMessage ¶
type IncomingMessage struct { From string To string Subject string Date time.Time Body string Attachments []string // Only attachment names, not content }
IncomingMessage represents an email message received from a mail server. It contains the essential fields from the email such as sender, recipient, subject, date, and the message body in plain text format.
func (*IncomingMessage) Parse ¶
func (email *IncomingMessage) Parse(msg *imap.Message) error
Parse converts an IMAP message into an IncomingMessage structure. It extracts headers, body content, and attachment information from the raw message.
type MailProvider ¶
type MailProvider interface { // Connection management Connect() error Disconnect() error // Mail operations SendEmail(message *OutgoingMessage) error QuickSend(to, subject, body string) error GetEmails(limit int) ([]*IncomingMessage, error) GetUserInfo() (auth.Credentials, error) }
MailProvider defines the interface for interacting with email providers. It abstracts the details of connecting to email servers, sending and receiving messages, and managing authentication.
func CreateDefaultMailProvider ¶
func CreateDefaultMailProvider() (MailProvider, error)
CreateDefaultMailProvider creates a mail provider with default configuration
type OutgoingMessage ¶
type OutgoingMessage struct { Headers textproto.MIMEHeader From string To []string Cc []string Bcc []string Subject string Text []byte Attachments []*Attachment AttachmentPaths []string ReplyTo []string }
OutgoingMessage represents an email message to be sent. It contains all the necessary fields for sending an email, including the sender, recipients, subject, body content, and any attachments.
func NewOutgoingMessage ¶
func NewOutgoingMessage() (*OutgoingMessage, error)
NewOutgoingMessage creates a new email message with sender information populated from the authenticated user's credentials. Returns an error if user credentials cannot be loaded or are incomplete.
func (*OutgoingMessage) AddBCC ¶
func (msg *OutgoingMessage) AddBCC(email string)
AddBCC adds an email address to the BCC (blind carbon copy) field of the message.
func (*OutgoingMessage) AddCC ¶
func (msg *OutgoingMessage) AddCC(email string)
AddCC adds an email address to the CC (carbon copy) field of the message.
func (*OutgoingMessage) AddRecipient ¶
func (msg *OutgoingMessage) AddRecipient(email string)
AddRecipient adds an email address to the To field of the message.
func (*OutgoingMessage) AppendAttachmentPath ¶ added in v1.0.0
func (msg *OutgoingMessage) AppendAttachmentPath(path string) error
AppendAttachmentPath appends the path for the attachment to the emsil.
func (*OutgoingMessage) ConvertToBytes ¶ added in v1.0.0
func (msg *OutgoingMessage) ConvertToBytes() ([]byte, error)
Bytes converts the OutgoingMessage object to a []byte representation, including all needed MIMEHeaders, boundaries, etc.
func (*OutgoingMessage) PrepAttachment ¶ added in v1.0.0
func (msg *OutgoingMessage) PrepAttachment(filename string) (a *Attachment, err error)
The function will then return the Attachment for reference, as well as nil for the error.
func (*OutgoingMessage) SendMessage ¶ added in v1.0.0
func (msg *OutgoingMessage) SendMessage(addr string, a smtp.Auth) error
Send an email using the given host and SMTP auth (optional), returns any error thrown by smtp.SendMail This function merges the To, Cc, and Bcc fields and calls the smtp.SendMail function using the Email.Bytes() output as the message
func (*OutgoingMessage) SetTextBody ¶
func (msg *OutgoingMessage) SetTextBody(textContent string)
SetTextBody sets the message body as plain text content and marks the message accordingly.
type UserConfig ¶
type UserConfig struct { Theme string `json:"theme"` // UI color theme DefaultNumMails int `json:"default_mails"` // Number of emails to fetch }
UserConfig holds user preferences
func LoadUserConfig ¶
func LoadUserConfig() (UserConfig, error)
LoadUserConfig loads user preferences from config file