Skip to content

Commit

Permalink
Merge pull request #32 from dotnich-io/fix-multipart-mixed
Browse files Browse the repository at this point in the history
Support some more attachment-related edge cases
  • Loading branch information
thingnotok authored Apr 30, 2024
2 parents 713431f + 34d026c commit 62c85dd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/GmailAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ async function getAttachments(gmail:gmail_v1.Gmail, account:string, msgId: strin
const part = parts[i];
const filename = part.filename
const attach_id = part.body.attachmentId

if(!filename || !attach_id) {
console.debug(msgId, `Part ${i} has no filename or attachmentId, skipping...`)
continue
}

const ares = await getAttachment(gmail, account, msgId, attach_id)
const red = ares.data?.data?.replace(/-/g, '+').replace(/_/g, '/') || ""
const init_name = filename
Expand All @@ -176,7 +182,7 @@ function flatten_parts(dst:any, parts:any){
}
else {
for(let i = 0; i < parts.length;i++){
if(parts[i].mimeType=='multipart/related'||parts[i].mimeType=="multipart/alternative")
if(parts[i].mimeType=='multipart/related'||parts[i].mimeType=="multipart/alternative" || parts[i].mimeType=="multipart/mixed")
flatten_parts(dst, parts[i].parts)
else
dst.assets.push(parts[i])
Expand Down

0 comments on commit 62c85dd

Please sign in to comment.