@social-mail/social-mail-web-server 1.5.113 → 1.5.115
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/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/wwwroot/routes/api/channel/file/get.d.ts +10 -0
- package/dist/wwwroot/routes/api/channel/file/get.d.ts.map +1 -0
- package/dist/wwwroot/routes/api/channel/file/get.js +86 -0
- package/dist/wwwroot/routes/api/channel/file/get.js.map +1 -0
- package/dist/wwwroot/routes/api/emails/channel/content/attachment/index.d.ts +1 -0
- package/dist/wwwroot/routes/api/emails/channel/content/attachment/index.d.ts.map +1 -1
- package/dist/wwwroot/routes/api/emails/channel/content/attachment/index.js +9 -3
- package/dist/wwwroot/routes/api/emails/channel/content/attachment/index.js.map +1 -1
- package/package.json +1 -1
- package/src/wwwroot/routes/api/channel/file/get.ts +85 -0
- package/src/wwwroot/routes/api/emails/channel/content/attachment/index.ts +10 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TempFileResult } from "@entity-access/server-pages/dist/Content.js";
|
|
2
|
+
import Page from "@entity-access/server-pages/dist/Page.js";
|
|
3
|
+
export default class extends Page {
|
|
4
|
+
private tfs;
|
|
5
|
+
private cacheService;
|
|
6
|
+
private db;
|
|
7
|
+
private wcs;
|
|
8
|
+
run(): Promise<TempFileResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=get.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../../../../src/wwwroot/routes/api/channel/file/get.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAa5D,MAAM,CAAC,OAAO,MAAO,SAAQ,IAAI;IAG7B,OAAO,CAAC,GAAG,CAAkB;IAG7B,OAAO,CAAC,YAAY,CAAe;IAGnC,OAAO,CAAC,EAAE,CAAoB;IAG9B,OAAO,CAAC,GAAG,CAAwB;IAE7B,GAAG;CAuDZ"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
|
|
11
|
+
import { TempFileResult } from "@entity-access/server-pages/dist/Content.js";
|
|
12
|
+
import Page from "@entity-access/server-pages/dist/Page.js";
|
|
13
|
+
import { Prepare } from "@entity-access/server-pages/dist/decorators/Prepare.js";
|
|
14
|
+
import TimeSpan from "@entity-access/entity-access/dist/types/TimeSpan.js";
|
|
15
|
+
import SocialMailContext from "../../../../../server/model/SocialMailContext.js";
|
|
16
|
+
import CacheService from "../../../../../server/services/cache/CacheService.js";
|
|
17
|
+
import FileConversionService from "../../../../../server/services/convert/FileConversionService.js";
|
|
18
|
+
import ImageConverterService from "../../../../../server/services/image-converter/ImageConverterService.js";
|
|
19
|
+
import TempFileService from "../../../../../server/storage/TempFileService.js";
|
|
20
|
+
import WebSiteChannelService from "../../../../../server/smtp/services/WebSiteChannelService.js";
|
|
21
|
+
import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
|
|
22
|
+
import { Base36 } from "../../../../../common/Base36.js";
|
|
23
|
+
let default_1 = class extends Page {
|
|
24
|
+
async run() {
|
|
25
|
+
const [channelID, emailID, fileID, type] = this.childPath;
|
|
26
|
+
const host = this.request.host;
|
|
27
|
+
const mailboxes = await this.wcs.getMailboxes(host);
|
|
28
|
+
const cid = Base36.decode(channelID);
|
|
29
|
+
const eid = Base36.decode(emailID);
|
|
30
|
+
const fid = Base36.decode(fileID);
|
|
31
|
+
// verify host ...
|
|
32
|
+
const af = await this.db.appFiles
|
|
33
|
+
.where({ fid, eid, cid, mailboxes }, (p) => (x) => x.appFileID === p.fid
|
|
34
|
+
&& x.emailID === p.eid
|
|
35
|
+
&& x.email.mailboxes.some((c) => c.mailboxID === p.cid
|
|
36
|
+
&& Sql.in(c.mailboxID, p.mailboxes)))
|
|
37
|
+
.include((x) => x.fileContent)
|
|
38
|
+
.first();
|
|
39
|
+
this.cacheControl = "public, max-age=2592000, immutable";
|
|
40
|
+
let file = await this.tfs.downloadAppFile(af);
|
|
41
|
+
const key = this.request.path;
|
|
42
|
+
const ttl = TimeSpan.fromDays(30);
|
|
43
|
+
// transform here...
|
|
44
|
+
if (/^(size|jpg|png|webp|gif|face\-circle)\(/i.test(type)) {
|
|
45
|
+
file = await this.cacheService.get({ key, ttl, factory: async () => {
|
|
46
|
+
// resize...
|
|
47
|
+
const ics = ServiceProvider.resolve(this, ImageConverterService);
|
|
48
|
+
return await ics.transform(type, file, this.childPath[this.childPath.length - 1]);
|
|
49
|
+
} });
|
|
50
|
+
}
|
|
51
|
+
else if (/^(pdf|html|webm)$/i.test(type)) {
|
|
52
|
+
file = await this.cacheService.get({ key, ttl, factory: async () => {
|
|
53
|
+
const ics = ServiceProvider.resolve(this, FileConversionService);
|
|
54
|
+
return await ics[type.toLowerCase()](file, this.childPath[this.childPath.length - 1]);
|
|
55
|
+
} });
|
|
56
|
+
}
|
|
57
|
+
return new TempFileResult(file, {
|
|
58
|
+
contentDisposition: type === "download"
|
|
59
|
+
? "attachment"
|
|
60
|
+
: "inline",
|
|
61
|
+
immutable: true,
|
|
62
|
+
etag: false
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__decorate([
|
|
67
|
+
Inject,
|
|
68
|
+
__metadata("design:type", TempFileService)
|
|
69
|
+
], default_1.prototype, "tfs", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
Inject,
|
|
72
|
+
__metadata("design:type", CacheService)
|
|
73
|
+
], default_1.prototype, "cacheService", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
Inject,
|
|
76
|
+
__metadata("design:type", SocialMailContext)
|
|
77
|
+
], default_1.prototype, "db", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
Inject,
|
|
80
|
+
__metadata("design:type", WebSiteChannelService)
|
|
81
|
+
], default_1.prototype, "wcs", void 0);
|
|
82
|
+
default_1 = __decorate([
|
|
83
|
+
Prepare.authorize
|
|
84
|
+
], default_1);
|
|
85
|
+
export default default_1;
|
|
86
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../../../../src/wwwroot/routes/api/channel/file/get.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,QAAQ,MAAM,qDAAqD,CAAC;AAC3E,OAAO,iBAAiB,MAAM,kDAAkD,CAAC;AACjF,OAAO,YAAY,MAAM,sDAAsD,CAAC;AAChF,OAAO,qBAAqB,MAAM,iEAAiE,CAAC;AACpG,OAAO,qBAAqB,MAAM,yEAAyE,CAAC;AAC5G,OAAO,eAAe,MAAM,kDAAkD,CAAC;AAC/E,OAAO,qBAAqB,MAAM,8DAA8D,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AAc,CACrB,IAAI,EACJ;YACI,kBAAkB,EAAE,IAAI,KAAK,UAAU;gBACnC,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,QAAQ;YACd,SAAS,EAAE,IAAI;YACf,IAAI,EAAE,KAAK;SACd,CACJ,CAAC;IACN,CAAC;CACJ,CAAA;AAlEW;IADP,MAAM;8BACM,eAAe;sCAAC;AAGrB;IADP,MAAM;8BACe,YAAY;+CAAC;AAG3B;IADP,MAAM;8BACK,iBAAiB;qCAAC;AAGtB;IADP,MAAM;8BACM,qBAAqB;sCAAC;AAZxB;IADd,OAAO,CAAC,SAAS;aAsEjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../src/wwwroot/routes/api/emails/channel/content/attachment/index.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../src/wwwroot/routes/api/emails/channel/content/attachment/index.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAO7E,MAAM,CAAC,OAAO,MAAO,SAAQ,IAAI;IAG7B,OAAO,CAAC,EAAE,CAAoB;IAG9B,OAAO,CAAC,GAAG,CAAkB;IAG7B,OAAO,CAAC,GAAG,CAAwB;IAE7B,GAAG;CAgCZ"}
|
|
@@ -13,17 +13,19 @@ import SocialMailContext from "../../../../../../../server/model/SocialMailConte
|
|
|
13
13
|
import Page from "@entity-access/server-pages/dist/Page.js";
|
|
14
14
|
import TempFileService from "../../../../../../../server/storage/TempFileService.js";
|
|
15
15
|
import { TempFileResult } from "@entity-access/server-pages/dist/Content.js";
|
|
16
|
+
import WebSiteChannelService from "../../../../../../../server/smtp/services/WebSiteChannelService.js";
|
|
17
|
+
import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
|
|
16
18
|
let default_1 = class extends Page {
|
|
17
19
|
async run() {
|
|
18
20
|
const [channelID, emailID, messageID, fileID] = this.childPath;
|
|
19
21
|
const host = this.request.host;
|
|
22
|
+
const mailboxes = await this.wcs.getMailboxes(host);
|
|
20
23
|
// verify host ...
|
|
21
24
|
const file = await this.db.appFiles
|
|
22
|
-
.where({ fileID, emailID, messageID, channelID,
|
|
25
|
+
.where({ fileID, emailID, messageID, channelID, mailboxes }, (p) => (x) => x.appFileID === p.fileID
|
|
23
26
|
&& x.emailID === p.emailID
|
|
24
27
|
&& x.email.headerMessageID === p.messageID
|
|
25
|
-
&& x.email.mailboxes.some((c) => c.mailboxID
|
|
26
|
-
&& c.mailbox.websiteChannels.some((wc) => wc.website.hosts.some((h) => h.host === p.host))))
|
|
28
|
+
&& x.email.mailboxes.some((c) => Sql.in(c.mailboxID, p.mailboxes)))
|
|
27
29
|
.first();
|
|
28
30
|
const body = await this.tfs.downloadAppFile(file);
|
|
29
31
|
this.cacheControl = "public, max-age=2592000, immutable";
|
|
@@ -42,6 +44,10 @@ __decorate([
|
|
|
42
44
|
Inject,
|
|
43
45
|
__metadata("design:type", TempFileService)
|
|
44
46
|
], default_1.prototype, "tfs", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
Inject,
|
|
49
|
+
__metadata("design:type", WebSiteChannelService)
|
|
50
|
+
], default_1.prototype, "wcs", void 0);
|
|
45
51
|
default_1 = __decorate([
|
|
46
52
|
Prepare.authorize
|
|
47
53
|
], default_1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../src/wwwroot/routes/api/emails/channel/content/attachment/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,4CAA4C,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,iBAAiB,MAAM,wDAAwD,CAAC;AAEvF,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAE5D,OAAO,eAAe,MAAM,wDAAwD,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../src/wwwroot/routes/api/emails/channel/content/attachment/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,4CAA4C,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,iBAAiB,MAAM,wDAAwD,CAAC;AAEvF,OAAO,IAAI,MAAM,0CAA0C,CAAC;AAE5D,OAAO,eAAe,MAAM,wDAAwD,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,qBAAqB,MAAM,oEAAoE,CAAC;AACvG,OAAO,GAAG,MAAM,8CAA8C,CAAC;AAKhD,gBAAA,KAAM,SAAQ,IAAI;IAW7B,KAAK,CAAC,GAAG;QAEL,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,SAAkB,CAAC;QAExE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QAE/B,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAEpD,kBAAkB;QAClB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,QAAQ;aAC9B,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9D,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,MAAM;eACrB,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO;eACvB,CAAC,CAAC,KAAK,CAAC,eAAe,KAAK,CAAC,CAAC,SAAS;eACvC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAC7E;aACA,KAAK,EAAE,CAAC;QAEb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAElD,IAAI,CAAC,YAAY,GAAG,oCAAoC,CAAC;QAEzD,OAAO,IAAI,cAAc,CACrB,IAAI,EACJ;YACI,kBAAkB,EAAE,QAAQ;YAC5B,SAAS,EAAE,IAAI;YACf,IAAI,EAAE,KAAK;SACd,CACJ,CAAC;IACN,CAAC;CAEJ,CAAA;AAxCW;IADP,MAAM;8BACK,iBAAiB;qCAAC;AAGtB;IADP,MAAM;8BACM,eAAe;sCAAC;AAGrB;IADP,MAAM;8BACM,qBAAqB;sCAAC;AATxB;IADd,OAAO,CAAC,SAAS;aA4CjB"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
|
|
2
|
+
import { TempFileResult } from "@entity-access/server-pages/dist/Content.js";
|
|
3
|
+
import Page from "@entity-access/server-pages/dist/Page.js";
|
|
4
|
+
import { Prepare } from "@entity-access/server-pages/dist/decorators/Prepare.js";
|
|
5
|
+
import TimeSpan from "@entity-access/entity-access/dist/types/TimeSpan.js";
|
|
6
|
+
import SocialMailContext from "../../../../../server/model/SocialMailContext.js";
|
|
7
|
+
import CacheService from "../../../../../server/services/cache/CacheService.js";
|
|
8
|
+
import FileConversionService from "../../../../../server/services/convert/FileConversionService.js";
|
|
9
|
+
import ImageConverterService from "../../../../../server/services/image-converter/ImageConverterService.js";
|
|
10
|
+
import TempFileService from "../../../../../server/storage/TempFileService.js";
|
|
11
|
+
import WebSiteChannelService from "../../../../../server/smtp/services/WebSiteChannelService.js";
|
|
12
|
+
import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
|
|
13
|
+
import { Base36 } from "../../../../../common/Base36.js";
|
|
14
|
+
|
|
15
|
+
@Prepare.authorize
|
|
16
|
+
export default class extends Page {
|
|
17
|
+
|
|
18
|
+
@Inject
|
|
19
|
+
private tfs: TempFileService;
|
|
20
|
+
|
|
21
|
+
@Inject
|
|
22
|
+
private cacheService: CacheService;
|
|
23
|
+
|
|
24
|
+
@Inject
|
|
25
|
+
private db: SocialMailContext;
|
|
26
|
+
|
|
27
|
+
@Inject
|
|
28
|
+
private wcs: WebSiteChannelService;
|
|
29
|
+
|
|
30
|
+
async run() {
|
|
31
|
+
|
|
32
|
+
const [channelID, emailID, fileID, type] = this.childPath as any[];
|
|
33
|
+
|
|
34
|
+
const host = this.request.host;
|
|
35
|
+
|
|
36
|
+
const mailboxes = await this.wcs.getMailboxes(host);
|
|
37
|
+
|
|
38
|
+
const cid = Base36.decode(channelID) as any;
|
|
39
|
+
const eid = Base36.decode(emailID) as any;
|
|
40
|
+
const fid = Base36.decode(fileID) as any;
|
|
41
|
+
|
|
42
|
+
// verify host ...
|
|
43
|
+
const af = await this.db.appFiles
|
|
44
|
+
.where({ fid, eid, cid, mailboxes }, (p) => (x) =>
|
|
45
|
+
x.appFileID === p.fid
|
|
46
|
+
&& x.emailID === p.eid
|
|
47
|
+
&& x.email.mailboxes.some((c) => c.mailboxID === p.cid
|
|
48
|
+
&& Sql.in(c.mailboxID, p.mailboxes))
|
|
49
|
+
)
|
|
50
|
+
.include((x) => x.fileContent)
|
|
51
|
+
.first();
|
|
52
|
+
|
|
53
|
+
this.cacheControl = "public, max-age=2592000, immutable";
|
|
54
|
+
let file = await this.tfs.downloadAppFile(af);
|
|
55
|
+
|
|
56
|
+
const key = this.request.path;
|
|
57
|
+
|
|
58
|
+
const ttl = TimeSpan.fromDays(30);
|
|
59
|
+
|
|
60
|
+
// transform here...
|
|
61
|
+
if (/^(size|jpg|png|webp|gif|face\-circle)\(/i.test(type)) {
|
|
62
|
+
file = await this.cacheService.get({ key, ttl, factory: async () => {
|
|
63
|
+
// resize...
|
|
64
|
+
const ics = ServiceProvider.resolve(this, ImageConverterService);
|
|
65
|
+
return await ics.transform(type, file, this.childPath[this.childPath.length-1] );
|
|
66
|
+
} });
|
|
67
|
+
} else if (/^(pdf|html|webm)$/i.test(type)) {
|
|
68
|
+
file = await this.cacheService.get({ key, ttl, factory: async () => {
|
|
69
|
+
const ics = ServiceProvider.resolve(this, FileConversionService);
|
|
70
|
+
return await ics[type.toLowerCase()](file, this.childPath[this.childPath.length-1] );
|
|
71
|
+
} });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return new TempFileResult(
|
|
75
|
+
file,
|
|
76
|
+
{
|
|
77
|
+
contentDisposition: type === "download"
|
|
78
|
+
? "attachment"
|
|
79
|
+
: "inline",
|
|
80
|
+
immutable: true,
|
|
81
|
+
etag: false
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -6,6 +6,9 @@ import Page from "@entity-access/server-pages/dist/Page.js";
|
|
|
6
6
|
import BaseStorage from "../../../../../../../server/storage/BaseStorage.js";
|
|
7
7
|
import TempFileService from "../../../../../../../server/storage/TempFileService.js";
|
|
8
8
|
import { TempFileResult } from "@entity-access/server-pages/dist/Content.js";
|
|
9
|
+
import WebSiteChannelService from "../../../../../../../server/smtp/services/WebSiteChannelService.js";
|
|
10
|
+
import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
|
|
11
|
+
import ImageConverterService from "../../../../../../../server/services/image-converter/ImageConverterService.js";
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
@Prepare.authorize
|
|
@@ -17,21 +20,24 @@ export default class extends Page {
|
|
|
17
20
|
@Inject
|
|
18
21
|
private tfs: TempFileService;
|
|
19
22
|
|
|
23
|
+
@Inject
|
|
24
|
+
private wcs: WebSiteChannelService;
|
|
25
|
+
|
|
20
26
|
async run() {
|
|
21
27
|
|
|
22
28
|
const [channelID, emailID, messageID, fileID] = this.childPath as any[];
|
|
23
29
|
|
|
24
30
|
const host = this.request.host;
|
|
25
31
|
|
|
32
|
+
const mailboxes = await this.wcs.getMailboxes(host);
|
|
33
|
+
|
|
26
34
|
// verify host ...
|
|
27
35
|
const file = await this.db.appFiles
|
|
28
|
-
.where({ fileID, emailID, messageID, channelID,
|
|
36
|
+
.where({ fileID, emailID, messageID, channelID, mailboxes }, (p) => (x) =>
|
|
29
37
|
x.appFileID === p.fileID
|
|
30
38
|
&& x.emailID === p.emailID
|
|
31
39
|
&& x.email.headerMessageID === p.messageID
|
|
32
|
-
&& x.email.mailboxes.some((c) => c.mailboxID
|
|
33
|
-
&& c.mailbox.websiteChannels.some((wc) =>
|
|
34
|
-
wc.website.hosts.some((h) => h.host === p.host)))
|
|
40
|
+
&& x.email.mailboxes.some((c) => Sql.in(c.mailboxID, p.mailboxes))
|
|
35
41
|
)
|
|
36
42
|
.first();
|
|
37
43
|
|