List of usage examples for javax.mail.internet MimePart addHeader
public void addHeader(String header_name, String header_value) throws MessagingException;
From source file:mitm.common.mail.MailUtils.java
/** * Converts any 8bit encoded parts to 7bit. Returns true if a part (or all parts) were converted from * 8bit to 7bit.//from w w w . j a v a 2s . c o m * * @param part * @throws MessagingException */ public static boolean convertTo7Bit(MimePart part) throws MessagingException, IOException { boolean converted = false; if (part.isMimeType("multipart/*")) { Multipart parts = (Multipart) part.getContent(); int count = parts.getCount(); for (int i = 0; i < count; i++) { boolean partConverted = convertTo7Bit((MimePart) parts.getBodyPart(i)); if (partConverted) { converted = true; } } } else if ("8bit".equalsIgnoreCase(part.getEncoding())) { String encoding = part.isMimeType("text/*") ? "quoted-printable" : "base64"; /* * We need to use a ByteArrayDataSource to make sure it will always be encoded */ part.setDataHandler( new DataHandler(new ByteArrayDataSource(part.getInputStream(), part.getContentType()))); part.setHeader("Content-Transfer-Encoding", encoding); part.addHeader("X-MIME-Autoconverted", "from 8bit to " + encoding + " by Djigzo"); converted = true; } return converted; }