@VisibleForTesting void download(MailboxSession mailboxSession, DownloadPath downloadPath, HttpServletResponse resp) { String blobId = downloadPath.getBlobId(); try { Blob blob = blobManager.retrieve(BlobId.fromString(blobId), mailboxSession); addContentDispositionHeader(downloadPath.getName(), resp); resp.setHeader("Content-Length", String.valueOf(blob.getSize())); resp.setStatus(SC_OK); IOUtils.copy(blob.getStream(), resp.getOutputStream()); } catch (BlobNotFoundException e) { LOGGER.info("Attachment '{}' not found", blobId, e); resp.setStatus(SC_NOT_FOUND); } catch (MailboxException | IOException e) { LOGGER.error("Error while downloading", e); resp.setStatus(SC_INTERNAL_SERVER_ERROR); } }