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


Java BodyPart.isMimeType方法代码示例

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


在下文中一共展示了BodyPart.isMimeType方法的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: 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

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

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

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

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

示例7: saveAttachment

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

示例8: saveAttachment

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

示例9: getTextFromMimeMultipart

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

示例10: getTextFromMultiPartAlternative

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * Returns the text from multipart/alternative, the type of text returned follows the preference of the sending agent.
 */
private static String getTextFromMultiPartAlternative(Multipart multipart) throws IOException, MessagingException {
    // search in reverse order as a multipart/alternative should have their most preferred format last
    for (int i = multipart.getCount() - 1; i >= 0; i--) {
        BodyPart bodyPart = multipart.getBodyPart(i);

        if (bodyPart.isMimeType("text/html")) {
            return (String) bodyPart.getContent();
        } else if (bodyPart.isMimeType("text/plain")) {
            // Since we are looking in reverse order, if we did not encounter a text/html first we can return the plain
            // text because that is the best preferred format that we understand. If a text/html comes along later it
            // means the agent sending the email did not set the html text as preferable or did not set their preferred
            // order correctly, and in that case we do not handle that.
            return (String) bodyPart.getContent();
        } else if (bodyPart.isMimeType("multipart/*") || bodyPart.isMimeType("message/rfc822")) {
            String text = getTextFromPart(bodyPart);
            if (text != null) {
                return text;
            }
        }
    }
    // we do not know how to handle the text in the multipart or there is no text
    return null;
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:27,代码来源:EmailAccount.java

示例11: isMultipartValid

import javax.mail.BodyPart; //导入方法依赖的package包/类
private boolean isMultipartValid(Message message) throws MessagingException, IOException {
	boolean retvalue = false;
	Multipart multipart = (Multipart)message.getContent();
	int count = multipart.getCount();
	for(int i = 0; i < count; i++) {
		BodyPart part = multipart.getBodyPart(i);
		if(part.isMimeType("text/plain")) {
			retvalue = true;
		}
	}
	
	return retvalue;
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:14,代码来源:ArdulinkMailMessageCountListener.java

示例12: getContent

import javax.mail.BodyPart; //导入方法依赖的package包/类
private String getContent(Message message) throws IOException, MessagingException {

		String retvalue = "";
		
		Object msgContent = message.getContent();
		if(msgContent instanceof Multipart) {
			Multipart multipart = (Multipart)message.getContent();
			int count = multipart.getCount();
			for(int i = 0; i < count; i++) {
				BodyPart part = multipart.getBodyPart(i);
				if(part.isMimeType("text/plain")) {
					retvalue += "Part" + i + ": " + part.getContent().toString();
				}
			}
		} else {
			retvalue = msgContent.toString();
		}
		
		return retvalue;
	}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:21,代码来源:ArdulinkMailMessageCountListener.java

示例13: extractAttachmentFromOriginalMime

import javax.mail.BodyPart; //导入方法依赖的package包/类
private List<BodyPart> extractAttachmentFromOriginalMime(MimeMessage mimeMessage, int inviteId) throws MessagingException, IOException
{
  MimeMultipart mimeMultipart = (MimeMultipart)mimeMessage.getContent();
  MimeMessage subMimeMessage = (MimeMessage)mimeMultipart.getBodyPart(0).getContent();
  for (int n = 0; n < mimeMultipart.getCount(); ++n)
  {
    BodyPart part = mimeMultipart.getBodyPart(n);
    String[] headerInvId = part.getHeader("invId");
    if (headerInvId != null && headerInvId.length > 0 && headerInvId[0].equals(String.valueOf(inviteId)))
    {
      subMimeMessage = (MimeMessage) part.getContent();
    }
  }
  MimeMultipart subMultipart = (MimeMultipart)subMimeMessage.getContent();

  List<BodyPart> bodyPartList = new LinkedList<BodyPart>();
  for( int n=0; n < subMultipart.getCount(); ++n )
  {
    BodyPart bodyPart = subMultipart.getBodyPart(n);
    boolean isAttachment = false;

    String contentDispositions = bodyPart.getDisposition();
    if( contentDispositions != null && contentDispositions.equals(Part.ATTACHMENT) )
    {
      isAttachment = true;
    }

    if( bodyPart.isMimeType("application/*") || bodyPart.isMimeType("image/*") )
    {
      isAttachment = true;
    }

    if( isAttachment )
    {
      bodyPartList.add(bodyPart);
    }
  }
  return bodyPartList;
}
 
开发者ID:ZeXtras,项目名称:OpenZAL,代码行数:40,代码来源:CalendarMime.java

示例14: save

import javax.mail.BodyPart; //导入方法依赖的package包/类
private void save(Store store, String wheretobackup, String f) throws MessagingException, IOException {

	    System.out.println("opening folder " + f);
	    Folder folder = store.getFolder(f);
	    folder.open(Folder.READ_ONLY);

	    FileUtils.forceMkdir(new File(wheretobackup));

		// Get directory
		Message message[] = folder.getMessages();
		for (int i = 0, n = message.length; i < n; i++) {
			// String from = (message[i].getFrom()[0]).toString();
			String subj = (message[i].getSubject()).toString();
			String nota = (message[i].getContent()).toString();

			if (message[i].getContent() instanceof MimeMultipart) {

				MimeMultipart multipart = (MimeMultipart) message[i].getContent();

				for (int j = 0; j < multipart.getCount(); j++) {

					BodyPart bodyPart = multipart.getBodyPart(j);
						
						if (bodyPart.isMimeType("text/html")) {
							nota = bodyPart.getContent().toString();
							generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
							
						} else if (bodyPart.isMimeType("IMAGE/PNG")) {
							String imagecid = ((MimePart) bodyPart).getContentID();
							
							InputStream is = bodyPart.getInputStream();
						    FileUtils.forceMkdir(new File(wheretobackup + "/images/"));
							File fimg = new File(wheretobackup + "/images/" + bodyPart.getFileName());
							System.out.println("saving " + wheretobackup + "/images/" + bodyPart.getFileName());
					        FileOutputStream fos = new FileOutputStream(fimg);
					        byte[] buf = new byte[4096];
					        int bytesRead;
					        while((bytesRead = is.read(buf))!=-1) {
					            fos.write(buf, 0, bytesRead);
					        }
					        fos.close();
					        
					        
					        // devi fare il replace 0DA094B7-933A-4B19-947F-2FC42FA9DABD
							System.out.println("html replace file name : " + imagecid);							
							System.out.println("into file name : " + bodyPart .getFileName());							

						}
				}
			} else {
				generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota, message[i].getSentDate());
			}
		}
		folder.close(false);
	}
 
开发者ID:edoardoc,项目名称:iCloudNotes,代码行数:56,代码来源:NotesSaver.java

示例15: getText

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * Attempts to reteive the string portion of a message... tries to handle
 * multipart messages as well.  This seems to be working so far with my tests
 * but could use some tweaking later as more types of mail servers are used
 * with this feature.
 *
 * @param msg a {@link javax.mail.Message} object.
 * @return The text portion of an email with each line being an element of the list.
 * @throws javax.mail.MessagingException if any.
 * @throws java.io.IOException if any.
 */
public static List<String> getText(Message msg) throws MessagingException, IOException {
    
    Object content = null;
    String text = null;
    
    log().debug("getText: getting text of message from MimeType: text/*");

    try {
        text = (String)msg.getContent();

    } catch (ClassCastException cce) {
        content = msg.getContent();

        if (content instanceof MimeMultipart) {

            log().debug("getText: content is MimeMultipart, checking for text from each part...");

            for (int cnt = 0; cnt < ((MimeMultipart)content).getCount(); cnt++) {
                BodyPart bp = ((MimeMultipart)content).getBodyPart(cnt);
                if (bp.isMimeType("text/*")) {
                    text = (String)bp.getContent();
                    log().debug("getText: found text MIME type: "+text);
                    break;
                }
            }
            log().debug("getText: did not find text within MimeMultipart message.");
        }
    }
    return string2Lines(text);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:42,代码来源:JavaReadMailer.java


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