Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 96 additions & 60 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,88 +724,124 @@ end tell`;
}

case "mailboxes": {
if (args.account) {
const mailboxes = await mailModule.getMailboxesForAccount(
args.account,
);
try {
if (args.account) {
const mailboxes = await mailModule.getMailboxesForAccount(
args.account,
);
return {
content: [
{
type: "text",
text:
mailboxes.length > 0
? `Found ${mailboxes.length} mailboxes for account "${args.account}":\n\n${mailboxes.join("\n")}`
: `No mailboxes found for account "${args.account}". Make sure the account name is correct.`,
},
],
isError: false,
};
} else {
const mailboxes = await mailModule.getMailboxes();
return {
content: [
{
type: "text",
text:
mailboxes.length > 0
? `Found ${mailboxes.length} mailboxes:\n\n${mailboxes.join("\n")}`
: "No mailboxes found. Make sure Mail app is running and properly configured.",
},
],
isError: false,
};
}
} catch (error) {
return {
content: [
{
type: "text",
text:
mailboxes.length > 0
? `Found ${mailboxes.length} mailboxes for account "${args.account}":\n\n${mailboxes.join("\n")}`
: `No mailboxes found for account "${args.account}". Make sure the account name is correct.`,
text: `Error accessing mailboxes: ${error instanceof Error ? error.message : String(error)}`,
},
],
isError: false,
isError: true,
};
} else {
const mailboxes = await mailModule.getMailboxes();
}
}

case "accounts": {
try {
const accounts = await mailModule.getAccounts();
return {
content: [
{
type: "text",
text:
mailboxes.length > 0
? `Found ${mailboxes.length} mailboxes:\n\n${mailboxes.join("\n")}`
: "No mailboxes found. Make sure Mail app is running and properly configured.",
accounts.length > 0
? `Found ${accounts.length} email accounts:\n\n${accounts.join("\n")}`
: "No email accounts found. Make sure Mail app is configured with at least one account.",
},
],
isError: false,
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error accessing email accounts: ${error instanceof Error ? error.message : String(error)}`,
},
],
isError: true,
};
}
}

case "accounts": {
const accounts = await mailModule.getAccounts();
return {
content: [
{
type: "text",
text:
accounts.length > 0
? `Found ${accounts.length} email accounts:\n\n${accounts.join("\n")}`
: "No email accounts found. Make sure Mail app is configured with at least one account.",
},
],
isError: false,
};
}

case "latest": {
let account = args.account;
if (!account) {
const accounts = await mailModule.getAccounts();
if (accounts.length === 0) {
throw new Error(
"No email accounts found. Make sure Mail app is configured with at least one account.",
);
try {
let account = args.account;
if (!account) {
const accounts = await mailModule.getAccounts();
if (accounts.length === 0) {
throw new Error(
"No email accounts found. Make sure Mail app is configured with at least one account.",
);
}
account = accounts[0]; // Use the first account if not provided
}
account = accounts[0]; // Use the first account if not provided
const emails = await mailModule.getLatestMails(
account,
args.limit,
);
return {
content: [
{
type: "text",
text:
emails.length > 0
? `Found ${emails.length} latest email(s) in account "${account}":\n\n` +
emails
.map(
(email: any) =>
`[${email.dateSent}] From: ${email.sender}\nMailbox: ${email.mailbox}\nSubject: ${email.subject}\n${email.content.substring(0, 500)}${email.content.length > 500 ? "..." : ""}`,
)
.join("\n\n")
: `No latest emails found in account "${account}"`,
},
],
isError: false,
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error accessing latest emails: ${error instanceof Error ? error.message : String(error)}`,
},
],
isError: true,
};
}
const emails = await mailModule.getLatestMails(
account,
args.limit,
);
return {
content: [
{
type: "text",
text:
emails.length > 0
? `Found ${emails.length} latest email(s) in account "${account}":\n\n` +
emails
.map(
(email: any) =>
`[${email.dateSent}] From: ${email.sender}\nMailbox: ${email.mailbox}\nSubject: ${email.subject}\n${email.content.substring(0, 500)}${email.content.length > 500 ? "..." : ""}`,
)
.join("\n\n")
: `No latest emails found in account "${account}"`,
},
],
isError: false,
};
}

default:
Expand Down
Loading