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


Java BodyPart.getDataHandler方法代码示例

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


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

示例1: receiveEmailPOPAndroid

import javax.mail.BodyPart; //导入方法依赖的package包/类
public static void receiveEmailPOPAndroid(MailProfile mailprofile, String folder, int offset, int limit) throws Exception{
	Properties props = new Properties();
       props.setProperty("mail.store.protocol", "pop3");
       props.put("mail.pop3.port", mailprofile.getPop3Port());   
        props.setProperty("mail.pop3.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.pop3.socketFactory.fallback",
				"false");
        props.setProperty("mail.pop3.port", "" + mailprofile.getPop3Port());
        props.setProperty("mail.pop3.socketFactory.port", ""
				+ mailprofile.getPop3Port());
        
           Session session = Session.getInstance(props, null);
           Store store = session.getStore();
           store.connect(mailprofile.getPop3Host(), mailprofile.getEmail(), mailprofile.getPassword());
           Folder inbox = store.getFolder(folder);
           inbox.open(Folder.READ_ONLY); 
           if(limit > inbox.getMessageCount()) limit = inbox.getMessageCount()-1;
           javax.mail.Message[] msg = inbox.getMessages(inbox.getMessageCount()-offset-limit, inbox.getMessageCount()-offset);
           String content = null;
           javax.mail.Message m;
           try{
            for(int i=msg.length-1; i >= 0; i--){
            	m = msg[i];
            	 Object msgContent = m.getContent();                   
            	     if (msgContent instanceof Multipart) {
            	         Multipart multipart = (Multipart) msgContent;
            	         for (int j = 0; j < multipart.getCount(); j++) {
            	         BodyPart bodyPart = multipart.getBodyPart(j);
            	         String disposition = bodyPart.getDisposition();
            	         if (disposition != null && (disposition.equalsIgnoreCase("ATTACHMENT"))) { 
            	              DataHandler handler = bodyPart.getDataHandler();                 
            	          }
            	          else { 
            	        	  if(bodyPart instanceof IMAPBodyPart){
	            	                 content = ((IMAPBodyPart)bodyPart).getContent().toString();  // the changed code 
	            	                 if(((IMAPBodyPart)bodyPart).getContent() instanceof MimeMultipart){
	            	                	 Multipart multi2 = (Multipart) ((IMAPBodyPart)bodyPart).getContent();
	            	                	 for (int k = 0; k < multi2.getCount(); k++) 
	            	                		 content =multi2.getBodyPart(k).getContent().toString();
	            	        		}
	            	        	}    
            	            }
            	        }
            	     }
            	     else                
            	         content= m.getContent().toString();
            	
            		if(m.getContentType().startsWith("com.sun.mail.util.BASE64DecoderStream"))
            			content = ((BASE64DecoderStream) m.getContent()).toString();
	            	mailprofile.addReceivedMessage(
	            			new Email(
	            					MimeUtility.decodeText(m.getFrom()[0].toString()), 
	            					MimeUtility.decodeText(m.getAllRecipients()[0].toString()), 
	            					MimeUtility.decodeText(m.getSubject()), m.getReceivedDate(), 
	            					content, 
	            					new ArrayList<File>()
	            			)
	            	);
            }
           } catch(Exception e){}
           finally{
           	if(inbox != null)
           		inbox.close(true);
           	if(store != null)
           		store.close();
           }
   
}
 
开发者ID:manuelsc,项目名称:Raven-Messenger,代码行数:70,代码来源:MailControlAndroid.java

示例2: receiveEmailIMAPAndroid

import javax.mail.BodyPart; //导入方法依赖的package包/类
public static void receiveEmailIMAPAndroid(MailProfile mailprofile, String folder, int offset, int limit) throws Exception{
	Properties props = new Properties();
       props.setProperty("mail.store.protocol", "imaps");
       props.put("mail.imap.port", mailprofile.getImapPort());   
       	props.setProperty("mail.imap.socketFactory.class",
  					"javax.net.ssl.SSLSocketFactory");
  	        props.setProperty("mail.imap.socketFactory.fallback",
  					"false");
  	        props.setProperty("mail.imap.port", "" + mailprofile.getImapPort());
  	        props.setProperty("mail.imap.socketFactory.port", ""
  					+ mailprofile.getImapPort());

           Session session = Session.getInstance(props, null);
           Store store = session.getStore();
           store.connect(mailprofile.getImapHost(), mailprofile.getEmail(), mailprofile.getPassword());
           Folder inbox = store.getFolder(folder);
           inbox.open(Folder.READ_ONLY); 
           if(limit > inbox.getMessageCount()) limit = inbox.getMessageCount()-1;
           javax.mail.Message[] msg = inbox.getMessages(inbox.getMessageCount()-offset-limit, inbox.getMessageCount()-offset);
           String content;
           javax.mail.Message m;
           try{
            for(int i=msg.length-1; i >= 0; i--){
            	m = msg[i];
            		content = m.getContent().toString();           		
            		 Object msgContent = m.getContent();
                  
            	     if (msgContent instanceof Multipart) {
            	         Multipart multipart = (Multipart) msgContent;
            	         for (int j = 0; j < multipart.getCount(); j++) {
            	         BodyPart bodyPart = multipart.getBodyPart(j);
            	         String disposition = bodyPart.getDisposition();
            	         if (disposition != null && (disposition.equalsIgnoreCase("ATTACHMENT"))) { 
            	             DataHandler handler = bodyPart.getDataHandler();                    
            	          }
            	          else { 
            	        	if(bodyPart instanceof IMAPBodyPart){
            	                 content = ((IMAPBodyPart)bodyPart).getContent().toString();  // the changed code 
            	                 if(((IMAPBodyPart)bodyPart).getContent() instanceof MimeMultipart){
            	                	 Multipart multi2 = (Multipart) ((IMAPBodyPart)bodyPart).getContent();
            	                	 for (int k = 0; k < multi2.getCount(); k++) 
            	                		 content =multi2.getBodyPart(k).getContent().toString();
            	        		}
            	        	}
            	        	
            	            }
            	        }
            	     }
            	    
            	     else                
            	         content= m.getContent().toString();
            		if(content.startsWith("com.sun.mail.util.BASE64DecoderStream")){
            			
            		}
	            	mailprofile.addReceivedMessage(
	            			new Email(
	            					MimeUtility.decodeText(m.getFrom()[0].toString()), 
	            					MimeUtility.decodeText(m.getAllRecipients()[0].toString()), 
	            					MimeUtility.decodeText(m.getSubject()), m.getReceivedDate(), 
	            					content, 
	            					new ArrayList<File>()
	            			)
	            	);
           
            } 
           } catch(Exception e){e.printStackTrace();} 
           finally{
           	if(inbox != null)
           		inbox.close(true);
           	if(store != null)
           		store.close();
           	
           	
           }
   
}
 
开发者ID:manuelsc,项目名称:Raven-Messenger,代码行数:77,代码来源:MailControlAndroid.java

示例3: extractDatiCertXML

import javax.mail.BodyPart; //导入方法依赖的package包/类
private Document extractDatiCertXML(final SMIMESignedParser s)
		throws Exception {
	final MimeBodyPart mimePart = s.getContent();
	final DataHandler data = mimePart.getDataHandler();

	final MimeMultipart multiPart = (MimeMultipart) data.getContent();

	if (multiPart.getCount() < 1) {
		throw new MessagingException("Missing attachments");
	}
	final BodyPart bodyCert = multiPart.getBodyPart(1);

	final DataHandler dataCert = bodyCert.getDataHandler();

	final DataSource dataSourceCert = dataCert.getDataSource();


	final InputStream idataCert = dataSourceCert.getInputStream();

	final DocumentBuilderFactory builderFactory = DocumentBuilderFactory
			.newInstance();

	final DocumentBuilder parser = builderFactory.newDocumentBuilder();
	final InputSource source = new InputSource(idataCert);
	final Document domCert = parser.parse(source);
	return domCert;
}
 
开发者ID:tornabene,项目名称:jopenpec,代码行数:28,代码来源:PECVerifier.java


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