From abfdd1b9e70d72eab69e141cba81c4259c61c11c Mon Sep 17 00:00:00 2001 From: mahyargdz Date: Mon, 21 Jul 2025 10:22:58 +0330 Subject: [PATCH] chore: new feature --- src/common/enums/message.enum.ts | 2 ++ src/modules/email/email.controller.ts | 8 +++++++ .../email/services/email-spam.service.ts | 4 +++- src/modules/email/services/email.service.ts | 21 +++++++++++++++++++ .../mail-server/DTO/domain-access.dto.ts | 2 +- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/common/enums/message.enum.ts b/src/common/enums/message.enum.ts index 574d3df..51d3d35 100755 --- a/src/common/enums/message.enum.ts +++ b/src/common/enums/message.enum.ts @@ -224,6 +224,8 @@ export const enum EmailMessage { SUBJECT_REQUIRED = "موضوع ایمیل مورد نیاز است", ALL_MESSAGES_DELETED_SUCCESSFULLY = "همه پیام ها با موفقیت حذف شدند", MAILBOX_ID_MUST_BE_MONGO_ID = "شناسه میل باکس ایمیل باید یک آی دی معتبر باشد", + MESSAGE_MARKED_AS_UNSEEN_SUCCESSFULLY = "پیام با موفقیت به عنوان خوانده نشده علامت گذاری شد", + MESSAGE_MARK_AS_UNSEEN_FAILED = "علامت گذاری پیام به عنوان خوانده نشده با خطا مواجه شد", } export const enum WebSocketMessage { diff --git a/src/modules/email/email.controller.ts b/src/modules/email/email.controller.ts index e12e44e..fb6c8ce 100644 --- a/src/modules/email/email.controller.ts +++ b/src/modules/email/email.controller.ts @@ -67,6 +67,14 @@ export class EmailController { return this.emailService.markMessageAsSeen(userId, Number(params.messageId), query.mailbox); } + @Patch("messages/:messageId/unseen") + @ApiOperation({ summary: "Mark a message as unseen" }) + @ApiResponse({ status: 200, description: "Message marked as unseen successfully" }) + @ApiResponse({ status: 404, description: "Message not found" }) + markMessageAsUnseen(@UserDec("wildduckUserId") userId: string, @Param() params: MessageParamDto, @Query() query: MailboxIdQueryDto) { + return this.emailService.markMessageAsUnseen(userId, Number(params.messageId), query.mailbox); + } + @Get("messages/inbox") @ApiOperation({ summary: "List messages in a inbox" }) @ApiResponse({ status: 200, description: "List of messages" }) diff --git a/src/modules/email/services/email-spam.service.ts b/src/modules/email/services/email-spam.service.ts index 10948d6..6a149c0 100644 --- a/src/modules/email/services/email-spam.service.ts +++ b/src/modules/email/services/email-spam.service.ts @@ -33,6 +33,8 @@ export class EmailSpamService { } } } catch (_error) { + // Expected: 404 errors occur when the message doesn't exist in this mailbox + // Continue searching other mailboxes continue; } } @@ -101,7 +103,7 @@ export class EmailSpamService { await firstValueFrom( this.mailServerService.domainAccess.addAllowedDomain(domainTag, { domain: senderInfo.senderDomain, - description: `Auto-allowed due to not-spam report from message ${messageId}`, + // Removed description field as WildDuck API doesn't accept it for allowlist operations }), ); diff --git a/src/modules/email/services/email.service.ts b/src/modules/email/services/email.service.ts index 21ab32c..3bc013b 100644 --- a/src/modules/email/services/email.service.ts +++ b/src/modules/email/services/email.service.ts @@ -269,6 +269,27 @@ export class EmailService { } } + //============================================== + async markMessageAsUnseen(wildduckUserId: string, messageId: number, mailboxId: string) { + try { + this.logger.log(`Marking message ${messageId} as unseen in ${mailboxId} mailbox for user: ${wildduckUserId}`); + + const { updated } = await firstValueFrom(this.mailServerService.messages.updateMessage(wildduckUserId, mailboxId, messageId, { seen: false })); + + this.logger.log(`Message ${messageId} marked as unseen successfully in ${mailboxId}`); + + return { + success: true, + message: EmailMessage.MESSAGE_MARKED_AS_UNSEEN_SUCCESSFULLY, + updated, + }; + } catch (error) { + this.logger.error( + `Failed to mark message ${messageId} as unseen for user ${wildduckUserId}: ${error instanceof Error ? error.message : "Unknown error"}`, + ); + throw error; + } + } //============================================== async getSentMessages(wildduckUserId: string, query: MessageListQueryDto) { try { diff --git a/src/modules/mail-server/DTO/domain-access.dto.ts b/src/modules/mail-server/DTO/domain-access.dto.ts index bea043f..a48f909 100644 --- a/src/modules/mail-server/DTO/domain-access.dto.ts +++ b/src/modules/mail-server/DTO/domain-access.dto.ts @@ -11,7 +11,7 @@ export class CreateDomainAccessDto { domain: string; @ApiPropertyOptional({ - description: "Optional description for this domain entry", + description: "Optional description for this domain entry. Note: May not be supported for all operations (e.g., allowlist operations)", example: "Trusted business partner domain", }) @IsOptional()