@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.
package/dist/index.js CHANGED
@@ -175,6 +175,18 @@ var init_credential_store = __esm({
175
175
  const data = this.read();
176
176
  return Object.values(data.accounts);
177
177
  }
178
+ /**
179
+ * The account already configured for this mailbox, if any. Provider plus
180
+ * address identifies a mailbox; the address comparison is case-insensitive
181
+ * because providers report it in varying case.
182
+ */
183
+ async findByProviderAndEmail(provider, email3) {
184
+ const wanted = email3.trim().toLowerCase();
185
+ const data = this.read();
186
+ return Object.values(data.accounts).find(
187
+ (a) => a.provider === provider && a.email.trim().toLowerCase() === wanted
188
+ ) ?? null;
189
+ }
178
190
  async remove(id) {
179
191
  const data = this.read();
180
192
  delete data.accounts[id];
@@ -9788,6 +9800,14 @@ async function testAndSave(creds) {
9788
9800
  async function promptAccountName(defaultName) {
9789
9801
  return askText("Account name:", defaultName);
9790
9802
  }
9803
+ async function resolveAccountIdentity(provider, email3, defaultName) {
9804
+ const existing = await store.findByProviderAndEmail(provider, email3);
9805
+ if (existing) {
9806
+ console.log(`An account for ${email3} already exists ("${existing.name}"), updating it in place.`);
9807
+ return { id: existing.id, name: await promptAccountName(existing.name) };
9808
+ }
9809
+ return { id: crypto5.randomUUID(), name: await promptAccountName(defaultName) };
9810
+ }
9791
9811
  async function setupGmail(scopeModeFlag) {
9792
9812
  console.log("\n--- Gmail Setup ---");
9793
9813
  if (process.env.EMAIL_MCP_GMAIL_CLIENT_ID) {
@@ -9834,8 +9854,7 @@ ${url2}
9834
9854
  const email3 = profile.emailAddress ?? "";
9835
9855
  if (!email3) throw new Error("Could not retrieve Gmail address from profile");
9836
9856
  console.log(`Authenticated as ${email3}`);
9837
- const name = await promptAccountName("Gmail");
9838
- const id = crypto5.randomUUID();
9857
+ const { id, name } = await resolveAccountIdentity(ProviderType.Gmail, email3.trim(), "Gmail");
9839
9858
  const creds = {
9840
9859
  id,
9841
9860
  name,
@@ -9872,8 +9891,7 @@ ${url2}
9872
9891
  const email3 = account?.username ?? "";
9873
9892
  if (!email3) throw new Error("Could not retrieve email from Microsoft account");
9874
9893
  console.log(`Authenticated as ${email3}`);
9875
- const name = await promptAccountName("Outlook");
9876
- const id = crypto5.randomUUID();
9894
+ const { id, name } = await resolveAccountIdentity(ProviderType.Outlook, email3.trim(), "Outlook");
9877
9895
  const creds = {
9878
9896
  id,
9879
9897
  name,
@@ -9904,8 +9922,7 @@ async function setupICloud() {
9904
9922
  console.log(" Password is required");
9905
9923
  password = await askPassword("App-specific password:");
9906
9924
  }
9907
- const name = await promptAccountName("iCloud");
9908
- const id = crypto5.randomUUID();
9925
+ const { id, name } = await resolveAccountIdentity(ProviderType.ICloud, email3.trim(), "iCloud");
9909
9926
  const creds = {
9910
9927
  id,
9911
9928
  name,
@@ -9945,8 +9962,7 @@ async function setupIMAP() {
9945
9962
  const smtpPortStr = await askValidated("SMTP port:", "587", portValidator);
9946
9963
  smtpPort = parseInt(smtpPortStr, 10);
9947
9964
  }
9948
- const name = await promptAccountName("IMAP");
9949
- const id = crypto5.randomUUID();
9965
+ const { id, name } = await resolveAccountIdentity(ProviderType.IMAP, email3.trim(), "IMAP");
9950
9966
  const creds = {
9951
9967
  id,
9952
9968
  name,