public MimeBodyPart(Body body, String contentType) throws MessagingException { mHeader = new MimeHeader(); if (contentType != null) { addHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); } MimeMessageHelper.setBody(this, body); }
/** * Returns the unfolded, decoded value of the Subject header. */ @Override public String getSubject() { return MimeUtility.unfoldAndDecode(getFirstHeader("Subject"), this); }
@Override public String getMimeType() { return MimeUtility.getHeaderParameter(getContentType(), null); }
public static MimeBodyPart multipart(String type, String typeParameters, BodyPart... subParts) throws MessagingException { MimeMultipart multiPart = MimeMultipart.newInstance(); multiPart.setSubType(type); for (BodyPart subPart : subParts) { multiPart.addBodyPart(subPart); } MimeBodyPart mimeBodyPart = new MimeBodyPart(multiPart); if (typeParameters != null) { mimeBodyPart.setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeBodyPart.getContentType() + "; " + typeParameters); } return mimeBodyPart; }
public static MimeBodyPart bodypart(String type, String text) throws MessagingException { TextBody textBody = new TextBody(text); return new MimeBodyPart(textBody, type); }
private static Message createMessage(String mimeType, Body body) { MimeMessage message = new MimeMessage(); message.setBody(body); message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeType); return message; }
private MimeMessage buildMimeMessageWithListPostValue(String... values) { MimeMessage message = new MimeMessage(); for (String value : values) { message.addHeader("List-Post", value); } return message; } }
public static MimeMessage parseMimeMessage(InputStream in, boolean recurse) throws IOException, MessagingException { MimeMessage mimeMessage = new MimeMessage(); mimeMessage.parse(in, recurse); return mimeMessage; }
private static MimeMultipart createMultipartBody(String mimeType, BodyPart[] parts) { MimeMultipart multipart = new MimeMultipart(mimeType, "boundary"); for (BodyPart part : parts) { multipart.addBodyPart(part); } return multipart; } }
@Override public String getMimeType() { return MimeUtility.getHeaderParameter(getContentType(), null); }
private void addContentType(MimeBodyPart bodyPart, String contentType, String name) throws MessagingException { String value = Headers.contentType(contentType, name); bodyPart.addHeader(MimeHeader.HEADER_CONTENT_TYPE, value); if (!MimeUtil.isMessage(contentType)) { bodyPart.setEncoding(MimeUtility.getEncodingforType(contentType)); } }
@Override public String toString() { return (hasRawData()) ? getRaw() : getName() + ": " + getValue(); } }
private void addContentDisposition(MimeBodyPart bodyPart, String fileName, Long size) { String value = Headers.contentDisposition("attachment", fileName, size); bodyPart.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, value); }
@Override public String[] getReferences() { if (mReferences == null) { mReferences = getHeader("References"); } return mReferences; }
public void setHeader(String name, String value) { if (name == null || value == null) { return; } removeHeader(name); addHeader(name, value); }
@Override public void setCharset(String charset) throws MessagingException { mHeader.setCharset(charset); if (mBody instanceof Multipart) { ((Multipart)mBody).setCharset(charset); } else if (mBody instanceof TextBody) { CharsetSupport.setCharset(charset, this); ((TextBody)mBody).setCharset(charset); } }
/** * Parse the given InputStream using Apache Mime4J to build a MimeMessage. * Does not recurse through nested bodyparts. */ public final void parse(InputStream in) throws IOException, MessagingException { parse(in, false); }
static String getExternalCharset(String charset) { if (JisSupport.isShiftJis(charset)) { return SHIFT_JIS; } else { return charset; } }
public String getFirstHeader(String name) { String[] header = getHeader(name); if (header.length == 0) { return null; } return header[0]; }
public static BodyPart createTextPart(String mimeType, String text) throws MessagingException { TextBody body = new TextBody(text); return new MimeBodyPart(body, mimeType); }