@@ -2,84 +2,86 @@ import { CopyResponseObject, ImapFlow } from 'imapflow';
2
2
import { IExecuteFunctions , INodeExecutionData , NodeApiError } from 'n8n-workflow' ;
3
3
import { IResourceOperationDef } from '../../../utils/CommonDefinitions' ;
4
4
import {
5
- getMailboxPathFromNodeParameter ,
6
- parameterSelectMailbox ,
5
+ getMailboxPathFromNodeParameter ,
6
+ parameterSelectMailbox ,
7
7
} from '../../../utils/SearchFieldParameters' ;
8
8
9
9
const PARAM_NAME_SOURCE_MAILBOX = 'sourceMailbox' ;
10
10
const PARAM_NAME_DESTINATION_MAILBOX = 'destinationMailbox' ;
11
11
12
12
export const copyEmailOperation : IResourceOperationDef = {
13
- operation : {
14
- name : 'Copy' ,
15
- value : 'copyEmail' ,
16
- } ,
17
- parameters : [
18
- {
19
- ...parameterSelectMailbox ,
20
- description : 'Select the mailbox' ,
21
- name : PARAM_NAME_SOURCE_MAILBOX ,
22
- } ,
23
- {
24
- displayName : 'Email UID' ,
25
- name : 'emailUid' ,
26
- type : 'string' ,
27
- default : '' ,
28
- description : 'UID of the email to copy' ,
29
- hint : 'You can use comma separated list of UIDs to copy multiple emails at once' ,
30
- } ,
31
- {
32
- ...parameterSelectMailbox ,
33
- description : 'Select the destination mailbox' ,
34
- name : PARAM_NAME_DESTINATION_MAILBOX ,
35
- } ,
36
- ] ,
37
- async executeImapAction (
38
- context : IExecuteFunctions ,
39
- itemIndex : number ,
40
- client : ImapFlow ,
41
- ) : Promise < INodeExecutionData [ ] | null > {
42
- var returnData : INodeExecutionData [ ] = [ ] ;
13
+ operation : {
14
+ name : 'Copy' ,
15
+ value : 'copyEmail' ,
16
+ } ,
17
+ parameters : [
18
+ {
19
+ ...parameterSelectMailbox ,
20
+ displayName : 'Source Mailbox' ,
21
+ description : 'Select the source mailbox' ,
22
+ name : PARAM_NAME_SOURCE_MAILBOX ,
23
+ } ,
24
+ {
25
+ displayName : 'Email UID' ,
26
+ name : 'emailUid' ,
27
+ type : 'string' ,
28
+ default : '' ,
29
+ description : 'UID of the email to copy' ,
30
+ hint : 'You can use comma separated list of UIDs to copy multiple emails at once' ,
31
+ } ,
32
+ {
33
+ ...parameterSelectMailbox ,
34
+ displayName : 'Destination Mailbox' ,
35
+ description : 'Select the destination mailbox' ,
36
+ name : PARAM_NAME_DESTINATION_MAILBOX ,
37
+ } ,
38
+ ] ,
39
+ async executeImapAction (
40
+ context : IExecuteFunctions ,
41
+ itemIndex : number ,
42
+ client : ImapFlow ,
43
+ ) : Promise < INodeExecutionData [ ] | null > {
44
+ var returnData : INodeExecutionData [ ] = [ ] ;
43
45
44
- const sourceMailboxPath = getMailboxPathFromNodeParameter (
45
- context ,
46
- itemIndex ,
47
- PARAM_NAME_SOURCE_MAILBOX ,
48
- ) ;
49
- const destinationMailboxPath = getMailboxPathFromNodeParameter (
50
- context ,
51
- itemIndex ,
52
- PARAM_NAME_DESTINATION_MAILBOX ,
53
- ) ;
46
+ const sourceMailboxPath = getMailboxPathFromNodeParameter (
47
+ context ,
48
+ itemIndex ,
49
+ PARAM_NAME_SOURCE_MAILBOX ,
50
+ ) ;
51
+ const destinationMailboxPath = getMailboxPathFromNodeParameter (
52
+ context ,
53
+ itemIndex ,
54
+ PARAM_NAME_DESTINATION_MAILBOX ,
55
+ ) ;
54
56
55
- const emailUid = context . getNodeParameter ( 'emailUid' , itemIndex ) as string ;
57
+ const emailUid = context . getNodeParameter ( 'emailUid' , itemIndex ) as string ;
56
58
57
- context . logger ?. info (
58
- `Copying email "${ emailUid } " from "${ sourceMailboxPath } " to "${ destinationMailboxPath } "` ,
59
- ) ;
59
+ context . logger ?. info (
60
+ `Copying email "${ emailUid } " from "${ sourceMailboxPath } " to "${ destinationMailboxPath } "` ,
61
+ ) ;
60
62
61
- await client . mailboxOpen ( sourceMailboxPath , { readOnly : false } ) ;
63
+ await client . mailboxOpen ( sourceMailboxPath , { readOnly : false } ) ;
62
64
63
- const resp : CopyResponseObject = await client . messageCopy ( emailUid , destinationMailboxPath , {
64
- uid : true ,
65
- } ) ;
65
+ const resp : CopyResponseObject = await client . messageCopy ( emailUid , destinationMailboxPath , {
66
+ uid : true ,
67
+ } ) ;
66
68
67
- if ( ! resp || ! resp . uidMap ) {
68
- throw new NodeApiError (
69
- context . getNode ( ) ,
70
- { } ,
71
- {
72
- message : 'Unable to copy email, unknown error' ,
73
- } ,
74
- ) ;
75
- }
69
+ if ( ! resp || ! resp . uidMap ) {
70
+ throw new NodeApiError (
71
+ context . getNode ( ) ,
72
+ { } ,
73
+ {
74
+ message : 'Unable to copy email, unknown error' ,
75
+ } ,
76
+ ) ;
77
+ }
76
78
77
- var item_json = JSON . parse ( JSON . stringify ( resp ) ) ;
79
+ var item_json = JSON . parse ( JSON . stringify ( resp ) ) ;
78
80
79
- returnData . push ( {
80
- json : item_json ,
81
- } ) ;
81
+ returnData . push ( {
82
+ json : item_json ,
83
+ } ) ;
82
84
83
- return returnData ;
84
- } ,
85
+ return returnData ;
86
+ } ,
85
87
} ;
0 commit comments