@timshel_npm/maildev 3.2.8 → 3.2.9

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/README.md CHANGED
@@ -30,8 +30,8 @@ Or can be installed using [Github](https://docs.npmjs.com/cli/v10/configuring-np
30
30
  Ex:
31
31
  ```json
32
32
  "devDependencies": {
33
- "maildev": "github:timshel/maildev#3.2.8",
34
- "maildev": "npm:@timshel_npm/maildev@^3.2.8"
33
+ "maildev": "github:timshel/maildev#3.2.9",
34
+ "maildev": "npm:@timshel_npm/maildev@^3.2.9"
35
35
  }
36
36
  ```
37
37
 
@@ -35,6 +35,7 @@ export declare class MailServer {
35
35
  mailEventSubjectMapper: (Mail: any) => string | undefined;
36
36
  smtp: typeof SMTPServer;
37
37
  outgoing: Outgoing | undefined;
38
+ private _reloadInProgress;
38
39
  /**
39
40
  * Extend Event Emitter methods
40
41
  * events:
@@ -111,5 +112,6 @@ export declare class MailServer {
111
112
  * Download a given email
112
113
  */
113
114
  getEmailEml(id: any): Promise<[string, string, ReadStream]>;
114
- loadMailsFromDirectory(): Promise<void[]>;
115
+ loadMailsFromDirectory(): Promise<void>;
116
+ private _loadMailsFromDirectory;
115
117
  }
@@ -107,6 +107,7 @@ class MailServer {
107
107
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
108
108
  this.store = [];
109
109
  this.eventEmitter = new events.EventEmitter();
110
+ this._reloadInProgress = undefined;
110
111
  /**
111
112
  * Extend Event Emitter methods
112
113
  * events:
@@ -379,6 +380,19 @@ class MailServer {
379
380
  });
380
381
  }
381
382
  loadMailsFromDirectory() {
383
+ return __awaiter(this, void 0, void 0, function* () {
384
+ if (this._reloadInProgress == undefined) {
385
+ this._reloadInProgress = this._loadMailsFromDirectory().finally(() => {
386
+ this._reloadInProgress = undefined;
387
+ });
388
+ return this._reloadInProgress;
389
+ }
390
+ else {
391
+ return this._reloadInProgress;
392
+ }
393
+ });
394
+ }
395
+ _loadMailsFromDirectory() {
382
396
  return __awaiter(this, void 0, void 0, function* () {
383
397
  const self = this;
384
398
  const persistencePath = yield fs_1.promises.realpath(this.mailDir);
@@ -387,14 +401,19 @@ class MailServer {
387
401
  throw new Error(`Error during reading of the mailDir ${persistencePath}`);
388
402
  });
389
403
  this.store.length = 0;
390
- const saved = files.map(function (file) {
391
- return __awaiter(this, void 0, void 0, function* () {
392
- const id = path.parse(file).name;
393
- const email = yield getDiskEmail(self.mailDir, id);
394
- return saveEmailToStore(self, email);
404
+ this.eventEmitter.emit("delete", { id: "all" });
405
+ const concurrency = 20;
406
+ for (let i = 0; i < files.length; i += concurrency) {
407
+ const chunk = files.slice(i, i + concurrency);
408
+ let saved = chunk.map(function (file) {
409
+ return __awaiter(this, void 0, void 0, function* () {
410
+ const id = path.parse(file).name;
411
+ const email = yield getDiskEmail(self.mailDir, id);
412
+ return saveEmailToStore(self, email);
413
+ });
395
414
  });
396
- });
397
- return Promise.all(saved);
415
+ yield Promise.all(saved);
416
+ }
398
417
  });
399
418
  }
400
419
  }
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.routes = routes;
4
13
  const utils_1 = require("./utils");
@@ -132,8 +141,10 @@ function routes(app, mailserver, basePathname) {
132
141
  res.status(200).json(true);
133
142
  });
134
143
  router.get("/reloadMailsFromDirectory", function (req, res) {
135
- mailserver.loadMailsFromDirectory();
136
- res.status(200).json(true);
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ yield mailserver.loadMailsFromDirectory();
146
+ res.status(200).json(true);
147
+ });
137
148
  });
138
149
  app.use(basePathname, router);
139
150
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@timshel_npm/maildev",
3
3
  "description": "SMTP Server with async API and Web Interface for viewing and testing emails during development",
4
- "version": "3.2.8",
4
+ "version": "3.2.9",
5
5
  "keywords": [
6
6
  "email",
7
7
  "e-mail",