bot-functions 1.3.3 → 1.3.5
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/index.js +18 -30
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -324,42 +324,29 @@ class EmailManager {
|
|
|
324
324
|
if (!this.connection) {
|
|
325
325
|
throw new Error('Not connected to email account');
|
|
326
326
|
}
|
|
327
|
+
|
|
327
328
|
const uidArray = Array.isArray(uids) ? uids : [uids];
|
|
329
|
+
|
|
328
330
|
try {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
await this.connection.move(uid, '[Gmail]/Trash');
|
|
332
|
-
}
|
|
333
|
-
return { success: true, deletedCount: uidArray.length, action: 'moved_to_trash' };
|
|
334
|
-
} catch (moveError) {
|
|
335
|
-
try {
|
|
336
|
-
for (const uid of uidArray) {
|
|
337
|
-
await this.connection.move(uid, 'Deleted Items');
|
|
338
|
-
}
|
|
339
|
-
return { success: true, deletedCount: uidArray.length, action: 'moved_to_deleted_items' };
|
|
340
|
-
} catch (moveError2) {
|
|
341
|
-
try {
|
|
342
|
-
for (const uid of uidArray) {
|
|
343
|
-
await this.connection.move(uid, 'TRASH');
|
|
344
|
-
}
|
|
345
|
-
return { success: true, deletedCount: uidArray.length, action: 'moved_to_trash_folder' };
|
|
346
|
-
} catch (moveError3) {
|
|
347
|
-
for (const uid of uidArray) {
|
|
348
|
-
await this.connection.addFlags(uid, '\\Deleted');
|
|
349
|
-
}
|
|
350
|
-
await this.connection.closeBox(false);
|
|
351
|
-
await this.connection.openBox('INBOX');
|
|
352
|
-
return { success: true, deletedCount: uidArray.length, action: 'marked_deleted' };
|
|
353
|
-
}
|
|
354
|
-
}
|
|
331
|
+
for (const uid of uidArray) {
|
|
332
|
+
await this.connection.addFlags(uid, '\\Deleted');
|
|
355
333
|
}
|
|
334
|
+
await this.connection.imap.expunge();
|
|
335
|
+
log.info(`Successfully deleted ${uidArray.length} email(s)`);
|
|
336
|
+
|
|
337
|
+
return {
|
|
338
|
+
success: true,
|
|
339
|
+
deletedCount: uidArray.length,
|
|
340
|
+
action: 'deleted'
|
|
341
|
+
};
|
|
342
|
+
|
|
356
343
|
} catch (error) {
|
|
357
344
|
log.error("Error deleting emails:", error);
|
|
358
|
-
|
|
345
|
+
throw new Error(`Failed to delete emails: ${error.message}`);
|
|
359
346
|
} finally {
|
|
360
347
|
if (this.connection) {
|
|
361
348
|
try {
|
|
362
|
-
this.connection.end();
|
|
349
|
+
await this.connection.end();
|
|
363
350
|
this.connection = null;
|
|
364
351
|
} catch (error) {
|
|
365
352
|
log.error("Error disconnecting:", error);
|
|
@@ -889,7 +876,7 @@ const sendDataCH = async (params, dataJSON) => {
|
|
|
889
876
|
const batchPromises = [];
|
|
890
877
|
const stringData = JSON.stringify(dataJSON);
|
|
891
878
|
const response = await axios({
|
|
892
|
-
method: 'post', url:
|
|
879
|
+
method: 'post', url: process.env.INSERT_CH, data: {jsonContent: stringData },
|
|
893
880
|
maxBodyLength: Infinity, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }
|
|
894
881
|
});
|
|
895
882
|
batchPromises.push(response.status);
|
|
@@ -1409,5 +1396,6 @@ module.exports = {
|
|
|
1409
1396
|
EmailManager,
|
|
1410
1397
|
manageEmails,
|
|
1411
1398
|
insertLogExec,
|
|
1412
|
-
sendDataCH
|
|
1399
|
+
sendDataCH,
|
|
1400
|
+
processDataDaily
|
|
1413
1401
|
}
|