Creates a MimePart from text part.

@return mimePart from HTML string
@throws MessagingException
344368
private MimePart createTextMimePart() throws MessagingException {
		MimePart bodyPart = new MimeBodyPart();
		bodyPart.setText(textPart);
		return bodyPart;
	}
1107550
public function getMimeDocument()
    {
        $textPart = false;
        $htmlPart = false;

        $html = $this->getHtml();
        $text = $this->getText();
        $subject = $this->getSubject();

        /**
         * @var string|bool Tracks which part should contain the text and html parts.
         */
        $alternativePart = false;

        if (count($this->attachments) > 0) {
            $mime = new MimeDocument("multipart/mixed", crc32($html) . crc32($text) . crc32($subject));
        } else {
            $mime = new MimeDocument("multipart/alternative", crc32($html) . crc32($text) . crc32($subject));

            // The outer mime part is our alternative part
            $alternativePart = $mime;
        }

        if ($text != "") {
            $textPart = new MimePartText("text/plain");
            $textPart->setTransformedBody($text);
        }

        if ($html != "") {
            $htmlPart = new MimePartText("text/html");
            $htmlPart->setTransformedBody($html);
        }

        if ($text != "" && $html != "") {
            if (count($this->attachments) > 0) {
                // As this email has attachments we need to create an alternative part to store the text and html
                $alternativePart = new MimeDocument("multipart/alternative");

                $mime->addPart($alternativePart);
            }

            $alternativePart->addPart($textPart);
            $alternativePart->addPart($htmlPart);
        } else {
            if ($text != "") {
                $mime->addPart($textPart);
            }

            if ($html != "") {
                $mime->addPart($htmlPart);
            }
        }

        foreach ($this->attachments as $attachment) {
            $mime->addPart(MimePartBinaryFile::fromLocalPath($attachment->path, $attachment->name));
        }

        $mime->addHeader("To", $this->getRecipientList());
        $mime->addHeader("From", $this->getSender()->getRfcFormat());
        $mime->addHeader("Subject", $this->getSubject());
        $mime->addHeader("Reply-To", $this->getReplyToRecipient());

        return $mime;
    }
910281
public String convert(String messagePayload) {
        initialize();

        // check if we already have XHTML message content
        if (messagePayload.contains(XHTML_DOCTYPE_DEFINITION)) {
            return messagePayload;
        } else {
            String xhtmlPayload;
            StringWriter xhtmlWriter = new StringWriter();
            tidyInstance.parse(new StringReader(messagePayload), xhtmlWriter);

            xhtmlPayload = xhtmlWriter.toString();
            xhtmlPayload = xhtmlPayload.replaceFirst(W3_XHTML1_URL, "org/w3/xhtml/");
            return xhtmlPayload;
        }
    }
345653
public static MimeBodyPart newAttachmentBodyPart( String content, String contentId, String mimeType, String fileName)
    throws MessagingException, IOException
  {
    MimeBodyPart mimeBodyPart = new MimeBodyPart();
//    log.debug("Creating an attachment for content '{}', mimeType '{}', fileName '{}'.", new Object[] {content, mimeType, fileName});
    mimeBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(content, mimeType + UTF_8_CHARACTER_SET)));
    if( contentId != null ) {
      mimeBodyPart.setHeader("Content-ID", contentId);
    }
    mimeBodyPart.setDisposition(DISPOSITION_ATTACHMENT);
    if( fileName != null ) {
      mimeBodyPart.setFileName(fileName);
    }
    return mimeBodyPart;
  }
791034
public function createMimeMessage()
    {
        $this->createBody();

        $envelopeAllowedType = array(
            'remail', 'return_path', 'date', 'from', 'reply_to', 'in_reply_to',
            'subject', 'to', 'cc', 'bcc', 'message_id', 'custom_headers',
        );
        /* @var $envelope array */
        $envelope = Helper::preparingProperties($this->envelope, $envelopeAllowedType, Helper::OUT_ARRAY);
        $bodyAllowedType = array(
            'type', 'encoding', 'charset', 'type.parameters', 'subtype',
            'id', 'description', 'disposition.type', 'disposition', 'contents.data',
            'lines', 'bytes', 'md5',
        );
        /* @var $body array */
        foreach ($this->body as $key => $part) {
            $this->body[$key] = Helper::preparingProperties($part, $bodyAllowedType, Helper::OUT_ARRAY);
        }
        $body = $this->body;

        return imap_mail_compose($envelope, $body);
    }
203833
public function assembleAttachmentBody()
    {
        $body = array();
        $body[] = "This is a multi-part message in MIME format.";
        $body[] = "--{$this->_uid}";
        $body[] = "Content-Type: text/html; charset=\"utf-8\"";
        $body[] = "Content-Transfer-Encoding: quoted-printable";
        $body[] = "";
        $body[] = quoted_printable_encode($this->_message);
        $body[] = "";
        $body[] = "--{$this->_uid}";

        foreach ($this->_attachments as $attachment) {
            $body[] = $this->getAttachmentMimeTemplate($attachment);
        }

        return implode(PHP_EOL, $body) . '--';
    }
336236
private static MimeMultipart getContentAsMimeMultipart(ContentTypeHeader contentTypeHeader, byte[] rawContent) {
		// Issue 1123 : http://code.google.com/p/mobicents/issues/detail?id=1123 : Multipart type is supported
		String delimiter = contentTypeHeader.getParameter(MULTIPART_BOUNDARY);
		String start = contentTypeHeader.getParameter(MULTIPART_START);

		MimeMultipart mimeMultipart = new MimeMultipart(contentTypeHeader.getContentSubType());
		if (delimiter == null) {
			MimeBodyPart mbp = new MimeBodyPart();
		    DataSource ds = new ByteArrayDataSource(rawContent, contentTypeHeader.getContentSubType());
		    try {
				mbp.setDataHandler(new DataHandler(ds));
				mimeMultipart.addBodyPart(mbp);
			} catch (MessagingException e) {
				throw new IllegalArgumentException("couldn't create the multipart object from the message content " + rawContent, e);
			}
		} else {
			// splitting the body content by delimiter
		    String[] fragments = new String(rawContent).split(MULTIPART_BOUNDARY_DELIM + delimiter);
			for (String fragment: fragments) {
				final String trimmedFragment = fragment.trim();
				// skipping empty fragment and ending fragment looking like --
				if(trimmedFragment.length() > 0 && !MULTIPART_BOUNDARY_DELIM.equals(trimmedFragment)) {
					String fragmentHeaders = null;
					String fragmentBody = fragment;
					// if there is a start, it means that there is probably headers before the content that need to be added to the mime body part
					// so we split headers from body content
					if(start != null && start.length() > 0) {
						int indexOfStart = fragment.indexOf(start);
						if(indexOfStart != -1) {
							fragmentHeaders = fragmentBody.substring(0, indexOfStart + start.length());
							fragmentBody = fragmentBody.substring(indexOfStart + start.length()).trim();
						}
					}
					MimeBodyPart mbp = new MimeBodyPart();
				    try {
				    	String contentType = contentTypeHeader.getContentSubType();
				    	// check if the body content start with a Content-Type header
				    	// if so we strip it from the content body
				    	if(fragmentBody.startsWith(ContentTypeHeader.NAME)) {
				    		int indexOfLineReturn =  fragmentBody.indexOf(LINE_RETURN_DELIM);
				    		contentType = fragmentBody.substring(0, indexOfLineReturn -1).trim();
				    		fragmentBody = fragmentBody.substring(indexOfLineReturn).trim();
				    	}
				    	// setting the content body stripped from the headers
				    	mbp.setContent(fragmentBody, contentType);
				    	// adding the headers to the body part
				    	mbp.addHeaderLine(contentType);
				    	if(fragmentHeaders != null) {
				    		StringTokenizer stringTokenizer = new StringTokenizer(fragmentHeaders, LINE_RETURN_DELIM);
				    		while (stringTokenizer.hasMoreTokens()) {
				    			String token = stringTokenizer.nextToken().trim();
				    			if(token != null && token.length() > 0) {
				    				mbp.addHeaderLine(token);
				    			}
							}
				    	}
						mimeMultipart.addBodyPart(mbp);
					} catch (MessagingException e) {
						throw new IllegalArgumentException("couldn't create the multipart object from the message content " + rawContent, e);
					}
				}
			}
		}
		return mimeMultipart;
	}
1128803
private function build_multipart() {
    $boundary =  "b".md5(uniqid(time()));

    $multipart =  "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n";

    if(count($this->altparts)>0){
      $multipart .=  "\n--$boundary\n".$this->build_alternative_multipart();
    }

    for($i = sizeof($this->parts)-1; $i >= 0; $i--)
    {
      $multipart .=  "\n--$boundary\n".$this->build_message($this->parts[$i]);
    }
    return $multipart.=  "\n--"."$boundary"."--";
  }
1259419
public MimeMultipart getMimeMultipart() throws MessagingException,
            IOException, JAXBException {
        List<DataSource> bodyPartContents = createRequestBody();
        return toMimeMultipart(bodyPartContents);

    }
685133
public function toMessage()
    {
        $message = clone $this;

        $altBody = $message->altBody();
        $attachments = $message->attachments();
        $inlines = $message->inlines();

        $root = $cursor = $message->stream();

        $body = $message->body();
        $bodyMime = $cursor->mime() ?: 'text/plain';
        $bodyCharset = $cursor->charset() ?: Mime::optimalCharset($body);

        if (count($attachments)) {
            $cursor->mime('multipart/mixed');
            $current = $cursor->add(new MixedPart());
            foreach ($attachments as $path => $attachment) {
                $cursor->add(fopen($path, 'r'), $attachment);
            }
            $cursor = $current;
        }

        if ($altBody || count($inlines)) {
            $cursor->mime('multipart/alternative');
        }

        if ($altBody) {
            $cursor->add($altBody, [
                'mime'     => 'text/plain',
                'charset'  => Mime::optimalCharset($altBody),
                'encoding' => Mime::optimalEncoding($altBody)
            ]);
        }

        if ($body) {
            $options = [
                'mime'     => $bodyMime,
                'charset'  => $bodyCharset,
                'encoding' => Mime::optimalEncoding($body)
            ];

            if ($inlines) {
                $current = $cursor->add(new MixedPart(['mime' => 'multipart/related']));
                $current->add($body, $options);
                foreach ($inlines as $path => $inline) {
                    $current->add(fopen($path, 'r'), $inline);
                }
            } else {
                $cursor->add($body, $options);
            }
        }

        $headers = $root->headers();
        $headers['Date'] = date('r');
        $headers['Message-ID'] = static::generateId($this->client());
        return $root->toMessage();
    }
194916
public static MessageProtocol fromContentTypeHeader(Optional<String> contentType) {
        return contentType.map(ct -> {
            String[] parts = ct.split(";");
            String justContentType = parts[0];
            Optional<String> charset = Optional.empty();
            for (int i = 1; i < parts.length; i++) {
                String toTest = parts[i].trim();
                if (toTest.startsWith("charset=")) {
                    charset = Optional.of(toTest.split("=", 2)[1]);
                    break;
                }
            }
            return new MessageProtocol(Optional.of(justContentType), charset, Optional.empty());
        }).orElse(new MessageProtocol());
    }
417059
public AnnotatedText build() {
    int plainTextPosition = 0;
    int totalPosition = 0;
    Map<Integer,Integer> mapping = new HashMap<>();
    mapping.put(0, 0);
    for (TextPart part : parts) {
      if (part.getType() == TextPart.Type.TEXT) {
        plainTextPosition += part.getPart().length();
        totalPosition += part.getPart().length();
      } else if (part.getType() == TextPart.Type.MARKUP) {
        totalPosition += part.getPart().length();
      } else if (part.getType() == TextPart.Type.FAKE_CONTENT) {
        plainTextPosition += part.getPart().length();
      }
      mapping.put(plainTextPosition, totalPosition);
    }
    return new AnnotatedText(parts, mapping, metaData, customMetaData);
  }
1240268
protected function becomeMimePart()
    {
        $part = new parent($this->getHeaders()->newInstance(), $this->getEncoder(),
            $this->getCache(), $this->getIdGenerator(), $this->userCharset
            );
        $part->setContentType($this->userContentType);
        $part->setBody($this->getBody());
        $part->setFormat($this->userFormat);
        $part->setDelSp($this->userDelSp);
        $part->setNestingLevel($this->getTopNestingLevel());

        return $part;
    }
1097341
protected BodyPart handleApplicationContentPart(MimePart applicationData, String contentType) throws IOException, MessagingException {
        if (applicationData.isMimeType("application/pdf")) {
            return handleImageBinaryPart(applicationData, contentType);
        } else if (applicationData.isMimeType("application/rtf")) {
            return handleImageBinaryPart(applicationData, contentType);
        } else if (applicationData.isMimeType("application/java")) {
            return handleTextPart(applicationData, contentType);
        } else if (applicationData.isMimeType("application/x-javascript")) {
            return handleTextPart(applicationData, contentType);
        } else if (applicationData.isMimeType("application/xhtml+xml")) {
            return handleTextPart(applicationData, contentType);
        } else if (applicationData.isMimeType("application/json")) {
            return handleTextPart(applicationData, contentType);
        } else if (applicationData.isMimeType("application/postscript")) {
            return handleTextPart(applicationData, contentType);
        } else {
            return handleBinaryPart(applicationData, contentType);
        }
    }
739206
static JsMessage createInboundWebMessage(String data) throws MessageDecodeFailedException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "createInboundWebMessage");
        JsJmsMessage result = null;

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            SibTr.debug(tc, "Decoding message from web data", data);

        // The inbound data consists of a number of '~' delimited fields. Refer to the
        // description in WebJsJmsMessageEncoderImpl for details.
        StringTokenizer st = new StringTokenizer(data, "~", true);

        // Pull out the header fields and the message payload.  Remember that it is possible
        // for fields to be empty strings which will be encoded consecutive delimiters.
        String version, id, type, format, topic, props, body;
        version = id = type = format = topic = props = body = null;
        try {
            version = st.nextToken();
            st.nextToken();
            String s = st.nextToken();
            if (!s.equals("~")) {
                id = s;
                st.nextToken();
            }
            s = st.nextToken();
            if (!s.equals("~")) {
                type = s;
                st.nextToken();
            }
            s = st.nextToken();
            if (!s.equals("~")) {
                format = s;
                st.nextToken();
            }
            s = st.nextToken();
            if (!s.equals("~")) {
                topic = s;
                st.nextToken();
            }
            s = st.nextToken();
            if (!s.equals("~")) {
                props = s;
                // This may be the end
                if (st.hasMoreTokens())
                    st.nextToken();
            }
            // The body may be omitted completely
            if (st.hasMoreTokens()) {
                body = st.nextToken();
            }
        } catch (NoSuchElementException e) {
            FFDCFilter.processException(e, "com.ibm.ws.sib.mfp.impl.WebJsMessageFactoryImpl.createInboundWebMessage", "119");
            throw new MessageDecodeFailedException("Inccorect WebClient encoding", e);
        }

        // Verify the data
        if (!version.equals("1"))
            throw new MessageDecodeFailedException("Incorrect WebClient encoding version: " + version);
        if (!format.startsWith(SIApiConstants.JMS_FORMAT))
            throw new MessageDecodeFailedException("Incorrect WebClient message format: " + format);

        // Decode the mesasge
        if (format.equalsIgnoreCase(SIApiConstants.JMS_FORMAT_TEXT))
            result = decodeTextBody(body);
        else if (format.equalsIgnoreCase(SIApiConstants.JMS_FORMAT_BYTES))
            result = decodeBytesBody(body);
        else if (format.equalsIgnoreCase(SIApiConstants.JMS_FORMAT_OBJECT))
            result = decodeObjectBody(body);
        else if (format.equalsIgnoreCase(SIApiConstants.JMS_FORMAT_STREAM))
            result = decodeStreamBody(body);
        else if (format.equalsIgnoreCase(SIApiConstants.JMS_FORMAT_MAP))
            result = decodeMapBody(body);
        else
            result = new JsJmsMessageImpl(MfpConstants.CONSTRUCTOR_NO_OP);

        decodeHeader(result, id, type, topic, props);

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            SibTr.debug(tc, "Decoded Web Message", ((MessageImpl) result).debugMsg());
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "createInboundWebMessage");
        return result;
    }
1114731
public Object convertToMessage()
    {
        try {
            Object reply = this.getRawData();

            org.w3c.dom.Node nodeBody = this.getMessageBody(reply, false);

            if (this.getConvertToMessage() == null)
                return null;
            Object msg = this.getConvertToMessage().unmarshalRootElement(nodeBody, this);

            return msg;
        } catch(Throwable ex) {
            this.setMessageException(ex);
        }
        return null;    // Error
    }
7353
public MessageToSend prepareMessageToSend() {
        originalMessage.getParts().clear();
        originalMessage.getParts().addAll(publicParts);
        return originalMessage;
    }