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
- func IsEncrypted(dbPath string) (bool, error)
- func OpenSharedDB(basePath, filename string) (*sql.DB, error)
- type ActionType
- type AttachmentCacheStats
- type AttachmentStore
- func (s *AttachmentStore) Count() (int, error)
- func (s *AttachmentStore) Delete(id string) error
- func (s *AttachmentStore) DeleteByEmail(emailID string) error
- func (s *AttachmentStore) Get(id string) (*CachedAttachment, error)
- func (s *AttachmentStore) GetByHash(hash string) (*CachedAttachment, error)
- func (s *AttachmentStore) GetStats() (*AttachmentCacheStats, error)
- func (s *AttachmentStore) LRUEvict(bytesToFree int64) (int, error)
- func (s *AttachmentStore) ListByEmail(emailID string) ([]*CachedAttachment, error)
- func (s *AttachmentStore) Open(id string) (*os.File, error)
- func (s *AttachmentStore) Prune() (int, error)
- func (s *AttachmentStore) Put(attachment *CachedAttachment, content io.Reader) error
- func (s *AttachmentStore) RemoveOrphaned() (int, error)
- func (s *AttachmentStore) TotalSize() (int64, error)
- type CacheStats
- type CachedAttachment
- type CachedCalendar
- type CachedContact
- type CachedEmail
- type CachedEvent
- type CachedFolder
- type CachedPhoto
- type CalendarStore
- func (s *CalendarStore) Count() (int, error)
- func (s *CalendarStore) Delete(id string) error
- func (s *CalendarStore) Get(id string) (*CachedCalendar, error)
- func (s *CalendarStore) GetPrimary() (*CachedCalendar, error)
- func (s *CalendarStore) List() ([]*CachedCalendar, error)
- func (s *CalendarStore) ListWritable() ([]*CachedCalendar, error)
- func (s *CalendarStore) Put(calendar *CachedCalendar) error
- func (s *CalendarStore) PutBatch(calendars []*CachedCalendar) error
- type Config
- type ContactListOptions
- type ContactStore
- func (s *ContactStore) Count() (int, error)
- func (s *ContactStore) Delete(id string) error
- func (s *ContactStore) Get(id string) (*CachedContact, error)
- func (s *ContactStore) GetByEmail(email string) (*CachedContact, error)
- func (s *ContactStore) List(opts ContactListOptions) ([]*CachedContact, error)
- func (s *ContactStore) ListGroups() ([]string, error)
- func (s *ContactStore) Put(contact *CachedContact) error
- func (s *ContactStore) PutBatch(contacts []*CachedContact) error
- func (s *ContactStore) Search(query string, limit int) ([]*CachedContact, error)
- type DraftPayload
- type EmailStore
- func (s *EmailStore) Count() (int, error)
- func (s *EmailStore) CountUnread() (int, error)
- func (s *EmailStore) Delete(id string) error
- func (s *EmailStore) Get(id string) (*CachedEmail, error)
- func (s *EmailStore) List(opts ListOptions) ([]*CachedEmail, error)
- func (s *EmailStore) Put(email *CachedEmail) error
- func (s *EmailStore) PutBatch(emails []*CachedEmail) error
- func (s *EmailStore) Search(query string, limit int) ([]*CachedEmail, error)
- func (s *EmailStore) SearchAdvanced(query string, limit int) ([]*CachedEmail, error)
- func (s *EmailStore) SearchWithQuery(sq *SearchQuery, limit int) ([]*CachedEmail, error)
- func (s *EmailStore) UpdateFlags(id string, unread, starred *bool) error
- type EncryptedManager
- type EncryptionConfig
- type EventListOptions
- type EventStore
- func (s *EventStore) Count() (int, error)
- func (s *EventStore) Delete(id string) error
- func (s *EventStore) DeleteByCalendar(calendarID string) error
- func (s *EventStore) Get(id string) (*CachedEvent, error)
- func (s *EventStore) GetUpcoming(limit int) ([]*CachedEvent, error)
- func (s *EventStore) List(opts EventListOptions) ([]*CachedEvent, error)
- func (s *EventStore) ListByDateRange(start, end time.Time) ([]*CachedEvent, error)
- func (s *EventStore) Put(event *CachedEvent) error
- func (s *EventStore) PutBatch(events []*CachedEvent) error
- func (s *EventStore) Search(query string, limit int) ([]*CachedEvent, error)
- type FolderStore
- func (s *FolderStore) Count() (int, error)
- func (s *FolderStore) Delete(id string) error
- func (s *FolderStore) Get(id string) (*CachedFolder, error)
- func (s *FolderStore) GetByType(folderType string) (*CachedFolder, error)
- func (s *FolderStore) GetTotalUnread() (int, error)
- func (s *FolderStore) IncrementUnread(id string, delta int) error
- func (s *FolderStore) List() ([]*CachedFolder, error)
- func (s *FolderStore) Put(folder *CachedFolder) error
- func (s *FolderStore) PutBatch(folders []*CachedFolder) error
- func (s *FolderStore) UpdateCounts(id string, unreadCount, totalCount int) error
- type ListOptions
- type Manager
- func (m *Manager) ClearAllCaches() error
- func (m *Manager) ClearCache(email string) error
- func (m *Manager) Close() error
- func (m *Manager) CloseDB(email string) error
- func (m *Manager) DBPath(email string) string
- func (m *Manager) GetDB(email string) (*sql.DB, error)
- func (m *Manager) GetStats(email string) (*CacheStats, error)
- func (m *Manager) ListCachedAccounts() ([]string, error)
- type MarkReadPayload
- type MovePayload
- type OfflineQueue
- func (q *OfflineQueue) Clear() error
- func (q *OfflineQueue) Count() (int, error)
- func (q *OfflineQueue) Dequeue() (*QueuedAction, error)
- func (q *OfflineQueue) Enqueue(actionType ActionType, resourceID string, payload any) error
- func (q *OfflineQueue) HasPendingActions() (bool, error)
- func (q *OfflineQueue) List() ([]*QueuedAction, error)
- func (q *OfflineQueue) MarkFailed(id int64, err error) error
- func (q *OfflineQueue) Peek() (*QueuedAction, error)
- func (q *OfflineQueue) Remove(id int64) error
- func (q *OfflineQueue) RemoveByResourceID(resourceID string) error
- func (q *OfflineQueue) RemoveStale(maxAge time.Duration) (int, error)
- type PhotoCacheStats
- type PhotoStore
- func (s *PhotoStore) Count() (int, error)
- func (s *PhotoStore) Delete(contactID string) error
- func (s *PhotoStore) Get(contactID string) ([]byte, string, error)
- func (s *PhotoStore) GetStats() (*PhotoCacheStats, error)
- func (s *PhotoStore) IsValid(contactID string) bool
- func (s *PhotoStore) Prune() (int, error)
- func (s *PhotoStore) Put(contactID, contentType string, data []byte) error
- func (s *PhotoStore) RemoveOrphaned() (int, error)
- func (s *PhotoStore) TotalSize() (int64, error)
- type QueuedAction
- type SearchQuery
- type SendEmailPayload
- type Settings
- func (s *Settings) Get() Settings
- func (s *Settings) GetMaxSizeBytes() int64
- func (s *Settings) GetSyncInterval() time.Duration
- func (s *Settings) GetTTL() time.Duration
- func (s *Settings) IsCacheEnabled() bool
- func (s *Settings) IsEncryptionEnabled() bool
- func (s *Settings) Reset() error
- func (s *Settings) Save() error
- func (s *Settings) SetEnabled(enabled bool) error
- func (s *Settings) SetEncryption(enabled bool) error
- func (s *Settings) SetMaxSize(sizeMB int) error
- func (s *Settings) SetTheme(theme string) error
- func (s *Settings) ToConfig(basePath string) Config
- func (s *Settings) ToEncryptionConfig() EncryptionConfig
- func (s *Settings) Update(fn func(*Settings)) error
- func (s *Settings) Validate() error
- type StarPayload
- type SyncState
- type SyncStore
- func (s *SyncStore) Delete(resource string) error
- func (s *SyncStore) Get(resource string) (*SyncState, error)
- func (s *SyncStore) MarkSynced(resource string) error
- func (s *SyncStore) NeedsSync(resource string, maxAge time.Duration) (bool, error)
- func (s *SyncStore) Set(state *SyncState) error
- func (s *SyncStore) UpdateCursor(resource, cursor string) error
- type UnifiedSearchResult
Constants ¶
const ( ResourceEmails = "emails" ResourceEvents = "events" ResourceContacts = "contacts" ResourceFolders = "folders" ResourceCalendars = "calendars" )
Resource types for sync state.
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 ¶
IsEncrypted checks if the database for an email is encrypted.
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 ¶
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 ¶
func (s *AttachmentStore) Get(id string) (*CachedAttachment, error)
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.
type ContactListOptions ¶
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 ¶
NewManager creates a new cache manager.
func (*Manager) ClearAllCaches ¶
ClearAllCaches removes all cache databases.
func (*Manager) ClearCache ¶
ClearCache removes the cache database for an email.
func (*Manager) GetStats ¶
func (m *Manager) GetStats(email string) (*CacheStats, error)
GetStats returns statistics for a cache database.
func (*Manager) ListCachedAccounts ¶
ListCachedAccounts returns emails that have cache databases.
type MarkReadPayload ¶
MarkReadPayload is the payload for mark read/unread actions.
type MovePayload ¶
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) 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 ¶
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) 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 ¶
LoadSettings loads settings from file, or creates default if not exists.
func (*Settings) GetMaxSizeBytes ¶
GetMaxSizeBytes returns the maximum cache size in bytes.
func (*Settings) GetSyncInterval ¶
GetSyncInterval returns the sync interval as a duration.
func (*Settings) IsCacheEnabled ¶
IsCacheEnabled returns whether caching is enabled.
func (*Settings) IsEncryptionEnabled ¶
IsEncryptionEnabled returns whether encryption is enabled.
func (*Settings) SetEnabled ¶
SetEnabled enables or disables caching.
func (*Settings) SetEncryption ¶
SetEncryption enables or disables encryption.
func (*Settings) SetMaxSize ¶
SetMaxSize sets the maximum cache size in MB.
func (*Settings) ToEncryptionConfig ¶
func (s *Settings) ToEncryptionConfig() EncryptionConfig
ToEncryptionConfig converts settings to EncryptionConfig.
type StarPayload ¶
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 ¶
NewSyncStore creates a sync store for a database.
func (*SyncStore) MarkSynced ¶
MarkSynced updates the last sync time for a resource.
func (*SyncStore) UpdateCursor ¶
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 ¶
UnifiedSearch performs search across all data types.