AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(imap): clearer connection setup, full folder paths and a delete warning (#15822)
Talal Jaber269918bd16e7
diff --git a/bun.lock b/bun.lockindex 400690c8935..771fadcd26a 100644--- a/bun.lock+++ b/bun.lock@@ -4497,7 +4497,7 @@},"packages/pieces/community/imap": {"name": "@activepieces/piece-imap",- "version": "0.5.0",+ "version": "0.6.0","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",diff --git a/packages/pieces/community/imap/package.json b/packages/pieces/community/imap/package.jsonindex e8afe53f125..d4e6b35e8b3 100644--- a/packages/pieces/community/imap/package.json+++ b/packages/pieces/community/imap/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/piece-imap",- "version": "0.5.0",+ "version": "0.6.0","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","dependencies": {diff --git a/packages/pieces/community/imap/src/index.ts b/packages/pieces/community/imap/src/index.tsindex 4fcdcac967f..a29e8860a56 100644--- a/packages/pieces/community/imap/src/index.ts+++ b/packages/pieces/community/imap/src/index.ts@@ -24,7 +24,7 @@ import { createDraft } from './lib/actions/create-draft';export const imapPiece = createPiece({displayName: 'IMAP',- description: 'Receive new email trigger',+ description: 'Watch for new emails and copy, move, mark or delete them over IMAP.',minimumSupportedRelease: '0.88.2',logoUrl: 'https://cdn.activepieces.com/pieces/imap.png',categories: [PieceCategory.BUSINESS_INTELLIGENCE],diff --git a/packages/pieces/community/imap/src/lib/actions/copy-email.ts b/packages/pieces/community/imap/src/lib/actions/copy-email.tsindex 946162f3259..d024acaac02 100644--- a/packages/pieces/community/imap/src/lib/actions/copy-email.ts+++ b/packages/pieces/community/imap/src/lib/actions/copy-email.ts@@ -9,17 +9,17 @@ import { copyEmailActionOutputSchema } from '../output-schemas';const props = {sourceMailbox: mailboxDropdown({displayName: 'Source Folder',- description: 'Folder to copy the email from.',+ description: 'Folder the email is in.',required: true,}),uid: Property.Number({displayName: 'Message UID',- description: 'The UID of the email to copy.',+ description: "Map uid from the New Email trigger. It's only valid in its folder.",required: true,}),targetMailbox: mailboxDropdown({displayName: 'Target Folder',- description: 'Folder to copy the email to.',+ description: 'Folder to put the copy in.',required: true,}),};@@ -29,7 +29,7 @@ export const copyEmail = createAction({name: 'copy_email',classification: 'WRITE',displayName: 'Copy Email',- description: 'Copy an email to another mailbox',+ description: 'Copy an email to another folder and keep the original.',outputSchema: copyEmailActionOutputSchema,audience: 'human',aiMetadata: { description: 'Copies an email (by message UID) from a source IMAP folder into a target folder, leaving the original in place. Use to duplicate a message into another mailbox without removing it from the source. Requires the source folder, target folder, and the UID; not idempotent since each call appends another copy with a new UID.', idempotent: false },diff --git a/packages/pieces/community/imap/src/lib/actions/delete-email.ts b/packages/pieces/community/imap/src/lib/actions/delete-email.tsindex 001701a1363..7ee0cf401c9 100644--- a/packages/pieces/community/imap/src/lib/actions/delete-email.ts+++ b/packages/pieces/community/imap/src/lib/actions/delete-email.ts@@ -1,27 +1,24 @@-import { createAction, Property } from '@activepieces/pieces-framework';+import { createAction, MarkdownVariant, Property } from '@activepieces/pieces-framework';import { imapAuth, deleteEmail as deleteImapEmail, mailboxDropdown } from '../common';import { deleteEmailActionOutputSchema } from '../output-schemas';-const permanentDeletionNotice = `-**Permanent Deletion:**--This action permanently deletes the email. This action cannot be undone. To move an email to the Trash folder, use the Move Email action instead.-`;+const permanentDeletionNotice = `This deletes the email for good and can't be undone. To keep it recoverable, use **Move Email** to send it to Trash instead.`;const props = {+ permanentDeletionNotice: Property.MarkDown({+ value: permanentDeletionNotice,+ variant: MarkdownVariant.WARNING,+ }),mailbox: mailboxDropdown({- displayName: 'Parent Folder',- description: 'Folder to delete the email from.',+ displayName: 'Folder',+ description: 'Folder the email is in.',required: true,}),uid: Property.Number({displayName: 'Message UID',- description: 'The UID of the email to delete.',+ description: "Map uid from the New Email trigger. It's only valid in its folder.",required: true,}),- permanentDeletionNotice: Property.MarkDown({- value: permanentDeletionNotice,- }),};export const deleteEmail = createAction({@@ -29,7 +26,7 @@ export const deleteEmail = createAction({name: 'delete_email',classification: 'DESTRUCTIVE',displayName: 'Delete Email',- description: 'Permanently delete an email',+ description: 'Permanently delete an email.',outputSchema: deleteEmailActionOutputSchema,audience: 'human',aiMetadata: { description: 'Permanently deletes an email (by message UID) from an IMAP folder; this cannot be undone and does not move the message to Trash (use Move Email for that). Use only when irreversible removal is intended. Requires the folder and the UID; destructive and not idempotent since a repeat call cannot find the already-deleted message.', idempotent: false },diff --git a/packages/pieces/community/imap/src/lib/actions/mark-email-read.ts b/packages/pieces/community/imap/src/lib/actions/mark-email-read.tsindex d7afa8f37d4..d1036bccbdd 100644--- a/packages/pieces/community/imap/src/lib/actions/mark-email-read.ts+++ b/packages/pieces/community/imap/src/lib/actions/mark-email-read.ts@@ -4,18 +4,18 @@ import { markEmailReadActionOutputSchema } from '../output-schemas';const props = {mailbox: mailboxDropdown({- displayName: 'Parent Folder',- description: 'Select the parent folder containing the email.',+ displayName: 'Folder',+ description: 'Folder the email is in.',required: true,}),uid: Property.Number({displayName: 'Message UID',- description: 'The UID of the email to mark.',+ description: "Map uid from the New Email trigger. It's only valid in its folder.",required: true,}),markAsRead: Property.Checkbox({displayName: 'Mark as Read',- description: 'Check to mark as read, uncheck to mark as unread.',+ description: 'Turn off to mark the email as unread instead.',defaultValue: true,required: false,}),@@ -26,7 +26,7 @@ export const markEmailAsRead = createAction({name: 'mark_email_read',classification: 'WRITE',displayName: 'Mark Email as Read/Unread',- description: 'Sets the read status of an email',+ description: 'Mark an email as read or unread.',outputSchema: markEmailReadActionOutputSchema,audience: 'human',aiMetadata: { description: 'Sets the read/unread (\\Seen) flag on a specific email in an IMAP mailbox, identified by its message UID. Use to mark a message as read after processing it or to flag one as unread. Requires the exact mailbox folder and UID; this is idempotent since it sets the flag to the chosen target state.', idempotent: true },diff --git a/packages/pieces/community/imap/src/lib/actions/move-email.ts b/packages/pieces/community/imap/src/lib/actions/move-email.tsindex e0f5077fc0e..00689eac48b 100644--- a/packages/pieces/community/imap/src/lib/actions/move-email.ts+++ b/packages/pieces/community/imap/src/lib/actions/move-email.ts@@ -5,17 +5,17 @@ import { moveEmailActionOutputSchema } from '../output-schemas';const props = {sourceMailbox: mailboxDropdown({displayName: 'Source Folder',- description: 'Folder to move the email from.',+ description: 'Folder the email is in.',required: true,}),uid: Property.Number({displayName: 'Message UID',- description: 'The UID of the email to move.',+ description: "Map uid from the New Email trigger. It's only valid in its folder.",required: true,}),targetMailbox: mailboxDropdown({displayName: 'Target Folder',- description: 'Destination folder for the email.',+ description: 'Folder to move the email to.',required: true,}),};@@ -25,7 +25,7 @@ export const moveEmail = createAction({name: 'move_email',classification: 'WRITE',displayName: 'Move Email',- description: 'Move an email to another mailbox',+ description: 'Move an email to another folder.',outputSchema: moveEmailActionOutputSchema,audience: 'human',aiMetadata: { description: 'Moves an email (by message UID) from a source IMAP folder to a target folder, removing it from the source. Use to file, archive, or send a message to a Trash folder. Requires the source folder, target folder, and the UID; not idempotent since after the move the message no longer exists at the source UID and a repeat call cannot find it.', idempotent: false },diff --git a/packages/pieces/community/imap/src/lib/common/auth.ts b/packages/pieces/community/imap/src/lib/common/auth.tsindex ba066491b32..58b0e2ab153 100644--- a/packages/pieces/community/imap/src/lib/common/auth.ts+++ b/packages/pieces/community/imap/src/lib/common/auth.ts@@ -1,20 +1,17 @@import {PieceAuth,Property,- PiecePropValueSchema,AppConnectionValueForAuthProperty,} from '@activepieces/pieces-framework';import { performImapOperation } from './imap';import { AppConnectionType } from '@activepieces/pieces-framework';-const description = `-**Gmail Users:**-<br><br>-Make Sure of the following:-<br>-* IMAP is enabled in your Gmail settings (https://support.google.com/mail/answer/7126229?hl=en)-* You have created an App Password to login with (https://support.google.com/accounts/answer/185833?hl=en)-* Enable TLS and set the port to 993 and the host to imap.gmail.com+const description = `Enter your email provider's IMAP settings. Their help pages list them.++**Gmail**+1. Turn on IMAP in [Gmail settings](https://support.google.com/mail/answer/7126229?hl=en).+2. Create an [App Password](https://support.google.com/accounts/answer/185833?hl=en) and use it as the password.+3. Use host \`imap.gmail.com\`, port \`993\`, and turn on **Use TLS**.`;export const imapAuth = PieceAuth.CustomAuth({@@ -22,30 +19,35 @@ export const imapAuth = PieceAuth.CustomAuth({props: {host: Property.ShortText({displayName: 'Host',+ description: "Your provider's IMAP server address.",required: true,}),username: Property.ShortText({displayName: 'Username',+ description: 'Usually your full email address.',required: true,}),password: PieceAuth.SecretText({displayName: 'Password',+ description: 'Your email password, or an App Password for Gmail.',required: true,}),port: Property.Number({displayName: 'Port',+ description: 'Usually 993 with TLS on, or 143 with TLS off.',required: true,defaultValue: 143,}),tls: Property.Checkbox({displayName: 'Use TLS',+ description: 'Turn on for port 993. Most providers require it.',defaultValue: false,required: true,}),validateCertificates: Property.Checkbox({displayName: 'Validate TLS Certificates',description:- 'Enable TLS certificate validation (recommended for production).',+ 'Reject servers whose certificate is invalid or self-signed.',defaultValue: false,required: true,}),@@ -54,10 +56,10 @@ export const imapAuth = PieceAuth.CustomAuth({auth,}): Promise<{ valid: true } | { valid: false; error: string }> {try {- return (await performImapOperation({ type: AppConnectionType.CUSTOM_AUTH, props: auth }, async (imapClient) => {- imapClient.noop();- return { valid: true };- })) as { valid: true };+ await performImapOperation({ type: AppConnectionType.CUSTOM_AUTH, props: auth }, async (imapClient) => {+ await imapClient.noop();+ });+ return { valid: true };} catch (e) {return {valid: false,diff --git a/packages/pieces/community/imap/src/lib/common/props.ts b/packages/pieces/community/imap/src/lib/common/props.tsindex 7cce9e40eac..826f5dd4a23 100644--- a/packages/pieces/community/imap/src/lib/common/props.ts+++ b/packages/pieces/community/imap/src/lib/common/props.ts@@ -1,6 +1,6 @@import { Property } from '@activepieces/pieces-framework';import { fetchMailboxes } from './imap';-import { imapAuth, type ImapAuth } from './auth';+import { imapAuth } from './auth';interface DropdownParams {description?: string;@@ -27,18 +27,26 @@ export const mailboxDropdown = (params: DropdownParams) =>try {const mailboxes = await fetchMailboxes(auth);const options = mailboxes.map(- ({ name, path }: { name: string; path: string }) => ({- label: name,+ ({ path }: { path: string }) => ({+ label: path,value: path,}));+ if (options.length === 0) {+ return {+ disabled: true,+ options: [],+ placeholder: 'No folders found on this account.',+ };+ }+return { disabled: false, options };- } catch (error: any) {+ } catch (error) {return {disabled: true,options: [],- placeholder: `Error: ${error.message}`,+ placeholder: `Couldn't load folders: ${error instanceof Error ? error.message : String(error)}`,};}},diff --git a/packages/pieces/community/imap/src/lib/triggers/new-email.ts b/packages/pieces/community/imap/src/lib/triggers/new-email.tsindex b67244d5b02..f2c767862c9 100644--- a/packages/pieces/community/imap/src/lib/triggers/new-email.ts+++ b/packages/pieces/community/imap/src/lib/triggers/new-email.ts@@ -6,7 +6,6 @@ import {import {AppConnectionValueForAuthProperty,FilesService,- PiecePropValueSchema,Property,StaticPropsValue,TriggerStrategy,@@ -22,16 +21,13 @@ import {} from '../common';import { newEmailTriggerOutputSchema } from '../output-schemas';-const filterInstructions = `-**Emails Filtering:**--Add a Router Piece to filter emails based on the subject, to, from, cc or other fields.-`;+const filterInstructions =+ 'New emails in this folder start the flow. An email whose sent date is older than the last check is skipped. To act on only some, add a **Router** step after this trigger.';const props = {mailbox: mailboxDropdown({- displayName: 'Mailbox',- description: 'Select the mailbox to search.',+ displayName: 'Folder',+ description: 'Folder to watch for new emails.',required: true,}),filterInstructions: Property.MarkDown({@@ -59,8 +55,6 @@ const polling: Polling<},};-// This wrapper's only purpose is to reverse the messages array to ensure that-// test polling returns the 5 most recent messages.const testPolling: typeof polling = {...polling,items: async (...args) => {@@ -74,7 +68,7 @@ export const newEmail = createTrigger({name: 'new_email',classification: 'READ',displayName: 'New Email',- description: 'Trigger when a new email is received',+ description: 'Starts the flow when a new email arrives in a folder.',outputSchema: newEmailTriggerOutputSchema,aiMetadata: {description: 'Fires when a new email arrives in the selected IMAP mailbox folder. Polls the folder on an interval and emits one event per newly received message, including its parsed content and any attachments. Represents an inbound email landing in that mailbox.',@@ -164,7 +158,6 @@ async function enrichAttachments(items: Message[], files: FilesService) {return {...rest,attachments: convertedAttachments,- // epochMilliSeconds: item.epochMilliSeconds,};}));