@marlinjai/email-mcp 1.7.1 → 1.7.2

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.
@@ -245,6 +245,18 @@ var CredentialStore = class {
245
245
  const data = this.read();
246
246
  return Object.values(data.accounts);
247
247
  }
248
+ /**
249
+ * The account already configured for this mailbox, if any. Provider plus
250
+ * address identifies a mailbox; the address comparison is case-insensitive
251
+ * because providers report it in varying case.
252
+ */
253
+ async findByProviderAndEmail(provider, email) {
254
+ const wanted = email.trim().toLowerCase();
255
+ const data = this.read();
256
+ return Object.values(data.accounts).find(
257
+ (a) => a.provider === provider && a.email.trim().toLowerCase() === wanted
258
+ ) ?? null;
259
+ }
248
260
  async remove(id) {
249
261
  const data = this.read();
250
262
  delete data.accounts[id];
@@ -2881,6 +2893,14 @@ async function testAndSave(creds) {
2881
2893
  async function promptAccountName(defaultName) {
2882
2894
  return askText("Account name:", defaultName);
2883
2895
  }
2896
+ async function resolveAccountIdentity(provider, email, defaultName) {
2897
+ const existing = await store.findByProviderAndEmail(provider, email);
2898
+ if (existing) {
2899
+ console.log(`An account for ${email} already exists ("${existing.name}"), updating it in place.`);
2900
+ return { id: existing.id, name: await promptAccountName(existing.name) };
2901
+ }
2902
+ return { id: crypto4.randomUUID(), name: await promptAccountName(defaultName) };
2903
+ }
2884
2904
  async function setupGmail(scopeModeFlag) {
2885
2905
  console.log("\n--- Gmail Setup ---");
2886
2906
  if (process.env.EMAIL_MCP_GMAIL_CLIENT_ID) {
@@ -2927,8 +2947,7 @@ ${url}
2927
2947
  const email = profile.emailAddress ?? "";
2928
2948
  if (!email) throw new Error("Could not retrieve Gmail address from profile");
2929
2949
  console.log(`Authenticated as ${email}`);
2930
- const name = await promptAccountName("Gmail");
2931
- const id = crypto4.randomUUID();
2950
+ const { id, name } = await resolveAccountIdentity(ProviderType.Gmail, email.trim(), "Gmail");
2932
2951
  const creds = {
2933
2952
  id,
2934
2953
  name,
@@ -2965,8 +2984,7 @@ ${url}
2965
2984
  const email = account?.username ?? "";
2966
2985
  if (!email) throw new Error("Could not retrieve email from Microsoft account");
2967
2986
  console.log(`Authenticated as ${email}`);
2968
- const name = await promptAccountName("Outlook");
2969
- const id = crypto4.randomUUID();
2987
+ const { id, name } = await resolveAccountIdentity(ProviderType.Outlook, email.trim(), "Outlook");
2970
2988
  const creds = {
2971
2989
  id,
2972
2990
  name,
@@ -2997,8 +3015,7 @@ async function setupICloud() {
2997
3015
  console.log(" Password is required");
2998
3016
  password = await askPassword("App-specific password:");
2999
3017
  }
3000
- const name = await promptAccountName("iCloud");
3001
- const id = crypto4.randomUUID();
3018
+ const { id, name } = await resolveAccountIdentity(ProviderType.ICloud, email.trim(), "iCloud");
3002
3019
  const creds = {
3003
3020
  id,
3004
3021
  name,
@@ -3038,8 +3055,7 @@ async function setupIMAP() {
3038
3055
  const smtpPortStr = await askValidated("SMTP port:", "587", portValidator);
3039
3056
  smtpPort = parseInt(smtpPortStr, 10);
3040
3057
  }
3041
- const name = await promptAccountName("IMAP");
3042
- const id = crypto4.randomUUID();
3058
+ const { id, name } = await resolveAccountIdentity(ProviderType.IMAP, email.trim(), "IMAP");
3043
3059
  const creds = {
3044
3060
  id,
3045
3061
  name,