/** * Set the content for a part using the encoding assigned to the handler. * @param part the part to assign. * @param buf the formatted data. * @param type the mime type or null, meaning text/plain. * @throws MessagingException if there is a problem. */ private void setContent(MimePart part, CharSequence buf, String type) throws MessagingException { final String charset = getEncodingName(); if (type != null && !"text/plain".equalsIgnoreCase(type)) { type = contentWithEncoding(type, charset); try { DataSource source = new ByteArrayDataSource(buf.toString(), type); part.setDataHandler(new DataHandler(source)); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); part.setText(buf.toString(), charset); } } else { part.setText(buf.toString(), MimeUtility.mimeCharset(charset)); } }
/** * Set the content for a part using the encoding assigned to the handler. * @param part the part to assign. * @param buf the formatted data. * @param type the mime type or null, meaning text/plain. * @throws MessagingException if there is a problem. */ private void setContent(MimePart part, CharSequence buf, String type) throws MessagingException { final String charset = getEncodingName(); if (type != null && !"text/plain".equalsIgnoreCase(type)) { type = contentWithEncoding(type, charset); try { DataSource source = new ByteArrayDataSource(buf.toString(), type); part.setDataHandler(new DataHandler(source)); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); part.setText(buf.toString(), charset); } } else { part.setText(buf.toString(), MimeUtility.mimeCharset(charset)); } }
/** * Set the content for a part using the encoding assigned to the handler. * @param part the part to assign. * @param buf the formatted data. * @param type the mime type or null, meaning text/plain. * @throws MessagingException if there is a problem. */ private void setContent(MimePart part, CharSequence buf, String type) throws MessagingException { final String charset = getEncodingName(); if (type != null && !"text/plain".equalsIgnoreCase(type)) { type = contentWithEncoding(type, charset); try { DataSource source = new ByteArrayDataSource(buf.toString(), type); part.setDataHandler(new DataHandler(source)); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); part.setText(buf.toString(), charset); } } else { part.setText(buf.toString(), MimeUtility.mimeCharset(charset)); } }
/** * Set the content for a part using the encoding assigned to the handler. * @param part the part to assign. * @param buf the formatted data. * @param type the mime type or null, meaning text/plain. * @throws MessagingException if there is a problem. */ private void setContent(MimePart part, CharSequence buf, String type) throws MessagingException { final String charset = getEncodingName(); if (type != null && !"text/plain".equalsIgnoreCase(type)) { type = contentWithEncoding(type, charset); try { DataSource source = new ByteArrayDataSource(buf.toString(), type); part.setDataHandler(new DataHandler(source)); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); part.setText(buf.toString(), charset); } } else { part.setText(buf.toString(), MimeUtility.mimeCharset(charset)); } }
/** * Set the content for a part using the encoding assigned to the handler. * @param part the part to assign. * @param buf the formatted data. * @param type the mime type or null, meaning text/plain. * @throws MessagingException if there is a problem. */ private void setContent(MimePart part, CharSequence buf, String type) throws MessagingException { final String charset = getEncodingName(); if (type != null && !"text/plain".equalsIgnoreCase(type)) { type = contentWithEncoding(type, charset); try { DataSource source = new ByteArrayDataSource(buf.toString(), type); part.setDataHandler(new DataHandler(source)); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); part.setText(buf.toString(), charset); } } else { part.setText(buf.toString(), MimeUtility.mimeCharset(charset)); } }
mainPart.setDataHandler(dataHandler);
mainPart.setDataHandler(dataHandler);
mainPart.setDataHandler(dataHandler);
protected MimePart setupTextPart(CardView view, MimePart part, String text, TextType textType) { assertArgumentNotNull("view", view); assertArgumentNotNull("part", part); assertArgumentNotNull("text", text); assertArgumentNotNull("textType", textType); final String textEncoding = getTextEncoding(view); final ByteBuffer buffer = prepareTextByteBuffer(view, text, textEncoding); final DataSource source = prepareTextDataSource(view, buffer); try { part.setDataHandler(createDataHandler(source)); if (!isSuppressTextTransferEncoding(view)) { part.setHeader("Content-Transfer-Encoding", getTextTransferEncoding(view)); } part.setHeader("Content-Type", buildTextContentType(view, textType, textEncoding)); } catch (MessagingException e) { throw new SMailMessageSettingFailureException("Failed to set headers: postcard=" + view, e); } return part; }
protected MimePart setupAttachmentPart(CardView view, SMailPostingMessage message, SMailAttachment attachment) { assertArgumentNotNull("view", view); assertArgumentNotNull("message", message); assertArgumentNotNull("attachment", attachment); final MimePart part = newMimeBodyPart(); final OptionalThing<String> textEncoding = getAttachmentTextEncoding(view, attachment); final DataSource source = prepareAttachmentDataSource(view, message, attachment, textEncoding); final String contentType = buildAttachmentContentType(view, attachment, textEncoding); final String contentDisposition = buildAttachmentContentDisposition(view, attachment, textEncoding); try { part.setDataHandler(createDataHandler(source)); if (!isSuppressAttachmentTransferEncoding(view)) { part.setHeader("Content-Transfer-Encoding", getAttachmentTransferEncoding(view)); } part.setHeader("Content-Type", contentType); part.setHeader("Content-Disposition", contentDisposition); } catch (MessagingException e) { String msg = "Failed to set headers: " + attachment; throw new SMailMessageSettingFailureException(msg, e); } return part; }