Skip to content

[PB-1967]: feat/download attachments#56

Merged
xabg2 merged 10 commits into
masterfrom
feat/download-attachments
Jun 3, 2026
Merged

[PB-1967]: feat/download attachments#56
xabg2 merged 10 commits into
masterfrom
feat/download-attachments

Conversation

@xabg2

@xabg2 xabg2 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Allow the user to download an attachment given its email.

We will need to validate, if we want to, if the attachment belongs to a specific email. To do so, I need the PR that returns the mail attachments.

@xabg2 xabg2 self-assigned this Jun 2, 2026
@xabg2 xabg2 added the enhancement New feature or request label Jun 2, 2026
@xabg2 xabg2 changed the base branch from master to feat/upload-attachments June 2, 2026 13:05
@xabg2 xabg2 requested a review from jzunigax2 June 2, 2026 13:14
Base automatically changed from feat/upload-attachments to master June 3, 2026 07:17
Comment thread src/modules/email/email.controller.ts Outdated
Comment on lines +303 to +326
const safeName = sanitizeFilename(name);
const safeType = sanitizeMimeType(type);

const mail = await this.emailService.getEmail(email, _id);
if (!mail) throw new NotFoundException('Email not found');

const attachment = mail.attachments.find((a) => a.blobId === blobId);
if (!attachment) throw new NotFoundException('Attachment not found');

const result = await this.emailService.downloadAttachment({
userEmail: email,
blobId,
name: safeName,
type: safeType ?? undefined,
});

const resolvedType = safeType ?? result.contentType;

res.setHeader('Content-Type', resolvedType);
res.setHeader('Content-Disposition', buildContentDisposition(safeName));
if (result.contentLength !== undefined)
res.setHeader('Content-Length', result.contentLength);

return new StreamableFile(result.stream);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick controller logic should stay thin with no business logic. the res.setHeader stuff does belong here

const namePart = encodeURIComponent(name ?? 'attachment');
const acceptQuery = type ? `?accept=${encodeURIComponent(type)}` : '';

const { statusCode, headers, body } = await this.uploadClient.request({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename uploadClient, to blob client or similar? sounds confusing

@sonarqubecloud

sonarqubecloud Bot commented Jun 3, 2026

Copy link
Copy Markdown

@xabg2 xabg2 requested a review from jzunigax2 June 3, 2026 13:51
@xabg2 xabg2 merged commit 560b724 into master Jun 3, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants