String cts = mp.getContentType(); if (cts == null) cts = CT_DEFAULT; else {         int semicolon = cts.indexOf(';'); if (semicolon != -1) cts = cts.substring(0, semicolon);    if (cts.equals("text")) cts = CT_TEXT_PLAIN; } ContentType ct = null; try { ct = new ContentType(cts.toLowerCase()); cts = ct.getPrimaryType() + "/" + ct.getSubType(); } catch (ParseException e) { if (mLog.isInfoEnabled()) mLog.info("Unrecognized Content-Type " + cts + "; assuming " + CT_DEFAULT); ct = new ContentType(CT_DEFAULT); } boolean isMultipart = ct.match(CT_MULTIPART_WILD); boolean isMessage = !isMultipart && ct.match(CT_MESSAGE_RFC822);
String cts = getContentType(mp); boolean isMultipart = cts.startsWith(CT_MULTIPART_PREFIX); boolean isMessage = !isMultipart && cts.equals(CT_MESSAGE_RFC822);
	private static void handlePart(MimePart mp, String prefix, List<MPartInfo> partList, MPartInfo parent, int partNum)    throws IOException, MessagingException {		String cts = mp.getContentType();		if (cts == null)			cts = CT_DEFAULT;		else {			// only use "type/subtype"			// This is a workaround for messages sent by some broken mailers			// that generate an invalid content type string which causes			// JavaMail ParseException.  The broken mailer that necessitated			// this hack is "X-Mailer: Balsa 2.0.17", which generated			// Content-Type of "Content-Type:   text/plain; charset=US-ASCII;\r\n"			// "\tFormat=Flowed   DelSp=Yes\r\n".  Notice it is missing ';' after			// "Flowed".			int semicolon = cts.indexOf(';');			if (semicolon != -1)				cts = cts.substring(0, semicolon);			// Some mailers don't specify subtype at all, e.g. "Content-Type: text"			// Special case "text" to "text/plain".			if (cts.equals("text"))				cts = CT_TEXT_PLAIN;		}		ContentType ct = null;		try {			ct = new ContentType(cts.toLowerCase());			cts = ct.getPrimaryType() + "/" + ct.getSubType();		} catch (ParseException e) {			if (mLog.isInfoEnabled())				mLog.info("Unrecognized Content-Type " + cts + "; assuming " + CT_DEFAULT);			ct = new ContentType(CT_DEFAULT);		}        boolean isMultipart = ct.match(CT_MULTIPART_WILD);         boolean isMessage = !isMultipart && ct.match(CT_MESSAGE_RFC822);        String disp = null, filename = null;        try {            disp = mp.getDisposition();            filename = Mime.getFilename(mp);        } catch (ParseException pe) { }        // the top-level part of a non-multipart message is numbered "1"        if (!isMultipart && mp instanceof MimeMessage)            prefix = (prefix.length() > 0 ? (prefix + ".") : "") + '1';        MPartInfo mpart = new MPartInfo();		mpart.mPart = mp;		mpart.mParent = parent;		mpart.mContentType = ct;		mpart.mContentTypeString = cts;		mpart.mPartName = prefix;		mpart.mPartNum = partNum;		mpart.mChildren = null;        mpart.mDisposition = (disp == null ? "" : disp.toLowerCase());        mpart.mFilename = (filename == null ? "" : filename.toLowerCase());		partList.add(mpart);		if (parent != null) {			if (parent.mChildren == null)				parent.mChildren = new ArrayList<MPartInfo>();			parent.mChildren.add(mpart);		}		// System.out.println("    " + mpart.info);		if (isMultipart) {            // IMAP part numbering is screwy: top-level multipart doesn't get a number			String newPrefix = prefix.length() > 0 ? (prefix + '.') : "";            if (mp instanceof MimeMessage)                mpart.mPartName = newPrefix + "TEXT";			mpart.mContent = getMultipartContent(mp, cts);			if (mpart.mContent instanceof MimeMultipart)				handleMultiPart((MimeMultipart) mpart.mContent, newPrefix, partList, mpart);		} else if (isMessage) {			mpart.mContent = getMessageContent(mp);			if (mpart.mContent instanceof MimeMessage)				handlePart((MimeMessage) mpart.mContent, prefix, partList, mpart, 0);		} else {			// nothing to do at this stage		}	}