/** * Checks whether the MimePart contains an object of the given mime type. * * @param part the current MimePart * @param mimeType the mime type to check * @return {@code true} if the MimePart matches the given mime type, {@code false} otherwise * @throws MessagingException parsing the MimeMessage failed * @throws IOException parsing the MimeMessage failed */ private boolean isMimeType(final MimePart part, final String mimeType) throws MessagingException, IOException { // Do not use part.isMimeType(String) as it is broken for MimeBodyPart // and does not really check the actual content type. try { final ContentType ct = new ContentType(part.getDataHandler().getContentType()); return ct.match(mimeType); } catch (final ParseException ex) { return part.getContentType().equalsIgnoreCase(mimeType); } }
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
/** * Parses the MimePart to create a DataSource. * * @param parent the parent multi-part * @param part the current part to be processed * @return the DataSource * @throws MessagingException creating the DataSource failed * @throws IOException creating the DataSource failed */ protected DataSource createDataSource(final Multipart parent, final MimePart part) throws MessagingException, IOException { final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); final byte[] content = this.getContent(dataSource.getInputStream()); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }
@SuppressWarnings("WeakerAccess") public static DataHandler retrieveDataHandler(@Nonnull final MimePart part) { try { return part.getDataHandler(); } catch (final MessagingException e) { throw new MimeMessageParseException(MimeMessageParseException.ERROR_GETTING_DATAHANDLER, e); } }
static void updateHeaders(MimePart part) throws MessagingException { DataHandler dh = part.getDataHandler(); if (dh == null) // Huh ? return;
static void updateHeaders(MimePart part) throws MessagingException { DataHandler dh = part.getDataHandler(); if (dh == null) // Huh ? return;
/** * Checks whether the MimePart contains an object of the given mime type. * * @param part the current MimePart * @param mimeType the mime type to check * @return {@code true} if the MimePart matches the given mime type, {@code false} otherwise * @throws MessagingException parsing the MimeMessage failed * @throws IOException parsing the MimeMessage failed */ private boolean isMimeType(final MimePart part, final String mimeType) throws MessagingException, IOException { // Do not use part.isMimeType(String) as it is broken for MimeBodyPart // and does not really check the actual content type. try { final ContentType ct = new ContentType(part.getDataHandler().getContentType()); return ct.match(mimeType); } catch (final ParseException ex) { return part.getContentType().equalsIgnoreCase(mimeType); } }
bodyPart.getDataHandler().writeTo(baos); baos.close(); result = baos.toByteArray();
/** * Checks whether the MimePart contains an object of the given mime type. * * @param part the current MimePart * @param mimeType the mime type to check * @return {@code true} if the MimePart matches the given mime type, {@code false} otherwise * @throws MessagingException parsing the MimeMessage failed * @throws IOException parsing the MimeMessage failed */ private boolean isMimeType(final MimePart part, final String mimeType) throws MessagingException, IOException { // Do not use part.isMimeType(String) as it is broken for MimeBodyPart // and does not really check the actual content type. try { final ContentType ct = new ContentType(part.getDataHandler().getContentType()); return ct.match(mimeType); } catch (final ParseException ex) { return part.getContentType().equalsIgnoreCase(mimeType); } }
static void writeTo(MimePart part, OutputStream os, String[] ignoreList) throws IOException, MessagingException { // see if we already have a LOS LineOutputStream los = null; if (os instanceof LineOutputStream) { los = (LineOutputStream) os; } else { los = new LineOutputStream(os); } // First, write out the header Enumeration hdrLines = part.getNonMatchingHeaderLines(ignoreList); while (hdrLines.hasMoreElements()) los.writeln((String)hdrLines.nextElement()); // The CRLF separator between header and content los.writeln(); // Finally, the content. Encode if required. // XXX: May need to account for ESMTP ? os = MimeUtility.encode(os, part.getEncoding()); part.getDataHandler().writeTo(os); os.flush(); // Needed to complete encoding } }
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
DataHandler dh = part.getDataHandler(); if (dh instanceof MimePartDataHandler) { MimePartDataHandler mpdh = (MimePartDataHandler)dh; os = MimeUtility.encode(os, restrictEncoding(part, part.getEncoding())); part.getDataHandler().writeTo(os);
/** * Parses the MimePart to create a DataSource. * * @param part the current part to be processed * @return the DataSource * @throws MessagingException creating the DataSource failed * @throws IOException creating the DataSource failed */ protected DataSource createDataSource(final MimePart part) throws MessagingException, IOException { final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); final byte[] content = this.getContent(dataSource.getInputStream()); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }
/** * Parses the MimePart to create a DataSource. * * @param parent the parent multi-part * @param part the current part to be processed * @return the DataSource * @throws MessagingException creating the DataSource failed * @throws IOException creating the DataSource failed */ protected DataSource createDataSource(final Multipart parent, final MimePart part) throws MessagingException, IOException { final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); final byte[] content = this.getContent(dataSource.getInputStream()); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }