@agenticmail/api 0.9.19 → 0.9.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2468,9 +2468,10 @@ function createMailRoutes(accountManager, config, db, gatewayManager) {
2468
2468
  res.status(400).json({ error: "Invalid UID" });
2469
2469
  return;
2470
2470
  }
2471
+ const folder = req.body?.folder || "INBOX";
2471
2472
  const password = getAgentPassword(agent);
2472
2473
  const receiver = await getReceiver(agent.stalwartPrincipal, password, config);
2473
- await receiver.markUnseen(uid);
2474
+ await receiver.markUnseen(uid, folder);
2474
2475
  invalidateParsedMessage(agent.id, uid);
2475
2476
  res.json({ ok: true });
2476
2477
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/api",
3
- "version": "0.9.19",
3
+ "version": "0.9.20",
4
4
  "description": "REST API server for AgenticMail — email and SMS endpoints for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -36,7 +36,20 @@ export async function openMessage(uid) {
36
36
  document.getElementById('msg-delete').addEventListener('click', () => deleteMessage());
37
37
 
38
38
  try {
39
- const msg = await apiGet(`/mail/messages/${uid}`, { agentKey: state.selectedAgent.apiKey });
39
+ // Pass the current folder so the API fetches from the right
40
+ // mailbox — Spam / Archive / Trash UIDs don't exist in INBOX,
41
+ // and the API defaults `folder` to INBOX when omitted. Without
42
+ // this, opening a message from any non-Inbox folder 404'd
43
+ // with `MESSAGE_NOT_FOUND` because UID N existed in (say) Junk
44
+ // Mail but the API looked in INBOX.
45
+ //
46
+ // We resolve the IMAP folder name via state.folderNames (the
47
+ // map populated by /mail/folders auto-discovery) so renames
48
+ // like Stalwart's "Junk Mail" vs "Spam" are handled in one
49
+ // place. "inbox" maps to "INBOX" by convention.
50
+ const imap = state.folderNames?.[state.selectedFolder] ?? 'INBOX';
51
+ const qs = imap && imap !== 'INBOX' ? `?folder=${encodeURIComponent(imap)}` : '';
52
+ const msg = await apiGet(`/mail/messages/${uid}${qs}`, { agentKey: state.selectedAgent.apiKey });
40
53
  state.currentMessage = msg;
41
54
  renderMessage(msg);
42
55
  } catch (err) {
@@ -220,7 +233,8 @@ function renderThreadQuote(dateRaw, sender, quotedBody) {
220
233
  async function markUnread() {
221
234
  if (!state.currentMessage || !state.selectedAgent) return;
222
235
  try {
223
- await apiPost(`/mail/messages/${state.selectedUid}/unseen`, {}, { agentKey: state.selectedAgent.apiKey });
236
+ const imap = state.folderNames?.[state.selectedFolder] ?? 'INBOX';
237
+ await apiPost(`/mail/messages/${state.selectedUid}/unseen`, { folder: imap }, { agentKey: state.selectedAgent.apiKey });
224
238
  toast('Marked unread.');
225
239
  location.hash = `#/folder/${state.selectedFolder ?? 'inbox'}`;
226
240
  await loadList(state.selectedAgent, state.selectedFolder);
@@ -262,7 +276,8 @@ async function markSpam() {
262
276
  });
263
277
  if (!ok) return;
264
278
  try {
265
- await apiPost(`/mail/messages/${state.selectedUid}/spam`, {}, { agentKey: state.selectedAgent.apiKey });
279
+ const imap = state.folderNames?.[state.selectedFolder] ?? 'INBOX';
280
+ await apiPost(`/mail/messages/${state.selectedUid}/spam`, { folder: imap }, { agentKey: state.selectedAgent.apiKey });
266
281
  toast('Reported as spam.');
267
282
  location.hash = `#/folder/${state.selectedFolder ?? 'inbox'}`;
268
283
  await loadList(state.selectedAgent, state.selectedFolder);