2022-08-07 09:38:07 +00:00
|
|
|
import * as plugins from './smartmail.plugins.js';
|
2018-09-29 21:57:25 +00:00
|
|
|
|
2020-01-13 15:19:47 +00:00
|
|
|
export interface ISmartmailOptions<T> {
|
2019-10-26 21:45:35 +00:00
|
|
|
from: string;
|
|
|
|
subject: string;
|
|
|
|
body: string;
|
2020-01-13 15:19:47 +00:00
|
|
|
creationObjectRef?: T;
|
2019-10-26 21:45:35 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 21:57:25 +00:00
|
|
|
/**
|
|
|
|
* a standard representation for mails
|
|
|
|
*/
|
2020-01-13 15:19:47 +00:00
|
|
|
export class Smartmail<T> {
|
|
|
|
public options: ISmartmailOptions<T>;
|
2019-10-28 14:38:44 +00:00
|
|
|
public attachments: plugins.smartfile.Smartfile[] = [];
|
2019-10-26 21:45:35 +00:00
|
|
|
|
2020-01-13 15:19:47 +00:00
|
|
|
constructor(optionsArg: ISmartmailOptions<T>) {
|
2019-10-26 21:45:35 +00:00
|
|
|
this.options = optionsArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addAttachment(smartfileArg: plugins.smartfile.Smartfile) {
|
|
|
|
this.attachments.push(smartfileArg);
|
|
|
|
}
|
|
|
|
|
2020-01-13 15:52:27 +00:00
|
|
|
public getCreationObject(): T {
|
2020-01-13 15:52:02 +00:00
|
|
|
return this.options.creationObjectRef;
|
|
|
|
}
|
|
|
|
|
2019-10-26 21:45:35 +00:00
|
|
|
public getSubject(dataArg: any = {}) {
|
|
|
|
const smartmustache = new plugins.smartmustache.SmartMustache(this.options.subject);
|
|
|
|
return smartmustache.applyData(dataArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getBody(dataArg: any = {}) {
|
|
|
|
const smartmustache = new plugins.smartmustache.SmartMustache(this.options.body);
|
|
|
|
return smartmustache.applyData(dataArg);
|
|
|
|
}
|
2018-09-29 21:57:25 +00:00
|
|
|
}
|