List of usage examples for javax.mail Part getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:de.mendelson.comm.as2.message.AS2MessageCreation.java
/**Signs the passed data and returns it *//*w ww . j av a 2s . c o m*/ private MimeMultipart signContentPart(Part part, Partner sender, Partner receiver) throws Exception { MimeMultipart signedPart = null; if (part instanceof MimeBodyPart) { signedPart = this.signContent((MimeBodyPart) part, sender, receiver); } else if (part instanceof MimeMessage) { signedPart = this.signContent((MimeMessage) part, sender, receiver); } else { throw new IllegalArgumentException( "signContentPart: unable to sign a " + part.getClass().getName() + "."); } return (signedPart); }
From source file:de.mendelson.comm.as2.message.AS2MessageCreation.java
/**Compresses the payload using the ZLIB algorithm */// www .ja v a 2 s . com private MimeBodyPart compressPayload(Partner receiver, Part contentPart) throws SMIMEException { SMIMECompressedGenerator generator = new SMIMECompressedGenerator(); if (receiver.getContentTransferEncoding() == AS2Message.CONTENT_TRANSFER_ENCODING_BASE64) { generator.setContentTransferEncoding("base64"); } else { generator.setContentTransferEncoding("binary"); } if (contentPart instanceof MimeBodyPart) { return (generator.generate((MimeBodyPart) contentPart, SMIMECompressedGenerator.ZLIB)); } else if (contentPart instanceof MimeMessage) { return (generator.generate((MimeMessage) contentPart, SMIMECompressedGenerator.ZLIB)); } else { throw new IllegalArgumentException( "compressPayload: Unable to compress a Part of class " + contentPart.getClass().getName()); } }
From source file:de.mendelson.comm.as2.message.AS2MessageCreation.java
/**Enwrapps the data into a signed MIME message structure and returns it*/ private void enwrappInMessageAndSign(AS2Message message, Part contentPart, Partner sender, Partner receiver) throws Exception { AS2MessageInfo info = (AS2MessageInfo) message.getAS2Info(); MimeMessage messagePart = new MimeMessage(Session.getInstance(System.getProperties(), null)); //sign message if this is requested if (info.getSignType() != AS2Message.SIGNATURE_NONE) { MimeMultipart signedPart = this.signContentPart(contentPart, sender, receiver); if (this.logger != null) { String signAlias = this.signatureCertManager.getAliasByFingerprint(sender.getSignFingerprintSHA1()); this.logger.log(Level.INFO, this.rb.getResourceString("message.signed", new Object[] { info.getMessageId(), signAlias, this.rbMessage.getResourceString("signature." + receiver.getSignType()) }), info);// w ww . j a v a 2 s . c om } messagePart.setContent(signedPart); messagePart.saveChanges(); } else { //unsigned message if (contentPart instanceof MimeBodyPart) { MimeMultipart unsignedPart = new MimeMultipart(); unsignedPart.addBodyPart((MimeBodyPart) contentPart); if (this.logger != null) { this.logger.log(Level.INFO, this.rb.getResourceString("message.notsigned", new Object[] { info.getMessageId() }), info); } messagePart.setContent(unsignedPart); } else if (contentPart instanceof MimeMultipart) { messagePart.setContent((MimeMultipart) contentPart); } else if (contentPart instanceof MimeMessage) { messagePart = (MimeMessage) contentPart; } else { throw new IllegalArgumentException("enwrappInMessageAndSign: Unable to set the content of a " + contentPart.getClass().getName()); } messagePart.saveChanges(); } //store signed or unsigned data ByteArrayOutputStream signedOut = new ByteArrayOutputStream(); //normally the content type header is folded (which is correct but some products are not able to parse this properly) //Now take the content-type, unfold it and write it Enumeration headerLines = messagePart.getMatchingHeaderLines(new String[] { "Content-Type" }); LineOutputStream los = new LineOutputStream(signedOut); while (headerLines.hasMoreElements()) { //requires java mail API >= 1.4 String nextHeaderLine = MimeUtility.unfold((String) headerLines.nextElement()); //write the line only if the as2 message is encrypted. If the as2 message is unencrypted this header is added later //in the class MessageHttpUploader if (info.getEncryptionType() != AS2Message.ENCRYPTION_NONE) { los.writeln(nextHeaderLine); } //store the content line in the as2 message object, this value is required later in MessageHttpUploader message.setContentType(nextHeaderLine.substring(nextHeaderLine.indexOf(':') + 1)); } messagePart.writeTo(signedOut, new String[] { "Message-ID", "Mime-Version", "Content-Type" }); signedOut.flush(); signedOut.close(); message.setDecryptedRawData(signedOut.toByteArray()); }
From source file:com.sonicle.webtop.mail.Service.java
private String getTextContentAsString(Part p) throws IOException, MessagingException { java.io.InputStream istream = null; String charset = MailUtils.getCharsetOrDefault(p.getContentType()); if (!java.nio.charset.Charset.isSupported(charset)) { charset = "ISO-8859-1"; }//from w w w . j a v a 2 s. com try { if (p instanceof javax.mail.internet.MimeMessage) { javax.mail.internet.MimeMessage mm = (javax.mail.internet.MimeMessage) p; istream = mm.getInputStream(); } else if (p instanceof javax.mail.internet.MimeBodyPart) { javax.mail.internet.MimeBodyPart mm = (javax.mail.internet.MimeBodyPart) p; istream = mm.getInputStream(); } } catch (Exception exc) { //unhandled format, get Raw data if (p instanceof javax.mail.internet.MimeMessage) { javax.mail.internet.MimeMessage mm = (javax.mail.internet.MimeMessage) p; istream = mm.getRawInputStream(); } else if (p instanceof javax.mail.internet.MimeBodyPart) { javax.mail.internet.MimeBodyPart mm = (javax.mail.internet.MimeBodyPart) p; istream = mm.getRawInputStream(); } } if (istream == null) { throw new IOException("Unknown message class " + p.getClass().getName()); } java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(istream, charset)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); } br.close(); return sb.toString(); }
From source file:org.nuxeo.ecm.platform.mail.action.TransformMessageAction.java
private void processMultipartMessage(MimeMultipart parts) throws MessagingException, IOException { log.debug("processing multipart message."); for (int i = 0; i < parts.getCount(); i++) { Part part = parts.getBodyPart(i); if (part.getDataHandler().getContent() instanceof MimeMultipart) { log.debug("** found embedded multipart message"); processMultipartMessage((MimeMultipart) part.getDataHandler().getContent()); continue; }/*from w w w . jav a2 s . co m*/ log.debug("processing single part message: " + part.getClass()); processSingleMessagePart(part); } }