1

I am using MimeBodyPart.getInputStream to retrieve a file attached to an incoming email. Anytime the attached file is larger than 8192 bytes (8 KiB), the rest of the data is lost. fileInput.readAllBytes().length seems to always be min(fileSize, 8192). My relevant code looks like this

val part = multiPart.getBodyPart(i).asInstanceOf[MimeBodyPart]
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition)) {
    val filePath = fileManager.generateRandomUniqueFilename
    val fileName = part.getFileName
    val fileSize = part.getSize
    val fileContentType = part.getContentType

    val fileInput = part.getInputStream

    doSomething(filePath, fileInput.readAllBytes(), fileName, fileSize, fileContentType)
}

Note that the variable fileSize contains the right value (e. g. 63209 for a roughly 64kb file). I've tried this with two different mail servers yielding the same result. In the documentation I cannot find anything about a 8KiB limit. What is happening here?

Note: When I use part.getRawInputStream I receive the full data!

mo_st
  • 149
  • 2
  • 12
  • 1
    Smells like the short size for GET as opposed to POST, email servers operate different to http but do have some similar request constraint systems. however, such settings may be adjustable in server configuration. Lookup the IETF RFC for SMTP transport. – Samuel Marchant Oct 06 '22 at 11:50

0 Answers0