public MimePart convertTo7Bit(MimePart part) throws MessagingException, IOException { if (part.isMimeType("multipart/*")) { List<BodyPart> bodyParts = MultipartUtil.retrieveBodyParts((MimeMultipart) part.getContent()); for (BodyPart bodyPart : bodyParts) { convertTo7Bit((MimePart) bodyPart); } } else if ("8bit".equals(part.getEncoding())) { // The content may already be in encoded the form (likely with mail // created from a // stream). In that case, just changing the encoding to // quoted-printable will mangle // the result when this is transmitted. We must first convert the // content into its // native format, set it back, and only THEN set the transfer // encoding to force the // content to be encoded appropriately. // if the part doesn't contain text it will be base64 encoded. String contentTransferEncoding = part.isMimeType("text/*") ? "quoted-printable" : "base64"; part.setContent(part.getContent(), part.getContentType()); part.setHeader("Content-Transfer-Encoding", contentTransferEncoding); part.addHeader("X-MIME-Autoconverted", "from 8bit to " + contentTransferEncoding + " by " + mailetContext.getServerInfo()); } return part; }
.setHeader("Content-Transfer-Encoding", contentTransferEncoding); part.addHeader("X-MIME-Autoconverted", "from 8bit to " + contentTransferEncoding + " by " + getMailetContext().getServerInfo());