Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not all attachments are downloaded #21

Open
HanaanY opened this issue Mar 27, 2021 · 3 comments
Open

not all attachments are downloaded #21

HanaanY opened this issue Mar 27, 2021 · 3 comments

Comments

@HanaanY
Copy link

HanaanY commented Mar 27, 2021

hello, firstly I'd like to say nice project!

I tried using it and it found the label I was looking for, it found all the emails under the label but it didn't find any attachments

I traced the problem to index.js, line 189 in the function pluckAllAttachments

      if (!p.body || !p.body.attachmentId) {
        return undefined;
      }

It seems not all messages that have attachments, have an attachmentId. Sometimes they are found in the same object but in the data key. See gmail api https://developers.google.com/gmail/api/reference/rest/v1/users.messages.attachments

it seems the messages that are causing the problem have nested parts which contain the relevant attachmentId

image

The messages in question were forwarded with an iPad FWIW

EDIT: removed something I was wrong about, added what the actual problem was 😅

@HanaanY
Copy link
Author

HanaanY commented Mar 28, 2021

changing it to the below snippet worked for my case 😁

Sorry I don't have time to do it properly as part of a pull request at the moment. I'm not sure if my use of lodash flattenDeep would cause problems in other scenarios.

I suspect there's only nested parts if the mimeType is 'multipart/mixed'

function pluckAllAttachments(mails) {
  return _.compact(_.flattenDeep(_.map(mails, (m) => {
    if (!m.data || !m.data.payload || !m.data.payload.parts) {
      return undefined;
    }
    return pluckParts(m.data.payload.parts, m.data.id);

  })));
}

function pluckParts(parts, dataId ) {
  const pluckedParts = _.map(parts, (p) => {
      if (p.parts !== undefined) {
        return pluckParts(p.parts, dataId);
      }
      if (!p.body || !p.body.attachmentId) {
        return undefined;
      }
      const attachment = {
        mailId: dataId,
        name: p.filename,
        id: p.body.attachmentId
      };
      return attachment;
    })
    return pluckedParts;
}

@munir131
Copy link
Owner

munir131 commented Apr 1, 2021

@HanaanY Thanks for sharing the issue and solution. I haven't got time to look into that. But, I will look into that and fix within 2 weeks. Thanks again.

@munir131
Copy link
Owner

@lpirkwieser fixed that issue. @HanaanY Please confirm for your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants