List of usage examples for javax.mail.internet MimePart getContentType
public String getContentType() throws MessagingException;
From source file:org.apache.james.smtpserver.fastfail.URIRBLHandler.java
/** * Recursively scans all MimeParts of an email for domain strings. Domain * strings that are found are added to the supplied HashSet. * /*from ww w .j a v a 2 s.c o m*/ * @param part * MimePart to scan * @param session * not null * @return domains The HashSet that contains the domains which were * extracted */ private HashSet<String> scanMailForDomains(MimePart part, SMTPSession session) throws MessagingException, IOException { HashSet<String> domains = new HashSet<String>(); session.getLogger().debug("mime type is: \"" + part.getContentType() + "\""); if (part.isMimeType("text/plain") || part.isMimeType("text/html")) { session.getLogger().debug("scanning: \"" + part.getContent().toString() + "\""); HashSet<String> newDom = URIScanner.scanContentForDomains(domains, part.getContent().toString()); // Check if new domains are found and add the domains if (newDom != null && newDom.size() > 0) { domains.addAll(newDom); } } else if (part.isMimeType("multipart/*")) { MimeMultipart multipart = (MimeMultipart) part.getContent(); int count = multipart.getCount(); session.getLogger().debug("multipart count is: " + count); for (int index = 0; index < count; index++) { session.getLogger().debug("recursing index: " + index); MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(index); HashSet<String> newDomains = scanMailForDomains(mimeBodyPart, session); // Check if new domains are found and add the domains if (newDomains != null && newDomains.size() > 0) { domains.addAll(newDomains); } } } return domains; }
From source file:org.simplejavamail.internal.util.MimeMessageParser.java
/** * Checks whether the MimePart contains an object of the given mime type. * * @param part the current MimePart/*www .ja va 2 s .c om*/ * @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 */ private static boolean isMimeType(final MimePart part, final String mimeType) throws MessagingException { // 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); } }