@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.
- package/CHANGELOG.md +4 -0
- package/LICENSE.md +21 -0
- package/README.md +10 -0
- package/package.json +22 -0
- package/server_connect/modules/imapcount.hjson +126 -0
- package/server_connect/modules/imapcount.js +53 -0
- package/server_connect/modules/imapcount.php +17 -0
- package/server_connect/modules/imapcreatefolder.hjson +124 -0
- package/server_connect/modules/imapcreatefolder.js +46 -0
- package/server_connect/modules/imapcreatefolder.php +17 -0
- package/server_connect/modules/imapdelete.hjson +148 -0
- package/server_connect/modules/imapdelete.js +73 -0
- package/server_connect/modules/imapdelete.php +17 -0
- package/server_connect/modules/imapdeletefolder.hjson +125 -0
- package/server_connect/modules/imapdeletefolder.js +65 -0
- package/server_connect/modules/imapdeletefolder.php +17 -0
- package/server_connect/modules/imapdirlist.hjson +122 -0
- package/server_connect/modules/imapdirlist.js +57 -0
- package/server_connect/modules/imapdirlist.php +17 -0
- package/server_connect/modules/imapexpunge.hjson +115 -0
- package/server_connect/modules/imapexpunge.js +63 -0
- package/server_connect/modules/imapexpunge.php +17 -0
- package/server_connect/modules/imapflag.hjson +153 -0
- package/server_connect/modules/imapflag.js +81 -0
- package/server_connect/modules/imapflag.php +17 -0
- package/server_connect/modules/imapgetattachments.hjson +159 -0
- package/server_connect/modules/imapgetattachments.js +94 -0
- package/server_connect/modules/imapgetattachments.php +17 -0
- package/server_connect/modules/imapgetrawheaders.hjson +120 -0
- package/server_connect/modules/imapgetrawheaders.js +121 -0
- package/server_connect/modules/imapgetrawheaders.php +17 -0
- package/server_connect/modules/imapmailcontent.hjson +192 -0
- package/server_connect/modules/imapmailcontent.js +113 -0
- package/server_connect/modules/imapmailcontent.php +17 -0
- package/server_connect/modules/imapmailheaders.hjson +174 -0
- package/server_connect/modules/imapmailheaders.js +184 -0
- package/server_connect/modules/imapmailheaders.php +71 -0
- package/server_connect/modules/imapmovefolder.hjson +158 -0
- package/server_connect/modules/imapmovefolder.js +86 -0
- package/server_connect/modules/imapmovefolder.php +17 -0
- package/server_connect/modules/imapremoveflag.hjson +151 -0
- package/server_connect/modules/imapremoveflag.js +72 -0
- package/server_connect/modules/imapremoveflag.php +17 -0
- package/server_connect/modules/imapsaveasdraft.hjson +202 -0
- package/server_connect/modules/imapsaveasdraft.js +184 -0
- package/server_connect/modules/imapsaveflag.php +17 -0
- package/server_connect/modules/imapsendmail.hjson +190 -0
- package/server_connect/modules/imapsendmail.js +171 -0
- package/server_connect/modules/imapsendmail.php +17 -0
- package/server_connect/modules/imapstore.hjson +160 -0
- package/server_connect/modules/imapstore.js +63 -0
- package/server_connect/modules/imapstore.php +17 -0
- package/server_connect/modules/imapsubscribe.hjson +128 -0
- package/server_connect/modules/imapsubscribe.js +43 -0
- package/server_connect/modules/imapsubscribe.php +17 -0
- package/server_connect/modules/imapsubscribedlist.hjson +122 -0
- package/server_connect/modules/imapsubscribedlist.js +57 -0
- package/server_connect/modules/imapsubscribedlist.php +17 -0
- package/server_connect/modules/imaptrashperms.hjson +115 -0
- package/server_connect/modules/imaptrashperms.js +51 -0
- package/server_connect/modules/imaptrashperms.php +17 -0
- package/server_connect/modules/imapunsubscribedlist.hjson +122 -0
- package/server_connect/modules/imapunsubscribedlist.js +80 -0
- package/server_connect/modules/imapunsubscribedlist.php +17 -0
- package/server_connect/modules/testfile.hjsonx +134 -0
- package/server_connect/modules/testfile.js +28 -0
- package/server_connect/modules/testfile_bug.hjsonx +141 -0
- package/server_connect/modules/testfile_bug.js +8 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
const nodemailer = require("nodemailer");
|
|
2
|
+
const imap = require("imap");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const { toSystemPath } = require("../../../lib/core/path");
|
|
7
|
+
|
|
8
|
+
exports.imapsendmail = async function (options) {
|
|
9
|
+
const upload = this.parseOptional(options.attachments, '*', '');
|
|
10
|
+
|
|
11
|
+
// Ensure attachments are properly formatted and converted to system paths
|
|
12
|
+
const attachmentList = Array.isArray(upload)
|
|
13
|
+
? upload.map(file => ({
|
|
14
|
+
...file, // Keep existing properties
|
|
15
|
+
systemPath: toSystemPath(file.path) // Convert relative path to system path
|
|
16
|
+
}))
|
|
17
|
+
: [];
|
|
18
|
+
|
|
19
|
+
console.log("Attachment upload initially:", upload);
|
|
20
|
+
console.log("Transformed Attachments List:", attachmentList);
|
|
21
|
+
|
|
22
|
+
const smtpFile = this.parseOptional(options.smtp_file, '*', 'default');
|
|
23
|
+
// const SMTP_SETTINGS_PATH = toSystemPath(`/.wappler/targets/${process.env.NODE_ENV}/app/modules/Mailer/${smtpFile}.json`);
|
|
24
|
+
const SMTP_SETTINGS_PATH = toSystemPath(`/app/modules/Mailer/${smtpFile}.json`);
|
|
25
|
+
console.log("SMTP Config Path:", SMTP_SETTINGS_PATH);
|
|
26
|
+
|
|
27
|
+
// Load SMTP settings dynamically
|
|
28
|
+
function loadSMTPSettings() {
|
|
29
|
+
try {
|
|
30
|
+
const settingsData = fs.readFileSync(SMTP_SETTINGS_PATH, "utf8");
|
|
31
|
+
const settings = JSON.parse(settingsData);
|
|
32
|
+
return settings.options;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error("Error loading SMTP settings:", error);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const smtpConfig = loadSMTPSettings();
|
|
40
|
+
if (!smtpConfig) {
|
|
41
|
+
return { status: 401, error: "Failed to load SMTP settings." };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const to = this.parseRequired(options.to, '*', "No to email address specified");
|
|
45
|
+
const cc = this.parseOptional(options.cc, '*', "");
|
|
46
|
+
const bcc = this.parseOptional(options.bcc, '*', "");
|
|
47
|
+
const from = this.parseRequired(options.from, '*', "No from email address specified");
|
|
48
|
+
const subject = this.parseOptional(options.subject, '*', "");
|
|
49
|
+
const body = this.parseRequired(options.body, '*', "No email body specified");
|
|
50
|
+
const saveToSent = this.parseOptional(options.save_to_send, '*', false);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const transporter = nodemailer.createTransport({
|
|
54
|
+
host: smtpConfig.host,
|
|
55
|
+
port: smtpConfig.port,
|
|
56
|
+
secure: smtpConfig.useSSL,
|
|
57
|
+
auth: {
|
|
58
|
+
user: smtpConfig.username,
|
|
59
|
+
pass: smtpConfig.password,
|
|
60
|
+
},
|
|
61
|
+
logger: true, // Enable logging
|
|
62
|
+
debug: true, // Enable debugging
|
|
63
|
+
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Prepare attachments for Nodemailer
|
|
67
|
+
const formattedAttachments = attachmentList.map(file => ({
|
|
68
|
+
filename: path.basename(file.systemPath),
|
|
69
|
+
path: file.systemPath // Use transformed system path
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
const mailOptions = {
|
|
73
|
+
from: from,
|
|
74
|
+
to: to,
|
|
75
|
+
cc: cc,
|
|
76
|
+
bcc: bcc,
|
|
77
|
+
subject: subject,
|
|
78
|
+
text: body,
|
|
79
|
+
html: body,
|
|
80
|
+
attachments: formattedAttachments,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
console.log("Final Attachments List:", formattedAttachments);
|
|
84
|
+
|
|
85
|
+
let info = await transporter.sendMail(mailOptions);
|
|
86
|
+
console.log("Email sent:", info.messageId);
|
|
87
|
+
|
|
88
|
+
// Save to Sent Items if requested
|
|
89
|
+
if (saveToSent) {
|
|
90
|
+
await saveToSentFolder(options, mailOptions);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { status: 200, messageId: info.messageId };
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error("Error sending email:", error);
|
|
96
|
+
return { status: 400, error: error.message };
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Function to **save email & attachments** in Sent Items (Promise-based)
|
|
101
|
+
async function saveToSentFolder(options, mailOptions) {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
const imapConfig = {
|
|
104
|
+
user: process.env.IMAP_USER,
|
|
105
|
+
password: process.env.IMAP_PASSWORD,
|
|
106
|
+
host: process.env.IMAP_HOST,
|
|
107
|
+
port: process.env.IMAP_PORT,
|
|
108
|
+
tls: true,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
let emailContent = `From: ${mailOptions.from}
|
|
112
|
+
To: ${mailOptions.to}
|
|
113
|
+
Subject: ${mailOptions.subject}
|
|
114
|
+
Content-Type: multipart/mixed; boundary="boundary"
|
|
115
|
+
|
|
116
|
+
--boundary
|
|
117
|
+
Content-Type: text/plain
|
|
118
|
+
|
|
119
|
+
${mailOptions.text || ""}
|
|
120
|
+
|
|
121
|
+
`;
|
|
122
|
+
|
|
123
|
+
// Attach files in MIME format
|
|
124
|
+
for (let attachment of mailOptions.attachments) {
|
|
125
|
+
try {
|
|
126
|
+
const fileData = fs.readFileSync(attachment.path).toString("base64");
|
|
127
|
+
emailContent += `--boundary
|
|
128
|
+
Content-Type: application/octet-stream; name="${attachment.filename}"
|
|
129
|
+
Content-Disposition: attachment; filename="${attachment.filename}"
|
|
130
|
+
Content-Transfer-Encoding: base64
|
|
131
|
+
|
|
132
|
+
${fileData}
|
|
133
|
+
|
|
134
|
+
`;
|
|
135
|
+
} catch (err) {
|
|
136
|
+
console.error(`Error reading attachment file: ${attachment.path}`, err);
|
|
137
|
+
return reject(err);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
emailContent += "--boundary--"; // Closing MIME boundary
|
|
142
|
+
|
|
143
|
+
const imapClient = new imap(imapConfig);
|
|
144
|
+
|
|
145
|
+
imapClient.once("ready", () => {
|
|
146
|
+
imapClient.openBox("Sent", true, (err) => {
|
|
147
|
+
if (err) {
|
|
148
|
+
console.error("Error opening Sent Items folder:", err);
|
|
149
|
+
return reject(err);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
imapClient.append(Buffer.from(emailContent), { mailbox: "Sent" }, (err) => {
|
|
153
|
+
if (err) {
|
|
154
|
+
console.error("Failed to save email to Sent Items:", err);
|
|
155
|
+
return reject(err);
|
|
156
|
+
}
|
|
157
|
+
console.log("Email successfully saved to Sent Items with attachments.");
|
|
158
|
+
imapClient.end();
|
|
159
|
+
resolve();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
imapClient.once("error", (err) => {
|
|
165
|
+
console.error("IMAP connection error:", err);
|
|
166
|
+
reject(err);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
imapClient.connect();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
@@ -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 imapsendmail($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,160 @@
|
|
|
1
|
+
[{
|
|
2
|
+
type: 'imapstore-imapstore',
|
|
3
|
+
module : 'imapstore',
|
|
4
|
+
action : 'imapstore',
|
|
5
|
+
groupTitle : 'Mailer',
|
|
6
|
+
groupIcon : 'fas fa-envelope comp-general',
|
|
7
|
+
title : 'IMAP store copy of mail',
|
|
8
|
+
icon : 'fas fa-solid fa-flag comp-exec',
|
|
9
|
+
dataPickObject: true,
|
|
10
|
+
usedModules : {
|
|
11
|
+
node: {
|
|
12
|
+
'imap' : '^8.8.19',
|
|
13
|
+
'mailparser' : '^3.7.2'
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
properties : [
|
|
18
|
+
{
|
|
19
|
+
group: 'IMAP Inputs',
|
|
20
|
+
variables: [
|
|
21
|
+
|
|
22
|
+
{ name: 'actionName',
|
|
23
|
+
optionName: 'name',
|
|
24
|
+
title: 'Name',
|
|
25
|
+
type: 'text',
|
|
26
|
+
required: true,
|
|
27
|
+
baseName: "imap"
|
|
28
|
+
},
|
|
29
|
+
{ name: 'selector', optionName: 'selector', title: 'IAMP Settings Selection',
|
|
30
|
+
type: 'droplist',
|
|
31
|
+
values: [
|
|
32
|
+
{title: 'Use ENV ', value: 'ENV' ,show:[],hide:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls']},
|
|
33
|
+
{title: 'Enable Manula Overrides', value: 'MANUAL',hide:[],show:['imap_msg','imap_host','imap_user','imap_password','imap_port','imap_tls'] },
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
],
|
|
37
|
+
defaultValue: 'ENV',
|
|
38
|
+
help: 'Choose your TLS settings.',
|
|
39
|
+
initValue: "ENV"
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
{name: 'imap_msg',
|
|
43
|
+
optionName: 'imap_msg',
|
|
44
|
+
title: 'IMAP password',
|
|
45
|
+
type: 'static',
|
|
46
|
+
help: 'IMAP .ENV OVERRIDE SETTINGS'
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
{name: 'imap_host',
|
|
50
|
+
optionName: 'imap_host',
|
|
51
|
+
title: 'IMAP Host',
|
|
52
|
+
type: 'text',
|
|
53
|
+
defaultValue: "", initDisplay: 'none',
|
|
54
|
+
serverDataBindings: true,
|
|
55
|
+
help: 'The IMAP Host Server'
|
|
56
|
+
},
|
|
57
|
+
{name: 'imap_user',
|
|
58
|
+
optionName: 'imap_user',
|
|
59
|
+
title: 'IMAP User',
|
|
60
|
+
type: 'text',
|
|
61
|
+
defaultValue: "", initDisplay: 'none',
|
|
62
|
+
serverDataBindings: true,
|
|
63
|
+
help: 'The IMAP user'
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
{name: 'imap_password',
|
|
67
|
+
optionName: 'imap_password',
|
|
68
|
+
title: 'IMAP password',
|
|
69
|
+
type: 'text',
|
|
70
|
+
defaultValue: "", initDisplay: 'none',
|
|
71
|
+
serverDataBindings: true,
|
|
72
|
+
help: 'The IMAP password'
|
|
73
|
+
},
|
|
74
|
+
{name: 'imap_port',
|
|
75
|
+
optionName: 'imap_port',
|
|
76
|
+
title: 'IMAP Port',
|
|
77
|
+
type: 'text',
|
|
78
|
+
defaultValue: "", initDisplay: 'none',
|
|
79
|
+
serverDataBindings: true,
|
|
80
|
+
help: 'The IMAP port'
|
|
81
|
+
},
|
|
82
|
+
{ name: 'imap_tls', optionName: 'imap_tls', title: 'TLS Settings',
|
|
83
|
+
type: 'droplist',
|
|
84
|
+
values: [
|
|
85
|
+
{title: 'Use ENV if available', value: 'ENV' },
|
|
86
|
+
{title: 'True', value: 'True' },
|
|
87
|
+
{title: 'False', value: 'False' },
|
|
88
|
+
|
|
89
|
+
],
|
|
90
|
+
defaultValue: 'ENV', initDisplay: 'none',
|
|
91
|
+
help: 'Choose your TLS settings.',
|
|
92
|
+
initValue: "ENV"
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
{name: 'imap_msg2',
|
|
96
|
+
optionName: 'imap_msg2',
|
|
97
|
+
title: '',
|
|
98
|
+
type: 'static',
|
|
99
|
+
help: 'API ACTION SETTINGS'
|
|
100
|
+
},
|
|
101
|
+
{ name: 'from',
|
|
102
|
+
optionName: 'from',
|
|
103
|
+
title: 'From',
|
|
104
|
+
type: 'text',
|
|
105
|
+
required: true,
|
|
106
|
+
defaultValue: "",
|
|
107
|
+
serverDataBindings: true,
|
|
108
|
+
help: 'From email'
|
|
109
|
+
},
|
|
110
|
+
{ name: 'to',
|
|
111
|
+
optionName: 'to',
|
|
112
|
+
title: 'To',
|
|
113
|
+
type: 'text',
|
|
114
|
+
required: true,
|
|
115
|
+
defaultValue: "",
|
|
116
|
+
serverDataBindings: true,
|
|
117
|
+
help: 'To email'
|
|
118
|
+
},
|
|
119
|
+
{ name: 'subject',
|
|
120
|
+
optionName: 'subject',
|
|
121
|
+
title: 'Subject',
|
|
122
|
+
type: 'text',
|
|
123
|
+
required: true,
|
|
124
|
+
defaultValue: "",
|
|
125
|
+
serverDataBindings: true,
|
|
126
|
+
help: 'Email subject'
|
|
127
|
+
},
|
|
128
|
+
{ name: 'body',
|
|
129
|
+
optionName: 'body',
|
|
130
|
+
title: 'Body',
|
|
131
|
+
type: 'text',
|
|
132
|
+
required: true,
|
|
133
|
+
defaultValue: "",
|
|
134
|
+
serverDataBindings: true,
|
|
135
|
+
help: 'Email body'
|
|
136
|
+
},
|
|
137
|
+
{ name: 'tomailbox',
|
|
138
|
+
optionName: 'tomailbox',
|
|
139
|
+
title: 'To Mailbox',
|
|
140
|
+
type: 'text',
|
|
141
|
+
required: true,
|
|
142
|
+
defaultValue: "",
|
|
143
|
+
serverDataBindings: true,
|
|
144
|
+
help: 'Mailbox to replicate to'
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
{ name: 'output',
|
|
149
|
+
optionName: 'output',
|
|
150
|
+
title: 'Output',
|
|
151
|
+
type: 'boolean',
|
|
152
|
+
defaultValue: false,
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const Imap = require('imap');
|
|
2
|
+
const { simpleParser } = require('mailparser');
|
|
3
|
+
|
|
4
|
+
exports.imapgetrawheaders = async function (options) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const imap = new Imap({
|
|
7
|
+
user: options.imap_user,
|
|
8
|
+
password: options.imap_password,
|
|
9
|
+
host: options.imap_host,
|
|
10
|
+
port: options.imap_port,
|
|
11
|
+
tls: true
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
imap.once('ready', () => {
|
|
15
|
+
imap.openBox(options.mailbox, false, (err, box) => { // Fixed `mailbox` reference
|
|
16
|
+
if (err) {
|
|
17
|
+
imap.end();
|
|
18
|
+
return reject(`Error opening mailbox: ${err.message}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (box.messages.total === 0) {
|
|
22
|
+
imap.end();
|
|
23
|
+
return reject('No messages found.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
imap.search(['ALL'], (err, results) => {
|
|
27
|
+
if (err || results.length === 0) {
|
|
28
|
+
imap.end();
|
|
29
|
+
return reject('No messages available.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const fetch = imap.fetch([results[0]], { bodies: 'HEADER' });
|
|
33
|
+
|
|
34
|
+
fetch.on('message', (msg) => {
|
|
35
|
+
let headerData = '';
|
|
36
|
+
|
|
37
|
+
msg.on('body', (stream) => {
|
|
38
|
+
stream.on('data', (chunk) => {
|
|
39
|
+
headerData += chunk.toString();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
stream.on('end', async () => {
|
|
43
|
+
try {
|
|
44
|
+
const parsed = await simpleParser(headerData);
|
|
45
|
+
resolve(parsed.headers);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
reject(`Error parsing headers: ${error.message}`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
fetch.once('error', (err) => reject(`Fetch error: ${err.message}`));
|
|
54
|
+
fetch.once('end', () => imap.end());
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
imap.once('error', (err) => reject(`IMAP Error: ${err.message}`));
|
|
60
|
+
imap.once('end', () => console.log('IMAP connection closed.'));
|
|
61
|
+
imap.connect();
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -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 imapstore($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,128 @@
|
|
|
1
|
+
[{
|
|
2
|
+
type: 'imapsubscribe-imapsubscribe',
|
|
3
|
+
module : 'imapsubscribe',
|
|
4
|
+
action : 'imapsubscribe',
|
|
5
|
+
groupTitle : 'Mailer',
|
|
6
|
+
groupIcon : 'fas fa-envelope comp-general',
|
|
7
|
+
title : 'IMAP Subscribe to Folder',
|
|
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: "status"},
|
|
18
|
+
{ type: "text",name: "message"}
|
|
19
|
+
]
|
|
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: 'foldername',
|
|
106
|
+
optionName: 'foldername',
|
|
107
|
+
title: 'Folder Name',
|
|
108
|
+
type: 'text',
|
|
109
|
+
required: true,
|
|
110
|
+
defaultValue: "0",
|
|
111
|
+
serverDataBindings: true,
|
|
112
|
+
help: 'i.e. INBOX/MySubfolder'
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
{ name: 'output',
|
|
117
|
+
optionName: 'output',
|
|
118
|
+
title: 'Output',
|
|
119
|
+
type: 'boolean',
|
|
120
|
+
defaultValue: false
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
const Imap = require('imap');
|
|
3
|
+
|
|
4
|
+
exports.imapsubscribe = async function (options) {
|
|
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
|
+
const foldername = this.parseOptional(options.foldername, '*', 'No Folder Specified');
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const imap = new Imap({
|
|
14
|
+
user: IMAP_USER,
|
|
15
|
+
password: IMAP_PASSWORD,
|
|
16
|
+
host: IMAP_HOST,
|
|
17
|
+
port: IMAP_PORT,
|
|
18
|
+
tls: IMAP_TLS
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
imap.once('ready', () => {
|
|
22
|
+
imap.subscribeBox(foldername, (err) => {
|
|
23
|
+
imap.end();
|
|
24
|
+
if (err) {
|
|
25
|
+
return reject({ status: 400, message: `Error subscribing to folder '${foldername}': ${err.message}` });
|
|
26
|
+
}
|
|
27
|
+
resolve({ status: 200, message: `Successfully subscribed to folder '${foldername}'` });
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
imap.once('error', (err) => {
|
|
32
|
+
reject({ status: 401, message: `Connection error: ${err.message}` });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
imap.once('end', () => {
|
|
36
|
+
console.log('IMAP connection closed.');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
imap.connect();
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
@@ -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 imapsubscribe($options, $name) {
|
|
10
|
+
|
|
11
|
+
$myObj->response = "This function is not yet available in PHP";
|
|
12
|
+
|
|
13
|
+
return json_encode($myObj);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
?>
|