cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package cache provides local SQLite caching for Nylas Air. Each email account has its own database file at ~/.config/nylas/air/{email}.db

Index

Constants

View Source
const (
	ResourceEmails    = "emails"
	ResourceEvents    = "events"
	ResourceContacts  = "contacts"
	ResourceFolders   = "folders"
	ResourceCalendars = "calendars"
)

Resource types for sync state.

View Source
const DefaultPhotoTTL = 30 * 24 * time.Hour

DefaultPhotoTTL is the default time-to-live for cached photos (30 days).

Variables

This section is empty.

Functions

func IsEncrypted

func IsEncrypted(dbPath string) (bool, error)

IsEncrypted checks if the database for an email is encrypted.

func OpenSharedDB

func OpenSharedDB(basePath, filename string) (*sql.DB, error)

OpenSharedDB opens a shared SQLite database for cross-account data (like photos).

Types

type ActionType

type ActionType string

ActionType represents the type of queued action.

const (
	ActionMarkRead      ActionType = "mark_read"
	ActionMarkUnread    ActionType = "mark_unread"
	ActionStar          ActionType = "star"
	ActionUnstar        ActionType = "unstar"
	ActionArchive       ActionType = "archive"
	ActionDelete        ActionType = "delete"
	ActionMove          ActionType = "move"
	ActionSend          ActionType = "send"
	ActionSaveDraft     ActionType = "save_draft"
	ActionDeleteDraft   ActionType = "delete_draft"
	ActionCreateEvent   ActionType = "create_event"
	ActionUpdateEvent   ActionType = "update_event"
	ActionDeleteEvent   ActionType = "delete_event"
	ActionCreateContact ActionType = "create_contact"
	ActionUpdateContact ActionType = "update_contact"
	ActionDeleteContact ActionType = "delete_contact"
)

type AttachmentCacheStats

type AttachmentCacheStats struct {
	Count     int
	TotalSize int64
	MaxSize   int64
	Usage     float64 // Percentage used
	Oldest    time.Time
	Newest    time.Time
}

AttachmentCacheStats contains statistics about the attachment cache.

type AttachmentStore

type AttachmentStore struct {
	// contains filtered or unexported fields
}

AttachmentStore provides attachment caching operations.

func NewAttachmentStore

func NewAttachmentStore(db *sql.DB, basePath string, maxSizeMB int) (*AttachmentStore, error)

NewAttachmentStore creates an attachment store.

func (*AttachmentStore) Count

func (s *AttachmentStore) Count() (int, error)

Count returns the number of cached attachments.

func (*AttachmentStore) Delete

func (s *AttachmentStore) Delete(id string) error

Delete removes an attachment.

func (*AttachmentStore) DeleteByEmail

func (s *AttachmentStore) DeleteByEmail(emailID string) error

DeleteByEmail removes all attachments for an email.

func (*AttachmentStore) Get

Get retrieves an attachment by ID.

func (*AttachmentStore) GetByHash

func (s *AttachmentStore) GetByHash(hash string) (*CachedAttachment, error)

GetByHash retrieves an attachment by content hash.

func (*AttachmentStore) GetStats

func (s *AttachmentStore) GetStats() (*AttachmentCacheStats, error)

GetStats returns attachment cache statistics.

func (*AttachmentStore) LRUEvict

func (s *AttachmentStore) LRUEvict(bytesToFree int64) (int, error)

LRUEvict removes the least recently used attachments to free up space.

func (*AttachmentStore) ListByEmail

func (s *AttachmentStore) ListByEmail(emailID string) ([]*CachedAttachment, error)

ListByEmail retrieves all attachments for an email.

func (*AttachmentStore) Open

func (s *AttachmentStore) Open(id string) (*os.File, error)

Open opens the attachment file for reading.

func (*AttachmentStore) Prune

func (s *AttachmentStore) Prune() (int, error)

Prune removes least recently used attachments to stay under maxSize.

func (*AttachmentStore) Put

func (s *AttachmentStore) Put(attachment *CachedAttachment, content io.Reader) error

Put stores an attachment and its content.

func (*AttachmentStore) RemoveOrphaned

func (s *AttachmentStore) RemoveOrphaned() (int, error)

RemoveOrphaned removes attachment files not referenced in database.

func (*AttachmentStore) TotalSize

func (s *AttachmentStore) TotalSize() (int64, error)

TotalSize returns the total size of cached attachments.

type CacheStats

type CacheStats struct {
	Email        string
	SizeBytes    int64
	EmailCount   int
	EventCount   int
	ContactCount int
	LastSync     time.Time
}

CacheStats contains statistics about a cache database.

type CachedAttachment

type CachedAttachment struct {
	ID          string    `json:"id"`
	EmailID     string    `json:"email_id"`
	Filename    string    `json:"filename"`
	ContentType string    `json:"content_type"`
	Size        int64     `json:"size"`
	Hash        string    `json:"hash"` // SHA256 of content
	LocalPath   string    `json:"local_path"`
	CachedAt    time.Time `json:"cached_at"`
	AccessedAt  time.Time `json:"accessed_at"`
}

CachedAttachment represents an attachment stored in the cache.

type CachedCalendar

type CachedCalendar struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	IsPrimary   bool      `json:"is_primary"`
	ReadOnly    bool      `json:"read_only"`
	HexColor    string    `json:"hex_color,omitempty"`
	CachedAt    time.Time `json:"cached_at"`
}

CachedCalendar represents a calendar stored in the cache.

type CachedContact

type CachedContact struct {
	ID          string    `json:"id"`
	GivenName   string    `json:"given_name,omitempty"`
	Surname     string    `json:"surname,omitempty"`
	DisplayName string    `json:"display_name,omitempty"`
	Email       string    `json:"email,omitempty"`
	Phone       string    `json:"phone,omitempty"`
	Company     string    `json:"company,omitempty"`
	JobTitle    string    `json:"job_title,omitempty"`
	Notes       string    `json:"notes,omitempty"`
	PhotoURL    string    `json:"photo_url,omitempty"`
	Groups      []string  `json:"groups,omitempty"`
	CachedAt    time.Time `json:"cached_at"`
}

CachedContact represents a contact stored in the cache.

type CachedEmail

type CachedEmail struct {
	ID             string    `json:"id"`
	ThreadID       string    `json:"thread_id,omitempty"`
	FolderID       string    `json:"folder_id,omitempty"`
	Subject        string    `json:"subject"`
	Snippet        string    `json:"snippet"`
	FromName       string    `json:"from_name"`
	FromEmail      string    `json:"from_email"`
	To             []string  `json:"to,omitempty"`
	CC             []string  `json:"cc,omitempty"`
	BCC            []string  `json:"bcc,omitempty"`
	Date           time.Time `json:"date"`
	Unread         bool      `json:"unread"`
	Starred        bool      `json:"starred"`
	HasAttachments bool      `json:"has_attachments"`
	BodyHTML       string    `json:"body_html,omitempty"`
	BodyText       string    `json:"body_text,omitempty"`
	CachedAt       time.Time `json:"cached_at"`
}

CachedEmail represents an email stored in the cache.

type CachedEvent

type CachedEvent struct {
	ID           string    `json:"id"`
	CalendarID   string    `json:"calendar_id,omitempty"`
	Title        string    `json:"title"`
	Description  string    `json:"description,omitempty"`
	Location     string    `json:"location,omitempty"`
	StartTime    time.Time `json:"start_time"`
	EndTime      time.Time `json:"end_time"`
	AllDay       bool      `json:"all_day"`
	Recurring    bool      `json:"recurring"`
	RRule        string    `json:"rrule,omitempty"`
	Participants []string  `json:"participants,omitempty"`
	Status       string    `json:"status,omitempty"`
	Busy         bool      `json:"busy"`
	CachedAt     time.Time `json:"cached_at"`
}

CachedEvent represents a calendar event stored in the cache.

type CachedFolder

type CachedFolder struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Type        string    `json:"type,omitempty"` // inbox, sent, drafts, trash, etc.
	UnreadCount int       `json:"unread_count"`
	TotalCount  int       `json:"total_count"`
	CachedAt    time.Time `json:"cached_at"`
}

CachedFolder represents an email folder stored in the cache.

type CachedPhoto

type CachedPhoto struct {
	ContactID   string    `json:"contact_id"`
	ContentType string    `json:"content_type"`
	Size        int64     `json:"size"`
	LocalPath   string    `json:"local_path"`
	CachedAt    time.Time `json:"cached_at"`
	AccessedAt  time.Time `json:"accessed_at"`
}

CachedPhoto represents a contact photo stored in the cache.

type CalendarStore

type CalendarStore struct {
	// contains filtered or unexported fields
}

CalendarStore provides calendar caching operations.

func NewCalendarStore

func NewCalendarStore(db *sql.DB) *CalendarStore

NewCalendarStore creates a calendar store for a database.

func (*CalendarStore) Count

func (s *CalendarStore) Count() (int, error)

Count returns the number of cached calendars.

func (*CalendarStore) Delete

func (s *CalendarStore) Delete(id string) error

Delete removes a calendar from the cache.

func (*CalendarStore) Get

func (s *CalendarStore) Get(id string) (*CachedCalendar, error)

Get retrieves a calendar by ID.

func (*CalendarStore) GetPrimary

func (s *CalendarStore) GetPrimary() (*CachedCalendar, error)

GetPrimary retrieves the primary calendar.

func (*CalendarStore) List

func (s *CalendarStore) List() ([]*CachedCalendar, error)

List retrieves all calendars.

func (*CalendarStore) ListWritable

func (s *CalendarStore) ListWritable() ([]*CachedCalendar, error)

ListWritable retrieves calendars that can be written to.

func (*CalendarStore) Put

func (s *CalendarStore) Put(calendar *CachedCalendar) error

Put stores a calendar in the cache.

func (*CalendarStore) PutBatch

func (s *CalendarStore) PutBatch(calendars []*CachedCalendar) error

PutBatch stores multiple calendars in a transaction.

type Config

type Config struct {
	// BasePath is the directory for cache files. Defaults to ~/.config/nylas/air/
	BasePath string
	// MaxSizeMB is the maximum cache size in MB (default: 500)
	MaxSizeMB int
	// TTLDays is how long to keep cached items (default: 30)
	TTLDays int
	// SyncIntervalMinutes is background sync frequency (default: 5)
	SyncIntervalMinutes int
}

Config holds cache configuration options.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default cache configuration.

type ContactListOptions

type ContactListOptions struct {
	Group  string
	Limit  int
	Offset int
}

ContactListOptions configures contact listing.

type ContactStore

type ContactStore struct {
	// contains filtered or unexported fields
}

ContactStore provides contact caching operations.

func NewContactStore

func NewContactStore(db *sql.DB) *ContactStore

NewContactStore creates a contact store for a database.

func (*ContactStore) Count

func (s *ContactStore) Count() (int, error)

Count returns the number of cached contacts.

func (*ContactStore) Delete

func (s *ContactStore) Delete(id string) error

Delete removes a contact from the cache.

func (*ContactStore) Get

func (s *ContactStore) Get(id string) (*CachedContact, error)

Get retrieves a contact by ID.

func (*ContactStore) GetByEmail

func (s *ContactStore) GetByEmail(email string) (*CachedContact, error)

GetByEmail retrieves a contact by email address.

func (*ContactStore) List

func (s *ContactStore) List(opts ContactListOptions) ([]*CachedContact, error)

List retrieves contacts with pagination.

func (*ContactStore) ListGroups

func (s *ContactStore) ListGroups() ([]string, error)

ListGroups returns all unique groups.

func (*ContactStore) Put

func (s *ContactStore) Put(contact *CachedContact) error

Put stores a contact in the cache.

func (*ContactStore) PutBatch

func (s *ContactStore) PutBatch(contacts []*CachedContact) error

PutBatch stores multiple contacts in a transaction.

func (*ContactStore) Search

func (s *ContactStore) Search(query string, limit int) ([]*CachedContact, error)

Search performs full-text search on contacts.

type DraftPayload

type DraftPayload struct {
	DraftID string   `json:"draft_id,omitempty"`
	To      []string `json:"to"`
	CC      []string `json:"cc,omitempty"`
	BCC     []string `json:"bcc,omitempty"`
	Subject string   `json:"subject"`
	Body    string   `json:"body"`
}

DraftPayload is the payload for draft actions.

type EmailStore

type EmailStore struct {
	// contains filtered or unexported fields
}

EmailStore provides email caching operations.

func NewEmailStore

func NewEmailStore(db *sql.DB) *EmailStore

NewEmailStore creates an email store for a database.

func (*EmailStore) Count

func (s *EmailStore) Count() (int, error)

Count returns the number of cached emails.

func (*EmailStore) CountUnread

func (s *EmailStore) CountUnread() (int, error)

CountUnread returns the number of unread emails.

func (*EmailStore) Delete

func (s *EmailStore) Delete(id string) error

Delete removes an email from the cache.

func (*EmailStore) Get

func (s *EmailStore) Get(id string) (*CachedEmail, error)

Get retrieves an email by ID.

func (*EmailStore) List

func (s *EmailStore) List(opts ListOptions) ([]*CachedEmail, error)

List retrieves emails with pagination and filtering.

func (*EmailStore) Put

func (s *EmailStore) Put(email *CachedEmail) error

Put stores an email in the cache.

func (*EmailStore) PutBatch

func (s *EmailStore) PutBatch(emails []*CachedEmail) error

PutBatch stores multiple emails in a transaction.

func (*EmailStore) Search

func (s *EmailStore) Search(query string, limit int) ([]*CachedEmail, error)

Search performs full-text search on emails.

func (*EmailStore) SearchAdvanced

func (s *EmailStore) SearchAdvanced(query string, limit int) ([]*CachedEmail, error)

SearchEmails performs an advanced search with operator support.

func (*EmailStore) SearchWithQuery

func (s *EmailStore) SearchWithQuery(sq *SearchQuery, limit int) ([]*CachedEmail, error)

SearchWithQuery performs a search using a parsed query.

func (*EmailStore) UpdateFlags

func (s *EmailStore) UpdateFlags(id string, unread, starred *bool) error

UpdateFlags updates read/starred status.

type EncryptedManager

type EncryptedManager struct {
	*Manager
	// contains filtered or unexported fields
}

EncryptedManager extends Manager with encryption support.

func NewEncryptedManager

func NewEncryptedManager(cfg Config, encCfg EncryptionConfig) (*EncryptedManager, error)

NewEncryptedManager creates a new cache manager with encryption support.

func (*EncryptedManager) ClearCache

func (m *EncryptedManager) ClearCache(email string) error

ClearCache removes the cache database and encryption key for an email.

func (*EncryptedManager) GetDB

func (m *EncryptedManager) GetDB(email string) (*sql.DB, error)

GetDB returns or creates an encrypted database for the given email.

func (*EncryptedManager) MigrateToEncrypted

func (m *EncryptedManager) MigrateToEncrypted(email string) error

MigrateToEncrypted migrates an unencrypted database to encrypted.

func (*EncryptedManager) MigrateToUnencrypted

func (m *EncryptedManager) MigrateToUnencrypted(email string) error

MigrateToUnencrypted migrates an encrypted database to unencrypted.

type EncryptionConfig

type EncryptionConfig struct {
	Enabled bool
	KeyID   string // Identifier for the key in keyring (usually email)
}

EncryptionConfig holds encryption configuration.

type EventListOptions

type EventListOptions struct {
	CalendarID string
	Start      time.Time
	End        time.Time
	Limit      int
	Offset     int
}

EventListOptions configures event listing.

type EventStore

type EventStore struct {
	// contains filtered or unexported fields
}

EventStore provides event caching operations.

func NewEventStore

func NewEventStore(db *sql.DB) *EventStore

NewEventStore creates an event store for a database.

func (*EventStore) Count

func (s *EventStore) Count() (int, error)

Count returns the number of cached events.

func (*EventStore) Delete

func (s *EventStore) Delete(id string) error

Delete removes an event from the cache.

func (*EventStore) DeleteByCalendar

func (s *EventStore) DeleteByCalendar(calendarID string) error

DeleteByCalendar removes all events for a calendar.

func (*EventStore) Get

func (s *EventStore) Get(id string) (*CachedEvent, error)

Get retrieves an event by ID.

func (*EventStore) GetUpcoming

func (s *EventStore) GetUpcoming(limit int) ([]*CachedEvent, error)

GetUpcoming retrieves upcoming events.

func (*EventStore) List

func (s *EventStore) List(opts EventListOptions) ([]*CachedEvent, error)

List retrieves events with filtering.

func (*EventStore) ListByDateRange

func (s *EventStore) ListByDateRange(start, end time.Time) ([]*CachedEvent, error)

ListByDateRange retrieves events within a date range.

func (*EventStore) Put

func (s *EventStore) Put(event *CachedEvent) error

Put stores an event in the cache.

func (*EventStore) PutBatch

func (s *EventStore) PutBatch(events []*CachedEvent) error

PutBatch stores multiple events in a transaction.

func (*EventStore) Search

func (s *EventStore) Search(query string, limit int) ([]*CachedEvent, error)

Search performs full-text search on events.

type FolderStore

type FolderStore struct {
	// contains filtered or unexported fields
}

FolderStore provides folder caching operations.

func NewFolderStore

func NewFolderStore(db *sql.DB) *FolderStore

NewFolderStore creates a folder store for a database.

func (*FolderStore) Count

func (s *FolderStore) Count() (int, error)

Count returns the number of cached folders.

func (*FolderStore) Delete

func (s *FolderStore) Delete(id string) error

Delete removes a folder from the cache.

func (*FolderStore) Get

func (s *FolderStore) Get(id string) (*CachedFolder, error)

Get retrieves a folder by ID.

func (*FolderStore) GetByType

func (s *FolderStore) GetByType(folderType string) (*CachedFolder, error)

GetByType retrieves a folder by type (inbox, sent, drafts, trash).

func (*FolderStore) GetTotalUnread

func (s *FolderStore) GetTotalUnread() (int, error)

GetTotalUnread returns the total unread count across all folders.

func (*FolderStore) IncrementUnread

func (s *FolderStore) IncrementUnread(id string, delta int) error

IncrementUnread increments or decrements the unread count.

func (*FolderStore) List

func (s *FolderStore) List() ([]*CachedFolder, error)

List retrieves all folders.

func (*FolderStore) Put

func (s *FolderStore) Put(folder *CachedFolder) error

Put stores a folder in the cache.

func (*FolderStore) PutBatch

func (s *FolderStore) PutBatch(folders []*CachedFolder) error

PutBatch stores multiple folders in a transaction.

func (*FolderStore) UpdateCounts

func (s *FolderStore) UpdateCounts(id string, unreadCount, totalCount int) error

UpdateCounts updates the unread and total counts for a folder.

type ListOptions

type ListOptions struct {
	FolderID    string
	ThreadID    string
	UnreadOnly  bool
	StarredOnly bool
	Since       time.Time
	Before      time.Time
	Limit       int
	Offset      int
}

ListOptions configures email listing.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles per-email cache databases.

func NewManager

func NewManager(cfg Config) (*Manager, error)

NewManager creates a new cache manager.

func (*Manager) ClearAllCaches

func (m *Manager) ClearAllCaches() error

ClearAllCaches removes all cache databases.

func (*Manager) ClearCache

func (m *Manager) ClearCache(email string) error

ClearCache removes the cache database for an email.

func (*Manager) Close

func (m *Manager) Close() error

Close closes all open database connections.

func (*Manager) CloseDB

func (m *Manager) CloseDB(email string) error

CloseDB closes the database for a specific email.

func (*Manager) DBPath

func (m *Manager) DBPath(email string) string

DBPath returns the database path for an email.

func (*Manager) GetDB

func (m *Manager) GetDB(email string) (*sql.DB, error)

GetDB returns or creates a database for the given email.

func (*Manager) GetStats

func (m *Manager) GetStats(email string) (*CacheStats, error)

GetStats returns statistics for a cache database.

func (*Manager) ListCachedAccounts

func (m *Manager) ListCachedAccounts() ([]string, error)

ListCachedAccounts returns emails that have cache databases.

type MarkReadPayload

type MarkReadPayload struct {
	EmailID string `json:"email_id"`
	Unread  bool   `json:"unread"`
}

MarkReadPayload is the payload for mark read/unread actions.

type MovePayload

type MovePayload struct {
	EmailID  string `json:"email_id"`
	FolderID string `json:"folder_id"`
}

MovePayload is the payload for move actions.

type OfflineQueue

type OfflineQueue struct {
	// contains filtered or unexported fields
}

OfflineQueue manages queued actions for offline support.

func NewOfflineQueue

func NewOfflineQueue(db *sql.DB) (*OfflineQueue, error)

NewOfflineQueue creates a new offline queue.

func (*OfflineQueue) Clear

func (q *OfflineQueue) Clear() error

Clear removes all queued actions.

func (*OfflineQueue) Count

func (q *OfflineQueue) Count() (int, error)

Count returns the number of queued actions.

func (*OfflineQueue) Dequeue

func (q *OfflineQueue) Dequeue() (*QueuedAction, error)

Dequeue retrieves and removes the oldest action.

func (*OfflineQueue) Enqueue

func (q *OfflineQueue) Enqueue(actionType ActionType, resourceID string, payload any) error

Enqueue adds an action to the queue.

func (*OfflineQueue) HasPendingActions

func (q *OfflineQueue) HasPendingActions() (bool, error)

HasPendingActions returns true if there are queued actions.

func (*OfflineQueue) List

func (q *OfflineQueue) List() ([]*QueuedAction, error)

List retrieves all queued actions.

func (*OfflineQueue) MarkFailed

func (q *OfflineQueue) MarkFailed(id int64, err error) error

MarkFailed increments the attempt count and records the error.

func (*OfflineQueue) Peek

func (q *OfflineQueue) Peek() (*QueuedAction, error)

Peek retrieves the oldest action without removing it.

func (*OfflineQueue) Remove

func (q *OfflineQueue) Remove(id int64) error

Remove deletes an action from the queue.

func (*OfflineQueue) RemoveByResourceID

func (q *OfflineQueue) RemoveByResourceID(resourceID string) error

RemoveByResourceID removes all actions for a specific resource.

func (*OfflineQueue) RemoveStale

func (q *OfflineQueue) RemoveStale(maxAge time.Duration) (int, error)

RemoveStale removes actions older than the given duration.

type PhotoCacheStats

type PhotoCacheStats struct {
	Count     int
	TotalSize int64
	TTLDays   int
	Oldest    time.Time
	Newest    time.Time
}

PhotoCacheStats contains statistics about the photo cache.

type PhotoStore

type PhotoStore struct {
	// contains filtered or unexported fields
}

PhotoStore provides contact photo caching operations.

func NewPhotoStore

func NewPhotoStore(db *sql.DB, basePath string, ttl time.Duration) (*PhotoStore, error)

NewPhotoStore creates a photo store.

func (*PhotoStore) Count

func (s *PhotoStore) Count() (int, error)

Count returns the number of cached photos.

func (*PhotoStore) Delete

func (s *PhotoStore) Delete(contactID string) error

Delete removes a cached photo.

func (*PhotoStore) Get

func (s *PhotoStore) Get(contactID string) ([]byte, string, error)

Get retrieves a cached photo if it exists and is not expired. Returns nil, nil if the photo is not cached or expired.

func (*PhotoStore) GetStats

func (s *PhotoStore) GetStats() (*PhotoCacheStats, error)

GetStats returns photo cache statistics.

func (*PhotoStore) IsValid

func (s *PhotoStore) IsValid(contactID string) bool

IsValid checks if a cached photo exists and is not expired.

func (*PhotoStore) Prune

func (s *PhotoStore) Prune() (int, error)

Prune removes expired photos.

func (*PhotoStore) Put

func (s *PhotoStore) Put(contactID, contentType string, data []byte) error

Put stores a contact photo.

func (*PhotoStore) RemoveOrphaned

func (s *PhotoStore) RemoveOrphaned() (int, error)

RemoveOrphaned removes photo files not referenced in database.

func (*PhotoStore) TotalSize

func (s *PhotoStore) TotalSize() (int64, error)

TotalSize returns the total size of cached photos in bytes.

type QueuedAction

type QueuedAction struct {
	ID         int64      `json:"id"`
	Type       ActionType `json:"type"`
	ResourceID string     `json:"resource_id"`
	Payload    string     `json:"payload"` // JSON-encoded action data
	CreatedAt  time.Time  `json:"created_at"`
	Attempts   int        `json:"attempts"`
	LastError  string     `json:"last_error,omitempty"`
}

QueuedAction represents an action to be synced when online.

func (*QueuedAction) GetActionData

func (a *QueuedAction) GetActionData(v any) error

GetActionData unmarshals the payload into the given type.

type SearchQuery

type SearchQuery struct {
	// Text is the free-text search portion
	Text string
	// Operators are field-specific filters
	From          string
	To            string
	Subject       string
	HasAttachment *bool
	IsUnread      *bool
	IsStarred     *bool
	After         time.Time
	Before        time.Time
	In            string // Folder ID
}

SearchQuery represents a parsed search query with operators.

func ParseSearchQuery

func ParseSearchQuery(query string) *SearchQuery

ParseSearchQuery parses a search string into structured query. Supports operators: from:, to:, subject:, has:attachment, is:unread, is:starred, after:, before:, in:

type SendEmailPayload

type SendEmailPayload struct {
	To      []string `json:"to"`
	CC      []string `json:"cc,omitempty"`
	BCC     []string `json:"bcc,omitempty"`
	Subject string   `json:"subject"`
	Body    string   `json:"body"`
	ReplyTo string   `json:"reply_to,omitempty"`
}

SendEmailPayload is the payload for send email actions.

type Settings

type Settings struct {
	// Cache behavior
	Enabled             bool `json:"cache_enabled"`
	MaxSizeMB           int  `json:"cache_max_size_mb"`
	TTLDays             int  `json:"cache_ttl_days"`
	SyncIntervalMinutes int  `json:"sync_interval_minutes"`
	OfflineQueueEnabled bool `json:"offline_queue_enabled"`
	EncryptionEnabled   bool `json:"encryption_enabled"`

	// Attachment settings
	AttachmentCacheEnabled bool `json:"attachment_cache_enabled"`
	AttachmentMaxSizeMB    int  `json:"attachment_max_size_mb"`

	// Sync settings
	InitialSyncDays       int  `json:"initial_sync_days"`
	BackgroundSyncEnabled bool `json:"background_sync_enabled"`

	// UI preferences (also stored here for convenience)
	Theme           string `json:"theme,omitempty"`        // "dark", "light", "system"
	DefaultView     string `json:"default_view,omitempty"` // "email", "calendar", "contacts"
	CompactMode     bool   `json:"compact_mode,omitempty"`
	PreviewPosition string `json:"preview_position,omitempty"` // "right", "bottom", "off"
	// contains filtered or unexported fields
}

Settings holds all cache configuration.

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns default cache settings.

func LoadSettings

func LoadSettings(basePath string) (*Settings, error)

LoadSettings loads settings from file, or creates default if not exists.

func (*Settings) Get

func (s *Settings) Get() Settings

Get returns a copy of settings (thread-safe).

func (*Settings) GetMaxSizeBytes

func (s *Settings) GetMaxSizeBytes() int64

GetMaxSizeBytes returns the maximum cache size in bytes.

func (*Settings) GetSyncInterval

func (s *Settings) GetSyncInterval() time.Duration

GetSyncInterval returns the sync interval as a duration.

func (*Settings) GetTTL

func (s *Settings) GetTTL() time.Duration

GetTTL returns the cache TTL as a duration.

func (*Settings) IsCacheEnabled

func (s *Settings) IsCacheEnabled() bool

IsCacheEnabled returns whether caching is enabled.

func (*Settings) IsEncryptionEnabled

func (s *Settings) IsEncryptionEnabled() bool

IsEncryptionEnabled returns whether encryption is enabled.

func (*Settings) Reset

func (s *Settings) Reset() error

Reset restores default settings.

func (*Settings) Save

func (s *Settings) Save() error

Save writes settings to file.

func (*Settings) SetEnabled

func (s *Settings) SetEnabled(enabled bool) error

SetEnabled enables or disables caching.

func (*Settings) SetEncryption

func (s *Settings) SetEncryption(enabled bool) error

SetEncryption enables or disables encryption.

func (*Settings) SetMaxSize

func (s *Settings) SetMaxSize(sizeMB int) error

SetMaxSize sets the maximum cache size in MB.

func (*Settings) SetTheme

func (s *Settings) SetTheme(theme string) error

SetTheme sets the UI theme.

func (*Settings) ToConfig

func (s *Settings) ToConfig(basePath string) Config

ToConfig converts settings to cache Config.

func (*Settings) ToEncryptionConfig

func (s *Settings) ToEncryptionConfig() EncryptionConfig

ToEncryptionConfig converts settings to EncryptionConfig.

func (*Settings) Update

func (s *Settings) Update(fn func(*Settings)) error

Update updates settings with the provided function.

func (*Settings) Validate

func (s *Settings) Validate() error

Validate checks if settings are valid.

type StarPayload

type StarPayload struct {
	EmailID string `json:"email_id"`
	Starred bool   `json:"starred"`
}

StarPayload is the payload for star/unstar actions.

type SyncState

type SyncState struct {
	Resource string
	LastSync time.Time
	Cursor   string
	Metadata map[string]string
}

SyncState tracks sync progress for a resource.

type SyncStore

type SyncStore struct {
	// contains filtered or unexported fields
}

SyncStore provides sync state operations.

func NewSyncStore

func NewSyncStore(db *sql.DB) *SyncStore

NewSyncStore creates a sync store for a database.

func (*SyncStore) Delete

func (s *SyncStore) Delete(resource string) error

Delete removes sync state for a resource.

func (*SyncStore) Get

func (s *SyncStore) Get(resource string) (*SyncState, error)

Get retrieves the sync state for a resource.

func (*SyncStore) MarkSynced

func (s *SyncStore) MarkSynced(resource string) error

MarkSynced updates the last sync time for a resource.

func (*SyncStore) NeedsSync

func (s *SyncStore) NeedsSync(resource string, maxAge time.Duration) (bool, error)

NeedsSync returns true if the resource needs to be synced.

func (*SyncStore) Set

func (s *SyncStore) Set(state *SyncState) error

Set updates the sync state for a resource.

func (*SyncStore) UpdateCursor

func (s *SyncStore) UpdateCursor(resource, cursor string) error

UpdateCursor updates just the cursor for a resource.

type UnifiedSearchResult

type UnifiedSearchResult struct {
	Type     string // "email", "event", "contact"
	ID       string
	Title    string
	Subtitle string
	Date     time.Time
}

UnifiedSearch searches across emails, events, and contacts.

func UnifiedSearch

func UnifiedSearch(db *sql.DB, query string, limit int) ([]*UnifiedSearchResult, error)

UnifiedSearch performs search across all data types.

Jump to

Keyboard shortcuts

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