postalsys / imapflow

IMAP Client library for EmailEngine Email API (https://emailengine.app)
https://imapflow.com
Other
350 stars 59 forks source link

Bug: Large message cannot be downloaded with `imapFlow.download()` method #203

Closed titanism closed 2 months ago

titanism commented 2 months ago

If part is undefined and if response.bodyParts is a Map such as the following:

response {
  seq: 1,
  uid: 1,
  size: 50000196,
  bodyParts: Map(1) {
    ']<0.65536>' => <Buffer 44 61 74 65 3a 20 32 30 32 34 2d 30 36 2d 32 34 54 30 39 3a 30 33 3a 35 30 2e 38 35 33 5a 0d 0a 54 6f 3a 20 66 6f 6f 2d 31 40 65 78 61 6d 70 6c 65 2d ... 50000146 more bytes>
  },
  modseq: 2n,
  id: '5538720b5b4805e674b821b303ac7797'
}

Then the download returned value will be {} since chunk is false.

Example usage:

const data = await imapFlow.download(1); // note that `part` and `options` are optional

Source code where bug can be found:

https://github.com/postalsys/imapflow/blob/954a9ded083edf638d90356a1ea38f28c69ac4ce/lib/imap-flow.js#L2529-L2532

titanism commented 2 months ago

This was a bug on my side (IMAP was not sending over the exact requested size/chunks)