diff --git a/plugins/smtp/package-lock.json b/plugins/smtp/package-lock.json index d0de8c79d..e5e288e1a 100644 --- a/plugins/smtp/package-lock.json +++ b/plugins/smtp/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/smtp", - "version": "0.0.10", + "version": "0.0.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/smtp", - "version": "0.0.10", + "version": "0.0.11", "dependencies": { "@types/node": "^16.6.1", "mailparser": "^3.5.0", diff --git a/plugins/smtp/package.json b/plugins/smtp/package.json index 7b299369a..59f4b1756 100644 --- a/plugins/smtp/package.json +++ b/plugins/smtp/package.json @@ -39,5 +39,5 @@ "@types/mailparser": "^3.0.3", "@types/smtp-server": "^3.5.7" }, - "version": "0.0.10" + "version": "0.0.11" } diff --git a/plugins/smtp/src/main.ts b/plugins/smtp/src/main.ts index 0d5242e46..ea22eaa4e 100644 --- a/plugins/smtp/src/main.ts +++ b/plugins/smtp/src/main.ts @@ -1,8 +1,8 @@ -import { MixinProvider, OnOff, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, Setting, Settings, SettingValue, StartStop } from '@scrypted/sdk'; -import sdk from '@scrypted/sdk'; -import { SettingsMixinDeviceBase } from "../../../common/src/settings-mixin"; -import smtp, { SMTPServer } from 'smtp-server'; +import sdk, { MixinProvider, OnOff, ScryptedDeviceBase, ScryptedDeviceType, ScryptedInterface, Setting, Settings, SettingValue, StartStop } from '@scrypted/sdk'; +import { StorageSettings } from '@scrypted/sdk/storage-settings'; import { ParsedMail, simpleParser } from 'mailparser'; +import smtp, { SMTPServer } from 'smtp-server'; +import { SettingsMixinDeviceBase } from "../../../common/src/settings-mixin"; const { systemManager } = sdk; @@ -74,6 +74,20 @@ class SmtpMixin extends SettingsMixinDeviceBase { class MailPlugin extends ScryptedDeviceBase implements Settings, MixinProvider { createdMixins = new Map(); server: SMTPServer; + storageSettings = new StorageSettings(this, { + smtpPort: { + title: "SMTP Port (No Authentication)", + defaultValue: 25, + type: 'number', + onPut: () => this.createServer(), + + }, + disableTls: { + title: 'Disable TLS', + type: 'boolean', + onPut: () => this.createServer(), + } + }) constructor(nativeId?: string) { super(nativeId); @@ -83,7 +97,7 @@ class MailPlugin extends ScryptedDeviceBase implements Settings, MixinProvider { for (const id of Object.keys(systemManager.getSystemState())) { const realDevice = systemManager.getDeviceById(id); if (realDevice.mixins?.includes(this.id)) - realDevice.probe().catch(e => {}); + realDevice.probe().catch(e => { }); } } @@ -94,6 +108,7 @@ class MailPlugin extends ScryptedDeviceBase implements Settings, MixinProvider { allowInsecureAuth: true, authOptional: true, logger: true, + disabledCommands: this.storageSettings.values.disableTls ? ['STARTTLS'] : undefined, onConnect: (session, callback) => { callback(); @@ -124,7 +139,7 @@ class MailPlugin extends ScryptedDeviceBase implements Settings, MixinProvider { this.server.on("error", e => { this.console.error("SMTP Error %s", e); }); - const port = this.getPort(); + const port = this.storageSettings.values.smtpPort as number; this.server.listen(port, '0.0.0.0'); this.console.log('created SMTP server'); } @@ -145,23 +160,11 @@ class MailPlugin extends ScryptedDeviceBase implements Settings, MixinProvider { } async getSettings(): Promise { - return [ - { - title: "SMTP Port (No Authentication)", - key: 'smtpPort', - value: this.getPort().toString(), - } - ] - } - - getPort() { - return parseInt(this.storage.getItem('smtpPort')) || 25; + return this.storageSettings.getSettings(); } async putSetting(key: string, value: SettingValue): Promise { - this.storage.setItem(key, value.toString()); - - this.server.close(); + return this.storageSettings.putSetting(key, value); } async canMixin(type: ScryptedDeviceType, interfaces: string[]): Promise { diff --git a/plugins/smtp/tsconfig.json b/plugins/smtp/tsconfig.json index 22d317309..0dca70a7c 100644 --- a/plugins/smtp/tsconfig.json +++ b/plugins/smtp/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "resolveJsonModule": true, - "moduleResolution": "node", + "moduleResolution": "Node16", "target": "esnext", "esModuleInterop": true, },