deletion

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package deletion provides safe, staged email deletion from Gmail.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecuteOptions

type ExecuteOptions struct {
	Method    Method // Trash or permanent delete
	BatchSize int    // Messages per batch for batch delete API
	Resume    bool   // Resume from last checkpoint
}

ExecuteOptions configures deletion execution.

func DefaultExecuteOptions

func DefaultExecuteOptions() *ExecuteOptions

DefaultExecuteOptions returns sensible defaults.

type Execution

type Execution struct {
	StartedAt          time.Time  `json:"started_at"`
	CompletedAt        *time.Time `json:"completed_at,omitempty"`
	Method             Method     `json:"method"`
	Succeeded          int        `json:"succeeded"`
	Failed             int        `json:"failed"`
	FailedIDs          []string   `json:"failed_ids,omitempty"`
	LastProcessedIndex int        `json:"last_processed_index"` // For resumability
}

Execution tracks progress of a deletion operation.

type Executor

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

Executor performs deletion operations.

func NewExecutor

func NewExecutor(manager *Manager, store *store.Store, client gmail.API) *Executor

NewExecutor creates a deletion executor.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, manifestID string, opts *ExecuteOptions) error

Execute performs the deletion for a manifest.

func (*Executor) ExecuteBatch

func (e *Executor) ExecuteBatch(ctx context.Context, manifestID string) error

ExecuteBatch performs batch deletion (more efficient but permanent).

func (*Executor) WithLogger

func (e *Executor) WithLogger(logger *slog.Logger) *Executor

WithLogger sets the logger.

func (*Executor) WithProgress

func (e *Executor) WithProgress(p Progress) *Executor

WithProgress sets the progress reporter.

type Filters

type Filters struct {
	Senders       []string `json:"senders,omitempty"`
	SenderDomains []string `json:"sender_domains,omitempty"`
	Recipients    []string `json:"recipients,omitempty"`
	Labels        []string `json:"labels,omitempty"`
	After         string   `json:"after,omitempty"`  // ISO date
	Before        string   `json:"before,omitempty"` // ISO date
	Account       string   `json:"account,omitempty"`
}

Filters specifies criteria for selecting messages.

type Manager

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

Manager handles deletion manifest files.

func NewManager

func NewManager(baseDir string) (*Manager, error)

NewManager creates a deletion manager.

func (*Manager) CancelManifest

func (m *Manager) CancelManifest(id string) error

CancelManifest removes a pending or in-progress manifest.

func (*Manager) CompletedDir

func (m *Manager) CompletedDir() string

CompletedDir returns the path to the completed directory.

func (*Manager) CreateManifest

func (m *Manager) CreateManifest(description string, gmailIDs []string, filters Filters) (*Manifest, error)

CreateManifest creates and saves a new manifest.

func (*Manager) FailedDir

func (m *Manager) FailedDir() string

FailedDir returns the path to the failed directory.

func (*Manager) GetManifest

func (m *Manager) GetManifest(id string) (*Manifest, string, error)

GetManifest loads a manifest by ID from any status directory.

func (*Manager) InProgressDir

func (m *Manager) InProgressDir() string

InProgressDir returns the path to the in_progress directory.

func (*Manager) ListCompleted

func (m *Manager) ListCompleted() ([]*Manifest, error)

ListCompleted returns all completed deletion manifests.

func (*Manager) ListFailed

func (m *Manager) ListFailed() ([]*Manifest, error)

ListFailed returns all failed deletion manifests.

func (*Manager) ListInProgress

func (m *Manager) ListInProgress() ([]*Manifest, error)

ListInProgress returns all in-progress deletion manifests.

func (*Manager) ListPending

func (m *Manager) ListPending() ([]*Manifest, error)

ListPending returns all pending deletion manifests.

func (*Manager) MoveManifest

func (m *Manager) MoveManifest(id string, fromStatus, toStatus Status) error

MoveManifest moves a manifest from one status directory to another.

func (*Manager) PendingDir

func (m *Manager) PendingDir() string

PendingDir returns the path to the pending directory.

func (*Manager) SaveManifest

func (m *Manager) SaveManifest(manifest *Manifest) error

SaveManifest saves a manifest to the appropriate directory based on status.

type Manifest

type Manifest struct {
	Version     int        `json:"version"`
	ID          string     `json:"id"`
	CreatedAt   time.Time  `json:"created_at"`
	CreatedBy   string     `json:"created_by"` // "tui", "cli", "api"
	Description string     `json:"description"`
	Filters     Filters    `json:"filters"`
	Summary     *Summary   `json:"summary,omitempty"`
	GmailIDs    []string   `json:"gmail_ids"`
	Status      Status     `json:"status"`
	Execution   *Execution `json:"execution,omitempty"`
}

Manifest represents a deletion batch.

func LoadManifest

func LoadManifest(path string) (*Manifest, error)

LoadManifest reads a manifest from a JSON file.

func NewManifest

func NewManifest(description string, gmailIDs []string) *Manifest

NewManifest creates a new deletion manifest.

func (*Manifest) FormatSummary

func (m *Manifest) FormatSummary() string

FormatSummary returns a human-readable summary of the deletion.

func (*Manifest) Save

func (m *Manifest) Save(path string) error

Save writes the manifest to a JSON file.

type Method

type Method string

Method represents how messages are deleted.

const (
	MethodTrash  Method = "trash"  // Move to Gmail trash (30-day recovery)
	MethodDelete Method = "delete" // Permanent deletion
)

type NullProgress

type NullProgress struct{}

NullProgress is a no-op progress reporter.

func (NullProgress) OnComplete

func (NullProgress) OnComplete(succeeded, failed int)

func (NullProgress) OnProgress

func (NullProgress) OnProgress(processed, succeeded, failed int)

func (NullProgress) OnStart

func (NullProgress) OnStart(total int)

type Progress

type Progress interface {
	OnStart(total int)
	OnProgress(processed, succeeded, failed int)
	OnComplete(succeeded, failed int)
}

Progress reports deletion progress.

type SenderCount

type SenderCount struct {
	Sender string `json:"sender"`
	Count  int    `json:"count"`
}

SenderCount represents a sender and their message count.

type Status

type Status string

Status represents the state of a deletion batch.

const (
	StatusPending    Status = "pending"
	StatusInProgress Status = "in_progress"
	StatusCompleted  Status = "completed"
	StatusFailed     Status = "failed"
	StatusCancelled  Status = "cancelled"
)

type Summary

type Summary struct {
	MessageCount   int           `json:"message_count"`
	TotalSizeBytes int64         `json:"total_size_bytes"`
	DateRange      [2]string     `json:"date_range"` // [earliest, latest]
	Accounts       []string      `json:"accounts"`
	TopSenders     []SenderCount `json:"top_senders"`
}

Summary contains statistics about messages to be deleted.

Jump to

Keyboard shortcuts

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