static boolean isMimeType(MimePart part, String mimeType) throws MessagingException { // XXX - lots of room for optimization here! String type = part.getContentType(); try { return new ContentType(type).match(mimeType); } catch (ParseException ex) { // we only need the type and subtype so throw away the rest try { int i = type.indexOf(';'); if (i > 0) return new ContentType(type.substring(0, i)).match(mimeType); } catch (ParseException pex2) { } return type.equalsIgnoreCase(mimeType); } }
static boolean isMimeType(MimePart part, String mimeType) throws MessagingException { // XXX - lots of room for optimization here! String type = part.getContentType(); try { return new ContentType(type).match(mimeType); } catch (ParseException ex) { // we only need the type and subtype so throw away the rest try { int i = type.indexOf(';'); if (i > 0) return new ContentType(type.substring(0, i)).match(mimeType); } catch (ParseException pex2) { } return type.equalsIgnoreCase(mimeType); } }
/** * Match with the specified content-type string. This method * compares <strong>only the <code>primaryType</code> and * <code>subType</code> </strong>. * The parameters of both operands are ignored. <p> * * For example, this method will return <code>true</code> when * comparing the ContentType for <strong>"text/plain"</strong> * with <strong>"text/plain; charset=foobar"</strong>. * * If the <code>subType</code> of either operand is the special * character '*', then the subtype is ignored during the match. * For example, this method will return <code>true</code> when * comparing the ContentType for <strong>"text/plain"</strong> * with <strong>"text/*" </strong> * * @param s the content-type string to match * @return true if it matches */ public boolean match(String s) { try { return match(new ContentType(s)); } catch (ParseException pex) { return false; } } }
/** * Match with the specified content-type string. This method * compares <strong>only the <code>primaryType</code> and * <code>subType</code> </strong>. * The parameters of both operands are ignored. <p> * * For example, this method will return <code>true</code> when * comparing the ContentType for <strong>"text/plain"</strong> * with <strong>"text/plain; charset=foobar"</strong>. * * If the <code>subType</code> of either operand is the special * character '*', then the subtype is ignored during the match. * For example, this method will return <code>true</code> when * comparing the ContentType for <strong>"text/plain"</strong> * with <strong>"text/*" </strong> * * @param s the content-type string to match * @return true if it matches */ public boolean match(String s) { try { return match(new ContentType(s)); } catch (ParseException pex) { return false; } } }
/** * 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); } }
is = ds.getInputStream(); boolean isText = cType.match("text/*");
is = ds.getInputStream(); boolean isText = cType.match("text/*");
/** * Test if this body structure represents an attached message. If it's a * message, this will be a single part of MIME type message/rfc822. * * @return True if this is a nested message type, false for either a multipart or * a single part of another type. */ public boolean isAttachedMessage() { return !isMultipart() && mimeType.match("message/rfc822"); } }
public boolean match(String contentType) { try { return match(new ContentType(contentType)); } catch (ParseException e) { return false; } } }
if (cType.match("text/*")) {
if (cType.match("text/*")) {
/** * Tests to see if this message has a mime-type match with the * given type name. * * @param type The tested type name. * * @return If this is a type match on the primary and secondare portion of the types. * @exception MessagingException */ public boolean isMimeType(String type) throws MessagingException { return new ContentType(getContentType()).match(type); }
/** * Tests to see if this message has a mime-type match with the * given type name. * * @param type The tested type name. * * @return If this is a type match on the primary and secondare portion of the types. * @exception MessagingException */ public boolean isMimeType(String type) throws MessagingException { return new ContentType(getContentType()).match(type); }
static boolean isMimeType(MimePart part, String mimeType) throws MessagingException { // XXX - lots of room for optimization here! try { ContentType ct = new ContentType(part.getContentType()); return ct.match(mimeType); } catch (ParseException ex) { return part.getContentType().equalsIgnoreCase(mimeType); } }
static boolean isMimeType(MimePart part, String mimeType) throws MessagingException { // XXX - lots of room for optimization here! try { ContentType ct = new ContentType(part.getContentType()); return ct.match(mimeType); } catch (ParseException ex) { return part.getContentType().equalsIgnoreCase(mimeType); } }
private void writeBodyPart(byte[] bodyContent, Part part, ContentType contentType) throws MessagingException { DataSource ds = new ByteArrayDataSource(bodyContent, contentType.toString()); part.setDataHandler(new DataHandler(ds)); part.setHeader(CONTENT_TYPE, contentType.toString()); if (contentType.match("text/*")) { part.setHeader(CONTENT_TRANSFER_ENCODING, "8bit"); } else if (binaryContent) { part.setHeader(CONTENT_TRANSFER_ENCODING, "binary"); } else { part.setHeader(CONTENT_TRANSFER_ENCODING, "base64"); } }