n8n-nodes-jmap 0.1.0
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/LICENSE +661 -0
- package/README.md +204 -0
- package/dist/credentials/JmapApi.credentials.d.ts +13 -0
- package/dist/credentials/JmapApi.credentials.js +105 -0
- package/dist/credentials/JmapOAuth2Api.credentials.d.ts +27 -0
- package/dist/credentials/JmapOAuth2Api.credentials.js +103 -0
- package/dist/nodes/Jmap/GenericFunctions.d.ts +121 -0
- package/dist/nodes/Jmap/GenericFunctions.js +466 -0
- package/dist/nodes/Jmap/Jmap.node.d.ts +11 -0
- package/dist/nodes/Jmap/Jmap.node.js +707 -0
- package/dist/nodes/Jmap/JmapTrigger.node.d.ts +10 -0
- package/dist/nodes/Jmap/JmapTrigger.node.js +236 -0
- package/dist/nodes/Jmap/jmap.svg +14 -0
- package/package.json +61 -0
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Jmap = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
6
|
+
class Jmap {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.description = {
|
|
9
|
+
displayName: 'JMAP',
|
|
10
|
+
name: 'jmap',
|
|
11
|
+
icon: 'file:jmap.svg',
|
|
12
|
+
group: ['transform'],
|
|
13
|
+
version: 1,
|
|
14
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
15
|
+
description: 'Interact with JMAP email servers (Apache James, Twake Mail, etc.)',
|
|
16
|
+
defaults: {
|
|
17
|
+
name: 'JMAP',
|
|
18
|
+
},
|
|
19
|
+
inputs: ['main'],
|
|
20
|
+
outputs: ['main'],
|
|
21
|
+
credentials: [
|
|
22
|
+
{
|
|
23
|
+
name: 'jmapApi',
|
|
24
|
+
required: true,
|
|
25
|
+
displayOptions: {
|
|
26
|
+
show: {
|
|
27
|
+
authentication: ['jmapApi'],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'jmapOAuth2Api',
|
|
33
|
+
required: true,
|
|
34
|
+
displayOptions: {
|
|
35
|
+
show: {
|
|
36
|
+
authentication: ['jmapOAuth2Api'],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
properties: [
|
|
42
|
+
// Authentication selection
|
|
43
|
+
{
|
|
44
|
+
displayName: 'Authentication',
|
|
45
|
+
name: 'authentication',
|
|
46
|
+
type: 'options',
|
|
47
|
+
options: [
|
|
48
|
+
{
|
|
49
|
+
name: 'OAuth2',
|
|
50
|
+
value: 'jmapOAuth2Api',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'Basic Auth / Bearer Token',
|
|
54
|
+
value: 'jmapApi',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
default: 'jmapOAuth2Api',
|
|
58
|
+
description: 'Authentication method to use',
|
|
59
|
+
},
|
|
60
|
+
// Resource selection
|
|
61
|
+
{
|
|
62
|
+
displayName: 'Resource',
|
|
63
|
+
name: 'resource',
|
|
64
|
+
type: 'options',
|
|
65
|
+
noDataExpression: true,
|
|
66
|
+
options: [
|
|
67
|
+
{
|
|
68
|
+
name: 'Email',
|
|
69
|
+
value: 'email',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'Mailbox',
|
|
73
|
+
value: 'mailbox',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Thread',
|
|
77
|
+
value: 'thread',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
default: 'email',
|
|
81
|
+
},
|
|
82
|
+
// ==================== EMAIL OPERATIONS ====================
|
|
83
|
+
{
|
|
84
|
+
displayName: 'Operation',
|
|
85
|
+
name: 'operation',
|
|
86
|
+
type: 'options',
|
|
87
|
+
noDataExpression: true,
|
|
88
|
+
displayOptions: {
|
|
89
|
+
show: {
|
|
90
|
+
resource: ['email'],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
options: [
|
|
94
|
+
{
|
|
95
|
+
name: 'Add Label',
|
|
96
|
+
value: 'addLabel',
|
|
97
|
+
description: 'Add a label (mailbox) to an email',
|
|
98
|
+
action: 'Add a label to an email',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'Create Draft',
|
|
102
|
+
value: 'createDraft',
|
|
103
|
+
description: 'Create a draft email without sending',
|
|
104
|
+
action: 'Create a draft email',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'Delete',
|
|
108
|
+
value: 'delete',
|
|
109
|
+
description: 'Delete an email',
|
|
110
|
+
action: 'Delete an email',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'Get',
|
|
114
|
+
value: 'get',
|
|
115
|
+
description: 'Get an email by ID',
|
|
116
|
+
action: 'Get an email',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'Get Labels',
|
|
120
|
+
value: 'getLabels',
|
|
121
|
+
description: 'Get all labels (mailboxes) for an email',
|
|
122
|
+
action: 'Get labels for an email',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: 'Get Many',
|
|
126
|
+
value: 'getMany',
|
|
127
|
+
description: 'Get multiple emails',
|
|
128
|
+
action: 'Get many emails',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'Mark as Read',
|
|
132
|
+
value: 'markAsRead',
|
|
133
|
+
description: 'Mark an email as read',
|
|
134
|
+
action: 'Mark an email as read',
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'Mark as Unread',
|
|
138
|
+
value: 'markAsUnread',
|
|
139
|
+
description: 'Mark an email as unread',
|
|
140
|
+
action: 'Mark an email as unread',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'Move',
|
|
144
|
+
value: 'move',
|
|
145
|
+
description: 'Move an email to a different mailbox',
|
|
146
|
+
action: 'Move an email',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'Remove Label',
|
|
150
|
+
value: 'removeLabel',
|
|
151
|
+
description: 'Remove a label (mailbox) from an email',
|
|
152
|
+
action: 'Remove a label from an email',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'Reply',
|
|
156
|
+
value: 'reply',
|
|
157
|
+
description: 'Reply to an email',
|
|
158
|
+
action: 'Reply to an email',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: 'Send',
|
|
162
|
+
value: 'send',
|
|
163
|
+
description: 'Send an email',
|
|
164
|
+
action: 'Send an email',
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
default: 'send',
|
|
168
|
+
},
|
|
169
|
+
// ==================== MAILBOX OPERATIONS ====================
|
|
170
|
+
{
|
|
171
|
+
displayName: 'Operation',
|
|
172
|
+
name: 'operation',
|
|
173
|
+
type: 'options',
|
|
174
|
+
noDataExpression: true,
|
|
175
|
+
displayOptions: {
|
|
176
|
+
show: {
|
|
177
|
+
resource: ['mailbox'],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
options: [
|
|
181
|
+
{
|
|
182
|
+
name: 'Get',
|
|
183
|
+
value: 'get',
|
|
184
|
+
description: 'Get a mailbox by ID',
|
|
185
|
+
action: 'Get a mailbox',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: 'Get Many',
|
|
189
|
+
value: 'getMany',
|
|
190
|
+
description: 'Get all mailboxes',
|
|
191
|
+
action: 'Get many mailboxes',
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
default: 'getMany',
|
|
195
|
+
},
|
|
196
|
+
// ==================== THREAD OPERATIONS ====================
|
|
197
|
+
{
|
|
198
|
+
displayName: 'Operation',
|
|
199
|
+
name: 'operation',
|
|
200
|
+
type: 'options',
|
|
201
|
+
noDataExpression: true,
|
|
202
|
+
displayOptions: {
|
|
203
|
+
show: {
|
|
204
|
+
resource: ['thread'],
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
options: [
|
|
208
|
+
{
|
|
209
|
+
name: 'Get',
|
|
210
|
+
value: 'get',
|
|
211
|
+
description: 'Get a thread by ID',
|
|
212
|
+
action: 'Get a thread',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: 'Get Many',
|
|
216
|
+
value: 'getMany',
|
|
217
|
+
description: 'Get emails in a thread',
|
|
218
|
+
action: 'Get many threads',
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
default: 'get',
|
|
222
|
+
},
|
|
223
|
+
// ==================== EMAIL PARAMETERS ====================
|
|
224
|
+
// Email ID (for get, delete, markAsRead, markAsUnread, move, reply, addLabel, removeLabel, getLabels)
|
|
225
|
+
{
|
|
226
|
+
displayName: 'Email ID',
|
|
227
|
+
name: 'emailId',
|
|
228
|
+
type: 'string',
|
|
229
|
+
required: true,
|
|
230
|
+
displayOptions: {
|
|
231
|
+
show: {
|
|
232
|
+
resource: ['email'],
|
|
233
|
+
operation: ['get', 'delete', 'markAsRead', 'markAsUnread', 'move', 'reply', 'addLabel', 'removeLabel', 'getLabels'],
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
default: '',
|
|
237
|
+
description: 'The ID of the email',
|
|
238
|
+
},
|
|
239
|
+
// Label (mailbox) selection for addLabel/removeLabel
|
|
240
|
+
{
|
|
241
|
+
displayName: 'Label',
|
|
242
|
+
name: 'label',
|
|
243
|
+
type: 'options',
|
|
244
|
+
typeOptions: {
|
|
245
|
+
loadOptionsMethod: 'getMailboxes',
|
|
246
|
+
},
|
|
247
|
+
required: true,
|
|
248
|
+
displayOptions: {
|
|
249
|
+
show: {
|
|
250
|
+
resource: ['email'],
|
|
251
|
+
operation: ['addLabel', 'removeLabel'],
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
default: '',
|
|
255
|
+
description: 'The label (mailbox) to add or remove',
|
|
256
|
+
},
|
|
257
|
+
// Mailbox selection for getMany
|
|
258
|
+
{
|
|
259
|
+
displayName: 'Mailbox',
|
|
260
|
+
name: 'mailbox',
|
|
261
|
+
type: 'options',
|
|
262
|
+
typeOptions: {
|
|
263
|
+
loadOptionsMethod: 'getMailboxes',
|
|
264
|
+
},
|
|
265
|
+
displayOptions: {
|
|
266
|
+
show: {
|
|
267
|
+
resource: ['email'],
|
|
268
|
+
operation: ['getMany'],
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
default: '',
|
|
272
|
+
description: 'The mailbox to get emails from',
|
|
273
|
+
},
|
|
274
|
+
// Target mailbox for move
|
|
275
|
+
{
|
|
276
|
+
displayName: 'Target Mailbox',
|
|
277
|
+
name: 'targetMailbox',
|
|
278
|
+
type: 'options',
|
|
279
|
+
typeOptions: {
|
|
280
|
+
loadOptionsMethod: 'getMailboxes',
|
|
281
|
+
},
|
|
282
|
+
required: true,
|
|
283
|
+
displayOptions: {
|
|
284
|
+
show: {
|
|
285
|
+
resource: ['email'],
|
|
286
|
+
operation: ['move'],
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
default: '',
|
|
290
|
+
description: 'The mailbox to move the email to',
|
|
291
|
+
},
|
|
292
|
+
// From (sender identity) for send/reply
|
|
293
|
+
{
|
|
294
|
+
displayName: 'From',
|
|
295
|
+
name: 'fromIdentity',
|
|
296
|
+
type: 'options',
|
|
297
|
+
typeOptions: {
|
|
298
|
+
loadOptionsMethod: 'getIdentities',
|
|
299
|
+
},
|
|
300
|
+
required: true,
|
|
301
|
+
displayOptions: {
|
|
302
|
+
show: {
|
|
303
|
+
resource: ['email'],
|
|
304
|
+
operation: ['send', 'reply'],
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
default: '',
|
|
308
|
+
description: 'The sender identity to use',
|
|
309
|
+
},
|
|
310
|
+
// To recipients
|
|
311
|
+
{
|
|
312
|
+
displayName: 'To',
|
|
313
|
+
name: 'to',
|
|
314
|
+
type: 'string',
|
|
315
|
+
required: true,
|
|
316
|
+
displayOptions: {
|
|
317
|
+
show: {
|
|
318
|
+
resource: ['email'],
|
|
319
|
+
operation: ['send', 'createDraft'],
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
default: '',
|
|
323
|
+
placeholder: 'recipient@example.com',
|
|
324
|
+
description: 'Recipient email addresses (comma-separated)',
|
|
325
|
+
},
|
|
326
|
+
// Subject
|
|
327
|
+
{
|
|
328
|
+
displayName: 'Subject',
|
|
329
|
+
name: 'subject',
|
|
330
|
+
type: 'string',
|
|
331
|
+
required: true,
|
|
332
|
+
displayOptions: {
|
|
333
|
+
show: {
|
|
334
|
+
resource: ['email'],
|
|
335
|
+
operation: ['send', 'createDraft'],
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
default: '',
|
|
339
|
+
description: 'The email subject',
|
|
340
|
+
},
|
|
341
|
+
// Email body type
|
|
342
|
+
{
|
|
343
|
+
displayName: 'Email Type',
|
|
344
|
+
name: 'emailType',
|
|
345
|
+
type: 'options',
|
|
346
|
+
displayOptions: {
|
|
347
|
+
show: {
|
|
348
|
+
resource: ['email'],
|
|
349
|
+
operation: ['send', 'reply', 'createDraft'],
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
options: [
|
|
353
|
+
{
|
|
354
|
+
name: 'Text',
|
|
355
|
+
value: 'text',
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: 'HTML',
|
|
359
|
+
value: 'html',
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
default: 'text',
|
|
363
|
+
},
|
|
364
|
+
// Message body
|
|
365
|
+
{
|
|
366
|
+
displayName: 'Message',
|
|
367
|
+
name: 'message',
|
|
368
|
+
type: 'string',
|
|
369
|
+
typeOptions: {
|
|
370
|
+
rows: 5,
|
|
371
|
+
},
|
|
372
|
+
required: true,
|
|
373
|
+
displayOptions: {
|
|
374
|
+
show: {
|
|
375
|
+
resource: ['email'],
|
|
376
|
+
operation: ['send', 'reply', 'createDraft'],
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
default: '',
|
|
380
|
+
description: 'The email body content',
|
|
381
|
+
},
|
|
382
|
+
// Additional options for send/createDraft
|
|
383
|
+
{
|
|
384
|
+
displayName: 'Options',
|
|
385
|
+
name: 'options',
|
|
386
|
+
type: 'collection',
|
|
387
|
+
placeholder: 'Add Option',
|
|
388
|
+
default: {},
|
|
389
|
+
displayOptions: {
|
|
390
|
+
show: {
|
|
391
|
+
resource: ['email'],
|
|
392
|
+
operation: ['send', 'createDraft'],
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
options: [
|
|
396
|
+
{
|
|
397
|
+
displayName: 'CC',
|
|
398
|
+
name: 'cc',
|
|
399
|
+
type: 'string',
|
|
400
|
+
default: '',
|
|
401
|
+
description: 'CC recipients (comma-separated)',
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
displayName: 'BCC',
|
|
405
|
+
name: 'bcc',
|
|
406
|
+
type: 'string',
|
|
407
|
+
default: '',
|
|
408
|
+
description: 'BCC recipients (comma-separated)',
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
},
|
|
412
|
+
// Limit for getMany
|
|
413
|
+
{
|
|
414
|
+
displayName: 'Limit',
|
|
415
|
+
name: 'limit',
|
|
416
|
+
type: 'number',
|
|
417
|
+
typeOptions: {
|
|
418
|
+
minValue: 1,
|
|
419
|
+
maxValue: 500,
|
|
420
|
+
},
|
|
421
|
+
displayOptions: {
|
|
422
|
+
show: {
|
|
423
|
+
resource: ['email'],
|
|
424
|
+
operation: ['getMany'],
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
default: 50,
|
|
428
|
+
description: 'Max number of results to return',
|
|
429
|
+
},
|
|
430
|
+
// ==================== MAILBOX PARAMETERS ====================
|
|
431
|
+
{
|
|
432
|
+
displayName: 'Mailbox ID',
|
|
433
|
+
name: 'mailboxId',
|
|
434
|
+
type: 'string',
|
|
435
|
+
required: true,
|
|
436
|
+
displayOptions: {
|
|
437
|
+
show: {
|
|
438
|
+
resource: ['mailbox'],
|
|
439
|
+
operation: ['get'],
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
default: '',
|
|
443
|
+
description: 'The ID of the mailbox',
|
|
444
|
+
},
|
|
445
|
+
// ==================== THREAD PARAMETERS ====================
|
|
446
|
+
{
|
|
447
|
+
displayName: 'Thread ID',
|
|
448
|
+
name: 'threadId',
|
|
449
|
+
type: 'string',
|
|
450
|
+
required: true,
|
|
451
|
+
displayOptions: {
|
|
452
|
+
show: {
|
|
453
|
+
resource: ['thread'],
|
|
454
|
+
operation: ['get', 'getMany'],
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
default: '',
|
|
458
|
+
description: 'The ID of the thread',
|
|
459
|
+
},
|
|
460
|
+
],
|
|
461
|
+
};
|
|
462
|
+
this.methods = {
|
|
463
|
+
loadOptions: {
|
|
464
|
+
async getMailboxes() {
|
|
465
|
+
const accountId = await GenericFunctions_1.getPrimaryAccountId.call(this);
|
|
466
|
+
const mailboxes = await GenericFunctions_1.getMailboxes.call(this, accountId);
|
|
467
|
+
return mailboxes.map((mailbox) => ({
|
|
468
|
+
name: `${mailbox.name} (${mailbox.totalEmails} emails)`,
|
|
469
|
+
value: mailbox.id,
|
|
470
|
+
}));
|
|
471
|
+
},
|
|
472
|
+
async getIdentities() {
|
|
473
|
+
const accountId = await GenericFunctions_1.getPrimaryAccountId.call(this);
|
|
474
|
+
const identities = await GenericFunctions_1.getIdentities.call(this, accountId);
|
|
475
|
+
return identities.map((identity) => ({
|
|
476
|
+
name: `${identity.name} <${identity.email}>`,
|
|
477
|
+
value: identity.id,
|
|
478
|
+
}));
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
async execute() {
|
|
484
|
+
const items = this.getInputData();
|
|
485
|
+
const returnData = [];
|
|
486
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
487
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
488
|
+
const accountId = await GenericFunctions_1.getPrimaryAccountId.call(this);
|
|
489
|
+
for (let i = 0; i < items.length; i++) {
|
|
490
|
+
try {
|
|
491
|
+
let responseData = {};
|
|
492
|
+
// ==================== EMAIL ====================
|
|
493
|
+
if (resource === 'email') {
|
|
494
|
+
if (operation === 'send') {
|
|
495
|
+
const fromIdentity = this.getNodeParameter('fromIdentity', i);
|
|
496
|
+
const to = this.getNodeParameter('to', i);
|
|
497
|
+
const subject = this.getNodeParameter('subject', i);
|
|
498
|
+
const emailType = this.getNodeParameter('emailType', i);
|
|
499
|
+
const message = this.getNodeParameter('message', i);
|
|
500
|
+
const options = this.getNodeParameter('options', i);
|
|
501
|
+
// Parse recipients
|
|
502
|
+
const toAddresses = to.split(',').map((addr) => ({
|
|
503
|
+
email: addr.trim(),
|
|
504
|
+
}));
|
|
505
|
+
const email = {
|
|
506
|
+
to: toAddresses,
|
|
507
|
+
subject,
|
|
508
|
+
bodyValues: {
|
|
509
|
+
body: { value: message, isEncodingProblem: false, isTruncated: false },
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
if (emailType === 'html') {
|
|
513
|
+
email.htmlBody = [{ partId: 'body', type: 'text/html' }];
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
email.textBody = [{ partId: 'body', type: 'text/plain' }];
|
|
517
|
+
}
|
|
518
|
+
if (options.cc) {
|
|
519
|
+
email.cc = options.cc.split(',').map((addr) => ({
|
|
520
|
+
email: addr.trim(),
|
|
521
|
+
}));
|
|
522
|
+
}
|
|
523
|
+
if (options.bcc) {
|
|
524
|
+
email.bcc = options.bcc.split(',').map((addr) => ({
|
|
525
|
+
email: addr.trim(),
|
|
526
|
+
}));
|
|
527
|
+
}
|
|
528
|
+
responseData = await GenericFunctions_1.sendEmail.call(this, accountId, email, fromIdentity);
|
|
529
|
+
}
|
|
530
|
+
if (operation === 'createDraft') {
|
|
531
|
+
const to = this.getNodeParameter('to', i);
|
|
532
|
+
const subject = this.getNodeParameter('subject', i);
|
|
533
|
+
const emailType = this.getNodeParameter('emailType', i);
|
|
534
|
+
const message = this.getNodeParameter('message', i);
|
|
535
|
+
const options = this.getNodeParameter('options', i);
|
|
536
|
+
// Parse recipients
|
|
537
|
+
const toAddresses = to.split(',').map((addr) => ({
|
|
538
|
+
email: addr.trim(),
|
|
539
|
+
}));
|
|
540
|
+
const email = {
|
|
541
|
+
to: toAddresses,
|
|
542
|
+
subject,
|
|
543
|
+
bodyValues: {
|
|
544
|
+
body: { value: message, isEncodingProblem: false, isTruncated: false },
|
|
545
|
+
},
|
|
546
|
+
};
|
|
547
|
+
if (emailType === 'html') {
|
|
548
|
+
email.htmlBody = [{ partId: 'body', type: 'text/html' }];
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
email.textBody = [{ partId: 'body', type: 'text/plain' }];
|
|
552
|
+
}
|
|
553
|
+
if (options.cc) {
|
|
554
|
+
email.cc = options.cc.split(',').map((addr) => ({
|
|
555
|
+
email: addr.trim(),
|
|
556
|
+
}));
|
|
557
|
+
}
|
|
558
|
+
if (options.bcc) {
|
|
559
|
+
email.bcc = options.bcc.split(',').map((addr) => ({
|
|
560
|
+
email: addr.trim(),
|
|
561
|
+
}));
|
|
562
|
+
}
|
|
563
|
+
responseData = await GenericFunctions_1.createDraft.call(this, accountId, email);
|
|
564
|
+
}
|
|
565
|
+
if (operation === 'get') {
|
|
566
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
567
|
+
const emails = await GenericFunctions_1.getEmails.call(this, accountId, [emailId]);
|
|
568
|
+
responseData = emails[0] || {};
|
|
569
|
+
}
|
|
570
|
+
if (operation === 'getLabels') {
|
|
571
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
572
|
+
const labels = await GenericFunctions_1.getLabels.call(this, accountId, emailId);
|
|
573
|
+
responseData = {
|
|
574
|
+
emailId,
|
|
575
|
+
labels,
|
|
576
|
+
count: labels.length,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
if (operation === 'getMany') {
|
|
580
|
+
const mailbox = this.getNodeParameter('mailbox', i);
|
|
581
|
+
const limit = this.getNodeParameter('limit', i);
|
|
582
|
+
const filter = {};
|
|
583
|
+
if (mailbox) {
|
|
584
|
+
filter.inMailbox = mailbox;
|
|
585
|
+
}
|
|
586
|
+
const { ids } = await GenericFunctions_1.queryEmails.call(this, accountId, filter, [{ property: 'receivedAt', isAscending: false }], limit);
|
|
587
|
+
if (ids.length > 0) {
|
|
588
|
+
responseData = await GenericFunctions_1.getEmails.call(this, accountId, ids);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
responseData = [];
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (operation === 'delete') {
|
|
595
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
596
|
+
responseData = await GenericFunctions_1.deleteEmails.call(this, accountId, [emailId]);
|
|
597
|
+
}
|
|
598
|
+
if (operation === 'markAsRead') {
|
|
599
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
600
|
+
responseData = await GenericFunctions_1.updateEmailKeywords.call(this, accountId, emailId, {
|
|
601
|
+
$seen: true,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
if (operation === 'markAsUnread') {
|
|
605
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
606
|
+
responseData = await GenericFunctions_1.updateEmailKeywords.call(this, accountId, emailId, {
|
|
607
|
+
$seen: false,
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
if (operation === 'move') {
|
|
611
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
612
|
+
const targetMailbox = this.getNodeParameter('targetMailbox', i);
|
|
613
|
+
responseData = await GenericFunctions_1.moveEmail.call(this, accountId, emailId, targetMailbox);
|
|
614
|
+
}
|
|
615
|
+
if (operation === 'addLabel') {
|
|
616
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
617
|
+
const label = this.getNodeParameter('label', i);
|
|
618
|
+
responseData = await GenericFunctions_1.addLabel.call(this, accountId, emailId, label);
|
|
619
|
+
}
|
|
620
|
+
if (operation === 'removeLabel') {
|
|
621
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
622
|
+
const label = this.getNodeParameter('label', i);
|
|
623
|
+
responseData = await GenericFunctions_1.removeLabel.call(this, accountId, emailId, label);
|
|
624
|
+
}
|
|
625
|
+
if (operation === 'reply') {
|
|
626
|
+
const emailId = this.getNodeParameter('emailId', i);
|
|
627
|
+
const fromIdentity = this.getNodeParameter('fromIdentity', i);
|
|
628
|
+
const emailType = this.getNodeParameter('emailType', i);
|
|
629
|
+
const message = this.getNodeParameter('message', i);
|
|
630
|
+
// Get the original email
|
|
631
|
+
const [originalEmail] = await GenericFunctions_1.getEmails.call(this, accountId, [emailId]);
|
|
632
|
+
if (!originalEmail) {
|
|
633
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Original email not found', {
|
|
634
|
+
itemIndex: i,
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
// Build reply
|
|
638
|
+
const replyTo = originalEmail.replyTo ||
|
|
639
|
+
originalEmail.from;
|
|
640
|
+
const email = {
|
|
641
|
+
to: replyTo,
|
|
642
|
+
subject: `Re: ${originalEmail.subject}`,
|
|
643
|
+
inReplyTo: originalEmail.id,
|
|
644
|
+
references: originalEmail.id,
|
|
645
|
+
threadId: originalEmail.threadId,
|
|
646
|
+
bodyValues: {
|
|
647
|
+
body: { value: message, isEncodingProblem: false, isTruncated: false },
|
|
648
|
+
},
|
|
649
|
+
};
|
|
650
|
+
if (emailType === 'html') {
|
|
651
|
+
email.htmlBody = [{ partId: 'body', type: 'text/html' }];
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
email.textBody = [{ partId: 'body', type: 'text/plain' }];
|
|
655
|
+
}
|
|
656
|
+
responseData = await GenericFunctions_1.sendEmail.call(this, accountId, email, fromIdentity);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
// ==================== MAILBOX ====================
|
|
660
|
+
if (resource === 'mailbox') {
|
|
661
|
+
if (operation === 'getMany') {
|
|
662
|
+
responseData = await GenericFunctions_1.getMailboxes.call(this, accountId);
|
|
663
|
+
}
|
|
664
|
+
if (operation === 'get') {
|
|
665
|
+
const mailboxId = this.getNodeParameter('mailboxId', i);
|
|
666
|
+
const mailboxes = await GenericFunctions_1.getMailboxes.call(this, accountId);
|
|
667
|
+
const mailbox = mailboxes.find((mb) => mb.id === mailboxId);
|
|
668
|
+
responseData = mailbox || {};
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// ==================== THREAD ====================
|
|
672
|
+
if (resource === 'thread') {
|
|
673
|
+
if (operation === 'get') {
|
|
674
|
+
const threadId = this.getNodeParameter('threadId', i);
|
|
675
|
+
const threads = await GenericFunctions_1.getThreads.call(this, accountId, [threadId]);
|
|
676
|
+
responseData = threads[0] || {};
|
|
677
|
+
}
|
|
678
|
+
if (operation === 'getMany') {
|
|
679
|
+
const threadId = this.getNodeParameter('threadId', i);
|
|
680
|
+
const threads = await GenericFunctions_1.getThreads.call(this, accountId, [threadId]);
|
|
681
|
+
if (threads.length > 0 && threads[0].emailIds) {
|
|
682
|
+
const emailIds = threads[0].emailIds;
|
|
683
|
+
responseData = await GenericFunctions_1.getEmails.call(this, accountId, emailIds);
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
responseData = [];
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
|
|
691
|
+
returnData.push(...executionData);
|
|
692
|
+
}
|
|
693
|
+
catch (error) {
|
|
694
|
+
if (this.continueOnFail()) {
|
|
695
|
+
returnData.push({
|
|
696
|
+
json: { error: error.message },
|
|
697
|
+
pairedItem: { item: i },
|
|
698
|
+
});
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
throw error;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return [returnData];
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
exports.Jmap = Jmap;
|