List of usage examples for javax.mail.internet MimePart setFileName
public void setFileName(String filename) throws MessagingException;
From source file:mitm.common.pdf.MessagePDFBuilder.java
private Part convertRFC822(Part attachment) { try {/* w ww . j av a2s . c o m*/ Object o = attachment.getContent(); if (o instanceof MimeMessage) { MimeMessage message = (MimeMessage) o; MessagePDFBuilder pdfBuilder = this.clone(); ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); pdfBuilder.buildPDF(message, null, pdfStream); MimePart pdfPart = new MimeBodyPart(); pdfPart.setDataHandler( new DataHandler(new ByteArrayDataSource(pdfStream.toByteArray(), "application/pdf"))); String filename = getFilename(attachment, "message.pdf"); if (!filename.toLowerCase().endsWith(".pdf")) { filename = filename + ".pdf"; } pdfPart.setFileName(filename); return pdfPart; } } catch (IOException e) { logger.error("Error trying to converting to RFC822."); } catch (MessagingException e) { logger.error("Error trying to converting to RFC822."); } catch (DocumentException e) { logger.error("Error trying to converting to RFC822."); } return attachment; }