Skip to content

Refactor duplicated email keyword/patch methods in client #19

@cboone

Description

@cboone

Summary

The internal/client/email.go file contains several nearly identical methods for updating email properties via JMAP patches:

  • MarkAsRead() — sets keywords/$seen to true
  • SetFlagged() — sets keywords/$flagged to true
  • SetUnflagged() — sets keywords/$flagged to nil
  • MarkAsSpam() — moves to junk mailbox
  • MoveEmails() — moves to a target mailbox

The first three in particular share the same structure: batch loop, patch construction, request/response handling, and error collection. They differ only in the patch value applied.

Proposal

Extract a shared helper, something like:

func (c *Client) patchEmails(emailIDs []string, patchFn func(id string) jmap.Patch) (succeeded []string, errors []string)

Each caller would then reduce to a one-liner supplying its patch. MarkAsSpam and MoveEmails may also benefit if their mailbox-lookup logic can be separated from the patch-and-send loop.

Context

This duplication was introduced incrementally as new commands were added (mark-read, then flag/unflag in #15). Each method is ~55 lines and they share ~90% of their code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions