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


Java BodyPart类代码示例

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


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

示例1: getTextFromMimeMultipart

import javax.mail.BodyPart; //导入依赖的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: getMessagePart

import javax.mail.BodyPart; //导入依赖的package包/类
private static Multipart getMessagePart() throws MessagingException, IOException {
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(getVal("msg.Body"));
    multipart.addBodyPart(messageBodyPart);
    if (getBoolVal("attach.reports")) {
        LOG.info("Attaching Reports as zip");
        multipart.addBodyPart(getReportsBodyPart());
    } else {
        if (getBoolVal("attach.standaloneHtml")) {
            multipart.addBodyPart(getStandaloneHtmlBodyPart());
        }
        if (getBoolVal("attach.console")) {
            multipart.addBodyPart(getConsoleBodyPart());
        }
        if (getBoolVal("attach.screenshots")) {
            multipart.addBodyPart(getScreenShotsBodyPart());
        }
    }
    messageBodyPart.setContent(getVal("msg.Body")
            .concat("\n\n\n")
            .concat(MailComponent.getHTMLBody()), "text/html");
    return multipart;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:25,代码来源:Mailer.java

示例3: saveAttachMent

import javax.mail.BodyPart; //导入依赖的package包/类
/**   
 * 【保存附件】   
 */   
public void saveAttachMent(Part part) throws Exception {   
    String fileName = "";   
    if (part.isMimeType("multipart/*")) {   
        Multipart mp = (Multipart) part.getContent();   
        for (int i = 0; i < mp.getCount(); i++) {   
            BodyPart mpart = mp.getBodyPart(i);   
            String disposition = mpart.getDisposition();   
            if ((disposition != null)   
                    && ((disposition.equals(Part.ATTACHMENT)) || (disposition   
                            .equals(Part.INLINE)))) {   
                fileName = mpart.getFileName();   
                if (fileName.toLowerCase().indexOf("gb2312") != -1) {   
                    fileName = MimeUtility.decodeText(fileName);   
                }   
                saveFile(fileName, mpart.getInputStream());   
            } else if (mpart.isMimeType("multipart/*")) {   
                saveAttachMent(mpart);   
            } else {   
                fileName = mpart.getFileName();   
                if ((fileName != null)   
                        && (fileName.toLowerCase().indexOf("GB2312") != -1)) {   
                    fileName = MimeUtility.decodeText(fileName);   
                    saveFile(fileName, mpart.getInputStream());   
                }   
            }   
        }   
    } else if (part.isMimeType("message/rfc822")) {   
        saveAttachMent((Part) part.getContent());   
    }   
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:34,代码来源:ReciveMail.java

示例4: toString

import javax.mail.BodyPart; //导入依赖的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

示例5: isContainAttach

import javax.mail.BodyPart; //导入依赖的package包/类
/**  
 * 判断此邮件是否包含附件  
 */  
public boolean isContainAttach(Part part) throws Exception {   
    boolean attachflag = false;   
    String contentType = part.getContentType();   
    if (part.isMimeType("multipart/*")) {   
        Multipart mp = (Multipart) part.getContent();   
        for (int i = 0; i < mp.getCount(); i++) {   
            BodyPart mpart = mp.getBodyPart(i);   
            String disposition = mpart.getDisposition();   
            if ((disposition != null)   
                    && ((disposition.equals(Part.ATTACHMENT)) || (disposition   
                            .equals(Part.INLINE))))   
                attachflag = true;   
            else if (mpart.isMimeType("multipart/*")) {   
                attachflag = isContainAttach((Part) mpart);   
            } else {   
                String contype = mpart.getContentType();   
                if (contype.toLowerCase().indexOf("application") != -1)   
                    attachflag = true;   
                if (contype.toLowerCase().indexOf("name") != -1)   
                    attachflag = true;   
            }   
        }   
    } else if (part.isMimeType("message/rfc822")) {   
        attachflag = isContainAttach((Part) part.getContent());   
    }   
    return attachflag;   
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:31,代码来源:ReciveMail.java

示例6: getAttachments

import javax.mail.BodyPart; //导入依赖的package包/类
private static TreeMap<String, InputStream> getAttachments(BodyPart part) throws Exception {
    TreeMap<String, InputStream> result = new TreeMap<>();
    Object content = part.getContent();
    if (content instanceof InputStream || content instanceof String) {
        if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition()) || StringUtils.isNotBlank(part.getFileName())) {
            result.put(part.getFileName(), part.getInputStream());
            return result;
        } else {
            return new TreeMap<String, InputStream>();
        }
    }

    if (content instanceof Multipart) {
        Multipart multipart = (Multipart) content;
        for (int i = 0; i < multipart.getCount(); i++) {
            BodyPart bodyPart = multipart.getBodyPart(i);
            result.putAll(getAttachments(bodyPart));
        }
    }
    return result;
}
 
开发者ID:roberterdin,项目名称:thatsapp,代码行数:22,代码来源:MailUtilities.java

示例7: buildMessage

import javax.mail.BodyPart; //导入依赖的package包/类
private static Message buildMessage(Session session, String from, String recipients, String subject, String text, String filename) throws MessagingException, AddressException
{
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
    message.setSubject(subject);

    BodyPart messageTextPart = new MimeBodyPart();
    messageTextPart.setText(text);

    BodyPart messageAttachmentPart = new MimeBodyPart();
    DataSource source = new FileDataSource(new File(filename));
    messageAttachmentPart.setDataHandler(new DataHandler(source));
    messageAttachmentPart.setFileName(filename);

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageTextPart);
    multipart.addBodyPart(messageAttachmentPart);
    message.setContent(multipart);

    return message;
}
 
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:23,代码来源:MailHelper.java

示例8: isContainAttachment

import javax.mail.BodyPart; //导入依赖的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

示例9: isContainAttachment

import javax.mail.BodyPart; //导入依赖的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

示例10: handleAttachments

import javax.mail.BodyPart; //导入依赖的package包/类
/**
 * ������
 */
private void handleAttachments(Message message, Part part) throws Exception {
	if (part.isMimeType("multipart/*")) {
		Multipart mp = (Multipart) part.getContent();
		for (int i = 0; i < mp.getCount(); i++) {
			BodyPart bp = mp.getBodyPart(i);
			String disposition = bp.getDisposition();
			if (disposition != null && (disposition.equals(Part.ATTACHMENT) || disposition.equals(Part.INLINE))) {
				saveFile(message, bp);
			} else if (bp.isMimeType("multipart/*")) {
				handleAttachments(message, (Part) part.getContent());
			} else {
				saveFile(message, bp);
			}
		}
	} else if (part.isMimeType("message/rfc822")) {
		handleAttachments(message, (Part) part.getContent());
	}
}
 
开发者ID:toulezu,项目名称:play,代码行数:22,代码来源:MailHelper.java

示例11: getBodyPart

import javax.mail.BodyPart; //导入依赖的package包/类
public static String getBodyPart(Multipart multipart, String contentType) throws MessagingException, IOException {
	String body = null;

	for (int i = 0; i < multipart.getCount(); i++) {
		BodyPart bp = multipart.getBodyPart(i);
		if (contentType.equalsIgnoreCase(bp.getContentType())) {
			BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) bp.getContent()));
			StringBuilder strOut = new StringBuilder();
			String line;
			while ((line = reader.readLine()) != null) {
				strOut.append(line).append("\r\n");
			}
			body = strOut.toString();
			reader.close();
			break;
		}

	}
	return body;
}
 
开发者ID:mcdjw,项目名称:sip-servlets,代码行数:21,代码来源:Test.java

示例12: getBodyIfNotAttachment

import javax.mail.BodyPart; //导入依赖的package包/类
/**
 * Check if the body is from the content type and returns it if not attachment
 *
 * @param mimePart
 * @param contentType
 * @return null if not with specific content type or part is attachment
 */
private String getBodyIfNotAttachment(
                                       BodyPart mimePart,
                                       String contentType ) throws MessagingException, IOException {

    String mimePartContentType = mimePart.getContentType().toLowerCase();
    if (mimePartContentType.startsWith(contentType)) { // found a part with given mime type
        String contentDisposition = mimePart.getDisposition();
        if (!Part.ATTACHMENT.equalsIgnoreCase(contentDisposition)) {
            Object partContent = mimePart.getContent();
            if (partContent instanceof InputStream) {
                return IoUtils.streamToString((InputStream) partContent);
            } else {
                return partContent.toString();
            }
        }
    }
    return null;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:26,代码来源:MimePackage.java

示例13: getMailTextContent

import javax.mail.BodyPart; //导入依赖的package包/类
public void getMailTextContent(Part part, StringBuffer content)
        throws MessagingException, IOException {
    // 如果是文本类型的附件,通过getContent方法可以取到文本内容,但这不是我们需要的结果,所以在这里要做判断
    boolean isContainTextAttach = part.getContentType().indexOf("name") > 0;

    if (part.isMimeType("text/*") && !isContainTextAttach) {
        content.append(part.getContent().toString());
    } else if (part.isMimeType("message/rfc822")) {
        getMailTextContent((Part) part.getContent(), content);
    } else if (part.isMimeType("multipart/*")) {
        Multipart multipart = (Multipart) part.getContent();
        int partCount = multipart.getCount();

        for (int i = 0; i < partCount; i++) {
            BodyPart bodyPart = multipart.getBodyPart(i);
            getMailTextContent(bodyPart, content);
        }
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:20,代码来源:JavamailService.java

示例14: buildMultipartAlternativeMail

import javax.mail.BodyPart; //导入依赖的package包/类
private Email buildMultipartAlternativeMail(RawData rawData, String subject, Multipart multipart) throws MessagingException, IOException {
    Email email = null;
    for (int i = 0; i < multipart.getCount(); i++) {
        BodyPart part = multipart.getBodyPart(i);
        ContentType partContentType = ContentType.fromString(part.getContentType());
        Object partContent = part.getContent();
        email = new Email.Builder()
                .fromAddress(rawData.getFrom())
                .toAddress(rawData.getTo())
                .receivedOn(timestampProvider.now())
                .subject(subject)
                .rawData(rawData.getContentAsString())
                .content(Objects.toString(partContent, rawData.getContentAsString()).trim())
                .contentType(partContentType)
                .build();
        if (partContentType == ContentType.HTML) break;
    }
    return email;
}
 
开发者ID:gessnerfl,项目名称:fake-smtp-server,代码行数:20,代码来源:EmailFactory.java

示例15: getAttachments

import javax.mail.BodyPart; //导入依赖的package包/类
/**
 * Récupération d'une pièce jointe d'un mail
 * @param part : Corps du mail (Bodypart)
 * @return
 * @throws Exception
 */
private static Map<String, InputStream> getAttachments(BodyPart part) throws Exception {
	Map<String, InputStream> result = new HashMap<String, InputStream>();
    Object content = part.getContent();
    if (content instanceof InputStream || content instanceof String) {
        if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition()) || StringUtils.isNotBlank(part.getFileName())) {
            result.put(part.getFileName(), part.getInputStream());
            return result;
        } else {
            return new HashMap<String, InputStream>();
        }
    }

    if (content instanceof Multipart) {
            Multipart multipart = (Multipart) content;
            for (int i = 0; i < multipart.getCount(); i++) {
                BodyPart bodyPart = multipart.getBodyPart(i);
                result.putAll(getAttachments(bodyPart));
            }
    }
    return result;
}
 
开发者ID:mjfcolas,项目名称:infotaf,代码行数:28,代码来源:Utils.java


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