chore: add new featurew

This commit is contained in:
mahyargdz
2025-07-21 16:30:08 +03:30
parent abfdd1b9e7
commit dc5c5898aa
9 changed files with 235 additions and 11 deletions
@@ -1,7 +1,9 @@
import { Injectable } from "@nestjs/common";
import { Observable } from "rxjs";
import { catchError, map, throwError } from "rxjs";
import { WildDuckBaseService } from "./wildduck-base.service";
import { MailServerException } from "../../../core/exceptions/mail-server.exceptions";
import { ListMessagesQueryDto, SearchMessagesQueryDto, UpdateMessageDto, UploadMessageDto } from "../DTO/message.dto";
import { AttachmentResponse } from "../interfaces/attachment.interface";
import {
@@ -75,7 +77,37 @@ export class WildDuckMessagesService extends WildDuckBaseService {
*/
getMessageAttachment(userId: string, mailboxId: string, messageId: number, attachmentId: string): Observable<AttachmentResponse> {
// This returns binary content
return this.get<AttachmentResponse>(`/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}/attachments/${attachmentId}`);
const url = this.buildUrl(`/users/${userId}/mailboxes/${mailboxId}/messages/${messageId}/attachments/${attachmentId}`);
this.logger.debug(`WildDuck GET: ${url}`);
return this.httpService
.get(url, {
responseType: "stream",
headers: {
Accept: "*/*",
},
})
.pipe(
map((response) => {
this.logger.debug(`HTTP ${response.status}: ${response.config?.url}`);
return {
success: response.data,
headers: response.headers,
contentType: response.headers["content-type"],
contentDisposition: response.headers["content-disposition"],
contentLength: response.headers["content-length"],
} as AttachmentResponse;
}),
catchError((error) => {
this.logger.error(`WildDuck API error: ${error.message}`, error.stack);
if (error.response?.data?.error) {
return throwError(() => new MailServerException(error.response.data.error));
}
return throwError(() => error);
}),
);
}
/**