当前位置: 首页>>代码示例>>Java>>正文


Java Multipart.getBodyParts方法代码示例

本文整理汇总了Java中org.apache.james.mime4j.dom.Multipart.getBodyParts方法的典型用法代码示例。如果您正苦于以下问题:Java Multipart.getBodyParts方法的具体用法?Java Multipart.getBodyParts怎么用?Java Multipart.getBodyParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.james.mime4j.dom.Multipart的用法示例。


在下文中一共展示了Multipart.getBodyParts方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: 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


注:本文中的org.apache.james.mime4j.dom.Multipart.getBodyParts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。