use of org.apache.james.mime4j.dom.Entity in project gerrit by GerritCodeReview.
the class RawMailParser method handleMimePart.
/**
* Traverses a mime tree and parses out text and html parts. All other parts will be dropped.
*
* @param part MimePart to parse
* @param textBuilder StringBuilder to append all plaintext parts
* @param htmlBuilder StringBuilder to append all html parts
* @throws IOException
*/
private static void handleMimePart(Entity part, StringBuilder textBuilder, StringBuilder htmlBuilder) throws IOException {
if (isPlainOrHtml(part.getMimeType()) && !isAttachment(part.getDispositionType())) {
TextBody tb = (TextBody) part.getBody();
String result = CharStreams.toString(new InputStreamReader(tb.getInputStream(), tb.getMimeCharset()));
if (part.getMimeType().equals("text/plain")) {
textBuilder.append(result);
} else if (part.getMimeType().equals("text/html")) {
htmlBuilder.append(result);
}
} else if (isMixedOrAlternative(part.getMimeType())) {
Multipart multipart = (Multipart) part.getBody();
for (Entity e : multipart.getBodyParts()) {
handleMimePart(e, textBuilder, htmlBuilder);
}
}
}
use of org.apache.james.mime4j.dom.Entity in project Gargoyle by callakrsos.
the class MimeToHtmlAdapter method getContent.
/*
* (non-Javadoc)
*
* @see
* com.kyj.fx.voeditor.visual.framework.word.AbstractMimeAdapter#getContent(
* )
*/
@Override
public String getContent() {
StringBuilder sb = new StringBuilder();
try {
final MessageBuilder builder = new DefaultMessageBuilder();
Message message = builder.parseMessage(new ByteArrayInputStream(this.content));
Body body = ((Entity) message).getBody();
append(sb, body);
} catch (MimeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
use of org.apache.james.mime4j.dom.Entity in project Gargoyle by callakrsos.
the class MimeToHtmlAdapter method append.
/***************************************************************************/
/* sb에 번역된 텍스트데이터를 덧붙임 */
/***************************************************************************/
private void append(StringBuilder sb, Body body) {
if (body instanceof TextBody) {
/*
* A text body. Display its contents.
*/
TextBody textBody = (TextBody) body;
try {
Reader r = textBody.getReader();
int c;
while ((c = r.read()) != -1) {
sb.append((char) c);
}
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (body instanceof BinaryBody) {
BinaryBody bBody = (BinaryBody) body;
append(sb, bBody);
} else if (body instanceof Multipart) {
Multipart mbody = (Multipart) body;
for (Entity part : mbody.getBodyParts()) {
append(sb, part);
}
} else /*
* Ignore Fields </br>
*
* ContentTypeField,AddressListField,DateTimeField UnstructuredField,
* Field
*
*/
{
LOGGER.debug("{}", body);
sb.append(body.toString());
}
}
use of org.apache.james.mime4j.dom.Entity in project Gargoyle by callakrsos.
the class MimeToHtmlWordAdapter method getContent.
/*
* (non-Javadoc)
*
* @see
* com.kyj.fx.voeditor.visual.framework.word.AbstractMimeAdapter#getContent(
* )
*/
@Override
public String getContent() {
StringBuilder sb = new StringBuilder();
try {
final MessageBuilder builder = new DefaultMessageBuilder();
Message message = builder.parseMessage(new ByteArrayInputStream(this.content));
Body body = ((Entity) message).getBody();
append(sb, body);
} catch (MimeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
use of org.apache.james.mime4j.dom.Entity in project sling by apache.
the class MessageStoreImpl method recursiveMultipartProcessing.
static void recursiveMultipartProcessing(Multipart multipart, StringBuilder plainBody, StringBuilder htmlBody, Boolean hasBody, List<BodyPart> attachments) throws IOException {
for (Entity enitiy : multipart.getBodyParts()) {
BodyPart part = (BodyPart) enitiy;
if (part.getDispositionType() != null && !part.getDispositionType().equals("")) {
// if DispositionType is null or empty, it means that it's multipart, not attached file
attachments.add(part);
} else {
if (part.isMimeType(PLAIN_MIMETYPE) && !hasBody) {
plainBody.append(getTextPart(part));
hasBody = true;
} else if (part.isMimeType(HTML_MIMETYPE) && !hasBody) {
htmlBody.append(getTextPart(part));
} else if (part.isMultipart()) {
recursiveMultipartProcessing((Multipart) part.getBody(), plainBody, htmlBody, hasBody, attachments);
}
}
}
}
Aggregations