@hyperbytes/wappler-imap-manager 1.0.2 → 1.0.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbytes/wappler-imap-manager",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "IMAP eMail Management for Wappler",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -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);
@@ -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
- {type: "text",name: "subject"},
47
- {type: "text",name: "date"},
48
- {type: "text",name: "message-id"},
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"},
@@ -4,7 +4,7 @@
4
4
  action : 'imapsaveasdraft',
5
5
  groupTitle : 'Mailer',
6
6
  groupIcon : 'fas fa-envelope comp-general',
7
- title : 'IMAP Save as Draft (not funtional)',
7
+ title : 'IMAP Save as Draft',
8
8
  icon : 'fas fa-solid fa-pen comp-exec',
9
9
  dataPickObject: true,
10
10
  usedModules : {
@@ -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 attachments = this.parseOptional(options.attachments, '*', []);
43
- console.log('Attachments: ' + 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: attachments
90
+ attachments: formattedAttachments
76
91
  };
77
92
 
78
93
  const mail = mailcomposer(mailOptions);