@aiworkforge/piece-imap-extended 0.0.1
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/.claude/settings.local.json +9 -0
- package/aiworkforge-piece-imap-extended-0.0.1.tgz +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +19 -0
- package/dist/lib/actions/create-draft.d.ts +13 -0
- package/dist/lib/actions/create-draft.js +85 -0
- package/dist/lib/actions/move-email.d.ts +11 -0
- package/dist/lib/actions/move-email.js +60 -0
- package/dist/lib/auth.d.ts +7 -0
- package/dist/lib/auth.js +34 -0
- package/package.json +22 -0
- package/src/index.ts +17 -0
- package/src/lib/actions/create-draft.ts +93 -0
- package/src/lib/actions/move-email.ts +60 -0
- package/src/lib/auth.ts +32 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(xargs grep:*)",
|
|
5
|
+
"Bash(find /c/Users/rathj/piece-imap-extended -not -path */node_modules/* -name *.md -o -not -path */node_modules/* -name *.txt -o -not -path */node_modules/* -name *.yaml -o -not -path */node_modules/* -name *.yml)",
|
|
6
|
+
"Bash(tar:*)"
|
|
7
|
+
]
|
|
8
|
+
}
|
|
9
|
+
}
|
|
Binary file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const imapExtended: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
port: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
4
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
5
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
6
|
+
tls: import("@activepieces/pieces-framework").CheckboxProperty<true>;
|
|
7
|
+
}>>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imapExtended = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const shared_1 = require("@activepieces/shared");
|
|
6
|
+
const move_email_1 = require("./lib/actions/move-email");
|
|
7
|
+
const create_draft_1 = require("./lib/actions/create-draft");
|
|
8
|
+
const auth_1 = require("./lib/auth");
|
|
9
|
+
exports.imapExtended = (0, pieces_framework_1.createPiece)({
|
|
10
|
+
displayName: 'IMAP Extended',
|
|
11
|
+
description: 'Extended IMAP actions: Move emails between folders and create reply drafts',
|
|
12
|
+
auth: auth_1.imapAuth,
|
|
13
|
+
minimumSupportedRelease: '0.36.1',
|
|
14
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/imap.png',
|
|
15
|
+
categories: [shared_1.PieceCategory.COMMUNICATION],
|
|
16
|
+
authors: ['AIWorkForge'],
|
|
17
|
+
actions: [move_email_1.moveEmail, create_draft_1.createDraft],
|
|
18
|
+
triggers: [],
|
|
19
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const createDraft: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
port: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
4
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
5
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
6
|
+
tls: import("@activepieces/pieces-framework").CheckboxProperty<true>;
|
|
7
|
+
}>, {
|
|
8
|
+
to: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
9
|
+
subject: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
10
|
+
body: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
11
|
+
inReplyTo: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
12
|
+
draftsFolder: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDraft = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const auth_1 = require("../auth");
|
|
6
|
+
const imapflow_1 = require("imapflow");
|
|
7
|
+
exports.createDraft = (0, pieces_framework_1.createAction)({
|
|
8
|
+
name: 'create_draft',
|
|
9
|
+
displayName: 'Create Reply Draft',
|
|
10
|
+
description: 'Create a draft reply email in the Drafts folder',
|
|
11
|
+
auth: auth_1.imapAuth,
|
|
12
|
+
props: {
|
|
13
|
+
to: pieces_framework_1.Property.ShortText({
|
|
14
|
+
displayName: 'To',
|
|
15
|
+
description: 'Recipient email address',
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
subject: pieces_framework_1.Property.ShortText({
|
|
19
|
+
displayName: 'Subject',
|
|
20
|
+
description: 'Email subject (Re: will be added automatically if not present)',
|
|
21
|
+
required: true,
|
|
22
|
+
}),
|
|
23
|
+
body: pieces_framework_1.Property.LongText({
|
|
24
|
+
displayName: 'Body',
|
|
25
|
+
description: 'The draft email body text',
|
|
26
|
+
required: true,
|
|
27
|
+
}),
|
|
28
|
+
inReplyTo: pieces_framework_1.Property.ShortText({
|
|
29
|
+
displayName: 'In-Reply-To Message ID',
|
|
30
|
+
description: 'Message-ID of the original email (for thread grouping)',
|
|
31
|
+
required: false,
|
|
32
|
+
}),
|
|
33
|
+
draftsFolder: pieces_framework_1.Property.ShortText({
|
|
34
|
+
displayName: 'Drafts Folder Name',
|
|
35
|
+
description: 'Name of the drafts folder on the IMAP server',
|
|
36
|
+
required: true,
|
|
37
|
+
defaultValue: 'Entwürfe',
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
async run(context) {
|
|
41
|
+
const { to, subject, body, inReplyTo, draftsFolder } = context.propsValue;
|
|
42
|
+
const { host, port, username, password, tls } = context.auth.props;
|
|
43
|
+
const reSubject = subject.startsWith('Re:') ? subject : `Re: ${subject}`;
|
|
44
|
+
const date = new Date().toUTCString();
|
|
45
|
+
const messageId = `<${Date.now()}.${Math.random().toString(36).slice(2)}@aiworkforge.de>`;
|
|
46
|
+
let headers = `From: ${username}\r\n`;
|
|
47
|
+
headers += `To: ${to}\r\n`;
|
|
48
|
+
headers += `Subject: ${reSubject}\r\n`;
|
|
49
|
+
headers += `Date: ${date}\r\n`;
|
|
50
|
+
headers += `Message-ID: ${messageId}\r\n`;
|
|
51
|
+
headers += `MIME-Version: 1.0\r\n`;
|
|
52
|
+
headers += `Content-Type: text/plain; charset=utf-8\r\n`;
|
|
53
|
+
if (inReplyTo) {
|
|
54
|
+
headers += `In-Reply-To: ${inReplyTo}\r\n`;
|
|
55
|
+
headers += `References: ${inReplyTo}\r\n`;
|
|
56
|
+
}
|
|
57
|
+
const rawEmail = `${headers}\r\n${body}`;
|
|
58
|
+
const client = new imapflow_1.ImapFlow({
|
|
59
|
+
host: host,
|
|
60
|
+
port: port,
|
|
61
|
+
secure: tls,
|
|
62
|
+
auth: {
|
|
63
|
+
user: username,
|
|
64
|
+
pass: password,
|
|
65
|
+
},
|
|
66
|
+
logger: false,
|
|
67
|
+
});
|
|
68
|
+
try {
|
|
69
|
+
await client.connect();
|
|
70
|
+
await client.append(draftsFolder, Buffer.from(rawEmail), ['\\Draft', '\\Seen']);
|
|
71
|
+
await client.logout();
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
messageId,
|
|
75
|
+
subject: reSubject,
|
|
76
|
+
to,
|
|
77
|
+
draftsFolder,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
await client.logout().catch(() => { });
|
|
82
|
+
throw new Error(`Failed to create draft: ${error}`);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const moveEmail: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
port: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
4
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
5
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
6
|
+
tls: import("@activepieces/pieces-framework").CheckboxProperty<true>;
|
|
7
|
+
}>, {
|
|
8
|
+
messageUid: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
9
|
+
sourceFolder: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
10
|
+
destinationFolder: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moveEmail = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const auth_1 = require("../auth");
|
|
6
|
+
const imapflow_1 = require("imapflow");
|
|
7
|
+
exports.moveEmail = (0, pieces_framework_1.createAction)({
|
|
8
|
+
name: 'move_email',
|
|
9
|
+
displayName: 'Move Email',
|
|
10
|
+
description: 'Move an email to a different IMAP folder',
|
|
11
|
+
auth: auth_1.imapAuth,
|
|
12
|
+
props: {
|
|
13
|
+
messageUid: pieces_framework_1.Property.Number({
|
|
14
|
+
displayName: 'Message UID',
|
|
15
|
+
description: 'The UID of the email to move (from IMAP trigger)',
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
sourceFolder: pieces_framework_1.Property.ShortText({
|
|
19
|
+
displayName: 'Source Folder',
|
|
20
|
+
description: 'The folder where the email currently is',
|
|
21
|
+
required: true,
|
|
22
|
+
defaultValue: 'INBOX',
|
|
23
|
+
}),
|
|
24
|
+
destinationFolder: pieces_framework_1.Property.ShortText({
|
|
25
|
+
displayName: 'Destination Folder',
|
|
26
|
+
description: 'The folder to move the email to',
|
|
27
|
+
required: true,
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
async run(context) {
|
|
31
|
+
const { messageUid, sourceFolder, destinationFolder } = context.propsValue;
|
|
32
|
+
const { host, port, username, password, tls } = context.auth.props;
|
|
33
|
+
const client = new imapflow_1.ImapFlow({
|
|
34
|
+
host: host,
|
|
35
|
+
port: port,
|
|
36
|
+
secure: tls,
|
|
37
|
+
auth: {
|
|
38
|
+
user: username,
|
|
39
|
+
pass: password,
|
|
40
|
+
},
|
|
41
|
+
logger: false,
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
await client.connect();
|
|
45
|
+
await client.mailboxOpen(sourceFolder);
|
|
46
|
+
await client.messageMove(String(messageUid), destinationFolder, { uid: true });
|
|
47
|
+
await client.logout();
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
messageUid,
|
|
51
|
+
from: sourceFolder,
|
|
52
|
+
to: destinationFolder,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
await client.logout().catch(() => { });
|
|
57
|
+
throw new Error(`Failed to move email: ${error}`);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const imapAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
host: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
port: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
4
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
5
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
6
|
+
tls: import("@activepieces/pieces-framework").CheckboxProperty<true>;
|
|
7
|
+
}>;
|
package/dist/lib/auth.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imapAuth = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
exports.imapAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
6
|
+
displayName: 'IMAP Connection',
|
|
7
|
+
required: true,
|
|
8
|
+
props: {
|
|
9
|
+
host: pieces_framework_1.Property.ShortText({
|
|
10
|
+
displayName: 'Host',
|
|
11
|
+
description: 'IMAP server hostname (e.g. imap.ionos.de)',
|
|
12
|
+
required: true,
|
|
13
|
+
}),
|
|
14
|
+
port: pieces_framework_1.Property.Number({
|
|
15
|
+
displayName: 'Port',
|
|
16
|
+
description: 'IMAP port (usually 993 for TLS)',
|
|
17
|
+
required: true,
|
|
18
|
+
defaultValue: 993,
|
|
19
|
+
}),
|
|
20
|
+
username: pieces_framework_1.Property.ShortText({
|
|
21
|
+
displayName: 'Username / Email',
|
|
22
|
+
required: true,
|
|
23
|
+
}),
|
|
24
|
+
password: pieces_framework_1.PieceAuth.SecretText({
|
|
25
|
+
displayName: 'Password',
|
|
26
|
+
required: true,
|
|
27
|
+
}),
|
|
28
|
+
tls: pieces_framework_1.Property.Checkbox({
|
|
29
|
+
displayName: 'Use TLS',
|
|
30
|
+
required: true,
|
|
31
|
+
defaultValue: true,
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiworkforge/piece-imap-extended",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "IMAP Extended piece for Activepieces - Move emails and create drafts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": ["activepieces", "imap", "email", "draft"],
|
|
12
|
+
"author": "AIWorkForge",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@activepieces/pieces-framework": "0.26.0",
|
|
16
|
+
"imapflow": "^1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"typescript": "^5.0.0",
|
|
20
|
+
"@types/node": "^20.0.0"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createPiece } from '@activepieces/pieces-framework';
|
|
2
|
+
import { PieceCategory } from '@activepieces/shared';
|
|
3
|
+
import { moveEmail } from './lib/actions/move-email';
|
|
4
|
+
import { createDraft } from './lib/actions/create-draft';
|
|
5
|
+
import { imapAuth } from './lib/auth';
|
|
6
|
+
|
|
7
|
+
export const imapExtended = createPiece({
|
|
8
|
+
displayName: 'IMAP Extended',
|
|
9
|
+
description: 'Extended IMAP actions: Move emails between folders and create reply drafts',
|
|
10
|
+
auth: imapAuth,
|
|
11
|
+
minimumSupportedRelease: '0.36.1',
|
|
12
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/imap.png',
|
|
13
|
+
categories: [PieceCategory.COMMUNICATION],
|
|
14
|
+
authors: ['AIWorkForge'],
|
|
15
|
+
actions: [moveEmail, createDraft],
|
|
16
|
+
triggers: [],
|
|
17
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createAction, Property } from '@activepieces/pieces-framework';
|
|
2
|
+
import { imapAuth } from '../auth';
|
|
3
|
+
import { ImapFlow } from 'imapflow';
|
|
4
|
+
|
|
5
|
+
export const createDraft = createAction({
|
|
6
|
+
name: 'create_draft',
|
|
7
|
+
displayName: 'Create Reply Draft',
|
|
8
|
+
description: 'Create a draft reply email in the Drafts folder',
|
|
9
|
+
auth: imapAuth,
|
|
10
|
+
props: {
|
|
11
|
+
to: Property.ShortText({
|
|
12
|
+
displayName: 'To',
|
|
13
|
+
description: 'Recipient email address',
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
subject: Property.ShortText({
|
|
17
|
+
displayName: 'Subject',
|
|
18
|
+
description: 'Email subject (Re: will be added automatically if not present)',
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
body: Property.LongText({
|
|
22
|
+
displayName: 'Body',
|
|
23
|
+
description: 'The draft email body text',
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
inReplyTo: Property.ShortText({
|
|
27
|
+
displayName: 'In-Reply-To Message ID',
|
|
28
|
+
description: 'Message-ID of the original email (for thread grouping)',
|
|
29
|
+
required: false,
|
|
30
|
+
}),
|
|
31
|
+
draftsFolder: Property.ShortText({
|
|
32
|
+
displayName: 'Drafts Folder Name',
|
|
33
|
+
description: 'Name of the drafts folder on the IMAP server',
|
|
34
|
+
required: true,
|
|
35
|
+
defaultValue: 'Entwürfe',
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
async run(context) {
|
|
39
|
+
const { to, subject, body, inReplyTo, draftsFolder } = context.propsValue;
|
|
40
|
+
const { host, port, username, password, tls } = context.auth.props;
|
|
41
|
+
|
|
42
|
+
const reSubject = subject.startsWith('Re:') ? subject : `Re: ${subject}`;
|
|
43
|
+
const date = new Date().toUTCString();
|
|
44
|
+
const messageId = `<${Date.now()}.${Math.random().toString(36).slice(2)}@aiworkforge.de>`;
|
|
45
|
+
|
|
46
|
+
let headers = `From: ${username}\r\n`;
|
|
47
|
+
headers += `To: ${to}\r\n`;
|
|
48
|
+
headers += `Subject: ${reSubject}\r\n`;
|
|
49
|
+
headers += `Date: ${date}\r\n`;
|
|
50
|
+
headers += `Message-ID: ${messageId}\r\n`;
|
|
51
|
+
headers += `MIME-Version: 1.0\r\n`;
|
|
52
|
+
headers += `Content-Type: text/plain; charset=utf-8\r\n`;
|
|
53
|
+
|
|
54
|
+
if (inReplyTo) {
|
|
55
|
+
headers += `In-Reply-To: ${inReplyTo}\r\n`;
|
|
56
|
+
headers += `References: ${inReplyTo}\r\n`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const rawEmail = `${headers}\r\n${body}`;
|
|
60
|
+
|
|
61
|
+
const client = new ImapFlow({
|
|
62
|
+
host: host,
|
|
63
|
+
port: port,
|
|
64
|
+
secure: tls,
|
|
65
|
+
auth: {
|
|
66
|
+
user: username,
|
|
67
|
+
pass: password,
|
|
68
|
+
},
|
|
69
|
+
logger: false,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
await client.connect();
|
|
74
|
+
await client.append(
|
|
75
|
+
draftsFolder,
|
|
76
|
+
Buffer.from(rawEmail),
|
|
77
|
+
['\\Draft', '\\Seen']
|
|
78
|
+
);
|
|
79
|
+
await client.logout();
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
success: true,
|
|
83
|
+
messageId,
|
|
84
|
+
subject: reSubject,
|
|
85
|
+
to,
|
|
86
|
+
draftsFolder,
|
|
87
|
+
};
|
|
88
|
+
} catch (error) {
|
|
89
|
+
await client.logout().catch(() => {});
|
|
90
|
+
throw new Error(`Failed to create draft: ${error}`);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createAction, Property } from '@activepieces/pieces-framework';
|
|
2
|
+
import { imapAuth } from '../auth';
|
|
3
|
+
import { ImapFlow } from 'imapflow';
|
|
4
|
+
|
|
5
|
+
export const moveEmail = createAction({
|
|
6
|
+
name: 'move_email',
|
|
7
|
+
displayName: 'Move Email',
|
|
8
|
+
description: 'Move an email to a different IMAP folder',
|
|
9
|
+
auth: imapAuth,
|
|
10
|
+
props: {
|
|
11
|
+
messageUid: Property.Number({
|
|
12
|
+
displayName: 'Message UID',
|
|
13
|
+
description: 'The UID of the email to move (from IMAP trigger)',
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
sourceFolder: Property.ShortText({
|
|
17
|
+
displayName: 'Source Folder',
|
|
18
|
+
description: 'The folder where the email currently is',
|
|
19
|
+
required: true,
|
|
20
|
+
defaultValue: 'INBOX',
|
|
21
|
+
}),
|
|
22
|
+
destinationFolder: Property.ShortText({
|
|
23
|
+
displayName: 'Destination Folder',
|
|
24
|
+
description: 'The folder to move the email to',
|
|
25
|
+
required: true,
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
async run(context) {
|
|
29
|
+
const { messageUid, sourceFolder, destinationFolder } = context.propsValue;
|
|
30
|
+
const { host, port, username, password, tls } = context.auth.props;
|
|
31
|
+
|
|
32
|
+
const client = new ImapFlow({
|
|
33
|
+
host: host,
|
|
34
|
+
port: port,
|
|
35
|
+
secure: tls,
|
|
36
|
+
auth: {
|
|
37
|
+
user: username,
|
|
38
|
+
pass: password,
|
|
39
|
+
},
|
|
40
|
+
logger: false,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await client.connect();
|
|
45
|
+
await client.mailboxOpen(sourceFolder);
|
|
46
|
+
await client.messageMove(String(messageUid), destinationFolder, { uid: true });
|
|
47
|
+
await client.logout();
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
messageUid,
|
|
52
|
+
from: sourceFolder,
|
|
53
|
+
to: destinationFolder,
|
|
54
|
+
};
|
|
55
|
+
} catch (error) {
|
|
56
|
+
await client.logout().catch(() => {});
|
|
57
|
+
throw new Error(`Failed to move email: ${error}`);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
package/src/lib/auth.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PieceAuth, Property } from '@activepieces/pieces-framework';
|
|
2
|
+
|
|
3
|
+
export const imapAuth = PieceAuth.CustomAuth({
|
|
4
|
+
displayName: 'IMAP Connection',
|
|
5
|
+
required: true,
|
|
6
|
+
props: {
|
|
7
|
+
host: Property.ShortText({
|
|
8
|
+
displayName: 'Host',
|
|
9
|
+
description: 'IMAP server hostname (e.g. imap.ionos.de)',
|
|
10
|
+
required: true,
|
|
11
|
+
}),
|
|
12
|
+
port: Property.Number({
|
|
13
|
+
displayName: 'Port',
|
|
14
|
+
description: 'IMAP port (usually 993 for TLS)',
|
|
15
|
+
required: true,
|
|
16
|
+
defaultValue: 993,
|
|
17
|
+
}),
|
|
18
|
+
username: Property.ShortText({
|
|
19
|
+
displayName: 'Username / Email',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
password: PieceAuth.SecretText({
|
|
23
|
+
displayName: 'Password',
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
tls: Property.Checkbox({
|
|
27
|
+
displayName: 'Use TLS',
|
|
28
|
+
required: true,
|
|
29
|
+
defaultValue: true,
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"types": ["node"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*"]
|
|
16
|
+
}
|