當前位置: 首頁>>代碼示例>>Java>>正文


Java Multipart.getCount方法代碼示例

本文整理匯總了Java中javax.mail.Multipart.getCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Multipart.getCount方法的具體用法?Java Multipart.getCount怎麽用?Java Multipart.getCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.Multipart的用法示例。


在下文中一共展示了Multipart.getCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMessageContent

import javax.mail.Multipart; //導入方法依賴的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.Multipart; //導入方法依賴的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.Multipart; //導入方法依賴的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.Multipart; //導入方法依賴的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.Multipart; //導入方法依賴的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: handleAttachments

import javax.mail.Multipart; //導入方法依賴的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: getMailTextContent

import javax.mail.Multipart; //導入方法依賴的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

示例8: buildMultipartAlternativeMail

import javax.mail.Multipart; //導入方法依賴的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

示例9: getAttachments

import javax.mail.Multipart; //導入方法依賴的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

示例10: processMessageContent

import javax.mail.Multipart; //導入方法依賴的package包/類
protected static void processMessageContent(Message message, Mail mail) throws MessagingException, IOException {

    if (isMultipartMessage(message)) {
      Multipart multipart = (Multipart) message.getContent();

      int numberOfParts = multipart.getCount();
      for (int partCount = 0; partCount < numberOfParts; partCount++) {
        BodyPart bodyPart = multipart.getBodyPart(partCount);

        processMessagePartContent(bodyPart, mail);
      }

    } else {
      processMessagePartContent(message, mail);
    }
  }
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:17,代碼來源:Mail.java

示例11: saveAttachment

import javax.mail.Multipart; //導入方法依賴的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

示例12: getMailTextContent

import javax.mail.Multipart; //導入方法依賴的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

示例13: saveAttachment

import javax.mail.Multipart; //導入方法依賴的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

示例14: parseHtml

import javax.mail.Multipart; //導入方法依賴的package包/類
private String parseHtml(BodyPart body) throws Exception {
  //System.err.println(body.getContentType());
  if(body.getContentType().startsWith("text/html")) {
    Object content = body.getContent();
    return content == null ? null : content.toString();
  } else if(body.getContentType().startsWith("multipart")) {
    Multipart subpart = (Multipart) body.getContent();
    for(int j = 0; j < subpart.getCount(); j++) {
      BodyPart subbody = subpart.getBodyPart(j);
      String html = parseHtml(subbody);
      if(html != null) {
        return html;
      }
    }
  }
  return null;
}
 
開發者ID:xsocket,項目名稱:job,代碼行數:18,代碼來源:Job51ResumeParser.java

示例15: checkInboxSave

import javax.mail.Multipart; //導入方法依賴的package包/類
public void checkInboxSave(int mode) throws MessagingException, IOException {
	
	Store store = session.getStore();
	store.connect();
	Folder root = store.getDefaultFolder();
	Folder inbox = root.getFolder("inbox");
	inbox.open(Folder.READ_WRITE);
	Message[] msgs = inbox.getMessages();
	
	for (Message msg2 : msgs) {
		
		POP3Message msg = (POP3Message) msg2;
		
		Object object = msg.getContent();
		if (object instanceof Multipart) {
			Multipart multipart = (Multipart) object;
			
			for (int i = 0, n = multipart.getCount(); i < n; i++) {
				MailClient.handlePart(multipart.getBodyPart(i));
			}
			
		}
		
		System.out.println("    From: " + msg.getFrom()[0]);
		System.out.println(" Subject: " + msg.getSubject());
		System.out.println(" Content: " + object);
	}
	inbox.close(true);
	store.close();
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:31,代碼來源:MailClient.java


注:本文中的javax.mail.Multipart.getCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。