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


Java Part类代码示例

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


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

示例1: getMessageContent

import javax.mail.Part; //导入依赖的package包/类
/**
 * Get the content of a mail message.
 * 
 * @param message
 *            the mail message
 * @return the content of the mail message
 */
private String getMessageContent(Message message) throws MessagingException {
    try {
        Object content = message.getContent();
        if (content instanceof Multipart) {
            StringBuffer messageContent = new StringBuffer();
            Multipart multipart = (Multipart) content;
            for (int i = 0; i < multipart.getCount(); i++) {
                Part part = multipart.getBodyPart(i);
                if (part.isMimeType("text/plain")) {
                    messageContent.append(part.getContent().toString());
                }
            }
            return messageContent.toString();
        }
        return content.toString();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:29,代码来源:MailReader.java

示例2: saveAttachMent

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

示例3: processMultiPart

import javax.mail.Part; //导入依赖的package包/类
/**
 * Find "text" parts of message recursively and appends it to sb StringBuilder
 * 
 * @param multipart Multipart to process
 * @param sb StringBuilder 
 * @throws MessagingException
 * @throws IOException
 */
private void processMultiPart(Multipart multipart, StringBuilder sb) throws MessagingException, IOException
{
    boolean isAlternativeMultipart = multipart.getContentType().contains(MimetypeMap.MIMETYPE_MULTIPART_ALTERNATIVE);
    if (isAlternativeMultipart)
    {
        processAlternativeMultipart(multipart, sb);
    }
    else
    {
        for (int i = 0, n = multipart.getCount(); i < n; i++)
        {
            Part part = multipart.getBodyPart(i);
            if (part.getContent() instanceof Multipart)
            {
                processMultiPart((Multipart) part.getContent(), sb);
            }
            else
            {
                processPart(part, sb);
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:32,代码来源:EMLTransformer.java

示例4: isContainAttach

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

示例5: getAttachments

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

示例6: isContainAttachment

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

示例7: isContainAttachment

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

示例8: handleAttachments

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

示例9: getBodyIfNotAttachment

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

示例10: getMailTextContent

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

示例11: getAttachments

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

示例12: getBodyText

import javax.mail.Part; //导入依赖的package包/类
private List<String> getBodyText(Part part) throws MessagingException, IOException {
    Object c = part.getContent();
    if (c instanceof String) {
        return UtilMisc.toList((String) c);
    } else if (c instanceof Multipart) {
        List<String> textContent = new LinkedList<String>();
        int count = ((Multipart) c).getCount();
        for (int i = 0; i < count; i++) {
            BodyPart bp = ((Multipart) c).getBodyPart(i);
            textContent.addAll(this.getBodyText(bp));
        }
        return textContent;
    } else {
        return new LinkedList<String>();
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:17,代码来源:ServiceMcaCondition.java

示例13: saveAttachment

import javax.mail.Part; //导入依赖的package包/类
/** 
 * ���渽�� 
 * @param part �ʼ��ж��������е�����һ������� 
 * @param destDir  ��������Ŀ¼ 
 */ 
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException, 
        FileNotFoundException, IOException { 
    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); 
            //ijһ���ʼ���Ҳ�п������ɶ���ʼ�����ɵĸ����� 
            String disp = bodyPart.getDisposition(); 
            if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) { 
                InputStream is = bodyPart.getInputStream(); 
                saveFile(is, destDir, decodeText(bodyPart.getFileName())); 
            } else if (bodyPart.isMimeType("multipart/*")) { 
                saveAttachment(bodyPart,destDir); 
            } else { 
                String contentType = bodyPart.getContentType(); 
                if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) { 
                    saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName())); 
                } 
            } 
        } 
    } else if (part.isMimeType("message/rfc822")) { 
        saveAttachment((Part) part.getContent(),destDir); 
    } 
}
 
开发者ID:bjut-2014,项目名称:scada,代码行数:33,代码来源:MailUtils.java

示例14: getMailTextContent

import javax.mail.Part; //导入依赖的package包/类
/**
 * 获得邮件文本内容
 * @param part 邮件体
 * @param content 存储邮件文本内容的字符串
 * @throws MessagingException
 * @throws IOException
 */
public static 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:xiaomin0322,项目名称:alimama,代码行数:24,代码来源:POP3ReceiveMailTest.java

示例15: saveAttachment

import javax.mail.Part; //导入依赖的package包/类
/**
 * 保存附件
 * @param part 邮件中多个组合体中的其中一个组合体
 * @param destDir  附件保存目录
 * @throws UnsupportedEncodingException
 * @throws MessagingException
 * @throws FileNotFoundException
 * @throws IOException
 */
public static void saveAttachment(Part part, String destDir) throws UnsupportedEncodingException, MessagingException,
		FileNotFoundException, IOException {
	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);
			//某一个邮件体也有可能是由多个邮件体组成的复杂体
			String disp = bodyPart.getDisposition();
			if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
				InputStream is = bodyPart.getInputStream();
				saveFile(is, destDir, decodeText(bodyPart.getFileName()));
			} else if (bodyPart.isMimeType("multipart/*")) {
				saveAttachment(bodyPart,destDir);
			} else {
				String contentType = bodyPart.getContentType();
				if (contentType.indexOf("name") != -1 || contentType.indexOf("application") != -1) {
					saveFile(bodyPart.getInputStream(), destDir, decodeText(bodyPart.getFileName()));
				}
			}
		}
	} else if (part.isMimeType("message/rfc822")) {
		saveAttachment((Part) part.getContent(),destDir);
	}
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:37,代码来源:POP3ReceiveMailTest.java


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