There I have code that decodes all attachments in my mail:
for (String key : attachments.keySet()) { String fileContent = attachments.get(key); attachments.put(key, getEncodedPartFromAttachment(fileContent)); }
private String decodeFileContent(String encodedData) { return new String(Base64.getDecoder().decode(encodedData)); }
After encoding and decoding back, I faced some issues, like:
Original PDF: %âãÏÓ
Transformed PDF: %����
Original PDF: H‰d;1D¯2'°l'Χ¥¡¢@²Ü¿À†XØ&Ò›ÌG~€Épõ·
Transformed PDF: H�d�;1D�2'�l'Χ���@��ܿ���X�&қ�G~��p��
Is there some way not to corrupt content while encoding-decoding?
new String (...). This damages the binary PDF data, depending on the used encoding even beyond repair. Handle binary attachments as binaries instead, e.g. asbyte []or asByteBuffer.