import * as wmill from "windmill-client"
import { S3Object } from "windmill-client"
/**
* Download Attachment
* Download a message's file attachment to Windmill object storage and return its S3 reference. Get the attachment id from List Attachments. Requires Mail.Read (covered by the default Mail.ReadWrite).
*/
export async function main(
auth: RT.Outlook,
message_id: string,
attachment_id: string,
destination: S3Object,
mailbox: string | undefined
) {
const base = `https://graph.microsoft.com/v1.0/${
mailbox != null && mailbox !== ""
? `users/${encodeURIComponent(mailbox)}`
: "me"
}`
const response = await fetch(
`${base}/messages/${encodeURIComponent(
message_id
)}/attachments/${encodeURIComponent(attachment_id)}/$value`,
{ headers: { Authorization: `Bearer ${auth.token}` } }
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
await wmill.writeS3File(
destination,
response.body as ReadableStream<Uint8Array>
)
return destination
}
Submitted by hugo989 6 hours ago
import * as wmill from "windmill-client"
import { S3Object } from "windmill-client"
/**
* Download Attachment
* Download a message's file attachment to Windmill object storage and return its S3 reference. Get the attachment id from List Attachments. Requires Mail.Read on the connection.
*/
export async function main(
auth: RT.Outlook,
message_id: string,
attachment_id: string,
destination: S3Object,
mailbox: string | undefined
) {
const base = `https://graph.microsoft.com/v1.0/${
mailbox != null && mailbox !== ""
? `users/${encodeURIComponent(mailbox)}`
: "me"
}`
const response = await fetch(
`${base}/messages/${encodeURIComponent(
message_id
)}/attachments/${encodeURIComponent(attachment_id)}/$value`,
{ headers: { Authorization: `Bearer ${auth.token}` } }
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
await wmill.writeS3File(
destination,
response.body as ReadableStream<Uint8Array>
)
return destination
}
Submitted by hugo989 6 hours ago