feat: mail entity download
Build Test / test (pull_request) Successful in 32s
JS Unit Tests / test (pull_request) Failing after 31s
PHP Unit Tests / test (pull_request) Successful in 1m1s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-28 23:22:02 -04:00
parent 502b18962c
commit 935743963f
6 changed files with 227 additions and 27 deletions
+40 -5
View File
@@ -7,7 +7,8 @@ import { defineStore } from 'pinia'
import { entityService } from '../services'
import { EntityObject, MessageObject } from '../models'
import type {
EntityListStreamRequest,
EntityBlobSelector,
EntityDownloadRequest,
EntityTransmitRequest,
EntityTransmitResponse,
} from '../types/entity'
@@ -18,7 +19,7 @@ import type {
ListRange,
ListSort,
} from '../types/common'
import type { MessageInterface } from '@/types/message'
import type { MessageInterface, MessagePartInterface } from '@/types/message'
export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
// State
@@ -184,15 +185,15 @@ export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
const response = await entityService.delta({ sources })
// Process delta and update store
Object.entries(response).forEach(([provider, providerData]) => {
Object.entries(response).forEach(([, providerData]) => {
// Skip if no changes for provider
if (providerData === false) return
Object.entries(providerData).forEach(([service, serviceData]) => {
Object.entries(providerData).forEach(([, serviceData]) => {
// Skip if no changes for service
if (serviceData === false) return
Object.entries(serviceData).forEach(([collection, collectionData]) => {
Object.entries(serviceData).forEach(([, collectionData]) => {
// Skip if no changes for collection
if (collectionData === false) return
@@ -474,6 +475,39 @@ export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
}
}
async function download(target: EntityIdentifier, part?: Partial<MessagePartInterface>) {
let targetPart: EntityBlobSelector | undefined = undefined
if (part && (part.blobId || part.partId || part.cid)) {
targetPart = {
blobId: part.blobId ?? undefined,
partId: part.partId ?? undefined,
cid: part.cid ?? undefined,
}
}
let filename: string
if (part && part.name && part.name.trim().length > 0) {
filename = part.name.trim()
} else if (part) {
filename = `attachment-${part.partId || part.blobId || part.cid || 'unknown'}`
} else {
filename = 'message.eml'
}
const request: EntityDownloadRequest = {
target,
part: targetPart,
filename,
}
try {
entityService.download(request)
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to submit attachment download:', error)
throw error
}
}
// Return public API
return {
// State (readonly)
@@ -495,5 +529,6 @@ export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
delta,
move,
transmit,
download,
}
})