chore: update the template processor
This commit is contained in:
@@ -157,15 +157,15 @@ export class SendEmailDto {
|
||||
@ApiPropertyOptional({ description: "Message subject. If not then resolved from Reference message (optional)", example: "Test email" })
|
||||
subject: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: EmailMessage.TEXT_CONTENT_REQUIRED })
|
||||
@IsString({ message: EmailMessage.TEXT_CONTENT_MUST_BE_STRING })
|
||||
@ApiPropertyOptional({ description: "Plaintext message (optional)" })
|
||||
text?: string;
|
||||
text: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: EmailMessage.HTML_CONTENT_REQUIRED })
|
||||
@IsString({ message: EmailMessage.HTML_CONTENT_MUST_BE_STRING })
|
||||
@ApiPropertyOptional({ description: "HTML formatted message (optional)" })
|
||||
html?: string;
|
||||
html: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray({ message: EmailMessage.ATTACHMENTS_MUST_BE_ARRAY })
|
||||
|
||||
@@ -207,8 +207,8 @@ export class EmailController {
|
||||
@ApiResponse({ status: 200, description: "Draft sent successfully" })
|
||||
@ApiResponse({ status: 404, description: "Draft not found" })
|
||||
@ApiResponse({ status: 403, description: "Not authorized to send draft" })
|
||||
sendDraft(@UserDec("wildduckUserId") userId: string, @Param() params: MessageParamDto) {
|
||||
return this.emailService.sendDraft(userId, Number(params.messageId));
|
||||
sendDraft(@UserDec() user: User, @Param() params: MessageParamDto) {
|
||||
return this.emailService.sendDraft(user.wildduckUserId, user.id, Number(params.messageId));
|
||||
}
|
||||
|
||||
@Delete("messages/drafts/:messageId")
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// BASE INTERFACES
|
||||
// ====================
|
||||
|
||||
import { MessageAddress } from "../../mail-server/interfaces/messages-response.interface";
|
||||
|
||||
export interface IBaseEventPayload {
|
||||
userId: string;
|
||||
timestamp: string;
|
||||
@@ -23,21 +25,15 @@ export interface IBaseMessageMailboxEventPayload extends IBaseMessageEventPayloa
|
||||
// COMMON EMAIL INTERFACES
|
||||
// ====================
|
||||
|
||||
export interface IEmailContact {
|
||||
name?: string;
|
||||
address: string;
|
||||
}
|
||||
|
||||
export interface IEmailMetadata {
|
||||
subject: string;
|
||||
hasAttachments: boolean;
|
||||
mailboxName: string;
|
||||
isRead: boolean;
|
||||
}
|
||||
|
||||
export interface IEmailContent extends IEmailMetadata {
|
||||
from: IEmailContact;
|
||||
to: IEmailContact[];
|
||||
from: MessageAddress;
|
||||
to: MessageAddress[];
|
||||
preview?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,10 @@ export class EmailService {
|
||||
|
||||
if (processedTemplate.isHtml) {
|
||||
sendEmailDto.html = processedTemplate.content;
|
||||
sendEmailDto.text = undefined;
|
||||
sendEmailDto.text = "";
|
||||
} else {
|
||||
sendEmailDto.text = processedTemplate.content;
|
||||
sendEmailDto.html = undefined;
|
||||
sendEmailDto.html = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ export class EmailService {
|
||||
from: sendEmailDto.from,
|
||||
hasAttachments: false,
|
||||
mailboxName: "Sent",
|
||||
isRead: true,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
|
||||
@@ -514,10 +513,10 @@ export class EmailService {
|
||||
|
||||
if (processedTemplate.isHtml) {
|
||||
draftData.html = processedTemplate.content;
|
||||
draftData.text = undefined;
|
||||
draftData.text = "";
|
||||
} else {
|
||||
draftData.text = processedTemplate.content;
|
||||
draftData.html = undefined;
|
||||
draftData.html = "";
|
||||
}
|
||||
|
||||
const headers = this.generateHeadersForEmailType(user, {
|
||||
@@ -538,12 +537,27 @@ export class EmailService {
|
||||
}
|
||||
|
||||
//==============================================
|
||||
async sendDraft(wildduckUserId: string, messageId: number) {
|
||||
async sendDraft(wildduckUserId: string, userId: string, messageId: number) {
|
||||
const draftsMailboxId = await this.mailboxResolverService.getDraftsMailboxId(wildduckUserId);
|
||||
const result = await firstValueFrom(
|
||||
this.mailServerService.messages.submitDraft(wildduckUserId, draftsMailboxId, messageId, { deleteFiles: false }),
|
||||
);
|
||||
|
||||
const message = await firstValueFrom(this.mailServerService.messages.getMessage(wildduckUserId, draftsMailboxId, messageId));
|
||||
|
||||
await this.emailNotificationService.notifyEmailSentFromDraft({
|
||||
wildduckUserId,
|
||||
userId,
|
||||
from: message.from,
|
||||
to: message.to!,
|
||||
subject: message.subject,
|
||||
hasAttachments: false,
|
||||
mailboxName: message.mailbox,
|
||||
messageId: Number(message.id),
|
||||
mailboxId: message.mailbox,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
|
||||
return {
|
||||
message: EmailMessage.DRAFT_SENT_SUCCESSFULLY,
|
||||
messageId: result.message.id,
|
||||
|
||||
Reference in New Issue
Block a user