@hyperbytes/wappler-imap-manager 1.0.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +10 -0
  4. package/package.json +22 -0
  5. package/server_connect/modules/imapcount.hjson +126 -0
  6. package/server_connect/modules/imapcount.js +53 -0
  7. package/server_connect/modules/imapcount.php +17 -0
  8. package/server_connect/modules/imapcreatefolder.hjson +124 -0
  9. package/server_connect/modules/imapcreatefolder.js +46 -0
  10. package/server_connect/modules/imapcreatefolder.php +17 -0
  11. package/server_connect/modules/imapdelete.hjson +148 -0
  12. package/server_connect/modules/imapdelete.js +73 -0
  13. package/server_connect/modules/imapdelete.php +17 -0
  14. package/server_connect/modules/imapdeletefolder.hjson +125 -0
  15. package/server_connect/modules/imapdeletefolder.js +65 -0
  16. package/server_connect/modules/imapdeletefolder.php +17 -0
  17. package/server_connect/modules/imapdirlist.hjson +122 -0
  18. package/server_connect/modules/imapdirlist.js +57 -0
  19. package/server_connect/modules/imapdirlist.php +17 -0
  20. package/server_connect/modules/imapexpunge.hjson +115 -0
  21. package/server_connect/modules/imapexpunge.js +63 -0
  22. package/server_connect/modules/imapexpunge.php +17 -0
  23. package/server_connect/modules/imapflag.hjson +153 -0
  24. package/server_connect/modules/imapflag.js +81 -0
  25. package/server_connect/modules/imapflag.php +17 -0
  26. package/server_connect/modules/imapgetattachments.hjson +159 -0
  27. package/server_connect/modules/imapgetattachments.js +94 -0
  28. package/server_connect/modules/imapgetattachments.php +17 -0
  29. package/server_connect/modules/imapgetrawheaders.hjson +120 -0
  30. package/server_connect/modules/imapgetrawheaders.js +121 -0
  31. package/server_connect/modules/imapgetrawheaders.php +17 -0
  32. package/server_connect/modules/imapmailcontent.hjson +192 -0
  33. package/server_connect/modules/imapmailcontent.js +113 -0
  34. package/server_connect/modules/imapmailcontent.php +17 -0
  35. package/server_connect/modules/imapmailheaders.hjson +174 -0
  36. package/server_connect/modules/imapmailheaders.js +184 -0
  37. package/server_connect/modules/imapmailheaders.php +71 -0
  38. package/server_connect/modules/imapmovefolder.hjson +158 -0
  39. package/server_connect/modules/imapmovefolder.js +86 -0
  40. package/server_connect/modules/imapmovefolder.php +17 -0
  41. package/server_connect/modules/imapremoveflag.hjson +151 -0
  42. package/server_connect/modules/imapremoveflag.js +72 -0
  43. package/server_connect/modules/imapremoveflag.php +17 -0
  44. package/server_connect/modules/imapsaveasdraft.hjson +202 -0
  45. package/server_connect/modules/imapsaveasdraft.js +184 -0
  46. package/server_connect/modules/imapsaveflag.php +17 -0
  47. package/server_connect/modules/imapsendmail.hjson +190 -0
  48. package/server_connect/modules/imapsendmail.js +171 -0
  49. package/server_connect/modules/imapsendmail.php +17 -0
  50. package/server_connect/modules/imapstore.hjson +160 -0
  51. package/server_connect/modules/imapstore.js +63 -0
  52. package/server_connect/modules/imapstore.php +17 -0
  53. package/server_connect/modules/imapsubscribe.hjson +128 -0
  54. package/server_connect/modules/imapsubscribe.js +43 -0
  55. package/server_connect/modules/imapsubscribe.php +17 -0
  56. package/server_connect/modules/imapsubscribedlist.hjson +122 -0
  57. package/server_connect/modules/imapsubscribedlist.js +57 -0
  58. package/server_connect/modules/imapsubscribedlist.php +17 -0
  59. package/server_connect/modules/imaptrashperms.hjson +115 -0
  60. package/server_connect/modules/imaptrashperms.js +51 -0
  61. package/server_connect/modules/imaptrashperms.php +17 -0
  62. package/server_connect/modules/imapunsubscribedlist.hjson +122 -0
  63. package/server_connect/modules/imapunsubscribedlist.js +80 -0
  64. package/server_connect/modules/imapunsubscribedlist.php +17 -0
  65. package/server_connect/modules/testfile.hjsonx +134 -0
  66. package/server_connect/modules/testfile.js +28 -0
  67. package/server_connect/modules/testfile_bug.hjsonx +141 -0
  68. package/server_connect/modules/testfile_bug.js +8 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ all details are at:
2
+
3
+ https://community.wappler.io/t/custom-modules-imap-email-magement-node-build-you-own-webmail/62897
4
+
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Brian English
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.T
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ all support can be found here.
2
+
3
+ https://community.wappler.io/t/custom-modules-imap-email-magement-node-build-you-own-webmail/62897
4
+
5
+ This package currently only supports Node.js however PHP version is currently being evaluated
6
+
7
+ Next release will add management of drafts and nested folders
8
+
9
+
10
+
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@hyperbytes/wappler-imap-manager",
3
+ "version": "1.0.0",
4
+ "description": "IMAP eMail Management for Wappler",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Brian English - @hyperbytes"
8
+ },
9
+ "keywords": [
10
+ "wappler-extension",
11
+ "server-connect",
12
+ "IMAP",
13
+ "email"
14
+ ],
15
+ "dependencies": {
16
+ "imap": "^8.8.19",
17
+ "mailparser": "^3.7.2",
18
+ "imap-simple": "^5.1.0",
19
+ "mailtrap": "^4.1.0",
20
+ "mailcomposer": "^1.0.0"
21
+ }
22
+ }
@@ -0,0 +1,126 @@
1
+ [{
2
+ type: 'imapcount-imapcount',
3
+ module : 'imapcount',
4
+ action : 'imapcount',
5
+ groupTitle : 'Mailer',
6
+ groupIcon : 'fas fa-envelope comp-general',
7
+ title : 'IMAP Count eMails',
8
+ icon : 'fas fa-solid fa-calculator comp-exec',
9
+ dataPickObject: true,
10
+ usedModules : {
11
+ node: {
12
+ 'imap' : '^8.8.19',
13
+ 'mailparser' : '^3.7.2'
14
+ }
15
+ },
16
+ dataScheme: [
17
+ { type:"text", name: "mailbox"},
18
+ { type: "number",name: "count"},
19
+ {type: "number", name: "status"}
20
+ ],
21
+ properties : [
22
+ {
23
+ group: 'IMAP Inputs',
24
+ variables: [
25
+
26
+ { name: 'actionName',
27
+ optionName: 'name',
28
+ title: 'Name',
29
+ type: 'text',
30
+ required: true,
31
+ baseName: "imap"
32
+ },
33
+ { name: 'selector', optionName: 'selector', title: 'IAMP Settings Selection',
34
+ type: 'droplist',
35
+ values: [
36
+ {title: 'Use ENV ', value: 'ENV' ,show:[],hide:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls']},
37
+ {title: 'Enable Manual Overrides', value: 'MANUAL',hide:[],show:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls'] },
38
+
39
+
40
+ ],
41
+ defaultValue: 'ENV',
42
+ help: 'Choose your TLS settings.',
43
+ initValue: "ENV"
44
+ },
45
+
46
+ {name: 'imap_msg',
47
+ optionName: 'imap_msg',
48
+ title: 'IMAP password',
49
+ type: 'static',
50
+ help: 'IMAP .ENV OVERRIDE SETTINGS'
51
+ },
52
+
53
+ {name: 'imap_host',
54
+ optionName: 'imap_host',
55
+ title: 'IMAP Host',
56
+ type: 'text',
57
+ defaultValue: "", initDisplay: 'none',
58
+ serverDataBindings: true,
59
+ help: 'The IMAP Host Server'
60
+ },
61
+ {name: 'imap_user',
62
+ optionName: 'imap_user',
63
+ title: 'IMAP User',
64
+ type: 'text',
65
+ defaultValue: "", initDisplay: 'none',
66
+ serverDataBindings: true,
67
+ help: 'The IMAP user'
68
+ },
69
+
70
+ {name: 'imap_password',
71
+ optionName: 'imap_password',
72
+ title: 'IMAP password',
73
+ type: 'text',
74
+ defaultValue: "", initDisplay: 'none',
75
+ serverDataBindings: true,
76
+ help: 'The IMAP password'
77
+ },
78
+ {name: 'imap_port',
79
+ optionName: 'imap_port',
80
+ title: 'IMAP Port',
81
+ type: 'text',
82
+ defaultValue: "", initDisplay: 'none',
83
+ serverDataBindings: true,
84
+ help: 'The IMAP port'
85
+ },
86
+ { name: 'imap_tls', optionName: 'imap_tls', title: 'TLS Settings',
87
+ type: 'droplist',
88
+ values: [
89
+ {title: 'Use ENV if available', value: 'ENV' },
90
+ {title: 'True', value: 'True' },
91
+ {title: 'False', value: 'False' },
92
+
93
+ ],
94
+ defaultValue: 'ENV', initDisplay: 'none',
95
+ help: 'Choose your TLS settings.',
96
+ initValue: "ENV"
97
+ },
98
+
99
+ {name: 'imap_msg2',
100
+ optionName: 'imap_msg2',
101
+ title: '',
102
+ type: 'static',
103
+ help: 'API ACTION SETTINGS'
104
+ },
105
+ { name: 'mailbox',
106
+ optionName: 'mailbox',
107
+ title: 'Mailbox',
108
+ type: 'text',
109
+ required: true,
110
+ defaultValue: "INBOX",
111
+ serverDataBindings: true,
112
+ help: 'The Mailbox in which to count emails'
113
+ },
114
+ { name: 'output',
115
+ optionName: 'output',
116
+ title: 'Output',
117
+ type: 'boolean',
118
+ defaultValue: false
119
+ }
120
+
121
+ ]
122
+ },
123
+
124
+ ]
125
+ }
126
+ ]
@@ -0,0 +1,53 @@
1
+ const Imap = require('imap');
2
+ const { inspect } = require('util');
3
+
4
+ exports.imapcount = async function (options, name) {
5
+ const IMAP_HOST = this.parseOptional(options.imap_host, '*', process.env.IMAP_HOST);
6
+ const IMAP_PASSWORD = this.parseOptional(options.imap_password, '*', process.env.IMAP_PASSWORD);
7
+ const IMAP_USER = this.parseOptional(options.imap_usesr, '*', process.env.IMAP_USER);
8
+ const IMAP_PORT = this.parseOptional(options.imap_port, '*', process.env.IMAP_PORT);
9
+ const imap_tlsstring = this.parseOptional(options.imap_tls, '*', process.env.IMAP_TLS).toLowerCase();
10
+ const IMAP_TLS = (imap_tlsstring == 'true');
11
+
12
+ // Retrieve mailbox name from options, default to 'INBOX' if not provided
13
+ const mailbox = this.parseRequired(options.mailbox, '*', "No Mailbox specified");
14
+
15
+ function getEmailCount(config, mailbox) {
16
+ return new Promise((resolve) => {
17
+ const imap = new Imap(config);
18
+
19
+ imap.once('ready', function () {
20
+ imap.openBox(mailbox, true, function (err, box) {
21
+ if (err) {
22
+ imap.end();
23
+ return resolve({ mailbox: mailbox, count: 0, status: 401 });
24
+ }
25
+ console.log(`Mailbox ${mailbox} contains ${box.messages.total} emails.`);
26
+ resolve({ mailbox: mailbox, count: box.messages.total, status: 200 });
27
+ imap.end();
28
+ });
29
+ });
30
+
31
+ imap.once('error', function () {
32
+ resolve({ mailbox: mailbox, count: 0, status: 401 });
33
+ });
34
+
35
+ imap.once('end', function () {
36
+ console.log('IMAP Connection ended');
37
+ });
38
+
39
+ imap.connect();
40
+ });
41
+ }
42
+
43
+ // Config setup
44
+ const config = {
45
+ user: IMAP_USER,
46
+ password: IMAP_PASSWORD,
47
+ host: IMAP_HOST,
48
+ port: IMAP_PORT,
49
+ tls: IMAP_TLS
50
+ };
51
+
52
+ return getEmailCount(config, mailbox);
53
+ };
@@ -0,0 +1,17 @@
1
+ <?php
2
+
3
+ namespace modules;
4
+
5
+ use \lib\core\Module;
6
+
7
+ class custom extends Module
8
+ {
9
+ public function imapcount($options, $name) {
10
+
11
+ $myObj->response = "This function is not yet available in PHP";
12
+
13
+ return json_encode($myObj);
14
+ }
15
+ }
16
+
17
+ ?>
@@ -0,0 +1,124 @@
1
+ [{
2
+ type: 'imapcreatefolder-imapcreatefolder',
3
+ module : 'imapcreatefolder',
4
+ action : 'imapcreatefolder',
5
+ groupTitle : 'Mailer',
6
+ groupIcon : 'fas fa-envelope comp-general',
7
+ title : 'IMAP Create Folder',
8
+ icon : 'fas fa-solid fa-calculator comp-exec',
9
+ dataPickObject: true,
10
+ usedModules : {
11
+ node: {
12
+ 'imap' : '^8.8.19',
13
+ 'mailparser' : '^3.7.2'
14
+ }
15
+ },
16
+ dataScheme: [
17
+ { type: "number",name: "status"},
18
+ { type: "text",name: "message"}
19
+ ]
20
+ properties : [
21
+ {
22
+ group: 'IMAP Inputs',
23
+ variables: [
24
+
25
+ { name: 'actionName',
26
+ optionName: 'name',
27
+ title: 'Name',
28
+ type: 'text',
29
+ required: true,
30
+ baseName: "imap"
31
+ },
32
+ { name: 'selector', optionName: 'selector', title: 'IAMP Settings Selection',
33
+ type: 'droplist',
34
+ values: [
35
+ {title: 'Use ENV ', value: 'ENV' ,show:[],hide:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls']},
36
+ {title: 'Enable Manual Overrides', value: 'MANUAL',hide:[],show:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls'] },
37
+
38
+
39
+ ],
40
+ defaultValue: 'ENV',
41
+ help: 'Choose your TLS settings.',
42
+ initValue: "ENV"
43
+ },
44
+ {name: 'imap_msg',
45
+ optionName: 'imap_msg',
46
+ title: 'IMAP password',
47
+ type: 'static',
48
+ help: 'IMAP .ENV OVERRIDE SETTINGS'
49
+ },
50
+ {name: 'imap_host',
51
+ optionName: 'imap_host',
52
+ title: 'IMAP Host',
53
+ type: 'text',
54
+ defaultValue: "",
55
+ serverDataBindings: true,
56
+ help: 'The IMAP Host Server'
57
+ },
58
+ {name: 'imap_user',
59
+ optionName: 'imap_user',
60
+ title: 'IMAP User',
61
+ type: 'text',
62
+ defaultValue: "",
63
+ serverDataBindings: true,
64
+ help: 'The IMAP user'
65
+ },
66
+
67
+ {name: 'imap_password',
68
+ optionName: 'imap_password',
69
+ title: 'IMAP password',
70
+ type: 'text',
71
+ defaultValue: "",
72
+ serverDataBindings: true,
73
+ help: 'The IMAP password'
74
+ },
75
+ {name: 'imap_port',
76
+ optionName: 'imap_port',
77
+ title: 'IMAP Port',
78
+ type: 'text',
79
+ defaultValue: "",
80
+ serverDataBindings: true,
81
+ help: 'The IMAP port'
82
+ },
83
+ { name: 'imap_tls', optionName: 'imap_tls', title: 'TLS Settings',
84
+ type: 'droplist',
85
+ values: [
86
+ {title: 'Use ENV if available', value: 'ENV' },
87
+ {title: 'True', value: 'True' },
88
+ {title: 'False', value: 'False' },
89
+
90
+ ],
91
+ defaultValue: 'ENV',
92
+ help: 'Choose your TLS settings.',
93
+ initValue: "ENV"
94
+ },
95
+
96
+ {name: 'imap_msg2',
97
+ optionName: 'imap_msg2',
98
+ title: '',
99
+ type: 'static',
100
+ help: 'API ACTION SETTINGS'
101
+ },
102
+ { name: 'imapfolder',
103
+ optionName: 'imapfolder',
104
+ title: 'IMAP Folder',
105
+ type: 'text',
106
+ required: true,
107
+ serverDataBindings: true,
108
+ defaultValue: '',
109
+ help: 'The folder to create'
110
+
111
+ },
112
+ { name: 'output',
113
+ optionName: 'output',
114
+ title: 'Output',
115
+ type: 'boolean',
116
+ defaultValue: false
117
+ }
118
+
119
+ ]
120
+ },
121
+
122
+ ]
123
+ }
124
+ ]
@@ -0,0 +1,46 @@
1
+ const Imap = require('imap');
2
+
3
+
4
+
5
+ exports.imapcreatefolder = async function (options) {
6
+ // Load IMAP credentials from environment variables
7
+ const IMAP_USER = process.env.IMAP_USER;
8
+ const IMAP_PASSWORD = process.env.IMAP_PASSWORD;
9
+ const IMAP_HOST = process.env.IMAP_HOST;
10
+ const IMAP_PORT = process.env.IMAP_PORT;
11
+ const IMAP_TLS = true
12
+ const imapfolder = this.parseRequired(options.imapfolder, '*', "No folder specified'")
13
+ const separator = process.env.IMAP_SUB_SEPARATOR || '/';
14
+ return new Promise((resolve, reject) => {
15
+ const imap = new Imap({
16
+ user: IMAP_USER,
17
+ password: IMAP_PASSWORD,
18
+ host: IMAP_HOST,
19
+ port: IMAP_PORT,
20
+ tls: IMAP_TLS,
21
+ });
22
+
23
+
24
+ imap.connect();
25
+
26
+ imap.once('ready', () => {
27
+ const folderPath = 'INBOX' + separator + imapfolder;
28
+ imap.addBox(folderPath, (err) => {
29
+ if (err) {
30
+ reject({ status: 400, message: `Error: ${err.message}` });
31
+ } else {
32
+ resolve({ status: 200, message: `Folder "${folderPath}" created successfully.` });
33
+ }
34
+ imap.end();
35
+ });
36
+ });
37
+
38
+ imap.once('error', (err) => {
39
+ reject({ status: 401, message: `Connection error: ${err.message}` });
40
+ });
41
+
42
+ imap.once('end', () => {
43
+ console.log('IMAP connection closed.');
44
+ });
45
+ });
46
+ };
@@ -0,0 +1,17 @@
1
+ <?php
2
+
3
+ namespace modules;
4
+
5
+ use \lib\core\Module;
6
+
7
+ class custom extends Module
8
+ {
9
+ public function imapcreatefolder($options, $name) {
10
+
11
+ $myObj->response = "This function is not yet available in PHP";
12
+
13
+ return json_encode($myObj);
14
+ }
15
+ }
16
+
17
+ ?>
@@ -0,0 +1,148 @@
1
+ [{
2
+ type: 'imapdelete-imapdelete',
3
+ module : 'imapdelete',
4
+ action : 'imapdelete',
5
+ groupTitle : 'Mailer',
6
+ groupIcon : 'fas fa-envelope comp-general',
7
+ title : 'IMAP Delete message by UID',
8
+ icon : 'fas fa-solid fa-trash comp-exec',
9
+ dataPickObject: true,
10
+ usedModules : {
11
+ node: {
12
+ 'imap' : '^8.8.19',
13
+ 'mailparser' : '^3.7.2'
14
+ }
15
+ },
16
+ dataScheme: [
17
+ { type:"number", name: "uid"},
18
+ { type:"text", name: "mailbox"},
19
+ { type: "number",name: "count"},
20
+ {type: "text", name: "destination"},
21
+ { type: "number",name: "status"}
22
+ ],
23
+
24
+ properties : [
25
+ {
26
+ group: 'IMAP Inputs',
27
+ variables: [
28
+
29
+ { name: 'actionName',
30
+ optionName: 'name',
31
+ title: 'Name',
32
+ type: 'text',
33
+ required: true,
34
+ baseName: "imap"
35
+ },
36
+ { name: 'selector', optionName: 'selector', title: 'IAMP Settings Selection',
37
+ type: 'droplist',
38
+ values: [
39
+ {title: 'Use ENV ', value: 'ENV' ,show:[],hide:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls']},
40
+ {title: 'Enable Manual Overrides', value: 'MANUAL',hide:[],show:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls'] },
41
+
42
+
43
+ ],
44
+ defaultValue: 'ENV',
45
+ help: 'Choose your TLS settings.',
46
+ initValue: "ENV"
47
+ },
48
+
49
+ {name: 'imap_msg',
50
+ optionName: 'imap_msg',
51
+ title: 'IMAP password',
52
+ type: 'static',
53
+ help: 'IMAP .ENV OVERRIDE SETTINGS'
54
+ },
55
+
56
+ {name: 'imap_host',
57
+ optionName: 'imap_host',
58
+ title: 'IMAP Host',
59
+ type: 'text',
60
+ defaultValue: "", initDisplay: 'none',
61
+ serverDataBindings: true,
62
+ help: 'The IMAP Host Server'
63
+ },
64
+ {name: 'imap_user',
65
+ optionName: 'imap_user',
66
+ title: 'IMAP User',
67
+ type: 'text',
68
+ defaultValue: "", initDisplay: 'none',
69
+ serverDataBindings: true,
70
+ help: 'The IMAP user'
71
+ },
72
+
73
+ {name: 'imap_password',
74
+ optionName: 'imap_password',
75
+ title: 'IMAP password',
76
+ type: 'text',
77
+ defaultValue: "", initDisplay: 'none',
78
+ serverDataBindings: true,
79
+ help: 'The IMAP password'
80
+ },
81
+ {name: 'imap_port',
82
+ optionName: 'imap_port',
83
+ title: 'IMAP Port',
84
+ type: 'text',
85
+ defaultValue: "", initDisplay: 'none',
86
+ serverDataBindings: true,
87
+ help: 'The IMAP port'
88
+ },
89
+ { name: 'imap_tls', optionName: 'imap_tls', title: 'TLS Settings',
90
+ type: 'droplist',
91
+ values: [
92
+ {title: 'Use ENV if available', value: 'ENV' },
93
+ {title: 'True', value: 'True' },
94
+ {title: 'False', value: 'False' },
95
+
96
+ ],
97
+ defaultValue: 'ENV', initDisplay: 'none',
98
+ help: 'Choose your TLS settings.',
99
+ initValue: "ENV"
100
+ },
101
+
102
+ {name: 'imap_msg2',
103
+ optionName: 'imap_msg2',
104
+ title: '',
105
+ type: 'static',
106
+ help: 'API ACTION SETTINGS'
107
+ },
108
+ { name: 'uid',
109
+ optionName: 'uid',
110
+ title: 'uid',
111
+ type: 'text',
112
+ required: true,
113
+ defaultValue: "0",
114
+ serverDataBindings: true,
115
+ help: 'The uid of the email'
116
+ },
117
+ { name: 'uidvalidity',
118
+ optionName: 'uidvalidity',
119
+ title: 'uidvalidity',
120
+ type: 'text',
121
+ required: true,
122
+ defaultValue: "0",
123
+ serverDataBindings: true,
124
+ help: 'The uidvalidity key of the email'
125
+ },
126
+ { name: 'mailbox',
127
+ optionName: 'mailbox',
128
+ title: 'mailbox',
129
+ type: 'text',
130
+ required: true,
131
+ defaultValue: "INBOX",
132
+ serverDataBindings: true,
133
+ help: 'The mailbox containing the email'
134
+ },
135
+
136
+ { name: 'output',
137
+ optionName: 'output',
138
+ title: 'Output',
139
+ type: 'boolean',
140
+ defaultValue: false
141
+ }
142
+
143
+ ]
144
+ },
145
+
146
+ ]
147
+ }
148
+ ]
@@ -0,0 +1,73 @@
1
+ const Imap = require('imap');
2
+
3
+ exports.imapdelete = async function (options, name) {
4
+ const IMAP_HOST = this.parseOptional(options.imap_host, '*', process.env.IMAP_HOST);
5
+ const IMAP_PASSWORD = this.parseOptional(options.imap_password, '*', process.env.IMAP_PASSWORD);
6
+ const IMAP_USER = this.parseOptional(options.imap_usesr, '*', process.env.IMAP_USER);
7
+ const IMAP_PORT = this.parseOptional(options.imap_port, '*', process.env.IMAP_PORT);
8
+ const imap_tlsstring = this.parseOptional(options.imap_tls, '*', process.env.IMAP_TLS).toLowerCase();
9
+ const IMAP_TLS = (imap_tlsstring == 'true');
10
+
11
+ const uid = this.parseRequired(options.uid, '*', "No message UID specified");
12
+ const uidvalidity = Number(this.parseRequired(options.uidvalidity, '*', "No UIDVALIDITY specified"));
13
+ const mailbox = this.parseRequired(options.mailbox, '*', "No Mailbox specified");
14
+ const flagonly = this.parseOptional(options.flagonly, '*', false);
15
+
16
+ function deleteEmail(config, emailUID, uidvalidity) {
17
+ return new Promise((resolve) => {
18
+ const imap = new Imap(config);
19
+
20
+ function openMailbox(cb) {
21
+ imap.openBox(mailbox, false, cb);
22
+ }
23
+
24
+ imap.once('ready', function () {
25
+ openMailbox(function (err, box) {
26
+ if (err) {
27
+ imap.end();
28
+ return resolve({ uid: null, mailbox: mailbox, status: 401 });
29
+ }
30
+
31
+ if (box.uidvalidity !== uidvalidity) {
32
+ imap.end();
33
+ return resolve({ uid: null, mailbox: mailbox, status: 401 });
34
+ }
35
+
36
+ imap.addFlags(emailUID, ['\\Deleted'], function (err) {
37
+ if (err) {
38
+ imap.end();
39
+ return resolve({ uid: emailUID, mailbox: mailbox, status: 401 });
40
+ }
41
+
42
+ console.log(`Email UID ${emailUID} marked for deletion.`);
43
+
44
+
45
+ imap.end();
46
+ resolve({ uid: emailUID, mailbox: mailbox, expunged: !flagonly, status: 200 });
47
+ });
48
+ });
49
+ });
50
+
51
+ imap.once('error', function () {
52
+ resolve({ uid: null, mailbox: mailbox, status: 401 });
53
+ });
54
+
55
+ imap.once('end', function () {
56
+ console.log('IMAP Connection ended');
57
+ });
58
+
59
+ imap.connect();
60
+ });
61
+ }
62
+
63
+ // Config setup
64
+ const config = {
65
+ user: IMAP_USER,
66
+ password: IMAP_PASSWORD,
67
+ host: IMAP_HOST,
68
+ port: IMAP_PORT,
69
+ tls: IMAP_TLS
70
+ };
71
+
72
+ return deleteEmail(config, uid, uidvalidity);
73
+ };
@@ -0,0 +1,17 @@
1
+ <?php
2
+
3
+ namespace modules;
4
+
5
+ use \lib\core\Module;
6
+
7
+ class custom extends Module
8
+ {
9
+ public function imapdelete($options, $name) {
10
+
11
+ $myObj->response = "This function is not yet available in PHP";
12
+
13
+ return json_encode($myObj);
14
+ }
15
+ }
16
+
17
+ ?>