@social-mail/social-mail-web-server 1.4.897 → 1.4.899

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": "@social-mail/social-mail-web-server",
3
- "version": "1.4.897",
3
+ "version": "1.4.899",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -108,6 +108,9 @@ export default class Mailbox {
108
108
  })
109
109
  public logoID: number;
110
110
 
111
+ @Column({ dataType: "BigInt", default: () => false })
112
+ public isExternal: boolean;
113
+
111
114
  @Column({ dataType: "Char", nullable: true })
112
115
  public description: string;
113
116
 
@@ -3,7 +3,7 @@ import { HostedDomain } from "../entities/HostedDomain.js";
3
3
  import AuthenticatedEvents from "./AuthenticatedEvents.js";
4
4
  import { ForeignKeyFilter } from "@entity-access/entity-access/dist/model/events/EntityEvents.js";
5
5
  import ChangeEntry from "@entity-access/entity-access/dist/model/changes/ChangeEntry.js";
6
- import Inject from "@entity-access/entity-access/dist/di/di.js";
6
+ import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
7
7
  import EmailAddressService from "../../services/EmailAddressService.js";
8
8
  import SocialMailContext from "../SocialMailContext.js";
9
9
  import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
@@ -56,4 +56,20 @@ export default class HostedDomainEvents extends AuthenticatedEvents<HostedDomain
56
56
  beforeDelete(entity: HostedDomain, entry: ChangeEntry<HostedDomain>) {
57
57
  throw new EntityAccessError(`Not supported`);
58
58
  }
59
+
60
+ async afterInsert(entity: HostedDomain, entry: ChangeEntry<HostedDomain>) {
61
+ const db = ServiceProvider.resolve(this, SocialMailContext);
62
+ await db.mailboxes.where(entity, (p) => (x) => x.domainID === p.domainID)
63
+ .update(void 0, (p) => (x) => ({
64
+ isExternal: false
65
+ }));
66
+ }
67
+
68
+ async afterDelete(entity: HostedDomain, entry: ChangeEntry<HostedDomain>) {
69
+ const db = ServiceProvider.resolve(this, SocialMailContext);
70
+ await db.mailboxes.where(entity, (p) => (x) => x.domainID === p.domainID)
71
+ .update(void 0, (p) => (x) => ({
72
+ isExternal: true
73
+ }));
74
+ }
59
75
  }
@@ -160,6 +160,7 @@ export default class MailboxEvents extends AuthenticatedEvents<Mailbox> {
160
160
  const { emailAddressID: mailboxID, domainID } = await this.emailAddressService.getEmailAddressFrom(entity.externalEmailAddress);
161
161
  entity.mailboxID = mailboxID;
162
162
  entity.domainID = domainID;
163
+ entity.isExternal = true;
163
164
  await this.db.userMailboxes.statements.selectOrInsert({ mailboxID, userID }, { mailboxID , userID });
164
165
  }
165
166
 
@@ -77,13 +77,10 @@ export default class EmailAddressService {
77
77
  emailAddress = emailAddress.trim().toLocaleLowerCase();
78
78
  using scope = globalServices.createScope();
79
79
  const db = scope.resolve(SocialMailContext);
80
- const mb = await db.mailboxes.where({ emailAddress }, (p) => (x) => x.emailAddress.emailAddress === p.emailAddress)
81
- .include((x) => x.domain.hostedDomain)
80
+ const mb = await db.mailboxes.where({ emailAddress }, (p) => (x) => x.emailAddress.emailAddress === p.emailAddress
81
+ && x.isExternal === false)
82
82
  .first();
83
- if (mb.domain?.hostedDomain) {
84
- return mb.mailboxID;
85
- }
86
- return mb?.mailboxID > 0 ? mb.mailboxID : void 0;
83
+ return mb?.mailboxID > 0 ? mb.mailboxID : void 0;
87
84
  }
88
85
 
89
86
  @cacheFor()
@@ -76,7 +76,7 @@ export default class PrepareEmailToSend extends Workflow<number, string> {
76
76
  senderID: email.senderID,
77
77
  emailID: x.emailID,
78
78
  emailAddressID: x.emailAddressID,
79
- external: !email.senderEmail.mailbox.domain.hostedDomain,
79
+ external: email.senderEmail.mailbox.isExternal,
80
80
  to: [ x.replyTo ?? x.emailAddress.emailAddress]
81
81
  }));
82
82
  return outsiders;