Package javax.mail.internet

Examples of javax.mail.internet.PreencodedMimeBodyPart


                            // is content a reference to a file?
                            if (container.isInlineFilesEnabled() && textContent.startsWith("file:")) {
                                String filename = textContent.substring(5);
                                if (container.isMtomEnabled()) {
                                    MimeBodyPart part = new PreencodedMimeBodyPart("binary");
                                    String xmimeContentType = getXmlMimeContentType(cursor);

                                    if (StringUtils.isNullOrEmpty(xmimeContentType)) {
                                        xmimeContentType = ContentTypeHandler.getContentTypeFromFilename(filename);
                                    }

                                    part.setDataHandler(new DataHandler(new XOPPartDataSource(new File(filename),
                                            xmimeContentType, schemaType)));
                                    part.setContentID("<" + filename + ">");
                                    mp.addBodyPart(part);

                                    isXopAttachment = true;
                                } else {
                                    if (new File(filename).exists()) {
                                        inlineData(cursor, schemaType, new FileInputStream(filename));
                                    } else {
                                        Attachment att = getAttachmentForFilename(container, filename);
                                        if (att != null) {
                                            inlineData(cursor, schemaType, att.getInputStream());
                                        }
                                    }
                                }
                            } else {
                                Attachment[] attachmentsForPart = container.getAttachmentsForPart(textContent);
                                if (textContent.startsWith("cid:")) {
                                    textContent = textContent.substring(4);
                                    attachmentsForPart = container.getAttachmentsForPart(textContent);

                                    Attachment[] attachments = attachmentsForPart;
                                    if (attachments.length == 1) {
                                        attachment = attachments[0];
                                    } else if (attachments.length > 1) {
                                        attachment = buildMulitpartAttachment(attachments);
                                    }

                                    isXopAttachment = container.isMtomEnabled();
                                    contentIds.put(textContent, textContent);
                                }
                                // content should be binary data; is this an XOP element
                                // which should be serialized with MTOM?
                                else if (container.isMtomEnabled()
                                        && (SchemaUtils.isBinaryType(schemaType) || SchemaUtils.isAnyType(schemaType))) {
                                    if ("true".equals(System.getProperty("soapui.mtom.strict"))) {
                                        if (SchemaUtils.isAnyType(schemaType)) {
                                            textContent = null;
                                        } else {
                                            for (int c = 0; c < textContent.length(); c++) {
                                                if (Character.isWhitespace(textContent.charAt(c))) {
                                                    textContent = null;
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    if (textContent != null) {
                                        MimeBodyPart part = new PreencodedMimeBodyPart("binary");
                                        String xmimeContentType = getXmlMimeContentType(cursor);

                                        part.setDataHandler(new DataHandler(new XOPPartDataSource(textContent,
                                                xmimeContentType, schemaType)));

                                        textContent = "http://www.soapui.org/" + System.nanoTime();

                                        part.setContentID("<" + textContent + ">");
                                        mp.addBodyPart(part);

                                        isXopAttachment = true;
                                    }
                                } else if (container.isInlineFilesEnabled() && attachmentsForPart != null
View Full Code Here


        for (int c = 0; c < attachments.size(); c++) {
            Attachment att = attachments.get(c);
            String contentType = att.getContentType();
            totalSize += att.getSize();

            MimeBodyPart part = contentType.startsWith("text/") ? new MimeBodyPart() : new PreencodedMimeBodyPart(
                    "binary");

            part.setDataHandler(new DataHandler(new AttachmentDataSource(att)));
            initPartContentId(contentIds, part, att, false);
            multipart.addBodyPart(part);
        }

        MimeBodyPart part = new PreencodedMimeBodyPart("binary");

        if (totalSize > MAX_SIZE_IN_MEMORY_ATTACHMENT) {
            part.setDataHandler(new DataHandler(new MultipartAttachmentFileDataSource(multipart)));
        } else {
            part.setDataHandler(new DataHandler(new MultipartAttachmentDataSource(multipart)));
        }

        Attachment attachment = attachments.get(0);
        initPartContentId(contentIds, part, attachment, true);
View Full Code Here

    public static void addSingleAttachment(MimeMultipart mp, StringToStringMap contentIds, Attachment att)
            throws MessagingException {
        String contentType = att.getContentType();
        MimeBodyPart part = contentType.startsWith("text/") ? new MimeBodyPart()
                : new PreencodedMimeBodyPart("binary");

        part.setDataHandler(new DataHandler(new AttachmentDataSource(att)));
        initPartContentId(contentIds, part, att, false);

        mp.addBodyPart(part);
View Full Code Here

TOP

Related Classes of javax.mail.internet.PreencodedMimeBodyPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.