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


Java MimeMultipart.getBodyPart方法代码示例

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


在下文中一共展示了MimeMultipart.getBodyPart方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTextFromMimeMultipart

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
/**
 * Extracts the text content of a multipart email message
 */
private String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws Exception {
    String result = "";
    int partCount = mimeMultipart.getCount();
    for (int i = 0; i < partCount; i++) {
        BodyPart bodyPart = mimeMultipart.getBodyPart(i);
        if (bodyPart.isMimeType("text/plain")) {
            result = result + "\n" + bodyPart.getContent();
            break; // without break same text appears twice in my tests
        } else if (bodyPart.isMimeType("text/html")) {
            String html = (String) bodyPart.getContent();
            // result = result + "\n" + org.jsoup.Jsoup.parse(html).text();
            result = html;
        } else if (bodyPart.getContent() instanceof MimeMultipart) {
            result = result + getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent());
        }
    }
    return result;
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:22,代码来源:ReadEmailImap.java

示例2: toString

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
/**
 * Converts the given JavaMail message to a String body.
 * Can return null.
 */
@Converter
public static String toString(Message message) throws MessagingException, IOException {
    Object content = message.getContent();
    if (content instanceof MimeMultipart) {
        MimeMultipart multipart = (MimeMultipart) content;
        if (multipart.getCount() > 0) {
            BodyPart part = multipart.getBodyPart(0);
            content = part.getContent();
        }
    }
    if (content != null) {
        return content.toString();
    }
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:MailConverters.java

示例3: isContainAttachment

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
/**
 * �ж��ʼ����Ƿ��������
 * @param msg �ʼ�����
 * @return �ʼ��д��ڸ�������true�������ڷ���false
 */ 
public static boolean isContainAttachment(Part part) throws MessagingException, IOException { 
    boolean flag = false; 
    if (part.isMimeType("multipart/*")) { 
        MimeMultipart multipart = (MimeMultipart) part.getContent(); 
        int partCount = multipart.getCount(); 
        for (int i = 0; i < partCount; i++) { 
            BodyPart bodyPart = multipart.getBodyPart(i); 
            String disp = bodyPart.getDisposition(); 
            if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) { 
                flag = true; 
            } else if (bodyPart.isMimeType("multipart/*")) { 
                flag = isContainAttachment(bodyPart); 
            } else { 
                String contentType = bodyPart.getContentType(); 
                if (contentType.indexOf("application") != -1) { 
                    flag = true; 
                }   
                 
                if (contentType.indexOf("name") != -1) { 
                    flag = true; 
                }  
            } 
             
            if (flag) break; 
        } 
    } else if (part.isMimeType("message/rfc822")) { 
        flag = isContainAttachment((Part)part.getContent()); 
    } 
    return flag; 
}
 
开发者ID:bjut-2014,项目名称:scada,代码行数:36,代码来源:MailUtils.java

示例4: isContainAttachment

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
/**
 * 判断邮件中是否包含附件
 * @param msg 邮件内容
 * @return 邮件中存在附件返回true,不存在返回false
 * @throws MessagingException
 * @throws IOException
 */
public static boolean isContainAttachment(Part part) throws MessagingException, IOException {
	boolean flag = false;
	if (part.isMimeType("multipart/*")) {
		MimeMultipart multipart = (MimeMultipart) part.getContent();
		int partCount = multipart.getCount();
		for (int i = 0; i < partCount; i++) {
			BodyPart bodyPart = multipart.getBodyPart(i);
			String disp = bodyPart.getDisposition();
			if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
				flag = true;
			} else if (bodyPart.isMimeType("multipart/*")) {
				flag = isContainAttachment(bodyPart);
			} else {
				String contentType = bodyPart.getContentType();
				if (contentType.indexOf("application") != -1) {
					flag = true;
				}  
				
				if (contentType.indexOf("name") != -1) {
					flag = true;
				} 
			}
			
			if (flag) break;
		}
	} else if (part.isMimeType("message/rfc822")) {
		flag = isContainAttachment((Part)part.getContent());
	}
	return flag;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:38,代码来源:POP3ReceiveMailTest.java

示例5: getTextFromMimeMultipart

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
private String getTextFromMimeMultipart(MimeMultipart mimeMultipart)
    throws MessagingException, IOException {
  StringBuilder result = new StringBuilder();
  int count = mimeMultipart.getCount();
  for (int i = 0; i < count; i++) {
    BodyPart bodyPart = mimeMultipart.getBodyPart(i);
    if (bodyPart.isMimeType("text/plain")) {
      result.append("\n").append(bodyPart.getContent());
    } else if (bodyPart.isMimeType("text/html")) {
      result.append("\n").append((String) bodyPart.getContent());
    } else if (bodyPart.getContent() instanceof MimeMultipart) {
      result.append(getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent()));
    }
  }
  return result.toString();
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:17,代码来源:MailReceiverUtils.java

示例6: hasNonTextAttachments

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
public static boolean hasNonTextAttachments(Part m) {
    try {
        Object content = m.getContent();
        if (content instanceof MimeMultipart) {
            MimeMultipart mm = (MimeMultipart) content;
            for (int i=0;i<mm.getCount();i++) {
                BodyPart p = mm.getBodyPart(i);
                if (hasNonTextAttachments(p)) {
                    return true;
                }
            }
            return false;
        } else {
            return !m.getContentType().trim().toLowerCase().startsWith("text");
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:20,代码来源:GreenMailUtil.java

示例7: getTextFromMimeMultipart

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
private String getTextFromMimeMultipart( MimeMultipart mimeMultipart ) throws IOException, MessagingException
{

    int count = mimeMultipart.getCount();
    if ( count == 0 )
        throw new MessagingException( "Multipart with no body parts not supported." );

    boolean multipartAlt = new ContentType( mimeMultipart.getContentType() ).match( "multipart/alternative" );
    if ( multipartAlt )
        return getTextFromBodyPart( mimeMultipart.getBodyPart( count - 1 ) );

    String result = "";
    for ( int i = 0; i < count; i++ )
    {
        BodyPart bodyPart = mimeMultipart.getBodyPart( i );
        result += getTextFromBodyPart( bodyPart );
    }
    return result;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:20,代码来源:DefaultReceiveEmailProvider.java

示例8: appendMultiPart

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
private void appendMultiPart(SampleResult child, StringBuilder cdata,
        MimeMultipart mmp) throws MessagingException, IOException {
    String preamble = mmp.getPreamble();
    if (preamble != null ){
        cdata.append(preamble);
    }
    child.setResponseData(cdata.toString(),child.getDataEncodingNoDefault());
    int count = mmp.getCount();
    for (int j=0; j<count;j++){
        BodyPart bodyPart = mmp.getBodyPart(j);
        final Object bodyPartContent = bodyPart.getContent();
        final String contentType = bodyPart.getContentType();
        SampleResult sr = new SampleResult();
        sr.setSampleLabel("Part: "+j);
        sr.setContentType(contentType);
        sr.setDataEncoding(RFC_822_DEFAULT_ENCODING);
        sr.setEncodingAndType(contentType);
        sr.sampleStart();
        if (bodyPartContent instanceof InputStream){
            sr.setResponseData(IOUtils.toByteArray((InputStream) bodyPartContent));
        } else if (bodyPartContent instanceof MimeMultipart){
            appendMultiPart(sr, cdata, (MimeMultipart) bodyPartContent);
        } else {
            sr.setResponseData(bodyPartContent.toString(),sr.getDataEncodingNoDefault());
        }
        sr.setResponseOK();
        if (sr.getEndTime()==0){// not been set by any child samples
            sr.sampleEnd();
        }
        child.addSubResult(sr);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:33,代码来源:MailReaderSampler.java

示例9: parseMDN

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
private void parseMDN(MimeMultipart report) throws AS2MessageException {
    try {
        int reportCount = report.getCount();
        for (int i = 0; i < reportCount; i++) {
            MimeBodyPart reportsPart = (MimeBodyPart) report.getBodyPart(i);
            if (reportsPart.isMimeType("text/plain")) {
                setText(reportsPart.getContent().toString());
            }
            else if (reportsPart.isMimeType(AS2Header.CONTENT_TYPE_MESSAGE_DISPOSITION_NOTIFICATION)) {
                InternetHeaders rptValues = new InternetHeaders(reportsPart
                        .getInputStream());
                setReportValue(REPORTING_UA, rptValues.getHeader(
                        REPORTING_UA, ", "));
                setOriginalMessageID(rptValues.getHeader(
                        ORIG_RECIPIENT, ", "));
                setReportValue(FINAL_RECIPIENT, rptValues.getHeader(
                        FINAL_RECIPIENT, ", "));
                setReportValue(ORIG_MESSAGE_ID, rptValues.getHeader(
                        ORIG_MESSAGE_ID, ", "));
                setReportValue(DISPOSITION, rptValues.getHeader(
                        DISPOSITION, ", "));
                setReportValue(RECEIVED_CONTENT_MIC, rptValues
                        .getHeader(RECEIVED_CONTENT_MIC, ", "));
            }
        }
    }
    catch (Exception e) {
        throw new AS2MessageException("Error in parsing MDN", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:31,代码来源:DispositionNotification.java

示例10: getTextPart

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
private MimeBodyPart getTextPart(MimeMessage msg) throws IOException, MessagingException {
    assertTrue(msg.getContent() instanceof MimeMultipart);
    MimeMultipart mimeMultipart = (MimeMultipart) msg.getContent();

    Object content2 = mimeMultipart.getBodyPart(0).getContent();
    assertTrue(content2 instanceof MimeMultipart);
    MimeMultipart textBodyPart = (MimeMultipart) content2;

    return (MimeBodyPart) textBodyPart.getBodyPart(0);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:11,代码来源:EmailerTest.java

示例11: getInlineAttachment

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
private MimeBodyPart getInlineAttachment(MimeMessage msg) throws IOException, MessagingException {
    assertTrue(msg.getContent() instanceof MimeMultipart);
    MimeMultipart mimeMultipart = (MimeMultipart) msg.getContent();

    Object content2 = mimeMultipart.getBodyPart(0).getContent();
    assertTrue(content2 instanceof MimeMultipart);
    MimeMultipart textBodyPart = (MimeMultipart) content2;

    return (MimeBodyPart) textBodyPart.getBodyPart(1);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:11,代码来源:EmailerTest.java

示例12: postAdminUploadmultipart

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
@Validate
@Override
public void postAdminUploadmultipart(PersistMethod persistMethod, String busAddress,
    String fileName, MimeMultipart entity, Map<String, String> okapiHeaders,
    Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {

  if(entity != null){
    int parts = entity.getCount();
    for (int i = 0; i < parts; i++) {
      BodyPart bp = entity.getBodyPart(i);
      System.out.println(bp.getFileName());
      //System.out.println(bp.getContent());
      //System.out.println("-----------------------------------------");
    }
    String name = "";
    try{
      if(fileName == null){
        name = entity.getBodyPart(0).getFileName();
      }
      else{
        name = fileName;
      }
    }
    catch(Exception e){
      log.error(e.getMessage(), e);
    }
  }

  asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminUploadmultipartResponse.withOK("TODO"
      )));
}
 
开发者ID:folio-org,项目名称:raml-module-builder,代码行数:32,代码来源:AdminAPI.java

示例13: createMessage

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
/**
 * Creates a MIME message from a SOAP message.
 * 
 * @param from the 'from' mail address.
 * @param to the 'to' mail address(es).
 * @param cc the 'cc' mail address(es).
 * @param subject the mail subject.
 * @param soapMessage the SOAP message.
 * @param session the mail session.
 * @return a new MIME message.
 * @throws ConnectionException if error occurred in constructing the mail
 *             message.
 * @see hk.hku.cecid.piazza.commons.net.MailSender#createMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.mail.Session)
 */
public MimeMessage createMessage(String from, String to, String cc,
        String subject, SOAPMessage soapMessage, Session session) throws ConnectionException {
    try {
        MimeMessage message = super.createMessage(from, to, cc, subject, session);
        
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        soapMessage.writeTo(bos);
        String contentType = getContentType(soapMessage);
        
        ByteArrayDataSource content = new ByteArrayDataSource(bos.toByteArray(), contentType);
        soapMessage.getAttachments();
        boolean hasAttachments = soapMessage.countAttachments() > 0;
        if (hasAttachments) {
            putHeaders(soapMessage.getMimeHeaders(), message);
            MimeMultipart mmp = new MimeMultipart(content);
            for (int i=0; i<mmp.getCount(); i++) {
                BodyPart bp = mmp.getBodyPart(i);

                // encoding all parts in base64 to overcome length of character line limitation in SMTP
                InputStreamDataSource isds = new InputStreamDataSource(
                	bp.getInputStream(), bp.getContentType(), bp.getFileName());
                bp.setDataHandler(new DataHandler(isds));
                bp.setHeader("Content-Transfer-Encoding", "base64");              
            }
            message.setContent(mmp);
        }
        else {
            DataHandler dh = new DataHandler(content);
            message.setDataHandler(dh);
            message.setHeader("Content-Transfer-Encoding", "base64");
        }

        message.saveChanges();
        return message;
    }
    catch (Exception e) {
        throw new ConnectionException("Unable to construct mail message from SOAP message", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:54,代码来源:SOAPMailSender.java

示例14: getFirstAttachment

import javax.mail.internet.MimeMultipart; //导入方法依赖的package包/类
private MimeBodyPart getFirstAttachment(MimeMessage msg) throws IOException, MessagingException {
    assertTrue(msg.getContent() instanceof MimeMultipart);
    MimeMultipart mimeMultipart = (MimeMultipart) msg.getContent();
    return (MimeBodyPart) mimeMultipart.getBodyPart(1);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:6,代码来源:EmailerTest.java


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