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


Java Folder.getMessages方法代碼示例

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


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

示例1: getEmail

import javax.mail.Folder; //導入方法依賴的package包/類
public void getEmail() throws MessagingException, IOException {
    Session session = Session.getDefaultInstance(System.getProperties(),null);
    Store store = null;
    store = session.getStore("imaps");

    // store.connect(this.host, this.userName, this.password);

    // Get default folder
    Folder folder = store.getDefaultFolder();
    folder.getMessages();
    folder.getNewMessageCount();
    Message m = folder.getMessage(0);
    m.getMessageNumber();
    m.getAllRecipients();
    m.getReceivedDate();
    m.getFrom();
    m.getSubject();
    m.getReplyTo();
    m.getContent();
    m.getSize();

    // Get any folder by name
    Folder[] folderList = folder.list();
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:25,代碼來源:PNetwork.java

示例2: deleteMails

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * Connect to the mail server and delete all mails.
 */
public void deleteMails() throws MessagingException {
    Folder folder = getStore().getFolder(MAIL_INBOX);
    folder.open(Folder.READ_WRITE);

    // Get folder's list of messages.
    Message[] messages = folder.getMessages();

    // Retrieve message headers for each message in folder.
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    folder.fetch(messages, profile);

    for (Message message : messages) {
        message.setFlag(Flags.Flag.DELETED, true);
    }
    folder.close(true);

}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:22,代碼來源:MailReader.java

示例3: changeStatus

import javax.mail.Folder; //導入方法依賴的package包/類
public void changeStatus( String folderName, long mailIDs[], Flags.Flag newFlag, boolean value ){
  try{
  
    Folder folderToUse = mailStore.getFolder(folderName);
    folderToUse.open( Folder.READ_WRITE );
    
    Flags f = new Flags();
    f.add( newFlag );
	
	Message mlist[];
	if ( folderToUse instanceof UIDFolder )
		mlist = ((UIDFolder)folderToUse).getMessagesByUID( mailIDs );
	else
		mlist = folderToUse.getMessages( returnToInts(mailIDs) );
	
	for ( int x=0; x < mlist.length; x++ )
		mlist[x].setFlags( f, value );
    
    folderToUse.close( true );
	setData( "succeeded", 	cfBooleanData.TRUE );
  
  } catch (Exception E ){
	setData( "errortext", 	new cfStringData( E.getMessage() ) );
	setData( "succeeded", 	cfBooleanData.FALSE );
  }
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:27,代碼來源:cfImapConnection.java

示例4: getMessages

import javax.mail.Folder; //導入方法依賴的package包/類
protected Message[] getMessages(Folder folder, DeleteMailRequest request) throws MessagingException {

    if (request.getMails() != null) {
      LOGGER.debug("delete mails: {}", request.getMails());

      List<String> messageIds = collectMessageIds(request.getMails());
      return getMessagesByIds(folder, messageIds);

    } else if (request.getMessageIds() != null) {
      LOGGER.debug("delete mails with message ids: {}", request.getMessageIds());

      return getMessagesByIds(folder, request.getMessageIds());

    } else {
      LOGGER.debug("delete mails with message numbers: {}", request.getMessageNumbers());

      int[] numbers = request.getMessageNumbers().stream().mapToInt(i -> i).toArray();
      return folder.getMessages(numbers);
    }
  }
 
開發者ID:camunda,項目名稱:camunda-bpm-mail,代碼行數:21,代碼來源:DeleteMailConnector.java

示例5: deleteAllEmails

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * Delete all emails in the inbox.
 *
 * @param protocol protocol used to connect to the server
 * @throws MessagingException if we're unable to connect to the store
 */
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
    Folder inbox = null;
    Store store = getConnection(user, protocol);
    try {
        inbox = store.getFolder(EMAIL_INBOX);
        inbox.open(Folder.READ_WRITE);
        Message[] messages = inbox.getMessages();

        for (Message message : messages) {
            message.setFlag(Flags.Flag.DELETED, true);
            log.info("Deleted email Subject : " + message.getSubject());
        }
    } finally {
        if (inbox != null) {
            inbox.close(true);
        }
        if (store != null) {
            store.close();
        }
    }
}
 
開發者ID:wso2,項目名稱:product-ei,代碼行數:28,代碼來源:GreenMailServer.java

示例6: isMailReceived

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * Check whether email received by reading the emails.
 *
 * @param protocol to connect to the store
 * @param user whose mail store should be connected
 * @param subject the subject of the mail to search
 * @return
 * @throws MessagingException when unable to connect to the store
 */
public static boolean isMailReceived(String protocol, GreenMailUser user, String subject)
        throws MessagingException {
    Store store = getConnection(user, protocol);
    Folder folder = store.getFolder(EMAIL_INBOX);
    folder.open(Folder.READ_ONLY);
    boolean isReceived = false;
    Message[] messages = folder.getMessages();
    for (Message message : messages) {
        if (message.getSubject().contains(subject)) {
            log.info("Found the Email with Subject : " + subject);
            isReceived = true;
            break;
        }
    }
    return isReceived;
}
 
開發者ID:wso2,項目名稱:product-ei,代碼行數:26,代碼來源:GreenMailServer.java

示例7: testSendingAndReceiving

import javax.mail.Folder; //導入方法依賴的package包/類
@Test
public void testSendingAndReceiving() throws MessagingException {
	Session session = EmailUtils.getGMailSession(EmailUtils.user, EmailUtils.pass);
	String key = (new Long(System.currentTimeMillis())).toString();
	EmailUtils.postMail(session, EmailUtils.user, "test" + key, "testmsg" + key);
	Folder inbox = EmailUtils.openPop3InboxReadWrite(session);
	Folder trash = EmailUtils.openPop3TrashReadWrite(session);
	boolean emailReceived = false;
	for (Message m : inbox.getMessages()) {
		if (m.getSubject().startsWith("test" + key)) {
			emailReceived = true;
			Message[] m_array = inbox.getMessages(m.getMessageNumber(), m.getMessageNumber());
			// delete test mail
			inbox.copyMessages(m_array, trash);
			m.setFlag(Flags.Flag.DELETED, true);
		}
	}
	EmailUtils.closeFolder(inbox);
	EmailUtils.closeFolder(trash);
	assertTrue(emailReceived);
}
 
開發者ID:bptlab,項目名稱:Unicorn,代碼行數:22,代碼來源:EmailUtilTest.java

示例8: main

import javax.mail.Folder; //導入方法依賴的package包/類
public static void main(String[] args) throws MessagingException {

    String url = "https://outlook.office365.com/ews/exchange.asmx";
    Properties properties = new Properties();
    properties.setProperty("org.sourceforge.net.javamail4ews.util.Util.EnableServiceTrace", "true");
    Session session = Session.getInstance(properties);

    System.out.println("retrieving the store");
    //Get the EWS store implementation
    Store store = session.getStore("ewsstore");

    System.out.println("done");

    //Connect to the Exchange server - No port required.
    //Also connect() might be used if the session is initalized with the known mail.* properties
    System.out.println(String.format("connecting to %s", url));
    store.connect(url,
      "[email protected]",
      "p4ssw0rd");

    System.out.println(String.format("connected to %s", url));
    System.out.println(String.format("get default folder", url));
    Folder folder = store.getDefaultFolder();
    System.out.println(String.format("open default folder as read-only"));
    folder.open(Folder.READ_ONLY);
    System.out.println(String.format("done"));
    Message[] messages = folder.getMessages();
    System.out.println(String.format("there is %d messages", messages.length));

    System.out.println(messages[0].getFrom());
  }
 
開發者ID:gartcimore,項目名稱:javamail4ews,代碼行數:32,代碼來源:MailSample.java

示例9: checkInbox

import javax.mail.Folder; //導入方法依賴的package包/類
public void checkInbox(int mode) throws MessagingException, IOException {
	if (mode == 0) {
		return;
	}
	boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
	boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
	String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
	System.out.println(action + " INBOX for " + from);
	Store store = session.getStore();
	store.connect();
	Folder root = store.getDefaultFolder();
	Folder inbox = root.getFolder("inbox");
	inbox.open(Folder.READ_WRITE);
	Message[] msgs = inbox.getMessages();
	if (msgs.length == 0 && show) {
		System.out.println("No messages in inbox");
	}
	for (Message msg2 : msgs) {
		MimeMessage msg = (MimeMessage) msg2;
		if (show) {
			System.out.println("    From: " + msg.getFrom()[0]);
			System.out.println(" Subject: " + msg.getSubject());
			System.out.println(" Content: " + msg.getContent());
		}
		if (clear) {
			msg.setFlag(Flags.Flag.DELETED, true);
		}
	}
	inbox.close(true);
	store.close();
	System.out.println();
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:33,代碼來源:MailClient.java

示例10: checkInboxSave

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

示例11: _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

示例12: receive

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * �����ʼ�
 */ 
public static void receive() throws Exception { 
    // ׼�����ӷ������ĻỰ��Ϣ 
    Properties props = new Properties(); 
    props.setProperty("mail.store.protocol", "pop3");       // �� 
    props.setProperty("mail.pop3.port", "110");             // �˿� 
    props.setProperty("mail.pop3.host", "pop3.sina.com");    // pop3������ 
     
    // ����Sessionʵ������ 
    Session session = Session.getInstance(props); 
    Store store = session.getStore("pop3"); 
    store.connect("[email protected]", "mh899821671104"); 
     
    // ����ռ��� 
    Folder folder = store.getFolder("INBOX"); 
    /* Folder.READ_ONLY��ֻ��Ȩ��
     * Folder.READ_WRITE���ɶ���д�������޸��ʼ���״̬��
     */ 
    folder.open(Folder.READ_WRITE); //���ռ��� 
     
    // ����POP3Э���޷���֪�ʼ���״̬,����getUnreadMessageCount�õ������ռ�����ʼ����� 
    System.out.println("δ���ʼ���: " + folder.getUnreadMessageCount()); 
     
    // ����POP3Э���޷���֪�ʼ���״̬,��������õ��Ľ��ʼ�ն���Ϊ0 
    System.out.println("ɾ���ʼ���: " + folder.getDeletedMessageCount()); 
    System.out.println("���ʼ�: " + folder.getNewMessageCount()); 
     
    // ����ռ����е��ʼ����� 
    System.out.println("�ʼ�����: " + folder.getMessageCount()); 
     
    // �õ��ռ����е������ʼ�,������ 
    Message[] messages = folder.getMessages(); 
    parseMessage(messages); 
     
    //�ͷ���Դ 
    folder.close(true); 
    store.close(); 
}
 
開發者ID:bjut-2014,項目名稱:scada,代碼行數:41,代碼來源:MailUtils.java

示例13: main

import javax.mail.Folder; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

		Properties props = new Properties();

		String host = "pop.mailinator.com";
		String username = "x-test-m";
		String password = "mypwdxxx";
		String provider = "pop3";

		Session session = Session.getDefaultInstance(props, null);
		Store store = session.getStore(provider);
		store.connect(host, username, password);

		Folder inbox = store.getFolder("INBOX");
		if (inbox == null) {
			System.out.println("No INBOX");
			System.exit(1);
		}
		inbox.open(Folder.READ_ONLY);

		Message[] messages = inbox.getMessages();
		for (int i = 0; i < messages.length; i++) {
			System.out.println("Message " + (i + 1));
			messages[i].writeTo(System.out);
		}
		inbox.close(false);
		store.close();

	}
 
開發者ID:qmetry,項目名稱:qaf,代碼行數:30,代碼來源:MalinatorUtil.java

示例14: browseMessageFromFolder

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * 根據郵件夾對象瀏覽郵件
 * @param folder
 * @throws MessagingException 
 * @throws IOException 
 */
private Object browseMessageFromFolder(Folder folder) throws Exception {
	// TODO Auto-generated method stub
	folder.open(Folder.READ_ONLY);
	System.out.println("總共有"+folder.getMessageCount()+"封郵件");
	System.out.println("總共有"+folder.getUnreadMessageCount()+"封未讀郵件");
	Message[] messages=folder.getMessages();
	return call(messages);
	/*for (int i = 1; i <=messages.length; i++) {
		System.out.println("這是第"+i+"封郵件");
		//getMessageHeader(folder.getMessage(i));
		writeSubjectToOutPutStream(folder.getMessage(i));;
	}*/
	//folder.close(false);
}
 
開發者ID:xiaomin0322,項目名稱:alimama,代碼行數:21,代碼來源:SimpleSendReceiveMessage.java

示例15: receive

import javax.mail.Folder; //導入方法依賴的package包/類
/**
 * 接收郵件
 */
public static void receive() throws Exception {
	// 準備連接服務器的會話信息
	Properties props = new Properties();
	props.setProperty("mail.store.protocol", "pop3");		// 協議
	props.setProperty("mail.pop3.port", "995");				// 端口
	props.setProperty("mail.pop3.host", "pop3.live.com");	// pop3服務器
	
	// 創建Session實例對象
	Session session = Session.getInstance(props);
	Store store = session.getStore("pop3");
	store.connect("[email protected]", "Mo8yOU8u");
	
	// 獲得收件箱
	Folder folder = store.getFolder("INBOX");
	/* Folder.READ_ONLY:隻讀權限
	 * Folder.READ_WRITE:可讀可寫(可以修改郵件的狀態)
	 */
	folder.open(Folder.READ_WRITE);	//打開收件箱
	
	// 由於POP3協議無法獲知郵件的狀態,所以getUnreadMessageCount得到的是收件箱的郵件總數
	System.out.println("未讀郵件數: " + folder.getUnreadMessageCount());
	
	// 由於POP3協議無法獲知郵件的狀態,所以下麵得到的結果始終都是為0
	System.out.println("刪除郵件數: " + folder.getDeletedMessageCount());
	System.out.println("新郵件: " + folder.getNewMessageCount());
	
	// 獲得收件箱中的郵件總數
	System.out.println("郵件總數: " + folder.getMessageCount());
	
	// 得到收件箱中的所有郵件,並解析
	Message[] messages = folder.getMessages();
	parseMessage(messages);
	
	//釋放資源
	folder.close(true);
	store.close();
}
 
開發者ID:xiaomin0322,項目名稱:alimama,代碼行數:41,代碼來源:POP3ReceiveMailTest.java


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