本文整理汇总了Java中org.apache.james.mime4j.dom.Multipart类的典型用法代码示例。如果您正苦于以下问题:Java Multipart类的具体用法?Java Multipart怎么用?Java Multipart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Multipart类属于org.apache.james.mime4j.dom包,在下文中一共展示了Multipart类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: handleMimePart
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
/**
* Traverses a mime tree and parses out text and html parts. All other parts will be dropped.
*
* @param part {@code MimePart} to parse
* @param textBuilder {@link StringBuilder} to append all plaintext parts
* @param htmlBuilder {@link StringBuilder} to append all html parts
* @throws IOException in case of a failure while transforming the input to a {@link String}
*/
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 (isMultipart(part.getMimeType())) {
Multipart multipart = (Multipart) part.getBody();
for (Entity e : multipart.getBodyParts()) {
handleMimePart(e, textBuilder, htmlBuilder);
}
}
}
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:RawMailParser.java
示例2: append
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
/***************************************************************************/
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);
}
}
/*
* Ignore Fields </br>
*
* ContentTypeField,AddressListField,DateTimeField UnstructuredField,
* Field
*
*/
else {
sb.append(body.toString());
}
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:39,代码来源:MimeToHtmlWordAdapter.java
示例3: startMultipart
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
/**
* @see org.apache.james.mime4j.parser.ContentHandler#startMultipart(org.apache.james.mime4j.stream.BodyDescriptor)
*/
public void startMultipart(final BodyDescriptor bd) throws MimeException {
expect(Entity.class);
final Entity e = (Entity) stack.peek();
final String subType = bd.getSubType();
final Multipart multiPart = new MultipartImpl(subType);
e.setBody(multiPart);
stack.push(multiPart);
}
开发者ID:QSFT,项目名称:MimeUI,代码行数:13,代码来源:MimeUIEntityBuilder.java
示例4: startBodyPart
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
/**
* @see org.apache.james.mime4j.parser.ContentHandler#startBodyPart()
*/
public void startBodyPart() throws MimeException {
expect(Multipart.class);
BodyPart bodyPart = new BodyPart();
((Multipart) stack.peek()).addBodyPart(bodyPart);
stack.push(bodyPart);
}
开发者ID:QSFT,项目名称:MimeUI,代码行数:11,代码来源:MimeUIEntityBuilder.java
示例5: createNode
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
/**
* Create a node given a Multipart body.
* Add the Preamble, all Body parts and the Epilogue to the node.
*
* @param multipart the Multipart.
* @return the root node of the tree.
*/
private DefaultMutableTreeNode createNode(Multipart multipart) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(
new ObjectWrapper("Multipart", multipart));
node.add(new DefaultMutableTreeNode(
new ObjectWrapper("Preamble", multipart.getPreamble())));
for (Entity part : multipart.getBodyParts()) {
node.add(createNode(part));
}
node.add(new DefaultMutableTreeNode(
new ObjectWrapper("Epilogue", multipart.getEpilogue())));
return node;
}
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:22,代码来源:MessageTreeViewMain.java
示例6: apply
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
@Override
public TextBody apply(final Message msg) {
final Multipart body = (Multipart) msg.getBody();
final List<Entity> bodyParts = body.getBodyParts();
if (bodyParts.size() != 2) {
throw new AssertionError("Expected 2 but got " + bodyParts.size());
}
final Entity part0 = bodyParts.get(0);
final Entity part1 = bodyParts.get(1);
logger.trace("part0: {}, part1: {}", part0.getMimeType(), part1.getMimeType());
switch (part0.getMimeType()) {
case "multipart/related":
final Multipart part0body = (Multipart) part0.getBody();
if (part0body.getBodyParts().size() != 2) {
throw new AssertionError("Expected 2 parts but got " + part0body.getBodyParts());
}
final String mimeType = part0body.getBodyParts().get(0).getMimeType();
if (!mimeType.equals("text/html")) {
throw new AssertionError("Expected mime type text/html but got " + mimeType);
}
return convert(part0body.getBodyParts().get(0));
case "text/html":
return convert(part0);
case "text/plain":
switch (part1.getMimeType()) {
case "text/html":
return convert(part1);
case "multipart/related":
final Multipart part1body = (Multipart) part1.getBody();
if (part1body.getBodyParts().size() != 2) {
throw new AssertionError("Expected 2 parts but got " + part1body.getBodyParts());
}
final String mimeType2 = part1body.getBodyParts().get(0).getMimeType();
if (!mimeType2.equals("text/html")) {
throw new AssertionError("Expected mime type text/html but got " + mimeType2);
}
return convert(part1body.getBodyParts().get(0));
default:
throw new AssertionError("Unexpected mime type of part 1: " + part1.getMimeType());
}
default:
throw new AssertionError("Unexpected mime type of part 0: " + part0.getMimeType());
}
}
开发者ID:kaklakariada,项目名称:fritzbox-report-mail,代码行数:47,代码来源:MessageHtmlTextBodyConverter.java
示例7: multipartReport
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
private Multipart multipartReport() {
Multipart result = new MultipartImpl("report");
result.addBodyPart(humanReadableTextBodyPart());
result.addBodyPart(deliveryStatusBodyPart());
result.addBodyPart(originalMessageBodyPart());
return result;
}
开发者ID:hontvari,项目名称:mireka,代码行数:8,代码来源:DsnMailCreator.java
示例8: getEntityType
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
@Override
public EntityType getEntityType (final Entity entity)
{
final Body body = entity.getBody();
if (body instanceof Multipart)
{
final String multipartType = ((Multipart) body).getSubType().toLowerCase();
if ("alternative".equals(multipartType))
{
return EntityType.ALTERNATIVE;
}
else if ("related".equals(multipartType))
{
return EntityType.RELATED;
}
else
{
// This case covers "mixed", "report", "digest", "parallel", and any other multipart/* not covered
// above.
// Note that for multipart/report, we assume that each child entity in the report has a content-type
// header, as needed. A omitted content-type header will cause the child entity to be treated like
// text/plain. That may be fine for the first (human readable) part, but subsequent parts are usually
// intended to be machine readable (e.g. message/delivery-status, et al).
// Note that for multipart/digest, mime4j correctly defaults child entities' content-types to
// message/rfc822 for us so we don't have to deal with it here.
return EntityType.MIXED;
}
}
else if (body instanceof SingleBody)
{
return EntityType.SINGLE;
}
else
{
// This should never happen because we have a custom mime4j MessageBuilder that returns attached messages
// as "SingleBody" (above) instead of as "Message" and there are no other "Body" implementations in mime4j.
// In other words, the above cases cover every possibility that should normally arise.
// todo Consider throwing an exception. Returning null here will cause NPEs.
return null;
}
}
开发者ID:QSFT,项目名称:MimeUI,代码行数:48,代码来源:Mime4jEntityHandler.java
示例9: getMultipartChildEntities
import org.apache.james.mime4j.dom.Multipart; //导入依赖的package包/类
@Override
public List<Entity> getMultipartChildEntities (final Entity entity)
{
return ((Multipart) entity.getBody()).getBodyParts();
}
开发者ID:QSFT,项目名称:MimeUI,代码行数:6,代码来源:Mime4jEntityHandler.java
注:本文中的org.apache.james.mime4j.dom.Multipart类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论