mail archive search
This commit is contained in:
parent
af07a3d6de
commit
4dbfccf189
Binary file not shown.
|
|
@ -1334,7 +1334,7 @@ func openArchiveWindow(owner, date string) error {
|
||||||
} else {
|
} else {
|
||||||
w.Name(fmt.Sprintf("/AnviLLM/%s/archive", owner))
|
w.Name(fmt.Sprintf("/AnviLLM/%s/archive", owner))
|
||||||
}
|
}
|
||||||
w.Write("tag", []byte("Get "))
|
w.Write("tag", []byte("Get Search "))
|
||||||
|
|
||||||
go handleArchiveWindow(w, owner, date)
|
go handleArchiveWindow(w, owner, date)
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -1357,7 +1357,9 @@ func handleArchiveWindow(w *acme.Win, owner, date string) {
|
||||||
for e := range w.EventChan() {
|
for e := range w.EventChan() {
|
||||||
switch e.C2 {
|
switch e.C2 {
|
||||||
case 'x', 'X':
|
case 'x', 'X':
|
||||||
switch string(e.Text) {
|
cmd := string(e.Text)
|
||||||
|
arg := strings.TrimSpace(string(e.Arg))
|
||||||
|
switch cmd {
|
||||||
case "Get":
|
case "Get":
|
||||||
// Re-read date from window name
|
// Re-read date from window name
|
||||||
tag, _ := w.ReadAll("tag")
|
tag, _ := w.ReadAll("tag")
|
||||||
|
|
@ -1369,6 +1371,50 @@ func handleArchiveWindow(w *acme.Win, owner, date string) {
|
||||||
messages, _, loadErr = listMessages(owner + "/completed")
|
messages, _, loadErr = listMessages(owner + "/completed")
|
||||||
}
|
}
|
||||||
refreshArchiveWindowWithMessages(w, messages, owner, date, loadErr)
|
refreshArchiveWindowWithMessages(w, messages, owner, date, loadErr)
|
||||||
|
case "Search":
|
||||||
|
if arg == "" {
|
||||||
|
w.WriteEvent(e)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out, err := exec.Command("bash", "-c", fmt.Sprintf("bash <(9p read anvillm/tools/mail_search.sh) --agent-id user --pattern %q", arg)).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
w.Addr(",")
|
||||||
|
w.Write("data", []byte(fmt.Sprintf("Search error: %v\n%s", err, out)))
|
||||||
|
w.Ctl("clean")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var searchResults []Message
|
||||||
|
for _, line := range strings.Split(string(out), "\n") {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var entry struct {
|
||||||
|
Ts int64 `json:"ts"`
|
||||||
|
Data struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
From string `json:"from"`
|
||||||
|
To string `json:"to"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Subject string `json:"subject"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal([]byte(line), &entry); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
searchResults = append(searchResults, Message{
|
||||||
|
ID: entry.Data.ID,
|
||||||
|
From: entry.Data.From,
|
||||||
|
To: entry.Data.To,
|
||||||
|
Type: entry.Data.Type,
|
||||||
|
Subject: entry.Data.Subject,
|
||||||
|
Body: entry.Data.Body,
|
||||||
|
Timestamp: entry.Ts,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
messages = searchResults
|
||||||
|
refreshArchiveWindowWithMessages(w, messages, owner, "", nil)
|
||||||
default:
|
default:
|
||||||
w.WriteEvent(e)
|
w.WriteEvent(e)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,4 @@ if [[ ${#FILES[@]} -eq 0 ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat "${FILES[@]}" | jq -rs 'sort_by(.ts) | .[] |
|
cat "${FILES[@]}" | jq -cs 'sort_by(.ts) | .[]'
|
||||||
"\(.ts | strftime("%Y-%m-%d %H:%M:%S")) [\(.data.type)] \(.data.from) → \(.data.to)
|
|
||||||
Subject: \(.data.subject)
|
|
||||||
\(.data.body | split("\n") | join("\n "))
|
|
||||||
"'
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,22 @@ if [[ -z "$AGENT_ID" ]] || [[ -z "$PATTERN" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATE_FLAG=""
|
MAIL_DIR="$HOME/.local/share/anvillm/mail/$AGENT_ID"
|
||||||
[[ -n "$DATE" ]] && DATE_FLAG="--date $DATE"
|
|
||||||
|
|
||||||
bash <(9p read anvillm/tools/mail_history.sh) --agent-id "$AGENT_ID" $DATE_FLAG | grep -E "$PATTERN"
|
shopt -s nullglob
|
||||||
|
if [[ -n "$DATE" ]]; then
|
||||||
|
SENT="$MAIL_DIR/${DATE}-sent.jsonl"
|
||||||
|
RECV="$MAIL_DIR/${DATE}-recv.jsonl"
|
||||||
|
FILES=()
|
||||||
|
[[ -f "$SENT" ]] && FILES+=("$SENT")
|
||||||
|
[[ -f "$RECV" ]] && FILES+=("$RECV")
|
||||||
|
else
|
||||||
|
FILES=("$MAIL_DIR"/*-sent.jsonl "$MAIL_DIR"/*-recv.jsonl)
|
||||||
|
fi
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
|
if [[ ${#FILES[@]} -eq 0 ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat "${FILES[@]}" | grep -E "$PATTERN"
|
||||||
|
|
|
||||||
Reference in New Issue