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


Java Folder.getMessageCount方法代码示例

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


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

示例1: clear

import javax.mail.Folder; //导入方法依赖的package包/类
private static void clear(Folder folder) throws MessagingException {
	if(folder.exists() && (folder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
		int totMessages = folder.getMessageCount();
		System.out.println(totMessages + " messages from folder: " + folder.getFullName());
		folder.open(Folder.READ_WRITE);
		Message[] messages = folder.getMessages();
		for (int i = 0; i < messages.length; i++) {
			System.out.println("Deleting message: " + (i+1) + " of " + totMessages);
			messages[i].setFlag(Flags.Flag.DELETED, true);
		}
		folder.close(true);
	}
	Folder[] childs = folder.list();
	for (int i = 0; i < childs.length; i++) {
		clear(childs[i]);
	}
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:18,代码来源:MailListener.java

示例2: _getEmail

import javax.mail.Folder; //导入方法依赖的package包/类
public MessageWrapper _getEmail( String hostName, MessageFilter[] messageFilters, Map<String, String> propertyMap )
{
    Properties mailProps = new Properties();
    mailProps.putAll( propertyMap );

    List<Message> messageList = new ArrayList<Message>( 10 );
    MessageWrapper messageWrapper = null;

    try
    {
        Session emailSession = Session.getDefaultInstance( mailProps );
        Store store = emailSession.getStore( propertyMap.get( PROTOCOL ) );
        store.connect( hostName, propertyMap.get( USER_NAME ), propertyMap.get( PASSWORD ) );

        Folder emailFolder = store.getFolder( propertyMap.get( FOLDER_NAME ) != null ? propertyMap.get( FOLDER_NAME ) : DEFAULT_FOLDER_NAME );
        emailFolder.open( Folder.READ_WRITE );

        Message[] messages = emailFolder.getMessages();

        int messageCount = emailFolder.getMessageCount();
        if ( messageCount > MAX_MESSAGES )
            messageCount = MAX_MESSAGES;

        if ( log.isInfoEnabled() )
            log.info( "Processing " + messageCount + " messages" );

        for ( int i = 0; i < messageCount; i++ )
        {
            if ( applyFilters( messages[i], messageFilters ) )
            {
                messageList.add( messages[i] );
            }
        }

        if ( messageList.size() == 0 )
            throw new ScriptException( "Failed to find any email messages that met the criteria" );
            
        Collections.sort( messageList, new DateComparator() );

        String messageContent = null;
        String contentType = messageList.get( 0 ).getContentType();

        if ( contentType.startsWith( "text/" ) )
            messageContent = messageList.get( 0 ).getContent().toString();
        else if ( messageList.get( 0 ).isMimeType( "multipart/*" ) )
            messageContent = getTextFromMimeMultipart( (MimeMultipart) messageList.get( 0 ).getContent() );
        else
            messageContent = messageList.get( 0 ).getContent().getClass().getName();

        messageWrapper = new MessageWrapper( messageList.size(), messageList.get( 0 ).getFrom()[0].toString(), messageList.get( 0 ).getSubject(), messageContent, contentType );

        emailFolder.close( false );
        store.close();
    }
    catch ( Exception e )
    {
        e.printStackTrace();
        throw new ScriptException( "Failed to find email" );
    }

    return messageWrapper;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:63,代码来源:DefaultReceiveEmailProvider.java

示例3: retrieveViaImap

import javax.mail.Folder; //导入方法依赖的package包/类
private Message retrieveViaImap(String host, int port, String user,
		String password) throws MessagingException {
	Properties props = new Properties();
	props.setProperty("mail.store.protocol", "imap");
	props.setProperty("mail.imap.port", String.valueOf(port));
	Session session = Session.getInstance(props, null);
	Store store = session.getStore();
	store.connect(host, user, password);
	Folder inbox = store.getFolder("INBOX");
	inbox.open(Folder.READ_ONLY);
	int messageCount = inbox.getMessageCount();
	return messageCount == 0 ? null : inbox.getMessage(1);
}
 
开发者ID:Ardulink,项目名称:Ardulink-2,代码行数:14,代码来源:ArdulinkMailOnCamelIntegrationTest.java

示例4: getNextRowData

import javax.mail.Folder; //导入方法依赖的package包/类
@Override
protected Object getNextRowData(AdapterRowSet rows) throws AdapterException {
	try {
		Folder inbox = ((IMAPAdapter) getAdapter()).inbox;
		if (getRowNumberToRead() < inbox.getMessageCount()) {
			return inbox.getMessage(getRowNumberToRead()+1);
		} else {
			hasNoMoreRows();
			return null;
		}
	} catch (MessagingException e) {
		throw new AdapterException(e);
	}

}
 
开发者ID:SAP,项目名称:hana-native-adapters,代码行数:16,代码来源:TableLoaderInbox.java

示例5: receiveEmailPOPAndroid

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

示例6: receiveEmailIMAPAndroid

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

示例7: displayMessages

import javax.mail.Folder; //导入方法依赖的package包/类
/**
 * For debugging
 */
public void displayMessages() {

	try {
		Folder inbox = store.getFolder("INBOX");
		inbox.open(Folder.READ_WRITE);

		int count = inbox.getMessageCount();
		Message[] messages = inbox.getMessages(1, count);
		for (Message message : messages) {
			if (!message.getFlags().contains(Flags.Flag.SEEN)) {
				Address[] fromAddresses = message.getFrom();
				System.out.println("...................");
				System.out.println("\t From: " + fromAddresses[0].toString());
				System.out.println("\t To: " + parseAddresses(message.getRecipients(RecipientType.TO)));
				System.out.println("\t CC: " + parseAddresses(message.getRecipients(RecipientType.CC)));
				System.out.println("\t Subject: " + message.getSubject());
				System.out.println("\t Sent Date:" + message.getSentDate().toString());
				try {
					System.out.println(message.getContent().toString());
				} catch (Exception ex) {
					System.out.println("Error reading content!!");
					ex.printStackTrace();
				}
			}
		}

		inbox.close(false);
		store.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:mathieulegoc,项目名称:SmartTokens,代码行数:36,代码来源:MailBean.java

示例8: checkMessages

import javax.mail.Folder; //导入方法依赖的package包/类
protected void checkMessages(Store store, Session session) throws MessagingException {
    if (!store.isConnected()) {
        store.connect();
    }

    // open the default folder
    Folder folder = store.getDefaultFolder();
    if (!folder.exists()) {
        throw new MessagingException("No default (root) folder available");
    }

    // open the inbox
    folder = folder.getFolder(INBOX);
    if (!folder.exists()) {
        throw new MessagingException("No INBOX folder available");
    }

    // get the message count; stop if nothing to do
    folder.open(Folder.READ_WRITE);
    int totalMessages = folder.getMessageCount();
    if (totalMessages == 0) {
        folder.close(false);
        return;
    }

    // get all messages
    Message[] messages = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    profile.add(FetchProfile.Item.FLAGS);
    profile.add("X-Mailer");
    folder.fetch(messages, profile);

    // process each message
    for (Message message: messages) {
        // process each un-read message
        if (!message.isSet(Flags.Flag.SEEN)) {
            long messageSize = message.getSize();
            if (message instanceof MimeMessage && messageSize >= maxSize) {
                Debug.logWarning("Message from: " + message.getFrom()[0] + "not received, too big, size:" + messageSize + " cannot be more than " + maxSize + " bytes", module);

                // set the message as read so it doesn't continue to try to process; but don't delete it
                message.setFlag(Flags.Flag.SEEN, true);
            } else {
                this.processMessage(message, session);
                if (Debug.verboseOn()) Debug.logVerbose("Message from " + UtilMisc.toListArray(message.getFrom()) + " with subject [" + message.getSubject() + "]  has been processed." , module);
                message.setFlag(Flags.Flag.SEEN, true);
                if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is marked seen", module);

                // delete the message after processing
                if (deleteMail) {
                    if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is being deleted", module);
                    message.setFlag(Flags.Flag.DELETED, true);
                }
            }
        }
    }

    // expunge and close the folder
    folder.close(true);
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:62,代码来源:JavaMailContainer.java

示例9: listFolderMessages

import javax.mail.Folder; //导入方法依赖的package包/类
public cfQueryResultData listFolderMessages( cfImapConnection imapConnection, String rootFolder, int startRow, int totalMessages, boolean reverseOrder ) {
	cfQueryResultData query = new cfQueryResultData( new String[]{"subject","id","rxddate","sentdate","from","to","cc","bcc","size","lines","answered","deleted","draft","flagged","recent","seen"}, "CFIMAP" );

	try{
		Folder	folderToList;
		if ( rootFolder == null || rootFolder.length() == 0 )
			folderToList = imapConnection.mailStore.getDefaultFolder();
		else
			folderToList = imapConnection.mailStore.getFolder(rootFolder);
		
		if ( (folderToList.getType() & Folder.HOLDS_MESSAGES) != 0){
		
			if ( !folderToList.isOpen() )
				folderToList.open( Folder.READ_ONLY );
			
			Message[] messageArray;
			if ( startRow != -1 ){
				
				int folderCount = folderToList.getMessageCount();
				int start, end;
				if ( !reverseOrder ){
					start = startRow;
					if ( folderCount < (startRow+totalMessages-1) ){
						start = startRow;
						end = folderCount; 
					}else{
						end = startRow + totalMessages - 1;
					}
				}else{
					end = folderCount - startRow + 1;
					if ( folderCount < (startRow+totalMessages-1) ){ 
						start = 1;
					}else{
						start = folderCount - startRow - totalMessages + 2;
					}
					
				}
				
				messageArray = folderToList.getMessages( start, end );
				imapConnection.setTotalMessages( folderCount );
				
				
			}else{
				messageArray = folderToList.getMessages();
				imapConnection.setTotalMessages( messageArray.length );
			}

			// To improve performance, pre-fetch all of the message items
			// used by the CFIMAP list action. This will retrieve all of the
			// items for all of the messages with one single FETCH command.
			FetchProfile fp = new FetchProfile();
			fp.add(FetchProfile.Item.ENVELOPE);
			fp.add(FetchProfile.Item.FLAGS);
			fp.add(FetchProfile.Item.CONTENT_INFO);
			folderToList.fetch(messageArray, fp);
			List<Map<String, cfData>>	vectorMessages = new ArrayList<Map<String, cfData>>(messageArray.length);
			
			if ( reverseOrder ){
				int msgIndex = messageArray.length-1;
				for (int i = 0; i < messageArray.length; i++)
					vectorMessages.add( extractMessage( messageArray[msgIndex--] ) );
				
			}else{
				for (int i = 0; i < messageArray.length; i++)
					vectorMessages.add( extractMessage( messageArray[i] ) );
			}
			
			folderToList.close(false);
			query.populateQuery( vectorMessages );
		}

	}catch(Exception E){
		cfEngine.log( E.getMessage() );
		imapConnection.setStatus( false, E.getMessage() );
	}
	
	return query;
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:79,代码来源:cfMailFolderMessagesData.java

示例10: readMessages

import javax.mail.Folder; //导入方法依赖的package包/类
private void readMessages( cfSession _Session, Folder popFolder, cfQueryResultData popData, int _start, int _max, boolean GetAll, File attachmentDir )  throws cfmRunTimeException	{
  try{
  	int maxRows = _max;
  	int startRow = _start;
  	String messageNumber = getDynamic(_Session,"MESSAGENUMBER").getString();
  	boolean containsUID = containsAttribute( "UID" );
  	boolean usingMessageNumber = messageNumber.length() > 0;
  	int msgCount = popFolder.getMessageCount();
  	
  	// if MAXROWS is not specified, or UID or MESSAGENUMBER is, then we want to get all the messages
  	if ( _max == -1 || containsUID || usingMessageNumber ){
  		maxRows = msgCount;
  	}
  	if ( containsUID || usingMessageNumber ){
  		startRow = 1;
  	}
  	
  	if ( msgCount != 0 && startRow > msgCount ){
  		throw newRunTimeException( "The value of STARTROW must not be greater than the total number of messages in the folder, " + popFolder.getMessageCount() + "." );
  	}
  	
  	Message[] listOfMessages;
  	if ( !usingMessageNumber ){
  		listOfMessages = popFolder.getMessages();
  	}else{
  		listOfMessages = popFolder.getMessages( getMessageList( messageNumber ) );
  	}
  	
    FetchProfile fProfile = new FetchProfile();
    fProfile.add( FetchProfile.Item.ENVELOPE );
    fProfile.add(UIDFolder.FetchProfileItem.UID);
    popFolder.fetch( listOfMessages, fProfile );
    
    if ( containsUID ){
      String[] messageUIDList = getMessageUIDList( getDynamic(_Session,"UID").getString() );
    
      for ( int x=0; x < listOfMessages.length; x++ ){
        if ( messageUIDList.length == 0 || messageUIDValid( messageUIDList, getMessageUID( popFolder, listOfMessages[x] ) ) ){
          populateMessage( _Session, listOfMessages[x], popData, GetAll, attachmentDir, popFolder );
        }
      }
    }else{
			popFolder.fetch( listOfMessages, fProfile );
			int end = startRow -1 + maxRows;
			if ( end > listOfMessages.length ){
				end = listOfMessages.length;
			}
			for ( int x=startRow-1; x < end; x++ ){
				populateMessage( _Session, listOfMessages[x], popData, GetAll, attachmentDir, popFolder );
			}
    }
  }catch(Exception E){
    if ( E.getMessage() != null )
        throw newRunTimeException( E.getMessage() );
    else
  	  throw newRunTimeException( E.toString() );
  }

}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:60,代码来源:cfPOP3.java


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