if (type.startsWith(Mime.CT_MULTIPART + '/')) {
if (type.startsWith(Mime.CT_MULTIPART_PREFIX)) {
    private static void setContent(MimeMessage mm, Multipart mmp, Element elem, MimeBodyPart[] alternatives)     throws MessagingException {        String type = elem.getAttribute(MailService.A_CONTENT_TYPE, Mime.CT_DEFAULT).trim();        int slash = type.indexOf('/');        boolean invalidCT = (slash <= 0 || slash == type.length() - 1);        // is the client passing us a multipart?        if (type.startsWith(Mime.CT_MULTIPART + '/')) {            // yes!  Find out what the subtype is (assume "mixed" if none or invalid one is specified)            String subType = invalidCT ? "mixed" : type.substring(slash + 1);                        // do we need to add a multipart/alternative for the alternatives?            if (alternatives==null || subType.equals("alternative")) {                                // no need to add an extra multipart/alternative!                                // create the MimeMultipart and attach it to the existing structure:                MimeMultipart mmpNew = new MimeMultipart(subType);                if (mmp == null) {                    // there were no multiparts at all, we need to create one                     mm.setContent(mmpNew);                } else {                    // there was already a multipart/mixed at the top of the mm                    MimeBodyPart mbpWrapper = new MimeBodyPart();                    mbpWrapper.setContent(mmpNew);                    mmp.addBodyPart(mbpWrapper);                }                                // add each part in turn (recursively)                for (Iterator it = elem.elementIterator(); it.hasNext(); ) {                    // the alternatives will be placed below                    setContent(mm, mmpNew, (Element) it.next(), null);                }                                // finally, add the alternatives if there are any...                if (alternatives != null) {                    for (int i = 0; i < alternatives.length; i++) {                        mmpNew.addBodyPart(alternatives[i]);                    }                }            } else {                // create a multipart/alternative to hold all the client's struct + the alternatives                MimeMultipart mmpNew = new MimeMultipart("alternative");                if (mmp == null) {                    mm.setContent(mmpNew);                } else {                    MimeBodyPart mbpWrapper = new MimeBodyPart();                    mbpWrapper.setContent(mmpNew);                    mmp.addBodyPart(mbpWrapper);                }                mmp = mmpNew;                                // add the entire client's multipart/whatever here inside our multipart/alternative                setContent(mm, mmp, elem, null);                                // add all the alternatives                for (int i = 0; i < alternatives.length; i++) {                    mmp.addBodyPart(alternatives[i]);                }            }         } else {            // a single part from the client...we might still have to create a multipart/alternative if            // there are alternatives[] passed-in, but still this is fairly straightforward...                        if (alternatives != null) {                // create a multipart/alternative to hold all the alternatives                MimeMultipart mmpNew = new MimeMultipart("alternative");                if (mmp == null) {                    mm.setContent(mmpNew);                } else {                    MimeBodyPart mbpWrapper = new MimeBodyPart();                    mbpWrapper.setContent(mmpNew);                    mmp.addBodyPart(mbpWrapper);                }                mmp = mmpNew;            }            // once we get here, mmp is either NULL, a multipart/mixed from the toplevel,             // or a multipart/alternative created just above....either way we are safe to stick            // the client's nice and simple body right here            ContentType ct = new ContentType();            ct.setPrimaryType(invalidCT ? "text" : type.substring(0, slash));            ct.setSubType(invalidCT ? "plain" : type.substring(slash + 1));            ct.setParameter(Mime.P_CHARSET, Mime.P_CHARSET_UTF8);                Element contentElem = elem.getOptionalElement(MailService.E_CONTENT);            String data = (contentElem == null ? "" : contentElem.getText());            if (mmp != null) {                MimeBodyPart mbp = new MimeBodyPart();                mbp.setText(data, Mime.P_CHARSET_UTF8);                mbp.setHeader("Content-Type", ct.toString());                mmp.addBodyPart(mbp);            } else {                mm.setText(data, Mime.P_CHARSET_UTF8);                mm.setHeader("Content-Type", ct.toString());            }                        if (alternatives != null) {                for (int i = 0; i < alternatives.length; i++) {                    mmp.addBodyPart(alternatives[i]);                }            }        }    }