fix: recover orphaned mail migration to bd v0.32.0
The merge at96c773flost changes from5791752(beads-sync branch). Re-implementing: - router.go: Use bd create --type=message with labels - mailbox.go: Use bd list/show/close instead of bd mail commands - types.go: Add Pinned field to Message struct Original work was in commits5791752and4c060f4on beads-sync. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,11 +85,15 @@ func (m *Mailbox) List() ([]*Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mailbox) listBeads() ([]*Message, error) {
|
func (m *Mailbox) listBeads() ([]*Message, error) {
|
||||||
// bd mail inbox --json
|
// bd list --type=message --assignee=<identity> --json --status=open
|
||||||
cmd := exec.Command("bd", "mail", "inbox", "--json")
|
cmd := exec.Command("bd", "list",
|
||||||
|
"--type", "message",
|
||||||
|
"--assignee", m.identity,
|
||||||
|
"--status", "open",
|
||||||
|
"--json",
|
||||||
|
)
|
||||||
cmd.Dir = m.workDir
|
cmd.Dir = m.workDir
|
||||||
cmd.Env = append(cmd.Environ(),
|
cmd.Env = append(cmd.Environ(),
|
||||||
"BD_IDENTITY="+m.identity,
|
|
||||||
"BEADS_DIR="+m.beadsDir,
|
"BEADS_DIR="+m.beadsDir,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -189,7 +193,7 @@ func (m *Mailbox) Get(id string) (*Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mailbox) getBeads(id string) (*Message, error) {
|
func (m *Mailbox) getBeads(id string) (*Message, error) {
|
||||||
cmd := exec.Command("bd", "mail", "read", id, "--json")
|
cmd := exec.Command("bd", "show", id, "--json")
|
||||||
cmd.Dir = m.workDir
|
cmd.Dir = m.workDir
|
||||||
cmd.Env = append(cmd.Environ(), "BEADS_DIR="+m.beadsDir)
|
cmd.Env = append(cmd.Environ(), "BEADS_DIR="+m.beadsDir)
|
||||||
|
|
||||||
@@ -208,12 +212,16 @@ func (m *Mailbox) getBeads(id string) (*Message, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var bm BeadsMessage
|
// bd show --json returns an array
|
||||||
if err := json.Unmarshal(stdout.Bytes(), &bm); err != nil {
|
var bms []BeadsMessage
|
||||||
|
if err := json.Unmarshal(stdout.Bytes(), &bms); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(bms) == 0 {
|
||||||
|
return nil, ErrMessageNotFound
|
||||||
|
}
|
||||||
|
|
||||||
return bm.ToMessage(), nil
|
return bms[0].ToMessage(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mailbox) getLegacy(id string) (*Message, error) {
|
func (m *Mailbox) getLegacy(id string) (*Message, error) {
|
||||||
@@ -238,7 +246,7 @@ func (m *Mailbox) MarkRead(id string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mailbox) markReadBeads(id string) error {
|
func (m *Mailbox) markReadBeads(id string) error {
|
||||||
cmd := exec.Command("bd", "mail", "ack", id)
|
cmd := exec.Command("bd", "close", id)
|
||||||
cmd.Dir = m.workDir
|
cmd.Dir = m.workDir
|
||||||
cmd.Env = append(cmd.Environ(), "BEADS_DIR="+m.beadsDir)
|
cmd.Env = append(cmd.Environ(), "BEADS_DIR="+m.beadsDir)
|
||||||
|
|
||||||
|
|||||||
@@ -105,31 +105,31 @@ func isTownLevelAddress(address string) bool {
|
|||||||
func (r *Router) Send(msg *Message) error {
|
func (r *Router) Send(msg *Message) error {
|
||||||
// Convert addresses to beads identities
|
// Convert addresses to beads identities
|
||||||
toIdentity := addressToIdentity(msg.To)
|
toIdentity := addressToIdentity(msg.To)
|
||||||
fromIdentity := addressToIdentity(msg.From)
|
|
||||||
|
|
||||||
// Build command: bd mail send <recipient> -s <subject> -m <body>
|
// Build labels for from/thread/reply-to
|
||||||
args := []string{"mail", "send", toIdentity,
|
var labels []string
|
||||||
"-s", msg.Subject,
|
labels = append(labels, "from:"+msg.From)
|
||||||
"-m", msg.Body,
|
if msg.ThreadID != "" {
|
||||||
|
labels = append(labels, "thread:"+msg.ThreadID)
|
||||||
|
}
|
||||||
|
if msg.ReplyTo != "" {
|
||||||
|
labels = append(labels, "reply-to:"+msg.ReplyTo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build command: bd create <subject> --type=message --assignee=<recipient> -d <body>
|
||||||
|
args := []string{"create", msg.Subject,
|
||||||
|
"--type", "message",
|
||||||
|
"--assignee", toIdentity,
|
||||||
|
"-d", msg.Body,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add priority flag
|
// Add priority flag
|
||||||
beadsPriority := PriorityToBeads(msg.Priority)
|
beadsPriority := PriorityToBeads(msg.Priority)
|
||||||
args = append(args, "--priority", fmt.Sprintf("%d", beadsPriority))
|
args = append(args, "--priority", fmt.Sprintf("%d", beadsPriority))
|
||||||
|
|
||||||
// Add message type if set
|
// Add labels
|
||||||
if msg.Type != "" && msg.Type != TypeNotification {
|
if len(labels) > 0 {
|
||||||
args = append(args, "--type", string(msg.Type))
|
args = append(args, "--labels", strings.Join(labels, ","))
|
||||||
}
|
|
||||||
|
|
||||||
// Add thread ID if set
|
|
||||||
if msg.ThreadID != "" {
|
|
||||||
args = append(args, "--thread-id", msg.ThreadID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add reply-to if set
|
|
||||||
if msg.ReplyTo != "" {
|
|
||||||
args = append(args, "--reply-to", msg.ReplyTo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve the correct beads directory for the recipient
|
// Resolve the correct beads directory for the recipient
|
||||||
@@ -137,7 +137,6 @@ func (r *Router) Send(msg *Message) error {
|
|||||||
|
|
||||||
cmd := exec.Command("bd", args...)
|
cmd := exec.Command("bd", args...)
|
||||||
cmd.Env = append(cmd.Environ(),
|
cmd.Env = append(cmd.Environ(),
|
||||||
"BEADS_AGENT_NAME="+fromIdentity,
|
|
||||||
"BEADS_DIR="+beadsDir,
|
"BEADS_DIR="+beadsDir,
|
||||||
)
|
)
|
||||||
cmd.Dir = filepath.Dir(beadsDir) // Run in parent of .beads
|
cmd.Dir = filepath.Dir(beadsDir) // Run in parent of .beads
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ type Message struct {
|
|||||||
|
|
||||||
// ReplyTo is the ID of the message this is replying to.
|
// ReplyTo is the ID of the message this is replying to.
|
||||||
ReplyTo string `json:"reply_to,omitempty"`
|
ReplyTo string `json:"reply_to,omitempty"`
|
||||||
|
|
||||||
|
// Pinned marks the message as pinned (won't be auto-archived).
|
||||||
|
Pinned bool `json:"pinned,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMessage creates a new message with a generated ID and thread ID.
|
// NewMessage creates a new message with a generated ID and thread ID.
|
||||||
|
|||||||
Reference in New Issue
Block a user