@hyperbytes/wappler-imap-manager 1.0.2 → 1.0.4
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/package.json +1 -1
- package/server_connect/modules/imapdirlist.js +1 -0
- package/server_connect/modules/imapgetattachments.hjson +8 -1
- package/server_connect/modules/imapgetattachments.js +10 -1
- package/server_connect/modules/imapmailcontent.hjson +24 -15
- package/server_connect/modules/imapsaveasdraft.hjson +1 -1
- package/server_connect/modules/imapsaveasdraft.js +19 -4
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const Imap = require('imap');
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
exports.imapdirlist = async function (options) {
|
|
4
5
|
const IMAP_HOST = this.parseOptional(options.imap_host, '*', process.env.IMAP_HOST);
|
|
5
6
|
const IMAP_PASSWORD = this.parseOptional(options.imap_password, '*', process.env.IMAP_PASSWORD);
|
|
@@ -20,9 +20,16 @@ groupIcon : 'fas fa-envelope comp-general',
|
|
|
20
20
|
{name: 'message', type:'text'},
|
|
21
21
|
{name: 'url', type:'text'},
|
|
22
22
|
{name: 'path', type:'text'},
|
|
23
|
-
{name: 'status', type:'text'}
|
|
23
|
+
{name: 'status', type:'text'},
|
|
24
|
+
{name: 'pathschema', type:'array', sub:[
|
|
25
|
+
{name: '$value', type:'text'}
|
|
26
|
+
]},
|
|
27
|
+
{name: 'systempath', type:'array', sub:[
|
|
28
|
+
{name: '$value', type:'text'}
|
|
29
|
+
]}
|
|
24
30
|
],
|
|
25
31
|
|
|
32
|
+
|
|
26
33
|
properties : [
|
|
27
34
|
{
|
|
28
35
|
group: 'IMAP Inputs',
|
|
@@ -67,9 +67,18 @@ exports.imapgetattachments = async function (options, name) {
|
|
|
67
67
|
savedFiles.push(att.filename);
|
|
68
68
|
console.log(`Saved attachment: ${filePath}`);
|
|
69
69
|
});
|
|
70
|
+
const savedFilesExt = [];
|
|
71
|
+
const savedFilesSystem = []
|
|
72
|
+
parsed.attachments.forEach(att => {
|
|
73
|
+
const filePath = path.join(savePath, att.filename);
|
|
74
|
+
fs.writeFileSync(filePath, att.content);
|
|
75
|
+
savedFilesExt.push(sentPath + att.filename);
|
|
76
|
+
savedFilesSystem.push(toSystemPath(sentPath + att.filename));
|
|
77
|
+
console.log(`Saved attachment Extemded: ${filePath}`);
|
|
78
|
+
});
|
|
70
79
|
|
|
71
80
|
imap.end();
|
|
72
|
-
resolve({ savedFiles, message: savedFiles.join(", "), url: returnPath, path: sentPath, status: 200 });
|
|
81
|
+
resolve({ savedFiles, message: savedFiles.join(", "), url: returnPath, path: sentPath, status: 200, pathschema: savedFilesExt, systemschema: savedFilesSystem });
|
|
73
82
|
|
|
74
83
|
} catch (parseError) {
|
|
75
84
|
imap.end();
|
|
@@ -19,36 +19,45 @@ groupIcon : 'fas fa-envelope comp-general',
|
|
|
19
19
|
{type: "object",name: "from", sub: [
|
|
20
20
|
{type: "array",name: "value", sub: [
|
|
21
21
|
{type: "number",name: "address"},
|
|
22
|
-
{type: "number",name: "name"}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
{type: "number",name: "name"}]},
|
|
23
|
+
{type: "text",name: "html"},
|
|
24
|
+
{type: "text",name: "text"}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
26
27
|
{type: "object",name: "to", sub: [
|
|
27
28
|
{type: "array",name: "value", sub: [
|
|
28
29
|
{type: "number",name: "address"},
|
|
29
|
-
{type: "number",name: "name"}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
{type: "number",name: "name"}]},
|
|
31
|
+
{type: "text",name: "html"},
|
|
32
|
+
{type: "text",name: "text"}
|
|
33
|
+
]
|
|
34
|
+
},
|
|
33
35
|
{type: "object",name: "cc", sub: [
|
|
34
36
|
{type: "array",name: "value", sub: [
|
|
35
37
|
{type: "number",name: "address"},
|
|
36
38
|
{type: "number",name: "name"}
|
|
37
|
-
]}
|
|
38
|
-
|
|
39
|
+
]},
|
|
40
|
+
{type: "text",name: "html"},
|
|
41
|
+
{type: "text",name: "text"}
|
|
42
|
+
]
|
|
43
|
+
},
|
|
39
44
|
|
|
40
45
|
{type: "object",name: "bcc", sub: [
|
|
41
46
|
{type: "array",name: "value", sub: [
|
|
42
47
|
{type: "number",name: "address"},
|
|
43
48
|
{type: "number",name: "name"}
|
|
44
|
-
]}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
]},
|
|
50
|
+
{type: "text",name: "html"},
|
|
51
|
+
{type: "text",name: "text"}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
|
|
50
56
|
]
|
|
51
57
|
},
|
|
58
|
+
{type: "text",name: "subject"},
|
|
59
|
+
{type: "text",name: "date"},
|
|
60
|
+
{type: "text",name: "message-id"},
|
|
52
61
|
{type: "text",name: "body"},
|
|
53
62
|
{type: "array",name: "attachments" sub: [
|
|
54
63
|
{type: "text",name: "filename"},
|
|
@@ -2,7 +2,8 @@ const Imap = require('imap-simple');
|
|
|
2
2
|
const nodemailer = require('nodemailer');
|
|
3
3
|
const mailcomposer = require('mailcomposer');
|
|
4
4
|
const { simpleParser } = require('mailparser'); // Used for debugging email content
|
|
5
|
-
|
|
5
|
+
const { toSystemPath } = require("../../../lib/core/path");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
exports.imapsaveasdraft = async function (options) {
|
|
7
8
|
console.log('Starting IMAP draft save process...');
|
|
8
9
|
|
|
@@ -39,8 +40,8 @@ exports.imapsaveasdraft = async function (options) {
|
|
|
39
40
|
console.log('Subject: ' + subject);
|
|
40
41
|
const body = this.parseOptional(options.body, "*", ""); // Assuming this is HTML body
|
|
41
42
|
console.log('Body: ' + body);
|
|
42
|
-
const
|
|
43
|
-
console.log('Attachments: ' +
|
|
43
|
+
const upload = this.parseOptional(options.attachments, '*', []);
|
|
44
|
+
console.log('Attachments: ' + upload);
|
|
44
45
|
let folder = this.parseOptional(options.mailbox, '*', 'Drafts'); // Default to 'Drafts'
|
|
45
46
|
console.log('Folder: ' + folder);
|
|
46
47
|
|
|
@@ -48,6 +49,20 @@ exports.imapsaveasdraft = async function (options) {
|
|
|
48
49
|
const providedUid = this.parseOptional(options.uid, "*", "");
|
|
49
50
|
console.log('UID: ' + providedUid);
|
|
50
51
|
console.log(`Attempting to save draft to folder: ${folder}`);
|
|
52
|
+
// Ensure attachments are properly formatted and converted to system paths
|
|
53
|
+
const attachmentList = Array.isArray(upload)
|
|
54
|
+
? upload.map(file => ({
|
|
55
|
+
...file, // Keep existing properties
|
|
56
|
+
systemPath: toSystemPath(file.path) // Convert relative path to system path
|
|
57
|
+
}))
|
|
58
|
+
: [];
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// Prepare attachments for Nodemailer
|
|
62
|
+
const formattedAttachments = attachmentList.map(file => ({
|
|
63
|
+
filename: path.basename(file.systemPath),
|
|
64
|
+
path: file.systemPath // Use transformed system path
|
|
65
|
+
}));
|
|
51
66
|
|
|
52
67
|
const imapConfig = {
|
|
53
68
|
imap: {
|
|
@@ -72,7 +87,7 @@ exports.imapsaveasdraft = async function (options) {
|
|
|
72
87
|
bcc: bcc,
|
|
73
88
|
subject: subject,
|
|
74
89
|
html: body, // Use 'text' if it's plain text
|
|
75
|
-
attachments:
|
|
90
|
+
attachments: formattedAttachments
|
|
76
91
|
};
|
|
77
92
|
|
|
78
93
|
const mail = mailcomposer(mailOptions);
|